File system support on FreeBSD falls onto UFS (UNIX File System) or originally named the FFS (Fast File System and on ZFS (Zetabyte File System). If you are using your box as a desktop-workstation you will use USB drives to share files with other systems, to carry things on your pocket or safe the day by plugging some drive into a soon to be dead box which is causing some trouble and you need to rescue some valuable data. Or whatever that comes to your mind. This is a short simple guide on how to format an USB drive on FreeBSD.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.
Interoperability between different operating systems when it falls onto USB drives is often carried by the limited but still functional FAT32 file system type. By formatting a drive with FAT32 you will be able to share files between devices equipped with different operating systems, from Windows to Linux, through Mac, and of course FreeBSD. The limitation though is you won’t be able to pass around files larger than 4GB. But quite often this is not the case and when that is needed you are usually transferring the files through the network.
In order to format an USB drive on FreeBSD we’ll use the gpart tool. Don’t be confused with the GNU/Linux gparted tool. They are different and unrelated.
First we will list the devices by launching:
# gpart show
USB drives we’ll be presented as da0, da1, da2, etc. So if just one drive is plugged we should see a da0 device. If it comes formatted the command will let us know what kind of file system it’s on the drive.
albert@Workstation:~ % gpart show
=> 40 976773088 ada0 GPT (466G)
40 409600 1 efi (200M)
409640 1024 2 freebsd-boot (512K)
410664 984 - free - (492K)
411648 4194304 3 freebsd-swap (2.0G)
4605952 972167168 4 freebsd-zfs (464G)
976773120 8 - free - (4.0K)
=> 40 15148528 da0 GPT (7.2G)
40 15148528 1 freebsd-ufs (7.2G)
albert@Workstation:~ %
As you can see there are two drives shown here. An ada0 drive which is the main drive on this box which is where the OS is running. And there is a da0 drive which is our USB drive. This da0 drive is formatted with the UFS file system. If it were a Linux or Windows file system it would be also be shown.
Let’s imagine we want to share content with a Windows box so we have to format the USB drive with FAT32. We will first erase the format table of the drive. We’ll do that by issuing the following command as root (or using sudo):
# gpart destroy -F /dev/da0
Once this is done we will create a new partition table on the device. We’ll use the MBR partition table format because FAT32 needs this.
# gpart create -s mbr /dev/da0
Once this is done we will add the file system type to the drive by issuing:
# gpart add -t fat32 /dev/da0
We will now fill the drive with the fat32 file system blocks.
# newfs_msdos -L FILES -F 32 /dev/da0s1
So all the steps should look like:
albert@Workstation:~ % sudo gpart destroy -F /dev/da0
da0 destroyed
albert@Workstation:~ % sudo gpart create -s mbr /dev/da0
da0 created
albert@Workstation:~ % sudo gpart add -t fat32 /dev/da0
da0s1 added
albert@Workstation:~ % sudo newfs_msdos -L FILES -F 32 /dev/da0s1
newfs_msdos: trim 6 sectors to adjust to a multiple of 63
/dev/da0s1: 15144768 sectors in 236637 FAT32 clusters (32768 bytes/cluster)
BytesPerSec=512 SecPerClust=64 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=15148539 FATsecs=1849 RootCluster=2 FSInfo=1 Backup=2
albert@Workstation:~ %
Once here we can plug and unplug our USB drive and share files with any box supporting the FAT32 file system, which is almost all modern desktop operating systems. Following a cheat sheet:
gpart destroy -F /dev/da0
gpart create -s mbr /dev/da0
gpart add -t fat32 /dev/da0
newfs_msdos -L FILES -F 32 /dev/da0s1
Now it’s time to demonstrate the same procedure but using the native UFS file system.
Again as before we ‘clean’ the USB drive and erase the old partition table entry:
# gpart destroy -F /dev/da0
Then we create a new partition table. This time we will use the GPT format.
# gpart create -s gpt /dev/da0
After this we will set the new file system format and as we said we will use the native UFS one. Mind the UNIX File System was also shared, and still should be, with Solaris (at least with old releases). Interoperability between the two is very limited if any since the Solaris implementation drifted away very soon but you may be able to read some old formatted drives with Sun’s bits.
# gpart add -t freebsd-ufs /dev/da0
Once we’ve given the format we will fill the drive with the blocks.
# newfs /dev/da0p1
So now we have an USB drive formatted with the UFS file system. You can now share files with other FreeBSD boxes. GNU/Linux has very limitted support and it may only be able to read from the drive. Windows may be able to make use of it but through a third party program. The Mac had support for UFS file system but it was again their own implementation and it was abandonned many years ago.
A short cheat sheet for the ones in a hurry:
gpart destroy -F /dev/da0
gpart create -s gpt /dev/da0
gpart add -t freebsd-ufs /dev/da0
newfs /dev/da0p1
So this is all on how to format an USB drive on FreeBSD. Don’t miss a previous article on how to manipulate USB devices on FreeBSD.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.