Formatting a USB Drive on Linux

November 4, 2011 at 10:27 am | Posted in Oracle Developement | 7 Comments

This is something I just don’t do often enough to remember all the steps. So here is a little reminder for how to format a USB drive.

  • Insert the drive into the USB port
  • Check the bottom of /var/log/messages to see which device it is. You’ll see a message that looks something like this:
     Nov 4 08:44:38 svr: scsi6 : SCSI emulation for USB Mass Storage devices
     Nov 4 08:44:44 svr: Vendor: PNY Model: USB 2.0 FD Rev: 1638
     Nov 4 08:44:44 svr: Type: Direct-Access ANSI SCSI revision: 00
     Nov 4 08:44:44 svr: SCSI device sdd: 31703040 512-byte hdwr sectors (16232 MB)
     Nov 4 08:44:44 svr: sdd: Write Protect is off
     Nov 4 08:44:44 svr: sdd: assuming drive cache: write through
     Nov 4 08:44:44 svr: SCSI device sdd: 31703040 512-byte hdwr sectors (16232 MB)
     Nov 4 08:44:44 svr: sdd: Write Protect is off
     Nov 4 08:44:44 svr: sdd: assuming drive cache: write through
     Nov 4 08:44:44 svr: sdd: sdd1

Alternatively you can list /dev/disk/by-label:

# ls -l /dev/disk/by-label
total 0
lrwxrwxrwx 1 root root 10 May 17 09:15 1 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 17 09:15 boot1 -> ../../sda1
lrwxrwxrwx 1 root root 10 May 17 09:15 f68f102bae44 -> ../../sdb1
lrwxrwxrwx 1 root root 10 May 17 09:15 FreeAgent -> ../../sdd1

…or with fdisk:

# fdisk -l
Disk /dev/sdc: 750.1 GB, 750156374016 bytes
255 heads, 63 sectors/track, 91201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 91201 732572001 83 Linux

Here you can see my USB drive is sdd1.

In this case it is device sdd.

  • Format the device (in this case sdd) with fdisk:
    fdisk /dev/sdd
    • use ‘p’ to print the current partition table
    • use ‘d’ to delete partition(s)
    • use ‘n’ to create a new primary partition (p)
    • use ‘p’ to print the new partition table

    It should look something like this:

    Device Boot      Start         End      Blocks   Id  System
    /dev/sdd1               1        2293    15849189   83  Linux
    • use ‘w’ to write the new partition table
  • Create a new file system on the flash drive:
    mkfs -t vfat /dev/sdd1

    In this example I use the vfat filesystem. You can choose other filesystems like ext2 or ext3. To get a list of filesystem available (maked in blue below) use:

    ls -l /sbin/mkfs*
    -rwxr-xr-x. 1 root root 10336 May 21  2011 /sbin/mkfs
    -rwxr-xr-x. 1 root root 26208 May 21  2011 /sbin/mkfs.cramfs
    -rwxr-xr-x. 5 root root 66272 Mar 29  2011 /sbin/mkfs.ext2
    -rwxr-xr-x. 5 root root 66272 Mar 29  2011 /sbin/mkfs.ext3
    -rwxr-xr-x. 5 root root 66272 Mar 29  2011 /sbin/mkfs.ext4
    -rwxr-xr-x. 5 root root 66272 Mar 29  2011 /sbin/mkfs.ext4dev
    lrwxrwxrwx. 1 root root     7 Nov  6 20:17 /sbin/mkfs.msdos -> mkdosfs
    lrwxrwxrwx. 1 root root     7 Nov  6 20:17 /sbin/mkfs.vfat -> mkdosfs
  • Create a directory into which to mount the flash drive:
    mkdir /media/usb
  • Mount the flash drive:
    mount /dev/sdd1 /media/usb

And that should do it.

Additional info:

To list the drives by uuid use

ls -l /dev/disk/by-uuid

If you liked the post, please leave a comment or share/like it. Thanks! 🙂

Advertisements

7 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Good post. thanks!

  2. Great help! Many thanks!

  3. Useful, I will repost at my blog

  4. 83 Linux –> should be b Win95 if you want to use vfat

  5. Very good, tanks!

  6. thanks alot


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

Create a free website or blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: