Add an option to pass filesystem uuid
authorŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 14 Nov 2013 11:06:19 +0000 (12:06 +0100)
committerGui Chen <gui.chen@intel.com>
Fri, 22 Nov 2013 02:54:25 +0000 (21:54 -0500)
Introduce a new option for the "part" command to set the filesystem uuid.

Change-Id: I20fcc0dfde2c56d03433c37d905cf52c98f4254d
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
mic/imager/baseimager.py
mic/imager/loop.py
mic/kickstart/custom_commands/partition.py
mic/utils/fs_related.py

index 8dc4597..dedbaec 100644 (file)
@@ -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",
index 85ffe5d..8d26ad4 100644 (file)
@@ -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']
index 59a87fb..d4c39bf 100644 (file)
@@ -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
index 1a6bf96..e14844a 100644 (file)
@@ -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")