Mounting a UFS2 volume on Ubuntu from .raw

If you need to mount a UFS2 volume directly on Ubuntu–for example, from a snapshot of a XigmaNAS VM using UFS storage beneath a ZFS pool on the VM host–there are a few extra hurdles along the way.

First, you need to scan the .raw file for partitions (if any). Do this with the loopback setup utility, losetup:

losetup -fP /path/to/.raw

Losetup, unfortunately, doesn’t give you any helpful output–like, say, what loopback devicename it just created. In order to find out, try using lsblk piped through grep loop–or even lsblk | grep loop | grep part, if you know for certain that your raw file has partitions!

lsblk | grep loop | grep p1
└─loop19p1 259:0 0 3T 1 part

Now that we know the devicename we want is /dev/loop19p1, we can actually mount it. But since this is a UFS2 partition from a XigmaNAS VM, we’re going to again need to take a couple of extra steps–Ubuntu’s kernel is capable of mounting the image, but it’s going to need a few extra arguments to help it figure that fact out.

modprobe ufs
mkdir /tmp/restore

mount -t ufs -o ufstype=ufs2 /dev/loop19p1 /tmp/restore

Now we can cherrypick the files we need out of /tmp/restore, then it’s time to unmount everything and get rid of our temporary mess:umount /tmp/restore:

umount /dev/loop19p1
rm -r /tmp/restore
losetup -d /dev/loop19

And Bob’s your uncle.