Support UUID= (filesystem UUIDs), Armbian and partially Ubuntu #140

Open
matthijskooijman wants to merge 17 commits from matthijskooijman/support-fsuuid-and-armbian into master

17 Commits

Author SHA1 Message Date
Matthijs Kooijman
e559954a08 Do not sync owner/group for FAT filesystems
This can potentially cause rsync error messages, especially if the
filesystem is already mounted with a uid= option (which will not be
copied to the destination mount, leading to different owners and thus
rsync trying and failing to fix the owner).
2022-07-29 03:15:27 +02:00
Matthijs Kooijman
94b2bccc52 Add fixup_root_partition() function
This adds some consistency with fixup_boot_partition, making code easier
to read, and removes duplication of the list of files to update
(currently only fstab).
2022-07-28 23:37:49 +02:00
Matthijs Kooijman
a26aaff088 Ignore missing files in fixup_device_references_in_file
Since this is called for fstab on unmounted partitions now, without
checking if the file exists, just silently do nothing if the file does
not exist.
2022-07-28 23:20:26 +02:00
Matthijs Kooijman
d610218d2f Apply cmdline/fstab on non-mounted partitions too
This facilitates the case where some of the non-mounted partitions
contain a second operating system (possibly for a different
system/board), and updates these so that system also stays working.
2022-07-28 23:20:26 +02:00
Matthijs Kooijman
f083e6be5d Improve output for cmdline/fstab updates
This modifies fixup_device_references_in_file to accept the mountpoint
and filename separately to prevent printing the destination mountpoint
(which might be ugly and meaningless). fixup_boot_partition already had
this.

Then, a partition label is passed which is prefixed to this plain
filename to tell the user which partition is being modified. This could
just have used src_mount, but passing a separate label prepares for
using this code for non-mounted partitions too.

Finally, the UUID output is slightly reworded and some indentation is
added (preparing for this output to also be intermixed with mounting and
rsync calls later).
2022-07-28 23:20:26 +02:00
Matthijs Kooijman
31ec209e43 Simplify fixup_cmdline_txt()
This applied largely the same operations to cmdline.txt as
fixup_device_references_in_file did to fstab, so this can just call the
latter.

This should work the same, except that the PARTUUID is not replaced with
the g flag (all occurences instead of just one), all filesystem UUIDs
are replaced (instead of just the root partition), and progress output
messages are slightly different.

Also, fstab UUID= replacements are now done anywhere in the file,
instead of just at the start of a line.
2022-07-28 21:36:36 +02:00
Matthijs Kooijman
0c23cb23e5 Move cmdline/fstab updating functions up in file
This puts them together with the other function. This commit only moves
code, without making any changes.
2022-07-28 20:57:20 +02:00
Matthijs Kooijman
31b2c6b11b Refactor cmdline/fstab updating into functions
This mostly moves code into functions, but also makes minor changes to
how the code is called to prepare for more reuse of this code.

Moving these functions up in the file with the other functions is left
for the next commit to make review easier.

Diff best viewed with --ignore-all-space.
2022-07-28 20:55:41 +02:00
Matthijs Kooijman
34dda4f718 Support Ubuntu by modifying /boot/firmware/cmdline.txt
On Ubuntu, cmdline.txt is stored in a subdirectory, so if the file does
not exist in the usual location, fall back to the Ubuntu location (and
fall back to the Armbian version if the Ubuntu version does not exist
either).

Note that this does not support Ubuntu completely out of the box, since
it uses filesystem labels instead of UUIDs for mounting, but if you
manualy change them to UUIDs, this change allows cloning to work.
2022-07-28 20:33:44 +02:00
Matthijs Kooijman
ec4405b158 Support Armbian by modifying armbianEnv.txt
On Armbian, the kernel commandline (or at least the root device to use)
is stored in armbianEnv.txt rather than cmdline.txt, so update that if
it exists and cmdline.txt does not.

The actual operation on this file is just replacing UUIDs inside the
file, so it works even though the syntax of the file is different.
2022-07-28 20:33:44 +02:00
Matthijs Kooijman
0505ad9f39 Refactor cmdline.txt with more variables
This removes all hardcoded references to cmdline.txt and cmdline.boot by
removing the `$clone` prefix from cmdline_txt and introducing a
cmdline_txt variable.

In addition, this adds some quoting to any lines modified to be a bit
more robust when spaces are involved.

This should not change behavior (apart from maybe in cases with spaces
that were previously broken), the commands ran should be identical.
2022-07-28 20:33:44 +02:00
Matthijs Kooijman
21227567cc Support UUID in addition to PARTUUID
This supports systems where the filesystem's UUID is specified in fstab
and on the kernel commandline.

This is the first step in supporting Armbian, which uses UUID rather
than PARTUUID.
2022-03-16 12:08:47 +01:00
Matthijs Kooijman
0ca374dcd8 Run udevadm settle after running parted
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.
2022-03-16 12:08:19 +01:00
Matthijs Kooijman
2f062a9589 Run parted with --script
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?
2022-03-15 22:35:09 +01:00
Matthijs Kooijman
3441dace22 Preserve existing FS labels where possible
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 #100.
2020-07-14 14:42:04 +02:00
Matthijs Kooijman
74eb6a7572 Use previously retrieved destination root FS label
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.
2020-07-14 14:41:07 +02:00
Matthijs Kooijman
06abdd47ff Use lsblk to show all FS labels
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.
2020-07-14 14:40:26 +02:00