Closed leifliddy closed 2 years ago
something like this should work....
root_dev=$(findmnt -n -o SOURCE /)
efi_dev=$(findmnt -n -o SOURCE /boot/efi)
if [ -n "$root_dev" ] && [ -n "$efi_dev" ]; then
if [ "$(blkid "$efi_dev" | tr -d '"' | grep 'TYPE=vfat')" ]; then
echo "Randomizing root filesystem UUID..."
tune2fs -U random "$root_dev"
root_uuid="$(blkid -c /dev/null "$root_dev" -o export | grep '^UUID=')"
echo "Root filesystem: $root_uuid"
echo -e '\nRandomizing EFI system partition UUID...'
# Ugly... why isn't there a command to do this?
ssize="$(blockdev --getss "$efi_dev")"
dd bs=1 seek=67 count=4 conv=notrunc if=/dev/urandom of="$efi_dev"
dd bs=1 skip=67 seek=$((67+6*$ssize)) count=4 conv=notrunc if="$efi_dev" of="$efi_dev"
efi_uuid=$(blkid -c /dev/null "$efi_dev" -o export | grep '^UUID=')
echo -e "EFI partition: $efi_uuid\n"
fi
fi
if [ -n "$root_uuid" ] && [ -n "$efi_uuid" ]; then
....
In this script, it might a good idea to verify that
$root_dev
and$efi_dev
both have value before changing any of theUUIDs
If the efi partition wasn't mount for whatever reason, but root was -- then the UUID of the root partition would be modified, but/etc/fstab
wouldn't be modified.I actually ran into this issue when building my own image (and incorporating your scripts). For some reason the efi partition wasn't mounted when the first-boot.service ran....