To simplify filling in the UUID fields in /etc/fstab,
the following commands use blkid to extract the UUID of each partition.
The blkid tool prints device information in the form
UUID="xxxx-xxxx", and the pipeline below removes the quotes so the
value can be inserted directly into the file.
export DRIVE=/dev/vda
export ROOT=$(blkid -o value -s UUID ${DRIVE}3)
export SWAP=$(blkid -o value -s UUID ${DRIVE}2)
export UEFI=$(blkid -o value -s UUID ${DRIVE}1)
export PARTROOT=$(blkid -o value -s PARTUUID ${DRIVE}3)
cat > /etc/fstab <<EOF # Begin /etc/fstab # file system mount-point type options dump fsck # order $ROOT / ext4 defaults 1 1 $SWAP swap swap pri=1 0 0 $UEFI /boot/efi vfat noauto,codepage=437,iocharset=iso8859-1 0 1 # End /etc/fstab EOF
In the same way, GRUB can automatically locate the root filesystem by UUID using the search command. Here, blkid is again used to extract the filesystem UUID from the partition so that it can be inserted directly into the configuration.
cat > /boot/grub/grub.cfg <<EOF
# Begin /boot/grub/grub.cfg
set default=0
set timeout=10
insmod part_gpt
insmod ext2
insmod efi_gop
insmod efi_uga
search --no-floppy --fs-uuid --set=root $(blkid /dev/vda3 | awk '{print $2}' | sed 's/"//g')
set gfxpayload=1280x1024x32
menuentry "GNU/Linux, Linux-6.12.58-lfs-r12.4-45-systemd" {
linux /boot/vmlinuz-6.12.58-lfs-r12.4-45-systemd root=PARTUUID=$PARTROOT ro
}
EOF
unset ROOT SWAP UEFI PARTROOT