-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathinitramfs-init.patch
More file actions
115 lines (110 loc) · 4.47 KB
/
initramfs-init.patch
File metadata and controls
115 lines (110 loc) · 4.47 KB
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
--- a/usr/share/mkinitfs/initramfs-init
+++ b/usr/share/mkinitfs/initramfs-init
@@ -1,7 +1,7 @@
#!/bin/sh
# this is the init script version
-VERSION=3.8.1
+VERSION=3.8.1-EVE
SINGLEMODE=no
sysroot="$ROOT"/sysroot
splashfile=/.splash.ctrl
@@ -375,7 +375,7 @@ myopts="alpine_dev autodetect autoraid chart cryptroot cryptdm cryptheader crypt
cryptdiscards cryptkey debug_init dma init init_args keep_apk_new modules ovl_dev
pkgs quiet root_size root usbdelay ip alpine_repo apkovl alpine_start splash
blacklist overlaytmpfs overlaytmpfsflags rootfstype rootflags nbd resume s390x_net
- dasd ssh_key BOOTIF zfcp uevent_buf_size"
+ dasd ssh_key BOOTIF zfcp uevent_buf_size find_boot"
for opt; do
case "$opt" in
@@ -533,13 +533,64 @@ fi
# zpool reports /dev/zfs missing if it can't read /etc/mtab
ln -s /proc/mounts "$ROOT"/etc/mtab
+# let's see if we were told to identify a boot partition
+if [ -n "$KOPT_find_boot" ]; then
+ # locate boot media and mount it
+ # NOTE that we may require up to 3 tries with
+ # 30 seconds pauses between them to accomodate
+ # really slow controllers (such as bad USB sticks)
+ for i in 0 1 2; do
+ ebegin "Attempt $i to find and mount boot media"
+ MEDIA_ID=$(grep -l "$KOPT_find_boot" /media/*/boot/.uuid 2>/dev/null)
+ if [ -n "$MEDIA_ID" ]; then
+ mkdir -p /media/boot
+ $MOCK mount --bind "/media/$(echo "$MEDIA_ID" | cut -f3 -d/)" /media/boot
+ break
+ fi
+ sleep $(( i * 30 ))
+ $MOCK nlplug-findfs $cryptopts -p /sbin/mdev ${KOPT_debug_init:+-d} \
+ ${KOPT_usbdelay:+-t $(( $KOPT_usbdelay * 1000 ))} \
+ ${KOPT_uevent_buf_size:+-U $KOPT_uevent_buf_size} \
+ -n -b $repofile -a /tmp/apkovls
+ eend $?
+ done
+
+ # if we didn't find anything, but were asked to -- treat it
+ # as an error condition (it maybe transient, but it needs to
+ # be corrected
+ if [ -z "$MEDIA_ID" ]; then
+ echo "Failed to identify boot media. Try to re-run nlplug-findfs manually to see what's wrong:"
+ echo " nlplug-findfs -p /sbin/mdev -d -t 30000 -n -n -b $repofile -a /tmp/apkovls"
+ echo "once you find boot device, run:"
+ echo " mount --bind /media/XXX /media/boot"
+ echo "and then exit the shell."
+ sh
+ fi
+fi
+
# check if root=... was set
if [ -n "$KOPT_root" ]; then
# run nlplug-findfs before SINGLEMODE so we load keyboard drivers
ebegin "Mounting root"
- $MOCK nlplug-findfs $cryptopts -p /sbin/mdev ${KOPT_debug_init:+-d} \
- ${KOPT_uevent_buf_size:+-U $KOPT_uevent_buf_size} \
- $KOPT_root
+ if [ -f "$KOPT_root" ]; then
+ LOOP_IMG=$(realpath "$KOPT_root")
+ # workingaround linux kernel's desire to lump the entire
+ # set of initrd images into /initrd.image
+ if [ "$LOOP_IMG" = /initrd.image ]; then
+ OFFSET=$(LANG=C grep -obUaP hsqs /initrd.image|cut -f1 -d:|head -1)
+ if [ -n "$OFFSET" ]; then
+ LOSETUP_EXTRA_OPTS="-o$OFFSET"
+ fi
+ fi
+
+ KOPT_root=$(losetup -f)
+ losetup $LOSETUP_EXTRA_OPTS -r -f "$LOOP_IMG"
+ else
+ $MOCK nlplug-findfs $cryptopts -p /sbin/mdev ${KOPT_debug_init:+-d} \
+ ${KOPT_uevent_buf_size:+-U $KOPT_uevent_buf_size} \
+ $KOPT_root
+ fi
+
if [ "$SINGLEMODE" = "yes" ]; then
echo "Entering single mode. Type 'exit' to continue booting."
@@ -573,13 +624,15 @@ if [ -n "$KOPT_root" ]; then
$MOCK mount ${KOPT_rootfstype:+-t $KOPT_rootfstype} -o $rootflags \
$KOPT_root /media/root-ro
# Mount writable overlay tmpfs
- overlaytmpfsflags="mode=0755,${KOPT_overlaytmpfsflags:+$KOPT_overlaytmpfsflags,}rw"
- $MOCK mount -t tmpfs -o $overlaytmpfsflags root-tmpfs /media/root-rw
+ # overlaytmpfsflags="mode=0755,${KOPT_overlaytmpfsflags:+$KOPT_overlaytmpfsflags,}rw"
+ # $MOCK mount -t tmpfs -o $overlaytmpfsflags root-tmpfs /media/root-rw
# Create additional mountpoints and do the overlay mount
mkdir -p /media/root-rw/work /media/root-rw/root
$MOCK mount -t overlay -o \
lowerdir=/media/root-ro,upperdir=/media/root-rw/root,workdir=/media/root-rw/work \
overlayfs $sysroot
+ # this protects /media/root-rw from being destroyed by switch_root
+ $MOCK mount -t proc proc /media/root-rw
else
if [ "$rootfstype" = "zfs" ]; then
prepare_zfs_root
@@ -590,7 +643,7 @@ if [ -n "$KOPT_root" ]; then
fi
eend $?
- cat "$ROOT"/proc/mounts 2>/dev/null | while read DEV DIR TYPE OPTS ; do
+ grep -vE '^(proc|sysfs|devtmpfs|devpts|shm) ' /proc/mounts | while read DEV DIR TYPE OPTS ; do
if [ "$DIR" != "/" -a "$DIR" != "$sysroot" -a -d "$DIR" ]; then
mkdir -p $sysroot/$DIR
$MOCK mount -o move $DIR $sysroot/$DIR