Skip to content

Commit 67c98cc

Browse files
iavigorpecovnik
authored andcommitted
fix(extensions/lvm): resolve label mount point via findmnt, use case
Replace the `mount | grep | awk '{print $3}'` mount-point lookup with a single findmnt call — robust to spaces in paths and to multiple mounts of the same device — and convert the label dispatch and the unsupported-fs guard from if/elif chains to case blocks. Also label ext2 roots via e2label (previously only ext4 was matched, so ext2 fell through to the skip branch), and drop the stray escaped quotes in the xfs label command, which were otherwise embedded verbatim into the filesystem label. Assisted-by: Claude:claude-opus-4.8
1 parent 6f4d263 commit 67c98cc

1 file changed

Lines changed: 33 additions & 18 deletions

File tree

extensions/lvm.sh

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,53 @@ function prepare_root_device__create_volume_group() {
6868
}
6969

7070
function label_partition() {
71-
if [ "$ROOTFS_TYPE" == "ext4" ]; then
72-
e2label "/dev/mapper/${LVM_VG_NAME}-root" "${ROOT_FS_LABEL}"
73-
elif [ "$ROOTFS_TYPE" == "btrfs" ]; then
74-
btrfs filesystem label "$(mount | grep "/dev/mapper/${LVM_VG_NAME}-root" | awk '{print $3}')" "${ROOT_FS_LABEL}"
75-
elif [ "$ROOTFS_TYPE" == "nilfs2" ]; then
76-
nilfs-tune -L "${ROOT_FS_LABEL}" "/dev/mapper/${LVM_VG_NAME}-root"
77-
elif [ "$ROOTFS_TYPE" == "xfs" ]; then
78-
xfs_io -c "label -s \"${ROOT_FS_LABEL}\"" "$(mount | grep "/dev/mapper/${LVM_VG_NAME}-root" | awk '{print $3}')"
79-
fi
71+
local rootdevice="/dev/mapper/${LVM_VG_NAME}-root"
72+
# btrfs and xfs relabel via the mount point; resolve it structurally
73+
# (findmnt is a single util-linux call, robust to spaces and to multiple
74+
# mounts of the same device) instead of parsing mount(8) output.
75+
local mountpoint
76+
mountpoint="$(findmnt --noheadings --first-only --output TARGET --source "${rootdevice}")"
77+
78+
case "${ROOTFS_TYPE}" in
79+
ext4 | ext2)
80+
e2label "${rootdevice}" "${ROOT_FS_LABEL}"
81+
;;
82+
btrfs)
83+
btrfs filesystem label "${mountpoint}" "${ROOT_FS_LABEL}"
84+
;;
85+
nilfs2)
86+
nilfs-tune -L "${ROOT_FS_LABEL}" "${rootdevice}"
87+
;;
88+
xfs)
89+
xfs_io -c "label -s ${ROOT_FS_LABEL}" "${mountpoint}"
90+
;;
91+
esac
8092
}
8193

8294
function format_partitions__format_lvm() {
83-
# Skip unknown filesystems
84-
if echo "ext4 btrfs nilfs2 xfs" | grep -v -w -q "$ROOTFS_TYPE"; then
85-
display_alert "LVM partition labels skipped" "${EXTENSION}" "info"
86-
return
87-
fi
95+
# Only these filesystems support relabeling the mounted root here; skip the rest.
96+
case "${ROOTFS_TYPE}" in
97+
ext4 | ext2 | btrfs | nilfs2 | xfs) ;;
98+
*)
99+
display_alert "LVM partition labels skipped" "${EXTENSION} - unsupported ${ROOTFS_TYPE}" "info"
100+
return
101+
;;
102+
esac
88103

89104
# Label the root volume
90105
if label_partition; then
91106
blkid | grep "${LVM_VG_NAME}" >> "${DEST}/${LOG_SUBPATH}/lvm.log" 2>&1
92-
display_alert "LVM labeled $ROOTFS_TYPE partitions" "${EXTENSION}" "info"
107+
display_alert "LVM labeled ${ROOTFS_TYPE} partitions" "${EXTENSION}" "info"
93108
else
94-
display_alert "LVM failed to label $ROOTFS_TYPE partition. Ignoring." "${EXTENSION}" "info"
109+
display_alert "LVM failed to label ${ROOTFS_TYPE} partition. Ignoring." "${EXTENSION}" "info"
95110
fi
96111
}
97112

98-
function post_umount_final_image__cleanup_lvm(){
113+
function post_umount_final_image__cleanup_lvm() {
99114
execute_and_remove_cleanup_handler cleanup_lvm
100115
}
101116

102117
function cleanup_lvm() {
103118
vgchange -a n "${LVM_VG_NAME}" >> "${DEST}/${LOG_SUBPATH}/lvm.log" 2>&1 || true
104119
display_alert "LVM deactivated volume group" "${EXTENSION}" "info"
105-
}
120+
}

0 commit comments

Comments
 (0)