Format a USB pendrive from terminal.
So your pendrive refuses to get formatted via the GUI tools. Just do this and you'll have what you need! The post may seem a little long but its really simple to do this.
Go to the terminal and see if your device is showing up there by running the following command:
lsblk
This comand will give a table kind of output and you can find out your device by its size(eg. 8G = 8Gb). Note the /dev/_ path for your device.
Note : Throughout this post i am assuming you recognized your device and noted its /dev/sd_ path and i will be referring to it by the "/dev/sd_" in all of this post.
Next zero out all the data present in your device with following command:
sudo dd if=/dev/zero of=/dev/sd_ bs=4k; sync
dd is the disk dump command and bs is the block size.
This might take a while to finish. And you can skip this step if not required. This is like the windows long format and if you skip this step it will be like the quick format in windows.
Next, let us make a new partition table on your device. You can run the following command to do this:
sudo fdisk /dev/sd_
This will take you into the fdisk program and will ask you various options as to what you want to do with your /dev/sd_ device. You can do the following steps.
make a new partition table:
press letter o,this will create a new empty DOS partition table.
next, press the letter n, this will create a new partition. You will be prompted for the partition size you wish to make and you can go ahead as per your requirement or just keep pressing the enter key for the default options.
As a last step to fdisk, press letter w, this will write the table to the device and exit.
Now if you run the lsblk command again you can see you just have a single partition on your device /dev/sd_.
The final step is the formatting:
sudo mkfs.vfat /dev/sd_
After this is done, you can eject your device by issuing the following command:
sudo eject /dev/sd_.
And your done with formatting your device using terminal.
Go to the terminal and see if your device is showing up there by running the following command:
lsblk
This comand will give a table kind of output and you can find out your device by its size(eg. 8G = 8Gb). Note the /dev/_ path for your device.
Note : Throughout this post i am assuming you recognized your device and noted its /dev/sd_ path and i will be referring to it by the "/dev/sd_" in all of this post.
Next zero out all the data present in your device with following command:
sudo dd if=/dev/zero of=/dev/sd_ bs=4k; sync
dd is the disk dump command and bs is the block size.
This might take a while to finish. And you can skip this step if not required. This is like the windows long format and if you skip this step it will be like the quick format in windows.
Next, let us make a new partition table on your device. You can run the following command to do this:
sudo fdisk /dev/sd_
This will take you into the fdisk program and will ask you various options as to what you want to do with your /dev/sd_ device. You can do the following steps.
make a new partition table:
press letter o,this will create a new empty DOS partition table.
next, press the letter n, this will create a new partition. You will be prompted for the partition size you wish to make and you can go ahead as per your requirement or just keep pressing the enter key for the default options.
As a last step to fdisk, press letter w, this will write the table to the device and exit.
Now if you run the lsblk command again you can see you just have a single partition on your device /dev/sd_.
The final step is the formatting:
sudo mkfs.vfat /dev/sd_
After this is done, you can eject your device by issuing the following command:
sudo eject /dev/sd_.
And your done with formatting your device using terminal.
Comments
Post a Comment