billw2 / rpi-clone

A shell script to clone a booted disk.
BSD 3-Clause "New" or "Revised" License
2.56k stars 335 forks source link

Don't convert partuuids for empty src_partition element #149

Open aaronkollasch opened 2 years ago

aaronkollasch commented 2 years ago

Issue

When converting to partuuids, if there is an empty element in ${src_partition[@]}, then /etc/fstab will have /dev/ replaced with PARTUUID= without actually changing the device name to a PARTUUID.

I don't have the exact logs when this happened to me, but it looked something like this:

$ sudo rpi-clone -l sda --convert-fstab-to-partuuid

This will change your /etc/fstab, are you sure?  (yes/no): yes

Converting /etc/fstab from device names to PARTUUID
lsblk: /dev/: not a block device
  Editing /etc/fstab, changing /dev/ to
...

and I ended up with a broken fstab:

proc            /proc           proc    defaults          0       0
PARTUUID=mmcblk0p6  /boot           vfat    defaults          0       2
PARTUUID=mmcblk0p7  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

I had previously run sudo rpi-clone -l sda so perhaps that is why there was an empty element in src_partition, I'm not sure.

Changes

Check that ${src_partition[p]} is not empty before editing /etc/fstab.

Then, the command I used will instead exit with an error, which is much safer:

Could not find any sda partition names in /etc/fstab, nothing changed.