]> git.siccegge.de Git - forks/vmdebootstrap.git/commitdiff
Alternatively use mdconfig instead of kpartx if run on freebsd
authorChristoph Egger <christoph@christoph-egger.org>
Sun, 1 Nov 2015 15:19:17 +0000 (16:19 +0100)
committerChristoph Egger <christoph@christoph-egger.org>
Sun, 1 Nov 2015 15:19:17 +0000 (16:19 +0100)
vmdebootstrap

index 67ea2c867ca785d24e2b2a1d8204ceaa9280126c..f5041cde93025de934a9c17422f4dfa24b3bdc5b 100755 (executable)
@@ -20,6 +20,7 @@ import cliapp
 import crypt
 import logging
 import os
+import glob
 import re
 import sys
 import shutil
@@ -482,7 +483,11 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
     def setup_kpartx(self):
         bootindex = None
         swapindex = None
-        out = self.runcmd(['kpartx', '-avs', self.settings['image']])
+        if 'freebsd' in os.sys.platform:
+            out = self.runcmd(['mdconfig', '-a', '-t', 'vnode', '-f',
+                               self.settings['image']])
+        else:
+            out = self.runcmd(['kpartx', '-avs', self.settings['image']])
         if self.settings['bootsize'] and self.settings['swap'] > 0:
             bootindex = 0
             rootindex = 1
@@ -510,19 +515,22 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
             parts = 1
         boot = None
         swap = None
-        devices = [line.split()[2]
-                   for line in out.splitlines()
-                   if line.startswith('add map ')]
+        if 'freebsd' in os.sys.platform:
+            devices = glob.glob("/dev/%ss*" % out.strip())
+        else:
+            devices = ['/dev/mapper/%s' % line.split()[2]
+                       for line in out.splitlines()
+                       if line.startswith('add map ')]
         if len(devices) != parts:
             msg = 'Surprising number of partitions - check output of losetup -a'
             logging.debug("%s", self.runcmd(['losetup', '-a']))
             logging.debug("%s: devices=%s parts=%s", msg, devices, parts)
             raise cliapp.AppException(msg)
-        root = '/dev/mapper/%s' % devices[rootindex]
+        root = devices[rootindex]
         if self.settings['bootsize'] or self.settings['use-uefi']:
-            boot = '/dev/mapper/%s' % devices[bootindex]
+            boot = devices[bootindex]
         if self.settings['swap'] > 0:
-            swap = '/dev/mapper/%s' % devices[swapindex]
+            swap = devices[swapindex]
         return root, boot, swap
 
     def _efi_packages(self):
@@ -1020,7 +1028,13 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
                     time.sleep(5)
                     self.runcmd(['umount', mount_point], ignore_fail=False)
 
-            self.runcmd(['kpartx', '-d', self.settings['image']], ignore_fail=True)
+            if 'freebsd' in os.sys.platform:
+                out = self.runcmd(['mdconfig', '-l', '-f', self.settings['image']])
+                for devid in out.split():
+                    self.runcmd(['mdconfig', '-d', '-u', devid],
+                                ignore_fail=True)
+            else:
+                self.runcmd(['kpartx', '-d', self.settings['image']], ignore_fail=True)
 
         for dirname in self.remove_dirs:
             shutil.rmtree(dirname)