10

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.

4 Answers 4

8

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 
4

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 
2
  • 3
    /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. Commented Apr 12, 2016 at 12:05
  • 3
    Linux /dev/sda6 is FreeBSD /dev/ada0s6 but I want to mount FreeBSD /dev/ada0s6a in Linux. Commented Apr 12, 2016 at 14:56
4

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

1

Mounting the specific partition /dev/sdb2 without the need for offset calculation

  1. Load the UFS file system module
 sudo modprobe ufs 
  1. Create a mount point for UFS
 sudo mkdir -p /mnt/ufs 
  1. Mount the partition without offset (offset is not required when mounting a specific partition)
 sudo mount -t ufs -o rw,ufstype=ufs2 /dev/sdb2 /mnt/ufs 
  1. Check the contents of the mounted partition
 ls -la /mnt/ufs 

Mounting a Disk Image or Device with UFS File System Using Offset Calculation

  1. Determine the starting sector of the desired partition, this command lists the partition table of the disk image or device
 sudo fdisk -l /path/to/disk/image 
  1. Calculate the offset - your starting sector * 512 bytes Replace 'your_starting_sector' with the actual sector number obtained from the output of fdisk
 your_start_sector=<obtained_from_fdisk_output> offset=$((your_ starting_sector * 512)) 
  1. Mount the image or device with the calculated offset. The offset is used to mount the desired partition
 sudo mount -t ufs -o loop,offset=$offset,rw,ufstype=ufs2 /path/to/disk/image /mnt/ufs 

Example:

This is an example of mounting a partition inside a disk image so that no one gets confused.

Retrieving Partition Information from the Disk Image

To view the partition table inside the disk image, we use fdisk. This will help identify the starting sector of the desired partition.

sudo fdisk -l /path/to/disk/image.img 

Our Output:

Disk /path/to/disk/image.img: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Device Boot Start End Blocks Id System /dev/loop0p1 * 2048 1953791 975872 83 Linux /dev/loop0p2 1953792 11718655 4882432 a5 FreeBSD 

the partition /dev/loop0p2 (FreeBSD) starts at sector 1953792.

Calculating the Offset:

To calculate the offset in bytes, multiply the starting sector of the desired partition by the sector size (512 bytes in most cases).

If the starting sector is 1953792, the offset is calculated as follows:

offset=$((1953792 * 512)) 

The offset will be 1001885184 bytes.

Mounting the Partition Using the Offset:

Now that the offset has been calculated, you can mount the partition by specifying the path to the disk image and the offset:

sudo mount -t ufs -o loop,offset=1001885184,rw,ufstype=ufs2 /path/to/disk/image.img /mnt/ufs 

This command mounts the partition starting from the specified offset inside the disk image.

Checking the Contents of the Mounted Partition:

After successfully mounting, you can check the contents of the partition:

ls -la /mnt/ufs 

An offset is not needed when mounting a specific partition on a physical device, such as /dev/sdb2. In this case, the system already knows where the partition starts because the operating system reads the partition table from the device and manages access to each partition accordingly.

However, when working with a disk image, the partition table needs to be "emulated" manually — meaning you must locate the partition and specify the offset. This is because you're not mounting a physical device that automatically understands the partition structure, but rather a file that is a copy of the disk.

6
  • Could you explain how to determine the appropriate offset for the offset option to mount? Without that, your answer doesn’t add anything new to the existing answers. Commented Sep 28, 2024 at 16:04
  • Great suggestion, thanks. Commented Sep 29, 2024 at 22:44
  • Your initial answer had the correct offset, the new offset is wrong :-(. Since you’re mounting /dev/sdb2, calculating the offset of sdb2 inside sdb is not relevant here. Commented Sep 30, 2024 at 13:03
  • Thank you for the important note, I was in a hurry, I already corrected it Commented Oct 1, 2024 at 20:06
  • Like I said, your initial answer had the correct offset. Your update is still incorrect. Commented Oct 1, 2024 at 21:14

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.