Format PenDrive using Linux Command

Here is a tutorial to Format your Pendrive or Restore it to original format or partition your pendrive in Simple Steps. There are several easy way too to format the disk like using Disk Utility but this tutorial are those who would like to do the same task from command line. So here we go for format pen drive using linux command

Step 1 – Check the letter for your USB drive

# fdisk -l

Now for unpartitoned disk output would be like that in my case

Disk /dev/sdb: 4023 MB, 4023385600 bytes
124 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System

Step 2 – Delete or Make primary partion on your disk

# fdisk /dev/sdb
Output would be
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Step 3 – Now use options to make changes to Disk

You can use m for help, press m

You can see the help listing like this

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Step 4 – Creating new partiton

Press n for new partion

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

Then press p

Then It asks for partiton number

Partition number (1-4):

Then press 1, In case If you already have primary partion then output would be like this

else

First sector (62-7858174, default 62): 

Press enter to choose default values

Last sector, +sectors or +size{K,M,G} (62-7858174, default 7858174)

Then again Enter to use defualt end values

and at last to write these changes to disk you have to type w to make changes written to disk

Command (m for help): w

Then output would be like this
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Once you will reboot you can see the new partioning, you can see format and partion your pendrive using Disk Utility, please check it from links below to it

You may also like...