Format a drive on Linux – CLI

Really simple. But i keep forgetting this all the time. So wanted to write this down somewhere.

Find the drive that you want to erase.
fdisk -l
You will require root permission for this. So do what is necessary for that. su -c or sudo or whatever. This lists all the drives that you have in your system with their addresses. Usually with just one hard disk, and another target drive, the target drive should be /dev/sdb and your hard disk should be /dev/sda.

Now type in,
mkfs.vfat -I /dev/sdx
This should begin formatting. This would require root permission as well. Replace sdx with what ever drive is your target.
You are done.

There is a way to manually write zeros as well. You do this by typing in
dd if=/dev/zero of=/dev/sdx
if is the input file system. of is the output file system. What you are basically doing is writing zeros on the output file system. Here again, replace sdx with your target drive. Once this is done, you can use the mkfs.vfat command used above to format the drive to a fat file system.

Advertisements

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