build_library/disk_util: Add btrfs UUID randomizing

This is necessary if we want to mount a copy of the production image.
This commit is contained in:
Krzesimir Nowak 2023-03-14 17:27:50 +01:00
parent e6700fcc5c
commit 706356c459

View File

@ -743,18 +743,29 @@ def Tune(options):
config, partitions = LoadPartitionConfig(options) config, partitions = LoadPartitionConfig(options)
GetPartitionTableFromImage(options, config, partitions) GetPartitionTableFromImage(options, config, partitions)
part = GetPartition(partitions, options.partition) part = GetPartition(partitions, options.partition)
action_done = False
if not part['image_compat']: if not part['image_compat']:
raise InvalidLayout("Disk layout is incompatible with existing image") raise InvalidLayout("Disk layout is incompatible with existing image")
if options.disable2fs_rw is not None: if options.disable2fs_rw is not None:
action_done = True
if part.get('fs_type', None) in ('ext2', 'ext4'): if part.get('fs_type', None) in ('ext2', 'ext4'):
Tune2fsReadWrite(options, part, options.disable2fs_rw) Tune2fsReadWrite(options, part, options.disable2fs_rw)
elif part.get('fs_type', None) == 'btrfs': elif part.get('fs_type', None) == 'btrfs':
ReadWriteSubvol(options, part, options.disable2fs_rw) ReadWriteSubvol(options, part, options.disable2fs_rw)
else: else:
raise Exception("Partition %s is not a ext2 or ext4 or btrfs" % options.partition) raise Exception("Partition %s is not a ext2 or ext4 or btrfs" % options.partition)
else:
if options.randomize_uuid is not None:
action_done = True
if part.get('fs_type', None) == 'btrfs':
with PartitionLoop(options, part) as loop_dev:
Sudo(['btrfstune', '-m', loop_dev])
else:
raise Exception("Partition %s is not btrfs" % options.partition)
if not action_done:
raise Exception("No options specified!") raise Exception("No options specified!")
@ -1059,6 +1070,8 @@ def main(argv):
help='disable mounting ext2 filesystems read-write') help='disable mounting ext2 filesystems read-write')
a.add_argument('--enable2fs_rw', action='store_false', dest='disable2fs_rw', a.add_argument('--enable2fs_rw', action='store_false', dest='disable2fs_rw',
help='re-enable mounting ext2 filesystems read-write') help='re-enable mounting ext2 filesystems read-write')
a.add_argument('--randomize_uuid', action='store_true', default=None,
help='randomize btrfs UUIDs in the partition')
a.add_argument('disk_image', help='path to disk image file') a.add_argument('disk_image', help='path to disk image file')
a.add_argument('partition', help='number or label of partition to edit') a.add_argument('partition', help='number or label of partition to edit')
a.set_defaults(func=Tune) a.set_defaults(func=Tune)