billw2 / rpi-clone

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

Keep filesystem labels #101

Closed matthijskooijman closed 3 months ago

matthijskooijman commented 3 years ago

This makes some changes to display and preserve all filesystem labels rather than just for ext filesystems.

Displaying of labels should be supported for any filesystem supported by the kernel (using lsblk), while copying labels is supported for a limited set of filesystems (just ext and fat for existing filesystems, a few more for new filesystems).

See the commit messages for some more details.

bodiya commented 2 years ago

This allowed me to clone Ubuntu 21.10, which I was unable to do previously. Thanks!

matthijskooijman commented 2 years ago

I've added two more commits just now:

  1. To add --script to the parted commandline, to prevent rpi-clone locking up when parted asks a question. This is not strictly required to the main change of this PR, but because it touches the same code, putting this in a separate PR just adds conflicts for no real gain.
  2. To use udevadm settle after running parted, which could in some circumstances prevent labels from being read by triggering a partition scan (which temporarily hides labels and other info from lsblk).
ioogithub commented 2 years ago

I have used this code to make a bootable clone of Ubuntu 21.10 thank you.

I did run into another problem however. If I leave the clone attached to the USB drive, the pi actually boots from the clone and not the original!

When I try to do an incremental update: ./rpi-clone sdb I get an error message:

Destination disk sdb is the booted disk. Cannot clone!

I verified that indeed the pi always boots from the sd card clone attached to the USB rather than the card attached directly to the pi's sd card slot.

I also verified that my pi is set to boot from SD but it seems that doesn't know which SD to boot from:

BOOT_ORDER=0x1 which means SD CARD: 0x1 | SD CARD | SD card (or eMMC on Compute Module 4). https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-4-bootloader-configuration

@eddiem5 ran into the same problem here: https://github.com/billw2/rpi-clone/issues/106 but @robustini solution was to use an old version of rpi-clone which will not work as I need your code changes.

Is there anyway around this so I can update my clone with incremental updates?

matthijskooijman commented 2 years ago

I also verified that my pi is set to boot from SD but it seems that doesn't know which SD to boot from:

I'm pretty sure that the rpi will boot from its internal SD when configured like this, the rpi boot code probably doesn't even know that your USB card reader is an SD card (it's just "mass storage").

What I suspect might be happening, is that the old and new root filesystems have kept the same (PART)UUID, and the initrd is started from the real SD card, which then looks for the root filesystem based on a UUID, finds both the original and the clone and then picks the wrong one. There is code to fix this by changing and updating the PARTUUID, but maybe your Ubuntu is using UUID (filesystem UUID) rather than PARTUUID (partition UUID), which is not supported yet. If so, #140 might be helpful for you.

Also, I think that none of this is really related to this particular PR (I actually think things would have worked the same with an unpatched master), so if this probably persists, it might be better to open up a new issue rather than continuing this discussion here.

matthijskooijman commented 3 months ago

I've resubmitted this PR in a more actively maintained fork: https://github.com/geerlingguy/rpi-clone/pull/16