From ebcedb10bf782f074d6f4e2d116ea0602edfe25c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Thu, 14 Nov 2013 12:06:19 +0100 Subject: [PATCH] Add an option to pass filesystem uuid MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Introduce a new option for the "part" command to set the filesystem uuid. Change-Id: I20fcc0dfde2c56d03433c37d905cf52c98f4254d Signed-off-by: Łukasz Stelmach --- mic/imager/baseimager.py | 1 + mic/imager/loop.py | 7 +++++-- mic/kickstart/custom_commands/partition.py | 4 ++++ mic/utils/fs_related.py | 12 ++++++------ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 8dc4597..dedbaec 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -446,6 +446,7 @@ class BaseImageCreator(object): env.update(self._set_part_env(pnum, "BOOTFLAG", p.active)) env.update(self._set_part_env(pnum, "ALIGN", p.align)) env.update(self._set_part_env(pnum, "TYPE_ID", p.part_type)) + env.update(self._set_part_env(pnum, "UUID", p.uuid)) env.update(self._set_part_env(pnum, "DEVNODE", "/dev/%s%d" % (p.disk, pnum + 1))) env.update(self._set_part_env(pnum, "DISK_DEVNODE", diff --git a/mic/imager/loop.py b/mic/imager/loop.py index 85ffe5d..8d26ad4 100644 --- a/mic/imager/loop.py +++ b/mic/imager/loop.py @@ -153,6 +153,7 @@ class LoopImageCreator(BaseImageCreator): 'fstype': part.fstype or 'ext3', 'extopts': part.extopts or None, 'loop': None, # to be created in _mount_instroot + 'uuid': part.uuid or None, }) self._instloops = allloops @@ -323,7 +324,8 @@ class LoopImageCreator(BaseImageCreator): "size": self.__image_size or 4096L, "fstype": self.__fstype or "ext3", "extopts": None, - "loop": None + "loop": None, + "uuid": None, }) self._check_imgdir() @@ -349,7 +351,8 @@ class LoopImageCreator(BaseImageCreator): mp, fstype, self._blocksize, - loop['label']) + loop['label'], + fsuuid = loop['uuid']) if fstype in ("ext2", "ext3", "ext4"): loop['loop'].extopts = loop['extopts'] diff --git a/mic/kickstart/custom_commands/partition.py b/mic/kickstart/custom_commands/partition.py index 59a87fb..d4c39bf 100644 --- a/mic/kickstart/custom_commands/partition.py +++ b/mic/kickstart/custom_commands/partition.py @@ -27,6 +27,7 @@ class Mic_PartData(FC4_PartData): self.align = kwargs.get("align", None) self.extopts = kwargs.get("extopts", None) self.part_type = kwargs.get("part_type", None) + self.uuid = kwargs.get("uuid", None) def _getArgsAsStr(self): retval = FC4_PartData._getArgsAsStr(self) @@ -37,6 +38,8 @@ class Mic_PartData(FC4_PartData): retval += " --extoptions=%s" % self.extopts if self.part_type: retval += " --part-type=%s" % self.part_type + if self.uuid: + retval += " --uuid=%s" % self.uuid return retval @@ -54,4 +57,5 @@ class Mic_Partition(FC4_Partition): default=None) op.add_option("--part-type", type="string", action="store", dest="part_type", default=None) + op.add_option("--uuid", dest="uuid", action="store", type="string") return op diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index 1a6bf96..e14844a 100644 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -411,11 +411,11 @@ class DiskMount(Mount): class ExtDiskMount(DiskMount): """A DiskMount object that is able to format/resize ext[23] filesystems.""" - def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None): + def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid=None): DiskMount.__init__(self, disk, mountdir, fstype, rmmountdir) self.blocksize = blocksize self.fslabel = fslabel.replace("/", "") - self.uuid = str(uuid.uuid4()) + self.uuid = fsuuid or str(uuid.uuid4()) self.skipformat = skipformat self.fsopts = fsopts self.extopts = None @@ -522,13 +522,13 @@ class ExtDiskMount(DiskMount): class VfatDiskMount(DiskMount): """A DiskMount object that is able to format vfat/msdos filesystems.""" - def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None): + def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid = None): DiskMount.__init__(self, disk, mountdir, fstype, rmmountdir) self.blocksize = blocksize self.fslabel = fslabel.replace("/", "") rand1 = random.randint(0, 2**16 - 1) rand2 = random.randint(0, 2**16 - 1) - self.uuid = "%04X-%04X" % (rand1, rand2) + self.uuid = fsuuid or "%04X-%04X" % (rand1, rand2) self.skipformat = skipformat self.fsopts = fsopts self.fsckcmd = find_binary_path("fsck." + self.fstype) @@ -606,12 +606,12 @@ class VfatDiskMount(DiskMount): class BtrfsDiskMount(DiskMount): """A DiskMount object that is able to format/resize btrfs filesystems.""" - def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None): + def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid = None): self.__check_btrfs() DiskMount.__init__(self, disk, mountdir, fstype, rmmountdir) self.blocksize = blocksize self.fslabel = fslabel.replace("/", "") - self.uuid = None + self.uuid = fsuuid or None self.skipformat = skipformat self.fsopts = fsopts self.blkidcmd = find_binary_path("blkid") -- 2.7.4