blob: 8286f698957b08f76d6cf041106a26b52305958b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/busybox sh
die() {
echo ""
echo "Shit broke! Panic shell!"
echo ""
/busybox --install -s
exec /bin/sh
}
info() {
echo -n "-|-" ${@} "... "
}
isok() {
if [[ $1 -eq 0 ]]; then
echo "[ OK ]"
else
echo "[ FUCK ]"
die
fi
}
info "disabling console blanking, hopefully"
echo -e '\033[9;0]\033[14;0]' > /dev/console
info "waiting for usb devices to settle"
echo ""
for i in 10 9 8 7 6 5 4 3 2 1 0; do
echo -en ${i}'\r'
/busybox sleep 1
done
echo ""
isok 0
info "mounting devtmpfs"
/busybox mount -n -t devtmpfs devtmpfs ./dev
isok $?
info "mounting proc"
/busybox mount -n -t proc proc ./proc
isok $?
# rootfs_location_uuid=f822d881-d88a-4200-a9cf-6986c5a3e69a
info "looking for device with rootfs"
for var in $(cat /proc/cmdline); do
if [[ ${var/=*} = rootfs_location_uuid ]]; then
uuid="${var/*=}"
fi
done
device=$(findfs UUID=${uuid})
isok $?
# rootfs_filename=rootfs.tar.xz
info "getting rootfs filename"
for var in $(cat /proc/cmdline); do
if [[ ${var/=*} = rootfs_filename ]]; then
filename="${var/*=}"
fi
done
if [[ -z ${filename} ]]; then
info "going with default: rootfs.tar.xz"
filename="rootfs.tar.xz"
fi
isok 0
info "getting root tmpfs size"
for var in $(cat /proc/cmdline); do
if [[ ${var/=*} = rootfs_size ]]; then
size=${var/*=}
fi
done
if [[ -z ${size} ]]; then
info "going with default: 4G"
size="4G"
fi
isok 0
info "trying to mount ${device}"
/busybox mount -n -o ro ${device} /mnt
isok $?
info "trying to mount root tmpfs"
/busybox mount -n -o size=${size} -t tmpfs roottmpfs /roottmpfs
isok $?
info "checking if ${filename} exists"
[[ -e /mnt/${filename} ]]
isok $?
info "unpacking; will take some time"
/pv /mnt/${filename} | /busybox tar -C /roottmpfs -xJf -
info "unmounting rootfs package location"
/busybox umount -n /mnt
isok $?
info "unmounting /dev"
/busybox umount -n /dev
isok $?
info "unmounting /proc"
/busybox umount -n /proc
isok $?
info "trying to switch root"
exec /busybox switch_root /roottmpfs /sbin/init
echo ""
echo "we should not reach this place! here be dragons!"
echo ""
die
|