x86_64: sysupgrade: consider hdX and vdX devices as well
[openwrt/openwrt.git] / target / linux / x86_64 / base-files / lib / preinit / 79_move_config
1 #!/bin/sh
2 # Copyright (C) 2012-2014 OpenWrt.org
3
4 move_config() {
5 local cmdline uuid disk dev
6
7 if read cmdline < /proc/cmdline; then
8 case "$cmdline" in
9 *block2mtd=*)
10 disk="${cmdline##*block2mtd=}"
11 disk="${disk%%,*}"
12 ;;
13 *root=*)
14 disk="${cmdline##*root=}"
15 disk="${disk%% *}"
16 ;;
17 esac
18
19 case "$disk" in
20 PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-02)
21 uuid="${cmdline#PARTUUID=}"
22 uuid="${uuid%-02}"
23 for disk in /dev/[hsv]d[a-z]; do
24 set -- $(dd if=$disk bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "')
25 if [ "$4$3$2$1" = "$uuid" ]; then
26 dev="${disk}1"
27 break
28 fi
29 done
30 ;;
31 /dev/*)
32 dev="${disk%[0-9]}1"
33 ;;
34 esac
35 fi
36
37 if [ -n "$dev" ]; then
38 mount -t ext4 -o rw,noatime "$dev" /mnt
39 mv -f /mnt/sysupgrade.tgz /
40 umount /mnt
41 fi
42 }
43
44 boot_hook_add preinit_mount_root move_config
45