jump to navigation

Linux: Format Your USB Drive Via Command Line December 11, 2010

Posted by Tournas Dimitrios in Linux.

Formatting your USB memory pen / stick via command line is pretty easy. Once you know how to do it, that is.

  • 1) Insert your usb memory pen / stick  or whatever into the USB drive  (usually CentOs will auto-mount the device ) and immediately after that, open a terminal and one of these commands :
    • lsusb  (by default installed)
    • less  /var/log/messages  |grep  /dev/sd
    • dmesg  | tail
    • dmesg | grep sd
    • lsscsi

lsscsi lists SCSI devices (or hosts) and their attributes . It is not a default utility on CentOs , thus it must installed separately (from epel repository) .

yum install lsscsi

  • 2. Unmount your USB drive using the following command:

umount /dev/sd[xx]   

Where “sd[x]” is your media drive you had to remember at step 1.

USB drives (including USB keys ) appear on the SCSI bus. Typically, you’ll see them as “the next ” SCSI disk . So , if you already have an sda , the USB device will appear as sdb. The USB drive normally has a partition on it . To mount it , you must mount this partition .The numbering of partitions on USB drives works like the numbering of partitions on normal hard drives (from the Linux kernel perspective , there isn’t really a difference between these two different device types). So to mount the partition on a USB drive that has become available as /dev/sdb , you would typically use mount /dev/sdb1  /somewhere .

  • 3. Format the drive using the following command:  

mkfs.vfat  /dev/sd[xx]

  • 4. Mount the drive again on your local filesystem  :

mount /dev/sd[xx]   /media/testmount



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s