Linux – mount freebsd slice partition under linux

filesystemsfreebsdlinux

I have under linux:

       Device   Boot      Start         End      Blocks   Id  System
/filename.img      *         63     1007999      503968+  a5  FreeBsd

Under above partition i have two slices: ufs filesystem and swap. I don't know, how I can determine mount offset to mount ufs partition.

mount -r -t ufs -o loop,offset=32256,ufstype=ufs2 filename.img /test/

dmesg output

ufs_read_super: bad magic number

It's not working.

Best Answer

I suspect it's

mount -r -o loop,offset=32768,ufstype=ufs2 filename.img /test/

If I remember correctly, the first BSD partition starts on a 32kB boundary relative to the whole disk. That's 64 sectors of 512B. Relative to the PC partition, the offset of the BSD partition is 63 sectors, because the PC partition starts at an offset of 1 sector relative to the whole disk: the first sector of the disk contains the partition table.

As suggested by rozcietrzewiacz, you can confirm the offset of the BSD partition with

partx -l filename.img

There's a patch for the Linux kernel to support automatic access to partitions of loop devices. Debian applies it in their kernels. If you have this patch, then make sure the loop driver has a sufficiently large max_part parameter (you may need to do rmmod loop; modprobe max_part=63). Then the BSD partitions will appear as something like /dev/loop0p5 and /dev/loop0p6.

Related Question