Mount FreeBSD UFS from logical partition under Linux

22,340

Solution 1

A workaround is to calculate the offset of the BSD partition within the logical partition and use a loop device with offset:

mount -t ufs -o loop,offset=8192,ro,ufstype=ufs2 /dev/sda6 /mnt

Solution 2

Probably you have been confused by different harddisk naming convention in Linux and FreeBSD. From your output one can clearly see that Linux has detected your ufs partition and it is /dev/sda6. So, you just need to do the following

sudo modprobe ufs
sudo mount -t ufs -o ufstype=ufs2 /dev/sda6 /mnt

Solution 3

Use fdisk /dev/sdX using command b (for BSD disklabels) followed by p (for print) to get the list of BSD disklabels/slices. This will look like this:

Slice   Start     End Sectors   Size Type     Fsize Bsize   Cpg
a     4082400 4606687  524288   256M 4.2BSD    2048 16384 32776
b     4606688 5079391  472704 230.8M swap         0     0     0
c     4082400 8164799 4082400     2G unused       0     0     0
d     5079392 5603679  524288   256M 4.2BSD    2048 16384 32776
e     5603680 6127967  524288   256M 4.2BSD    2048 16384 32776
f     6127968 8164799 2036832 994.6M 4.2BSD    2048 16384 28552

This gives you the start sector for each partition. The sector multiplied by the sector size (512 bytes; see fdisk output) gives you an offset that you can use with with mount.

For example for slice f:

mount -t ufs -o loop,offset=$((6127968 * 512)),ro,ufstype=ufs2 /dev/sdX /mnt/freebsd

Share:
22,340

Related videos on Youtube

not-a-user
Author by

not-a-user

Updated on September 18, 2022

Comments

  • not-a-user
    not-a-user over 1 year

    How can I mount the FreeBSD UFS boot partition under Ubuntu in this setup:

    • a single HDD which contains
    • an MBR partition table which contains
    • some primary Linux partitions and an extended partition which contains
    • a Linux logical partition and a FreeBSD logical partition which contains
    • the FreeBSD disklabel (so the logical partition is the "slice") which contains
    • the FreeBSD boot (UFS) and swap partitions

    Here is the MBR partitioning:

    ubuntu$ sudo fdisk -l /dev/sda
    
    Disk /dev/sda: 42.9 GB, 42949672960 bytes
    
    255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0005d5af
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1953791      975872   83  Linux
    /dev/sda2         1953792    11718655     4882432   83  Linux
    /dev/sda3        11718656    13672447      976896   82  Linux swap /     Solaris
    /dev/sda4        13674494    83884031    35104769    5  Extended
    /dev/sda5        13674496    33204223     9764864   83  Linux
    /dev/sda6        33206272    83884031    25338880   a5  FreeBSD
    

    And here is the disklabel:

    freebsd$ disklabel /dev/ada0s6
    # /dev/ada0s6:
    8 partitions:
    #          size     offset    fstype   [fsize bsize bps/cpg]
      a:   48580592         16    4.2BSD        0     0     0
      b:    2097152   48580608      swap                    
      c:   50677760          0    unused        0     0     # "raw" part, don't edit
    

    I can boot FreeBSD using the following /etc/grub.d/40_custom:

    #!/bin/sh
    exec tail -n +3 $0
    # This file provides an easy way to add custom menu entries.  Simply type the
    # menu entries you want to add after this comment.  Be careful not to change
    # the 'exec tail' line above.
    
    menuentry "FreeBSD" {
        insmod part_bsd
        insmod ufs2
        set root="(hd0,msdos6,bsd1)"
        kfreebsd /boot/kernel/kernel
        set kFreeBSD.acpi_load=YES
        set kFreeBSD.hint.acpi.0.disabled=0
        set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ada0s6a
        kfreebsd_loadenv /boot/device.hints
    }
    

    That way I can access the FreeBSD partition from grub2 with no problems. But Linux does not detect any BSD partitions:

    ubuntu$ ls /dev/sda*
    /dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda4  /dev/sda5  /dev/sda6
    

    Versions: Ubuntu 14.04 with kernel 4.2.0-27-generic on x86_64, FreeBSD 10.3 RELEASE amd64, both fresh installs.

  • not-a-user
    not-a-user about 8 years
    /dev/sda6 is the logical partition that serves as a FreeBSD slice and that contains the two FreeBSD partitions (which I hope Linux can detect and make available as /dev/sda7 and /dev/sda8). So your mount command does not work.
  • not-a-user
    not-a-user about 8 years
    Linux /dev/sda6 is FreeBSD /dev/ada0s6 but I want to mount FreeBSD /dev/ada0s6a in Linux.