How to recover USB flash drive functionality after having used dd?

14,279

Solution 1

In the following steps I am assuming as an example that you want to restore an 8GB USB flash drive to usable condition after writing the Ubuntu iso to it using dd, although of course the exact size of the USB flash drive is not important. The results of these steps are reproducible. I reformatted 2 USB flash drives with the following steps after writing Ubuntu ISOs to them with dd. As a side remark, it's kind of annoying to use dd instead of a GUI program like Startup Disk Creator, but dd is the only program I have found that works for writing the Ubuntu Minimal CD to a bootable USB flash drive.

  1. Remove all of your USB devices except for the 8GB USB flash drive that you want to reformat, so you won't get confused about the device name of the USB flash drive later on.

  2. List all the partitions.

     sudo fdisk -l
    

    Search the results of the command for output that looks like this:

     Disk /dev/sdc: 7864 MB, 7864320000 bytes
     30 heads, 33 sectors/track, 15515 cylinders, total 15360000 sectors
     Units = sectors of 1 * 512 = 512 bytes
     Sector size (logical/physical): 512 bytes / 512 bytes
     I/O size (minimum/optimal): 512 bytes / 512 bytes
     Disk identifier: 0x00016288
    
        Device Boot      Start         End      Blocks   Id  System
     /dev/sdc1   *        2048    15359999     7678976    b  W95 FAT32
    

    If you see something like 7864 MB (8GB) in the output (see the example output above), then that is your 8GB USB flash drive. In this example it is called /dev/sdc. Now open the Disks application from the Dash and check again to make sure that the device name of your 8GB flash drive is the same as what you got from running the command: sudo fdisk -l.

  3. Create a partition table on the disk of type msdos, sometimes known as Master Boot Record (MBR).

     sudo parted /dev/sdc mklabel msdos
    

    In this example I used /dev/sdc for the name of the device which is what was found in the results of step 2. I can't stress strongly enough how important it is to verify the device name before running this step!

    Warning: If you type the wrong device name you may overwrite your operating system or another one of your partitions containing important personal files!!! So be careful and check the device name a second time. Open the Disks application and check the device name of your 8GB USB flash drive in Disks. It should be the same device name!!! Now check again! You don't want to accidentally type the wrong device name!

  4. Add an empty "primary" partition, which will hold a FAT filesystem later.

     sudo parted -a none /dev/sdc mkpart primary fat32 0 8192 
    

    Once again in this example I used /dev/sdc for the name of the device which is what was found in the results of step 2. The command specifies the start point (from 0 MB) to the end point (8192 MB). If the 8GB USB flash drive does not have the full 8192 MB space, parted will adjust it automatically. If the terminal returns a message that the start point can't start at 0 MB and you have to use some other small number close to 0 MB, type Y to accept this. Note the command is creating a single, primary partition on the whole disk.

    This newly created partition will have the ID /dev/sdc1. That is because the device name in this example is /dev/sdc and the 1 at the end is because it is the first partition on that device.

  5. Create a FAT filesystem on the /dev/sdc1 partition by formatting the partition.

     mkfs.vfat -n "8GB-USB" /dev/sdc1
    

    /dev/sdc1 is the partition ID from step 4. "8GB-USB" is the partition label, which can be your own choice of label, just enclose the label inside two double quote characters.

You now have a ready-to-use reformatted USB flash drive with an 8GB FAT partition.

Solution 2

If you want an easy and safe way to restore a USB pendrive to a standard storage device, you can use mkusb.

enter image description here

Find more details at the following links,

mkusb - how to install mkusb from a PPA ... - Ubuntu help link

mkusb/wipe - wipe and restore - Ubuntu help link

Restore to a standard storage device - AskUbuntu link

Installation/FromUSBStick - Postrequisites - restore the USB stick - Ubuntu help link

Solution 3

You can easily get your drive working as it previously had been.

  1. Use any windows pc , and download Rufus Utility on it.

  2. Plug in your drive in the pc and launch Rufus.

  3. Uncheck all options.

  4. Then check format option. And proceed. Your drive will get formatted. The usb drive will become fine as you want it.

Share:
14,279

Related videos on Youtube

karel
Author by

karel

Updated on September 18, 2022

Comments

  • karel
    karel over 1 year

    I have been installing Linux on my laptop via a bootable USB flash drive and I was having difficulty, so I ran the following command:

    dd if=/dev/zero of=/dev/sdb
    

    Was this a huge mistake? Did I wipe out some of the software that allows the USB drive to properly function?

    Now my computer no longer recognizes my device (which was previously in /media/USERNAME), although it makes a sound when I plug it in. I tried to mount it via How to access a USB flash drive from the terminal?. The following output shows up when I use sudo fdisk -l :

    Disk /dev/sdb: 14.7 GiB, 15728640000 bytes, 30720000 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x003e98d7
    
    Device     Boot Start      End  Sectors  Size Id Type
    /dev/sdb1  *       32 30719999 30719968 14.7G  c W95 FAT32 (LBA)
    

    When I try to mount it I get the following results:

    mkdir /media/usb
    sudo mount /dev/sdb1 /media/usb
    
    mount: wrong fs type, bad option, bad superblock on /dev/sdb,
       missing codepage or helper program, or other error
    
           In some cases useful info is found in syslog - try
           dmesg | tail or so.
    

    I found this question, but this and its references don't answer my question.

    • Admin
      Admin almost 6 years
      You can use mkusb according to this link, Restore to a standard storage device.
    • Admin
      Admin almost 6 years
      What you did is zero out the flash drive, now you need to add a partition table and a file system, in order to use it, easiest way I know is to take Sudodus's advice above. You can also use Gparted.
  • Fabby
    Fabby over 5 years
    fdisk is deprecated, so an edit and an upvote.
  • sudodus
    sudodus over 5 years
    @Fabby, in 18.04.1 LTS there is a new and better version fdisk from util-linux 2.31.1 and man fdisk is dated February 2016. It can manage also gpt. lsblk -fm is another good alternative, that can also identify iso file systems (for example in pendrives with a cloned live system).
  • Fabby
    Fabby over 5 years
    Thanks for the info. That's why I always leave a message when I edit... @sudodus
  • root-user
    root-user over 5 years
    It is the easiest solution of all.
  • Admin
    Admin over 5 years
    can gparted be used? I didn't use dd, but gparted always fixed it for me.
  • sudodus
    sudodus over 5 years
    @cipricus, Yes, you can often use gparted :-) But sometimes there are some data near the head end of the drive, that will make gparted confused. You can remove those data by overwriting the first mibibyte with zeros. This is done by mkusb before it creates any file systems (except when cloning because the cloning process will overwrite it anyway).