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:

mount

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 :-)

5 thoughts on “Formatting external disks for use with FreeBSD

  1. Richard McCord

    Thank you so much! Your step-by-step instructions helped me do what I absolutely, positively HAD to get done and which no one else seems to have bothered addressing.

  2. Bo

    I can’t get as far as you’re getting. Here’s my output from /var/log/messages:

    —–
    Nov 19 11:52:42 cw kernel: ugen2.2: at usbus2
    Nov 19 11:52:42 cw kernel: umass0: on usbus2
    Nov 19 11:52:42 cw kernel: umass0: SCSI over Bulk-Only; quirks = 0×4101
    Nov 19 11:52:42 cw kernel: umass0:8:0:-1: Attached to scbus8
    Nov 19 11:52:52 cw kernel: (da0:umass-sim0:0:0:0): got CAM status 0×4
    Nov 19 11:52:52 cw kernel: (da0:umass-sim0:0:0:0): fatal error, failed to attach to device
    Nov 19 11:52:52 cw kernel: (da0:umass-sim0:0:0:0): lost device – 0 outstanding, 4 refs
    Nov 19 11:52:52 cw kernel: (da0:umass-sim0:0:0:0): removing device entry
    —–

    But, I try to dd it anyway:

    root@cw:/root # dd if=/dev/zero of=/dev/scbus8 bs=1m count=128
    dd: /dev/scbus8: Operation not supported

    Any ideas?

  3. Bo

    Incidentally, I also get the same with:

    root@cw:/root # dd if=/dev/zero of=/dev/da0 bs=1m count=128
    dd: /dev/da0: Operation not supported

  4. dan Post author

    Unfortunately, it’s saying there’s an issue attaching the disk (i’ve never seen that before)
    Unless you can resolve that, you won’t be able to use it in FreeBSD at all.
    I’d suggest checking the drive on another computer or OS to ensure there’s not a problem with the drive itself.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>