Subhadip's Blog

My experience with the computing world!

Format USB drive after installing Debian from it

If you have used an USB drive to write iso images to before installing Debian or recent versions of Ubuntu, here are the steps to reclaim it after installation is over.

  1. Open a terminal and list the available device names using the following command:
    lsblk

    which should show you an output like the one below:

  2. Identify the device name of your USB drive. Extreme caution should be taken while at it because wrong device names can potentially wipe your entire hard disk. In this case, the USB drive that we want to format is sdb.
  3. Writing the iso image to the USB drive has made it a read-only device. To change it back, the partition table needs to broken. Issue the below command after replacing sdb with the device name identified in the previous step:
    sudo dd if=/dev/zero of=/dev/sdb bs=1M && sync

    This step might take some time to complete depending upon the size of the USB drive. So be patient. When it is over, you should see an output like the below:

  4. Next you need to create a new partition. First enter the following command after replacing sdb with your device name:
    sudo fdisk /dev/sdb

    You should see a prompt like below


    Enter n to create a new partition, press enter to go with the default options until the next Command prompt comes, then enter w to write the changes to disk.

  5. Enter the following command to check if the device partition settings have been refreshed. If not, unplug and replug the USB drive.
    lsblk
  6. Enter the following command to format the partition to FAT after replacing sdb with your device name and <label> with your label of choice.
    sudo mkfs.vfat /dev/sdb1 -n <label>

And now your USB drive should become usable again.



Tags