Commit 29fd973e authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Support mounting freebsd ufs filesystems

UFS2 filesystems don't get automatically detected by the linux
kernel. We need to explicitly state the correct filesystem type
and options
parent f564c1ff
......@@ -54,6 +54,7 @@ class Image(object):
self.guestfs_device = None
self.size = 0
self.mounted = False
self.mounted_ro = False
self.g = guestfs.GuestFS()
self.g.add_drive_opts(self.device, readonly=0, format="raw")
......@@ -158,10 +159,12 @@ class Image(object):
def mount(self, readonly=False):
"""Mount all disk partitions in a correct order."""
mount = self.g.mount_ro if readonly else self.g.mount
msg = " read-only" if readonly else ""
self.out.output("Mounting the media%s ..." % msg, False)
mps = self.g.inspect_get_mountpoints(self.root)
msg = "Mounting the media%s ..." % (" read-only" if readonly else "")
self.out.output(msg, False)
#If something goes wrong when mounting rw, remount the filesystem ro
remount_ro = False
rw_mpoints = ('/', '/etc', '/root', '/home', '/var')
# Sort the keys to mount the fs in a correct order.
# / should be mounted befor /boot, etc
......@@ -172,15 +175,45 @@ class Image(object):
return 0
return -1
mps = self.g.inspect_get_mountpoints(self.root)
mopts = 'ro' if readonly else 'rw'
for mp, dev in mps:
if self.ostype == 'freebsd':
# libguestfs can't handle correct freebsd partitions on GUID
# Partition Table. We have to do the translation to linux
# device names ourselves
m = re.match('^/dev/((?:ada)|(?:vtbd))(\d+)p(\d+)$', dev)
if m:
m2 = int(
m3 = int(
dev = '/dev/sd%c%d' % (chr(ord('a') + m2), m3)
mount(dev, mp)
self.g.mount_options(mopts, dev, mp)
except RuntimeError as msg:
self.out.warn("%s (ignored)" % msg)
self.mounted = True
if self.ostype == 'freebsd':
freebsd_mopts = "ufstype=ufs2,%s" % mopts
self.g.mount_vfs(freebsd_mopts, 'ufs', dev, mp)
except RuntimeError as msg:
if readonly is False and mp in rw_mpoints:
remount_ro = True
elif readonly is False and mp in rw_mpoints:
remount_ro = True
self.out.warn("%s (ignored)" % msg)
if remount_ro:
self.out.warn("Unable to mount %s read-write. "
"Remounting everything read-only..." % mp)
self.mounted = True
self.mounted_ro = readonly
def umount(self):
"""Umount all mounted filesystems."""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment