# Mini-Mini-Howto: Mount FreeBSD Filesystems (UFS1 and UFS2)

## daff

A very short Howto on mounting UFS partitions. FreeBSD, OpenBSD and NetBSD use the UFS file system and lay out the disk differently from Linux. I've seen a lot of posts that all ask more or less the same things and describe the same problems. 

These problems were

When trying to mount a UFS partition mount would bail with an error message like the following:

```

mount: wrong fs type, bad option, bad superblock on /dev/hdb1,

       or too many mounted file systems 

```

Linux would only see the first partition on the BSD disk, i.e. only the BSD / partition, no other partitions would be available (i.e. no BSD /usr, no BSD /var, etc.)

Here's how I solved it with/for FreeBSD. This was done on a gentoo-dev-sources 2.6.7-r12 machine.

Description of FreeBSD disk layout

What is known as a partition under Linux is called a slice under FreeBSD. Such a slice holds a set of (FreeBSD) partitions (which are created by applying a BSD disklabel). These partitions are formatted with the UFS file system and get mounted under /, /usr, /var, and so on. 

When FreeBSD occupies the whole disk then there's only one slice (almost as big as the disk itself). Using Linux's fdisk on that disk shows only the slice, not the partitions within the slice.

FreeBSD names the devices thus (for IDE drives): 

/dev/ad0 -- The whole disk

/dev/ad0s1 -- The first slice on the first disk

/dev/ad0s1a -- The first partition on the first slice on the first disk

/dev/ad0s1b -- The second partition on the first slice on the first disk

...

/dev/ad4s2f -- The sixth partition on the second slice on the fourth disk

FreeBSD also follows some tradition on which partition gets which name. Suppose we work on the first disk and the first slice. Typically the / partition is /dev/ad0s1a, /var gets /dev/ad0s1e and /usr gets /dev/ad0s1f.

There are two types of UFS for BSD. UFS1 is used in FreeBSD 4-STABLE as the default, UFS2 became default as of FreeBSD 5.1. Both seem to be supported in recent 2.6 kernels.

See here (FreeBSD handbook: pre-install tasks), here (FreeBSD handbook: allocating disk space), here and here for further information.

BSD/UFS disks on Linux

Linux doesn't know about slices. The BSD partitions are represented just like any other partition types. So /dev/ad0s1a under FreeBSD becomes /dev/hda1 under Linux, /dev/ad0s1f is /dev/hda8 and so on. Linux only sees partitions other than /dev/ad0s1a if the kernel supports BSD disklabels (next section).

Preparing the kernel for UFS and BSD disklabels

Activate UFS support:

```

Filesystems -> Miscellaneous filesystems -> 

<*> UFS file system support (read only)

```

Then allow for BSD disklabels:

```

Filesystems -> Partition types -> 

[*] Advanced partition selection

[*]   PC BIOS (MSDOS partition tables) support                                           

[*]     BSD disklabel (FreeBSD partition tables) support 

```

Recompile the kernel, install it and reboot.

```

# make 

# mount /boot

# cp arch/i386/boot/bzImage /boot/kernel

# reboot

```

Mounting

Depending on whether your FreeBSD partitions are of type UFS1 or UFS2 you need to apply different mount options. ufstype=44bsd is for UFS1, ufstype=ufs2 for UFS2.

A FreeBSD / partition (/dev/ad0s1a) of type UFS1 would be mounted thus:

```

# mount -r -t ufs -o ufstype=44bsd /dev/hda1 /mnt

```

This tells mount to mount the partition read-only and apply the mount option ufstype=44bsd to tell the kernel it is of type UFS1.

```

# mount -r -t ufs -o ufstype=44bsd /dev/hda8 /mnt/usr

```

This would mount the FreeBSD /usr partition on /mnt/usr. 

Notes

I only have disks of type UFS1 so I can't verify that it is possible to mix UFS1 and UFS2 mounts. For example the default setup under FreeBSD 5.1 onwards is to create a UFS1-type / partition and UFS2 partitions for everything else (/var, /usr, ...).

Theoretically it should be possible to do this:

```

# mount -r -t ufs -o ufstype=44bsd /dev/hda1 /mnt

# mount -r -t ufs -o ufstype=ufs2 /dev/hda8 /mnt/usr

```

As said, I can't verify that but it seems reasonable.

If you find any errors or mishaps in this Mini-howto please point them out.

----------

## Moloch

Thanks! Although I could have used this howto 4 weeks ago.   :Wink: 

----------

## dob

nice one  :Very Happy: 

----------

## isaacpeel

I've followed your mini how-to and am still unable to mount my ufs drive.  I get the following output:

#mount -r -t ufs -o ufstype=44bsd /dev/hdc1 /music

mount: unknown filesystem type 'ufs'

I have the following two lines in my kernel config file

CONFIG_UFS_FS=y

CONFIG_UFS_FS_WRITE=y (note: I've tried it with out this one too)

Any ideas?  I'm new to linux, just switching over from freeBSD.  Is there a way I can check to see if these new kernel options were installed correctly?

----------

## isaacpeel

Pay me no mind I've figured it out.  Thanks for the how-to.

----------

## PoUaScAiLLe

Thx for this how to very usefull for me:D

----------

## Gnux

Nice tip, just one addenda:

```
mount -t ufs -o ufstype=44bsd etc...
```

does not work for me with a freebsd 6.0... To mount this block I have to type:

```
mount -t ufs -o ufstype=5xbsd etc...
```

But this is not very practicable (a swap block between the two (in ext2fs for ex) worth it really much more)

----------

## kwisatz_haderais

thanks for the howto, however... doesn't really work for me  :Sad: 

 *Quote:*   

> usb 1-1: new high speed USB device using ehci_hcd and address 8
> 
> usb 1-1: configuration #1 chosen from 1 choice
> 
> scsi1 : SCSI emulation for USB Mass Storage devices
> ...

 

a command like

```
mount -r -t ufs -o ufstype=ufs2 /dev/sda /mnt/tmp/

```

results in:  *Quote:*   

> ufs_read_super: bad magic number

 

although it says sda1 in dmesg, there's no such device in /dev

sda is the only one.

The hdd works on my freebsd server though...

----------

## mofa

i have the same problem with my firewire hd.  

 *kwisatz_haderais wrote:*   

> thanks for the howto, however... doesn't really work for me 
> 
>  *Quote:*   usb 1-1: new high speed USB device using ehci_hcd and address 8
> 
> usb 1-1: configuration #1 chosen from 1 choice
> ...

 

----------

## gohmdoree

Thanks for this mini howto.  helped me a lot.

----------

