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 🙂
Thanks. This helped me debug some errors in FreeNAS.
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.
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 = 0x4101
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 0x4
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
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
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.