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