How to Recover (Format) a PEN Drive on Linux


When recording an ISO image on a USB flash drive, for example images of operating systems, it is not usual to be able to reformat it in order to make it available again. In Windows or Mac environment we use an application called SD Memory Card Formatter from SD Association. On Linux we have to resort to the command line.


This instruction applies to the formatting of Pen Drives, SD cards or other storage devices, with a fat32 partition.


  1. Insert the Pen Drive and run the command 'lsblk' to identify the device.
    On my system the output of the command 'lsblk' shows the Pen Drive as 'sdc', a 16GB flash memory:

    [pratajo@amd64 ~]$ lsblk
    NAME                                      MAJ:MIN   RM         SIZE   RO   TYPE    MOUNTPOINT
    sda                                                8:0           0     223,6G      0    disk
    ├─sda1                                        8:1           0             1G      0    part     /boot
    └─sda2                                        8:2            0     222,6G      0  part
         ├─fedora_amd64-root     253:0           0           50G      0   lvm      /
         ├─fedora_amd64-swap   253:1           0             4G      0   lvm     [SWAP]
         └─fedora_amd64-home  253:2           0      168,6G     0   lvm      /home
    sdb                                                8:16         0           1,8T     0   disk
    ├─sdb1                                        8:17         0      488,3G     0   part
    ├─sdb2                                        8:18         0      488,3G     0   part
    ├─sdb3                                        8:19         0      488,3G     0   part
    └─sdb4                                        8:20         0      398,2G     0   part
    sdc                                                8:32         1       14,8G      0   disk
    └─sdc1                                        8:33         1          1,5G      0   part
    sr0                                              11:0           1      1024M      0   rom
    sr1                                              11:1           1      1024M      0   rom
    [pratajo@amd64 ~]$

    If in doubt, remove the Pen Drive and run the command again. The 'sdc' device will disappear. Insert the Pen Drive again.
  2. We will use the 'parted' tool. For that you need administrator rights:

    [pratajo@amd64 ~]$ su -
     (enter the root password)
    [root@amd64 ~]$
  3. Run the command 'parted' with the device name of the Pen Drive, in this case 'sdc'.
    >> Pay attention not to format the wrong drive <<

    [root@amd64 ~]# parted /dev/sdc
    GNU Parted 3.2
    Using /dev/sdc
    Welcome to GNU Parted! Type 'help' to view a list of commands.
  4. First, let's create the MBR partition table:

    (parted) mklabel msdos
  5. After creating the partition table, let's create a partition on the drive:

    (parted) mkpart primary fat32 1MiB 100%
    (parted) set 1 boot on
  6. Exit the 'parted' tool

    (parted) quit
  7. Format the partition in fat32. Confirm that you are going to format the 'sdc partition' and not itself, 'sdc':

    [pratajo@amd64 ~]$ mkfs.vfat /dev/sdc1


You can start using the Pen Drive.