Skip to content

Commit

Permalink
Fixed hardcoded root partition device name sda2
Browse files Browse the repository at this point in the history
The root partition may not be /dev/sda2, for example if set the boot disk as the
second disk, the root partition device name will be /dev/sdb2. It may be
/dev/vda2 if not using san disk. The fix figured out the root partition device
UUID and set the UUID as the root, the root partition device UUID keeps no
change.

Depends on lxc/distrobuilder#830

Signed-off-by: JUN JIE NAN <nanjunjie@gmail.com>
  • Loading branch information
nanjj committed Apr 7, 2024
1 parent a7a0d8d commit b0293a7
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions images/almalinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ actions:
target="$(readlink -f /etc/grub2-efi.cfg)"
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
types:
- vm
releases:
Expand All @@ -424,11 +424,11 @@ actions:
# Create grub.cfg file
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
# Update files in /boot/loader/entries/. `grubby` needs to be run after
# `grub2-mkconfig` as the latter overwrites files in /boot/loader/entries/.
grubby --update-kernel=/boot/vmlinuz-${kver} --args="root=/dev/sda2 ro"
grubby --update-kernel=/boot/vmlinuz-${kver} --args="root=${DISTROBUILDER_ROOT_UUID} ro"
# Regenerate initramfs
dracut --kver "${kver}" -f
Expand Down
2 changes: 1 addition & 1 deletion images/alpine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ actions:
target=/boot/grub/grub.cfg
grub-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
TARGET="x86_64"
[ "$(uname -m)" = "aarch64" ] && TARGET="arm64"
Expand Down
2 changes: 1 addition & 1 deletion images/archlinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ actions:
grub-install --target="${TARGET}-efi" --efi-directory=/boot/efi --no-nvram --removable
grub-install --target="${TARGET}-efi" --efi-directory=/boot/efi --no-nvram
grub-mkconfig -o /boot/grub/grub.cfg
sed -i "s#root=[^ ]*#root=/dev/sda2#g" /boot/grub/grub.cfg
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" /boot/grub/grub.cfg
# Rebuild initrd
sed -i 's#^MODULES=.*#MODULES=(virtio_pci virtio_scsi virtio_console)#' /etc/mkinitcpio.conf
Expand Down
8 changes: 4 additions & 4 deletions images/centos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ actions:
umount /sys/firmware
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
# Workaround for broken systemd in centos7
systemctl enable incus-agent-workaround.service
Expand All @@ -852,7 +852,7 @@ actions:
target="$(readlink -f /etc/grub2-efi.cfg)"
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
types:
- vm
releases:
Expand All @@ -867,11 +867,11 @@ actions:
# Create grub.cfg file
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
# Update files in /boot/loader/entries/. `grubby` needs to be run after
# `grub2-mkconfig` as the latter overwrites files in /boot/loader/entries/.
grubby --update-kernel=/boot/vmlinuz-${kver} --args="root=/dev/sda2 ro"
grubby --update-kernel=/boot/vmlinuz-${kver} --args="root=${DISTROBUILDER_ROOT_UUID} ro"
# Regenerate initramfs
dracut --kver "${kver}" -f
Expand Down
2 changes: 1 addition & 1 deletion images/debian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ actions:
grub-install --uefi-secure-boot --target="${TARGET}-efi" --no-nvram
update-grub
sed -i "s#root=[^ ]*#root=/dev/sda2#g" /boot/grub/grub.cfg
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" /boot/grub/grub.cfg
types:
- vm
releases:
Expand Down
2 changes: 1 addition & 1 deletion images/fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ actions:
target=/boot/efi/EFI/fedora/grub.cfg
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
sed -Eri "s#^(linux|initrd) .+/overlay/#\1 /#g" /boot/loader/entries/*
sed -ri 's#^options .+#options $kernelopts#g' /boot/loader/entries/*
Expand Down
4 changes: 2 additions & 2 deletions images/gentoo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ actions:
systemd-machine-id-setup
bootctl install --no-variables --esp-path=/boot/efi/
echo "root=/dev/sda2" >> /etc/kernel/cmdline
echo "root=${DISTROBUILDER_ROOT_UUID}" >> /etc/kernel/cmdline
echo "sys-apps/systemd kernel-install" >> /etc/portage/package.use/systemd
echo "sys-kernel/installkernel dracut systemd systemd-boot" >> /etc/portage/package.use/installkernel
Expand Down Expand Up @@ -668,7 +668,7 @@ actions:
grub-install --target=${TARGET}-efi --no-nvram --removable
grub-install --target=${TARGET}-efi --no-nvram
grub-mkconfig -o /boot/grub/grub.cfg
sed -i "s#root=[^ ]*#root=/dev/sda2#g" /boot/grub/grub.cfg
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" /boot/grub/grub.cfg
types:
- vm
variants:
Expand Down
2 changes: 1 addition & 1 deletion images/openeuler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ actions:
umount /sys/firmware
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
# Workaround for broken systemd in centos7
systemctl enable incus-agent-workaround.service
Expand Down
2 changes: 1 addition & 1 deletion images/opensuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ actions:
grub2-mkconfig -o /boot/grub2/grub.cfg
umount /sys/firmware
sed -i "s#root=[^ ]*#root=/dev/sda2#g" /boot/grub2/grub.cfg
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" /boot/grub2/grub.cfg
types:
- vm

Expand Down
6 changes: 3 additions & 3 deletions images/rockylinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ actions:
dracut --kver "${kver}" -f
target="$(readlink -f /etc/grub2-efi.cfg)"
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
types:
- vm
releases:
Expand All @@ -374,10 +374,10 @@ actions:
target=/boot/efi/EFI/rocky/grub.cfg
# Create grub.cfg file
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
# Update files in /boot/loader/entries/. `grubby` needs to be run after
# `grub2-mkconfig` as the latter overwrites files in /boot/loader/entries/.
grubby --update-kernel=/boot/vmlinuz-${kver} --args="root=/dev/sda2 ro"
grubby --update-kernel=/boot/vmlinuz-${kver} --args="root=${DISTROBUILDER_ROOT_UUID} ro"
# Regenerate initramfs
dracut --kver "${kver}" -f
types:
Expand Down
4 changes: 2 additions & 2 deletions images/springdalelinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ actions:
umount /sys/firmware
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
# Workaround for broken systemd in centos7
systemctl enable incus-agent-workaround.service
Expand All @@ -452,7 +452,7 @@ actions:
target="$(readlink -f /etc/grub2-efi.cfg)"
grub2-mkconfig -o "${target}"
sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" "${target}"
types:
- vm
releases:
Expand Down
2 changes: 1 addition & 1 deletion images/ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ actions:
grub-install --uefi-secure-boot --target="${TARGET}-efi" --no-nvram
update-grub
sed -i "s#root=[^ ]*#root=/dev/sda2#g" /boot/grub/grub.cfg
sed -i "s#root=[^ ]*#root=${DISTROBUILDER_ROOT_UUID}#g" /boot/grub/grub.cfg
types:
- vm

Expand Down

0 comments on commit b0293a7

Please sign in to comment.