Lines 5-20
Link Here
|
5 |
|
5 |
|
6 |
newns "$@" |
6 |
newns "$@" |
7 |
require_tmpdir |
7 |
require_tmpdir |
|
|
8 |
ERR="n" |
9 |
|
10 |
tmpmnt=/var/lib/os-prober/mount |
11 |
if [ ! -d "$tmpmnt" ]; then |
12 |
mkdir "$tmpmnt" |
13 |
fi |
14 |
|
15 |
mounted= |
16 |
bootmnt= |
17 |
bootsv= |
18 |
bootuuid= |
8 |
|
19 |
|
9 |
grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true |
20 |
grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true |
10 |
|
21 |
|
11 |
partition="$1" |
22 |
if [ -z "$1" ]; then |
|
|
23 |
ERR=y |
24 |
elif [ "$1" = btrfs -a -z "$2" ]; then |
25 |
ERR=y |
26 |
elif [ "$1" = btrfs -a -z "$3" ]; then |
27 |
ERR=y |
28 |
elif [ "$1" = btrfs ]; then |
29 |
type=btrfs |
30 |
echo "$2" | grep -q "^UUID=" || ERR=y |
31 |
echo "$3" | grep -q "^subvol=" || ERR=y |
32 |
export "$2" |
33 |
export "$3" |
34 |
partition=$(blkid | grep "$UUID" | cut -d ':' -f 1 | tr '\n' ' ' | cut -d ' ' -f 1) |
35 |
debug "btrfs: partition=$partition, UUID=$UUID, subvol=$subvol" |
36 |
else |
37 |
partition="$1" |
38 |
type=other |
39 |
fi |
12 |
|
40 |
|
13 |
if [ -z "$partition" ]; then |
41 |
if [ "x$ERR" != xn ]; then |
14 |
echo "usage: linux-boot-prober partition" >&2 |
42 |
echo "usage: linux-boot-prober partition" >&2 |
|
|
43 |
echo " linux-boot-prober btrfs UUID=<> subvol=<>" >&2 |
15 |
exit 1 |
44 |
exit 1 |
16 |
fi |
45 |
fi |
17 |
|
46 |
|
|
|
47 |
if [ "$type" = btrfs ]; then |
48 |
# handle all of the btrfs stuff here |
49 |
if [ ! -e "/proc/self/mountinfo" ]; then |
50 |
warn "/proc/self/mountinfo does not exist, exiting" |
51 |
umount "$tmpmnt" 2>/dev/null |
52 |
rmdir "$tmpmnt" 2>/dev/null |
53 |
exit 1 |
54 |
fi |
55 |
mpoint=$(grep "btrfs" /proc/self/mountinfo | grep " /$subvol " | grep " $partition " | cut -d ' ' -f 5) |
56 |
if [ "$mpoint" = "/" ]; then |
57 |
warn "specifying active root not valid, exiting" |
58 |
umount "$tmpmnt" 2>/dev/null |
59 |
rmdir "$tmpmnt" 2>/dev/null |
60 |
exit 1 |
61 |
fi |
62 |
if [ "$mpoint" = "$tmpmnt" ]; then |
63 |
warn "btrfs subvol=$subvool, UUID=$UUID, already mounted on $tmpmnt **ERROR**" |
64 |
umount "$tmpmnt" 2>/dev/null |
65 |
rmdir "$tmpmnt" 2>/dev/null |
66 |
exit 1 |
67 |
fi |
68 |
if [ -z "$mpoint" ]; then |
69 |
# mount the btrfs root |
70 |
|
71 |
if [ -n "$subvol" ]; then |
72 |
opts="-o subvol=$subvol" |
73 |
fi |
74 |
|
75 |
if ! mount $opts -t btrfs -U $UUID "$tmpmnt" 2>/dev/null; then |
76 |
warn "error mounting btrfs subvol=$subvol UUID=$UUID" |
77 |
umount "$tmpmnt/boot" 2>/dev/null |
78 |
umount "$tmpmnt" 2>/dev/null |
79 |
rmdir "$tmpmnt" 2>/dev/null |
80 |
exit 1 |
81 |
fi |
82 |
else |
83 |
# bind-mount |
84 |
if ! mount -o bind "$mpoint" "$tmpmnt" 2>/dev/null; then |
85 |
warn "error mounting btrfs bindfrom=$mpoint subvol=$subvol UUID=$UUID" |
86 |
umount "$tmpmnt/boot" 2>/dev/null |
87 |
umount "$tmpmnt" 2>/dev/null |
88 |
rmdir "$tmpmnt" 2>/dev/null |
89 |
exit 1 |
90 |
fi |
91 |
fi |
92 |
debug "mounted btrfs $partition, subvol=$subvol on $tmpmnt" |
93 |
if [ ! -e "$tmpmnt/etc/fstab" ]; then |
94 |
warn "btrfs subvol=$subvol not root" |
95 |
umount "$tmpmnt" 2>/dev/null |
96 |
rmdir "$tmpmnt" 2>/dev/null |
97 |
exit 1 |
98 |
fi |
99 |
bootmnt=$(parsefstab < "$tmpmnt/etc/fstab" | grep " /boot ") || true |
100 |
if [ -z "$bootmnt" ]; then |
101 |
# /boot is part of the root |
102 |
bootpart="$partition" |
103 |
bootsv="$subvol" |
104 |
elif echo "$bootmnt" | cut -d ' ' -f 3 | grep -q "btrfs"; then |
105 |
# separate btrfs /boot subvolume |
106 |
bootsv=$(echo "$bootmnt" | cut -d ' ' -f 4 | grep "^subvol=" | sed "s/subvol=//" ) |
107 |
bootuuid=$(echo "$bootmnt" | cut -d ' ' -f 1 | grep "^UUID=" | sed "s/UUID=//" ) |
108 |
debug "mounting btrfs $tmpmnt/boot UUID=$bootuuid subvol=$bootsv" |
109 |
bindfrom=$(check_btrfs_mounted $bootsv $bootuuid) |
110 |
if [ -n "$bindfrom" ]; then |
111 |
# already mounted some place |
112 |
if ! mount -o bind $bindfrom "$tmpmnt/boot" 2>/dev/null; then |
113 |
warn "error bind mounting btrfs boot subvol=$bootsv, from=$bindfrom" |
114 |
umount "$tmpmnt/boot" 2>/dev/null |
115 |
umount "$tmpmnt" 2>/dev/null |
116 |
rmdir "$tmpmnt" 2>/dev/null |
117 |
exit 1 |
118 |
fi |
119 |
elif ! mount -o subvol=$bootsv -t btrfs -U $bootuuid "$tmpmnt/boot" 2>/dev/null; then |
120 |
warn "error mounting btrfs boot partition subvol=$bootsv, UUID=$bootuuid" |
121 |
umount "$tmpmnt/boot" 2>/dev/null |
122 |
umount "$tmpmnt" 2>/dev/null |
123 |
rmdir "$tmpmnt" 2>/dev/null |
124 |
exit 1 |
125 |
fi |
126 |
bootpart=$(grep " btrfs " /proc/self/mountinfo | grep " /$bootsv " | cut -d ' ' -f 10) |
127 |
else |
128 |
# non-btrfs partition or logical volume |
129 |
linux_mount_boot $partition $tmpmnt |
130 |
bootpart="${mountboot%% *}" |
131 |
bootsv= |
132 |
fi |
133 |
|
134 |
test="/usr/lib/linux-boot-probes/mounted/40grub2" |
135 |
if [ -f $test ] && [ -x $test ]; then |
136 |
debug "running $test $partition $bootpart $tmpmnt $type $subvol $bootsv" |
137 |
if $test "$partition" "$bootpart" "$tmpmnt" "$type" "$subvol" "$bootsv"; then |
138 |
debug "$test succeeded" |
139 |
fi |
140 |
fi |
141 |
umount "$tmpmnt/boot" 2>/dev/null || true |
142 |
if ! umount "$tmpmnt" 2>/dev/null; then |
143 |
warn "problem umount $tmpmnt" |
144 |
fi |
145 |
rmdir "$tmpmnt" 2>/dev/null || true |
146 |
|
147 |
exit 0 |
148 |
fi |
149 |
|
18 |
if ! mapped="$(mapdevfs "$partition")"; then |
150 |
if ! mapped="$(mapdevfs "$partition")"; then |
19 |
log "Device '$partition' does not exist; skipping" |
151 |
log "Device '$partition' does not exist; skipping" |
20 |
continue |
152 |
continue |
Lines 22-29
Link Here
|
22 |
|
154 |
|
23 |
if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map"; then |
155 |
if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map"; then |
24 |
for test in /usr/lib/linux-boot-probes/*; do |
156 |
for test in /usr/lib/linux-boot-probes/*; do |
25 |
debug "running $test" |
|
|
26 |
if [ -x $test ] && [ -f $test ]; then |
157 |
if [ -x $test ] && [ -f $test ]; then |
|
|
158 |
debug "running $test" |
27 |
if $test "$partition"; then |
159 |
if $test "$partition"; then |
28 |
debug "linux detected by $test" |
160 |
debug "linux detected by $test" |
29 |
break |
161 |
break |