Thursday, April 9, 2009

Formatting a Thumb/Flash Drive in Linux CLI

The ubiquitous flash/thumb drives, once a luxury among the geeks and techies is now staple among any self respecting computer user. Most Linux users are adept to use something like gparted or the Yast partitioner (in SLE/OpenSUSE) to format and/or rename the drive, but how to do it in CLI?

Insert the drive in the computer. It should automatically mount. To check which location and device assignment, from CLI use the mount command and it should display something like below:

/dev/sda3 on / type ext3 (rw,acl,user_xattr)
/proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
debugfs on /sys/kernel/debug type debugfs (rw)
udev on /dev type tmpfs (rw)
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
/dev/sda1 on /windows/c type fuseblk (rw,noexec,nosuid,nodev,allow_other,default_permissions,blksize=4096)
securityfs on /sys/kernel/security type securityfs (rw)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /home/eyeoh/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=eyeoh)
/dev/sdb1 on /media/disk type vfat (rw,nosuid,nodev,shortname=lower,flush,utf8,uid=1000)


So the thumb drive is mounted to /media/disk and the drive assignment is /dev/sdb1. The VFAT filetype is usually a dead give away as practically all thumb drives are formatted with VFAT (or FAT32).

Switch to root and unmount the drive:

#umount /media/disk

To format the drive to FAT32:

#mkfs.vfat /dev/sdb1

Rename the Flash/Thumb drive, ensure that mtools are installed:

#rpm -qa | grep mtools (in Fedora/OpenSUSE/RHEL/Centos/Mandriva)


#dpkg -l | grep mtools (in Debian/Ubuntu/Mepis)


Renaming the drive:

#mlabel -i /dev/sdb1 ::Thumbdrv

Where Thumbdrv is the name.

1 comment:

msian_tux_lover said...

Thanks for your kind comments. :)