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