Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep filesystem labels #101

Closed

Conversation

matthijskooijman
Copy link

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.

Previously, e2label was used, but that only works for ext partitions.
Using lsblk allows showing the filesystem labels for all filesystems
supported by the kernel.
Now labels are retrieved for all destination partitions, there is no
longer any point in separately retrieving the destination root label,
just use the previously retrieved label.
Instead of only setting FS labels on ext partitions when specified with
the --label-partitions option and leave all other partitions unlabeled,
this tries to copy the source filesystem labels to the destination where
possible.

Setting labels requires filesystem-specific commands or mkfs options, so
not all filesystems are supported. For changing labels on existing
partitions, only ext and fat partitions are supported. For mkfs a few
more are supported, though these are probably not used in practice.

This also refactors some of the code, introducing a `mkfs_label()` and
`change_label()` function to prevent having to duplicate the
filesystem-type checking code.

This fixes billw2#100.
@bodiya
Copy link

bodiya commented Dec 15, 2021

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

This makes it non-interactive and prevents the script from silently
hanging when parted finds something weird, e.g.:

    $ sudo rpi-clone /dev/sda
    Warning: The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes.

This just hangs, because parted is waiting for an answer:

    $ sudo parted -m /dev/sda unit s print
    Warning: The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes.
    Ignore/Cancel?
@matthijskooijman
Copy link
Author

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).

It seems that parted can force a partition scan (observed on a removable
USB disk), which temporaly clears the filesystem labels from lsblk
output. To prevent this, call udevadm settle to wait until all udev
events are processed before continuing.
@ioogithub
Copy link

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: #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
Copy link
Author

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
Copy link
Author

I've resubmitted this PR in a more actively maintained fork: geerlingguy#16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants