Solved "gpart: Device busy" when trying to format external USB thumbdrive

I'm trying to experiment and learn more about the gpart utility.

When I use the gpart "destroy" option to erase my USB stick, I get the dreaded "gpart: Device busy" message.

I'm stuck. I've searched the web as well as looked at the gpart man pages, but I don't know how to deal with the device busy roadblock.

Suggestions?

Thank you,
Ed
 
It typically means a partion on the device is mounted.
Are you doing this in a window/desktop environment? If so some of them will automount partions on devices.
"mount" will show things mounted and may give a clue. Most external USB things are "/ dev/daN" so look for that.
 
You also get that message if there are still some partitions in the table. Don't need to be active, just exist. Technically the partition table is still "in use". Remove the partitions first, then destroy the table.
 
You also get that message if there are still some partitions. Don't need to be active, just exist. Technically the partition table is still "in use". Remove the partitions first, then destroy the table.
In this case you can use The -F flag.

gpart(8)
destroy Destroy the partitioning scheme as implemented by geom geom.

The destroy command accepts these options:

-F Forced destroying of the partition table even if it
is not empty.
 
Here's what I have:

root@freebsd:/home/ed # umount -f /dev/da0
umount: /dev/da0: unknown file system
root@freebsd:/home/ed # gpart destroy -F /dev/da0
gpart: Device busy
root@freebsd:/home/ed #

Thank you for your suggestions. Thoughts?

Ed
 
Ahh that looks like an automount from a DE thing.
sudo umount /media/da0s1

should unmount it then you should be able to do the gpart destroy
 
Looking at the path (/media/...) it's probably some desktop automount feature. You can try unmounting it; umount /dev/da0s1 but the automounting feature might immediately mount it again (although that normally only happens when something has been inserted; i.e. the stick being plugged in).
 
Looking at the path (/media/...) it's probably some desktop automount feature. You can try unmounting it; umount /dev/da0s1 but the automounting feature might immediately mount it again (although that normally only happens when something has been inserted; i.e. the stick being plugged in).
And this is why I've always detested this type of automounting.
Old fashioned NFS mounting of user home directories from shared workstations like old Vax-stations or Sun machines? Sure but automounting USB devices problematic. I believe that a lot of Federal systems explicitly disable things like this.
 
umount /media/da0s1 worked like a charm!

I'm almost finished. I run these commands:

gpart destroy -F /dev/da0
gpart create -s gpt /dev/da0
gpart add -t exfat -l BACKUP1 /dev/da0

and the final command says:

gpart: Invalid argument

I've dropped the -l BACKUP1 option, but I still get the same error.

???

Ed
 
Sure but automounting USB devices problematic. I believe that a lot of Federal systems explicitly disable things like this.
It could be worse. Like automatically starting an executable from an autorun.inf file the second you inserted that stick.
 
I've dropped the -l BACKUP1 option, but I still get the same error.
exfat isn't a valid partition type. There is no registered partition type for exFAT. Use ms-basic-data

Code:
     ms-basic-data          A basic data partition (BDP) for Microsoft
                            operating systems.  In the GPT this type is the
                            equivalent to partition types fat16, fat32 and
                            ntfs in MBR.  This type is used for GPT exFAT
                            partitions.  The scheme-specific type is
                            "!ebd0a0a2-b9e5-4433-87c0-68b6b72699c7" for GPT.
 
gpart add -t ms-basic-data -l BACKUP1 /dev/da0 worked great!

When I try to create the filesystem using: newfs exfat /dev/da0 , gpart shows me the command list of options, so there's something about this command it doesn't like.

???

Ed
 
gpart add -t ms-basic-data -l BACKUP1 /dev/da0 worked great!

When I try to create the filesystem using: newfs exfat /dev/da0 , gpart shows me the command list of options, so there's something about this command it doesn't like.

???

Ed
newfs is used to create UFS partitions so the command is incorrect. I think you should install the package containing exfat utilities/tools to create one.

Also you're specifying raw disk /dev/da0 instead of the created partition like /dev/da0p1 for example.
 
I wondered about that too, but I have already installed (by packages): fuse fusefs-exfat fusefs-ext2 fusefs-gphotofs fusefs-hfsfuse fusefs-jmtpfs fusefs-ntfs fusefs-smbnetfs fusefs-sshfs

Ed
 
pkg list fusefs-exfat
should show what things the package installed to your system, pick one of them that will probably contain something like mkfs or mkexfat etc.
 
Back
Top