From 18fffb8e9784dd4d83bcdb94543e330e766a218a Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Aug 23 2020 16:42:01 +0000 Subject: appcreate: Ensure Btrfs volumes and subvolumes are set up first This should ensure that the appliance image mount structure is correct during image creation. --- diff --git a/appcreate/appliance.py b/appcreate/appliance.py index ef10481..a1a0a67 100644 --- a/appcreate/appliance.py +++ b/appcreate/appliance.py @@ -238,9 +238,6 @@ class ApplianceImageCreator(ImageCreator): except MountError as e: raise CreatorError("Failed mount disks : %s" % e) - if self.ks.handler.btrfs.btrfsList: - self.__instloop.setup_subvolumes() - self._create_mkinitrd_config() def _kernel_cmdline_append(self): diff --git a/appcreate/partitionedfs.py b/appcreate/partitionedfs.py index a1597ea..5f343e5 100644 --- a/appcreate/partitionedfs.py +++ b/appcreate/partitionedfs.py @@ -224,14 +224,21 @@ class PartitionedMount(Mount): def __calculate_mountorder(self): + btrfs_mountOrder = [] for p in self.partitions: - self.mountOrder.append(p['mountpoint']) + if p['fstype'] == 'btrfs': + btrfs_mountOrder.append(p['mountpoint']) + else: + self.mountOrder.append(p['mountpoint']) self.unmountOrder.append(p['mountpoint']) self.mountOrder.sort() + btrfs_mountOrder.sort() + # Btrfs mountpoints must be first in the list + self.mountOrder = btrfs_mountOrder + self.mountOrder self.unmountOrder.sort() self.unmountOrder.reverse() - print(str(self.mountOrder)) + logging.info(str(self.mountOrder)) def cleanup(self): Mount.cleanup(self) @@ -288,8 +295,10 @@ class PartitionedMount(Mount): base = "%s%s" % (self.mountdir, s['parent']) path = "%s/%s" % (base, s['name']) mountpath = "%s%s" % (self.mountdir, s['mountpoint']) + logging.debug("Creating Btrfs subvolume at path %s" % path) subprocess.call(['btrfs', 'subvol', 'create', path]) subprocess.call(['mkdir', '-p', mountpath]) + logging.debug("Mounting Btrfs subvolume %s at path %s" % (s['name'], mountpath)) device = subprocess.Popen(["findmnt", "-n", "-o", "SOURCE", base], stdout=subprocess.PIPE).communicate()[0].decode("utf-8").strip() subprocess.call(['mount', '-t', 'btrfs', '-o', 'subvol=%s' % s['name'], device, mountpath]) @@ -355,6 +364,8 @@ class PartitionedMount(Mount): p['mountpoint'], rmmountdir) pdisk.mount() + if p['fstype'] == 'btrfs': + self.setup_subvolumes() p['mount'] = pdisk p['UUID'] = self.__getuuid(p['device'])