Can't format my usb drive. I have already tried with mkdosfs and gparted
I have a MicroSD card in a USB adapter (which plugs into a USB port on my machine, and acts like a USB flash drive). I was using Unetbootin to make this a bootable USB flash drive with Kubuntu. But I needed to cancel while it was working. So I killed the Unetbootin process from the console.
Since then, I can't format the MicroSD or delete the folder that Kubuntu made. I have also tried mkdosfs
, with no success. I can't mount the drive anymore either? What can I do to make this drive usable again?
Trying to create a new partition table in GParted, as described in Eliah Kagan's answer, does not work. It fails with the error message "imposible crear tabla de particiones" ("unable to create a partition table").
Solution 1:
Analysis of the problem
Memory cards and USB pendrives have the same kind of hardware inside, so the same methods are relevant to both kinds of devices. The term 'drive' can refer to a USB pendrive as well as a memory card (and the memory card can be connected via a USB adapter or a built-in slot in the computer).
Confusion: There is some data in the drive, that makes the partitioning tool confused, to think that the drive does not work. In this case you can simply 'wipe' part of the drive (overwrite with zeros). It is usually enough to wipe the first megabyte, the megabyte at the head end of the drive.
-
The drive is read-only: I do not mean that there is a read-only file system, but that the drive is readable but not writable (like a CDROM or DVD). This might be caused by some help system or competing system, so it is worthwhile to try according to this list,
- On some pendrives and on many memory cards there is a small mechanical switch for write protection, that can toggle between read/write and read-only. You might have set it read-only without intention.
- Reboot the computer and try again to restore or wipe the first megabyte with mkusb.
- Disconnect other USB devices. Sometimes USB devices can disturb the function for each other.
- Try other USB ports, and/or other card adapters.
- Try another computer.
- Try another operating system (Windows, MacOS) in another computer.
- If you still cannot wipe the first megabyte of the drive, and the drive is read-only, it is probably 'gridlocked', and the next stage is that it will be completely 'bricked'. There is a limit, when you have to accept that the pendrive is damaged beyond repair, at least with tools available to normal users like you and me. See this link: Pendrive lifetime
-
The drive cannot be found: In order to use the tools for repair and partitioning, that are available to normal users like you and me, the drive must be recognized by the computer's system and listed for example by the command line tool
lsusb
orlspci
. You get more details with the verbose optionlsusb -v
The drive must also be recognized as a mass storage device for example by the command line tool
lsblk
. The two command linessudo lsblk -f sudo lsblk -m
should list the drive in a way, so that you can identify it. The following command line is even better, because it lists also the model (which typically includes the brand name and/or model of a pendrive or a card adapter).
sudo lsblk -o model,name,size,fstype,label,mountpoint
(You can copy and paste from here to a terminal window in order to avoid typing errors.)
Looking at a persistent live drive
/dev/sdd
and a cloned live-only drive/dev/sde
can produce the following output,MODEL NAME SIZE FSTYPE LABEL MOUNTPOINT ... Extreme sdd 14,6G ├─sdd1 4,5G ntfs usbdata /media/sudodus/usbdata ├─sdd2 1M ├─sdd3 244M vfat usbboot ├─sdd4 874M iso9660 Lubuntu 16.04.1 LTS amd64 /media/sudodus/Lubuntu 16.04.1 LTS amd64 └─sdd5 9,1G ext4 casper-rw /media/sudodus/casper-rw Transcend 4GB sde 3,8G iso9660 Lubuntu 16.04.1 LTS i386 └─sde1 858M iso9660 Lubuntu 16.04.1 LTS i386 ...
A memory card plugged into an internal slot may be recognized as
/dev/mmcblk0
as illustrated by the following example, where an Intel NUC is booted from a microSD card in an adapter in the SD card slot,MODEL NAME SIZE FSTYPE LABEL MOUNTPOINT mmcblk0 29.7G ├─mmcblk0p1 300M vfat EFI /boot/efi ├─mmcblk0p2 1M ├─mmcblk0p3 6.5G ext4 root / └─mmcblk0p4 512M swap [SWAP]
In this case, no model name is listed. You can probably be convinced, that you are 'looking at' the card anyway, but there are other tools, that can help you identify the card,
parted
andlspci
,sudo parted -ls Model: SD SP32G (sd/mmc) Disk /dev/mmcblk0: 31.9GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 316MB 315MB fat32 boot, esp 2 316MB 317MB 1049kB bios_grub 3 317MB 7262MB 6946MB ext2 root 4 7262MB 7799MB 537MB linux-swap(v1) lspci ... 00:1e.6 SD Host controller: Intel Corporation Sunrise Point-LP Secure Digital IO Controller (rev 21) ...
- Try according to the list in the previous paragraph, 'The drive is read-only: "On some pendrives ..."', if the drive is not found.
- If the drive is found and recognized as a mass storage device, there is hope that you will succeed according to the next chapter.
Let us hope that there is 'only' confusion
Try to restore the drive to a standard storage device
Install and use mkusb (mkusb-dus), which can format alias restore a drive to a standard storage device (with an MSDOS partition table and a partition with the FAT32 file system). These instructions are relevant for many kinds of drives (USB pendrives, memory cards, hard disk drives, HDD, solid state drives, SSD), but probably most often used for USB pendrives and memory cards.
If you run standard Ubuntu, you may need an extra instruction to get the repository Universe. (Kubuntu, Lubuntu ... Xubuntu have the repository Universe activated automatically.)
sudo add-apt-repository universe # only for standard Ubuntu
sudo add-apt-repository ppa:mkusb/ppa # and press Enter
sudo apt-get update
sudo apt-get install mkusb mkusb-nox usb-pack-efi
See these links with more detailed instructions,
mkUSB-quick-start-manual.pdf or if the link does not work, this alternate link
help.ubuntu.com/community/mkusb
mkusb version 12 alias mkusb-dus:
mkusb wipes the first megabyte as a first step of restoring it
Sometimes some data are 'tricking' the software to think that the drive does not work, even when it is good, and it is enough to wipe the first megabyte to get rid of those data. You may 'look at' the drive with a tool, that does not recognize or understand correctly the structure of the partition table or a system, for example
- if it was cloned from an iso file, or
- if there are traces from a RAID configuration on the drive.
So you can
- let mkusb restore the drive to a standard storage device (a convenient standard solution), or
- let mkusb wipe the first megabyte and after that use another tool, if you want another partition table and/or other file systems. gparted is a good tool, if you are running a graphical user interface (window manager or desktop environment).
What to do if mkusb fails
If mkusb fails, the drive is either not found by the system or read-only. In this case you should try according to the list in the paragraph 'The drive is read-only' (above).
Solution 2:
This is a bit late, but here's my input.
My brother somehow made his flash drive not work on Windows and read-only in Linux. Trying to use GParted to make a new partition table didn't work, so I tried the dd option. This didn't work either, but after a bit of fiddling I used the following command:
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=40
After this I could use GParted again, and it worked perfectly. Obviously the first block was not the problem, but the problem lay somewhere between there and block 40.
Solution 3:
Unmount the usb drive first and then format it with GParted.
Solution 4:
Install the gparted
package in the Software Center (or in the Terminal/Konsole by running sudo apt-get update
followed by sudo apt-get install gparted
). This gives you the GParted Partition Editor.
Then run GParted. Find the MicroSD/USB drive in the list of devices in the drop-down menu at the upper-right corner of the screen. Make sure you have the right device. (You can look at its size to help gauge this.) It would be very bad if you accidentally formatted a different drive that had valuable data, or your Ubuntu system, on it!
With the correct device selected, run Device...
> Create Partition Table...
. Use the default options (i.e., just click Apply
, don't change the option under Advanced
). Please note that, while other modifications in GParted are only performed when you apply your changes, creating a new partition table wipes out anything on the drive on which it is done, and is performed immediately when you click Apply
.
Now create a FAT32 partition on the device (or a FAT16 partition if it is very small, like just a few megabytes, or if you know you need a FAT16 partition, for example, because you are following directions that call for a FAT16 partition). The new FAT32 partition should cover the whole drive (which is the default in GParted). You'll see the partition there, but that's just showing you what it will look like when you apply your changes.
Then apply your changes (by clicking the green check mark). Quit GParted.
You should be able to find the new partition in any Nautilus (i.e., file browser) window, under Devices on the left. Mount the partition by clicking on it under Devices in Nautilus.
Now you should be able to write to it with UNetbootin.