Move mount/umount from image to os_type module
[snf-image-creator] / image_creator / os_type / freebsd.py
index d0ed78b..28d58bd 100644 (file)
@@ -41,6 +41,9 @@ class Freebsd(Unix):
     def __init__(self, rootdev, ghandler, output):
         super(Freebsd, self).__init__(rootdev, ghandler, output)
 
+    def _do_collect_metadata(self):
+
+        super(Freebsd, self)._do_collect_metadata()
         self.meta["USERS"] = " ".join(self._get_passworded_users())
 
         #The original product name key is long and ugly
@@ -72,6 +75,34 @@ class Freebsd(Unix):
 
         return users
 
+    def _do_mount(self, readonly):
+        """Mount partitions in the correct order"""
+
+        critical_mpoints = ('/', '/etc', '/root', '/home', '/var')
+
+        # libguestfs can't handle correct freebsd partitions on GUID
+        # Partition Table. We have to do the translation to linux
+        # device names ourselves
+        guid_device = re.compile('^/dev/((?:ada)|(?:vtbd))(\d+)p(\d+)$')
+
+        mopts = "ufstype=ufs2,%s" % ('ro' if readonly else 'rw')
+        for mp, dev in self._mountpoints():
+            match = guid_device.match(dev)
+            if match:
+                m2 = int(match.group(2))
+                m3 = int(match.group(3))
+                dev = '/dev/sd%c%d' % (chr(ord('a') + m2), m3)
+            try:
+                self.g.mount_vfs(mopts, 'ufs', dev, mp)
+            except RuntimeError as msg:
+                if mp in critical_mpoints:
+                    self.out.warn('unable to mount %s. Reason: %s' % (mp, msg))
+                    return False
+                else:
+                    self.out.warn('%s (ignored)' % msg)
+
+        return True
+
     @sysprep()
     def cleanup_password(self, print_header=True):
         """Remove all passwords and lock all user accounts"""