Skip to content

Commit ff96aef

Browse files
committed
root-hashes-gui.sh: generalize to work on debian/ubuntu/pureos/qubesos (luks+lvm; qubesos untested: I use btrfs)
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent b3cb325 commit ff96aef

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

initrd/bin/root-hashes-gui.sh

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ROOT_MOUNT="/root"
1313
export CONFIG_ROOT_DIRLIST_PRETTY=$(echo $CONFIG_ROOT_DIRLIST | sed -e 's/^/\//;s/ / \//g')
1414

1515
update_root_checksums() {
16+
TRACE_FUNC
1617
if ! detect_root_device; then
1718
whiptail_error --title 'ERROR: No Valid Root Disk Found' \
1819
--msgbox "No Valid Root Disk Found" 0 80
@@ -31,6 +32,7 @@ update_root_checksums() {
3132
mount -o rw,remount /boot
3233
fi
3334

35+
DEBUG "calculating hashes for $CONFIG_ROOT_DIRLIST_PRETTY on $ROOT_MOUNT"
3436
echo "+++ Calculating hashes for all files in $CONFIG_ROOT_DIRLIST_PRETTY "
3537
# Intentional wordsplit
3638
# shellcheck disable=SC2086
@@ -47,6 +49,8 @@ update_root_checksums() {
4749
unmount_root_device
4850
}
4951
check_root_checksums() {
52+
TRACE_FUNC
53+
DEBUG "verifying existing hash file for $CONFIG_ROOT_DIRLIST_PRETTY"
5054
if ! detect_root_device; then
5155
whiptail_error --title 'ERROR: No Valid Root Disk Found' \
5256
--msgbox "No Valid Root Disk Found" 0 80
@@ -74,6 +78,7 @@ check_root_checksums() {
7478
update_root_checksums
7579
return 0
7680
else
81+
DEBUG "user chose not to create root hash file, returning"
7782
exit 1
7883
fi
7984
fi
@@ -124,6 +129,7 @@ check_root_checksums() {
124129

125130
return 0
126131
else
132+
DEBUG "user chose not to update signatures after new-files warning"
127133
return 1
128134
fi
129135
fi
@@ -154,6 +160,7 @@ check_root_checksums() {
154160
update_root_checksums
155161
return 0
156162
else
163+
DEBUG "user chose not to update signatures after hash-check-failure"
157164
return 1
158165
fi
159166
fi
@@ -164,21 +171,43 @@ check_root_checksums() {
164171
open_block_device_lvm() {
165172
TRACE_FUNC
166173
local VG="$1"
174+
local LV MAPPER_VG MAPPER_LV name lvpath
167175

168176
if ! lvm vgchange -ay "$VG"; then
169177
DEBUG "Can't open LVM VG: $VG"
170178
return 1
171179
fi
172180

173-
# Use the LV 'root'. This is the default name used by Qubes. There's no
174-
# way to configure this at the moment.
175-
if ! [ -e "/dev/mapper/$VG-root" ]; then
176-
DEBUG "LVM volume group does not have 'root' logical volume"
181+
# Prefer an LV named 'root' (used by Qubes), but fall back to any LV
182+
# in the VG. This ensures Ubuntu-style names (e.g. ubuntu-vg/ubuntu-root)
183+
# also work.
184+
LV="/dev/$VG/root"
185+
if ! [ -e "$LV" ]; then
186+
MAPPER_VG="${VG//-/--}"
187+
LV="/dev/mapper/${MAPPER_VG}-root"
188+
fi
189+
if ! [ -e "$LV" ]; then
190+
DEBUG "LVM VG $VG has no 'root' LV, enumerating all LVs"
191+
# list LV names and try each one
192+
for name in $(lvm lvs --noheadings -o lv_name --separator ' ' "$VG" 2>/dev/null); do
193+
lvpath="/dev/$VG/$name"
194+
if ! [ -e "$lvpath" ]; then
195+
MAPPER_LV="${name//-/--}"
196+
lvpath="/dev/mapper/${VG//-/--}-${MAPPER_LV}"
197+
fi
198+
if [ -e "$lvpath" ]; then
199+
DEBUG "trying LV $lvpath"
200+
LV="$lvpath"
201+
break
202+
fi
203+
done
204+
fi
205+
if ! [ -e "$LV" ]; then
206+
DEBUG "no usable LV found in VG $VG"
177207
return 1
178208
fi
179-
180-
# Use the root LV now
181-
open_block_device_layers "/dev/mapper/$VG-root"
209+
# Use selected LV
210+
open_block_device_layers "$LV"
182211
}
183212

184213
# Open a LUKS device, then continue looking for more layers.
@@ -269,12 +298,21 @@ open_root_device_no_clean_up() {
269298
close_block_device_lvm() {
270299
TRACE_FUNC
271300
local VG="$1"
301+
local name lvpath MAPPER_VG MAPPER_LV
272302

273-
# We always use the LV 'root' currently
274-
local LV="/dev/mapper/$VG-root"
275-
if [ -e "$LV" ]; then
276-
close_block_device_layers "$LV"
277-
fi
303+
MAPPER_VG="${VG//-/--}"
304+
305+
# Close any layers found in all LVs in this VG, not just 'root'.
306+
for name in $(lvm lvs --noheadings -o lv_name --separator ' ' "$VG" 2>/dev/null); do
307+
lvpath="/dev/$VG/$name"
308+
if ! [ -e "$lvpath" ]; then
309+
MAPPER_LV="${name//-/--}"
310+
lvpath="/dev/mapper/${MAPPER_VG}-${MAPPER_LV}"
311+
fi
312+
if [ -e "$lvpath" ]; then
313+
close_block_device_layers "$lvpath"
314+
fi
315+
done
278316

279317
# The LVM VG might be open even if no 'root' LV exists, still try to close it.
280318
lvm vgchange -an "$VG" || \
@@ -368,6 +406,7 @@ detect_root_device()
368406

369407
# generate list of possible boot devices
370408
fdisk -l 2>/dev/null | grep "Disk /dev/" | cut -f2 -d " " | cut -f1 -d ":" > /tmp/disklist
409+
DEBUG "detect_root_device: initial disklist=$(cat /tmp/disklist | tr '\n' ' ')"
371410

372411
# filter out extraneous options
373412
> /tmp_root_device_list

0 commit comments

Comments
 (0)