Formatting a USB Drive on Linux

November 4, 2011 at 10:27 am | Posted in Oracle Developement | Leave a comment

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

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.

Advertisement

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

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 )

Connecting to %s

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.

Join 25 other followers