Admin... by accident!

You may have chosen to be an admin. I didn't!

  • Home
  • FreeBSD
  • GNU/Linux
  • Security
  • Network
  • Virtualization
  • Politics
  • Github
  • Donate
  • Me

How to format an USB drive on FreeBSD

June 22, 2019 by Albert Valbuena

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.

 

Filed Under: FreeBSD, How To's

Recent Posts

  • How to install Redis for WordPress on FreeBSD
  • How to compile cloudflared in FreeBSD 13/14
  • How to configure FreeBSD to use a webcam (version 12 and 13)
  • Symbolic and Hard Links in UNIX and Linux
  • How to import iocage jails to Bastille on FreeBSD 13
  • How to load and unload kernel modules in Linux
  • How to use find in GNU/Linux and FreeBSD
  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel
  • How to use Cloudflare’s Argo Tunnel service to publish a website on FreeBSD 12/13
  • How to setup MariaDB master-slave replication on FreeBSD
  • How to upload a FreeBSD custom image on DigitalOcean
  • How to install Drupal 9 on FreeBSD 13.0
  • How to manage site visitors based on IP Geolocation
  • How to enable Geolocation in AWStats on FreeBSD 13.0
  • How to install AWStats on FreeBSD 13.0
  • How to configure Modsecurity 3 for WordPress on FreeBSD
  • How to configure Apache HTTP with a TLS reverse proxy backend on FreeBSD
  • How to detect a WAF – Web Application Firewall

Archives

  • November 2024
  • October 2024
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • April 2022
  • March 2022
  • October 2021
  • September 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • September 2018
  • June 2018
  • May 2018
  • April 2018
  • February 2018
  • January 2018
  • November 2017
  • April 2017

RSS Admin… by accident!

  • How to install Redis for WordPress on FreeBSD
  • How to compile cloudflared in FreeBSD 13/14
  • How to configure FreeBSD to use a webcam (version 12 and 13)
  • Symbolic and Hard Links in UNIX and Linux
  • How to import iocage jails to Bastille on FreeBSD 13
  • How to load and unload kernel modules in Linux
  • How to use find in GNU/Linux and FreeBSD
  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in