Tag Archives: format

Formatting external disks for use with FreeBSD

A common question I get asked is how to reformat an external hard drive or USB penstick for use with FreeBSD.

NOTE: this will render the disk only usable in FreeBSD systems.  If you plug the disk into a windows computer, it will say it is not formatted.

First… plug the disk in, then check your console for details about the disk.  You can do this by typing:

tail /var/log/messages

You are looking for the disk name.  It will usually be something like da0 but it could be a different number at the end.

You may notice your disk has been automounted (if you’re running gnome for example) – check your current mounted disks with:


If your disk is mounted, you will need to unmount it before you can format it.  You can unmount it using is path (the bit after ” on ” in the output above).  If your disk was mounted on /media/usbdisk you would unmount with:

umount /media/usbdisk

Once the disk is unmounted (or if it wasnt already mounted) we need to wipe the start of the disk to remove any existing partitions.  You will need the disk name from the console earlier.  I will assume it is da0.  Wipe the start of the drive with:

dd if=/dev/zero of=/dev/da0 bs=1m count=128

This command will write zero’d (blank) data to the first 128MB of the disk at da0.

Next we are ready to format the disk for FreeBSD’s use using UFS2 filesystem.  You will need to decide a name/label for the drive.  I will assume it is usbdisk here.  Format with the following command:

newfs -L usbdisk -O2 -U -m 6 /dev/da0

Once the format is complete, any automounter will auto-mount the disk for you.  Check with the mount command to find out.

If the disk is not mounted, you can mount it with the following command:

mount /dev/ufs/usbdisk /mnt

By default, FreeBSD filesystems have ownership by root only.  You will most likely want to change the ownership to your user on the system.  If your username is ‘dan’ you would do this like so:

chown dan /mnt

That should be everything 🙂

Partitioning/Formatting disks in FreeBSD (manual method)

Here’s how to manually partition and format a disk in FreeBSD manually.

I’m going to assume you want to use the entire disk (/dev/da0)  in 1 partition and all data on it will be destroyed…

First, lets wipe out any data that might be on it…  we’ll destroy the GPT table (if one exists), and blank out the first chunk of the disk to destroy any MBR partition tables that might exist:

gpt destroy /dev/da0

dd if=/dev/zero of=/dev/da0 bs=1m count=128

Now we will create a single (bootable/active) partition spanning the entire disk.  You may not want it to be bootable, but it doesn’t hurt anyway so why not:

fdisk -BI /dev/da0

Now we will write a standard (bootable) freebsd disk label to the 1st partition.  The standard label has the entire space usable as “a”:

bsdlabel -wB /dev/da0s1

Now we will format it for FreeBSD to use.  We will use UFS2 with soft updates…

newfs -O2 -U /dev/da0s1a

Now all you need to do is mount it… e.g. to mount it as /mnt:

mount /dev/da0s1a /mnt

if you want it to mount on every boot, add it to /etc/fstab like this:

/dev/da0s1a     /mnt     ufs     rw     2     2

All done 🙂