Restore the size of an USB Drive (Linux)
I wanted to try a new distribution, so I decided to make a bootable USB, using dd :
sudo dd if=my.iso of=/dev/sdb bs=4M
I tried to boot on it, but despite choosing it as the boot media in the BIOS, the computer didn't boot on it and instead proceeded to start the base system. (as a side question, I don't understand why sometime I can boot the system, and sometimes I can't, using that same line to write the iso to usb).
I am not sure what else I did wrong, but this resulted in that 16GB drive only showing 10MB available.
Using gparted, there is only 10MB available on the drive, using lsblk however output :
sdb 8:16 1 14.9G 0 disk
I tried to format it using fdisk and other utilities, without success. Then I saw in gparted that the informations for the head, cylinders and sector where different than another exact same USB drive (same model, same brand, same capacity). Although this information (head, etc) is not really relevant to an USB drive, I though it might be the problem that made my USB 10MB "tall".
However any attempt to modify these, using fdisk's expert mode (x key once in the program) was unsuccessful, trying to write (w) them didn't work (there was no change in capacity).
I looked for other ways of modifying this (as I believe it's why the USB isn't showing its true size) but have been unsuccessful.
How can I change the header, sector, and cylinders of that drive permanently ? Is it why my USB is shrinked, and if not, what can I do to restore it to its true size ?
EDIT : The suggestions didn't work, although different words on my search engine made me discover testdisk
which might solve the issue.
EDIT : Trying to change the CHS didn't work : once I quit testdisk, it's reset to the values that make it 10MiB large.
SOLVED : Apparently, the size is correct if I use it on another computer. Rebooting may be required for the correct values to be displayed.
Solution 1:
Overwrite the first few sectors (32KB is more than enough) with zeroes, then open cfdisk or fdisk or gparted and create a new partition table in the format you like (gpt or mbr).
dd if=/dev/zero of=/dev/sdb bs=32k count=1
And for that side node, you can only dd
an ISO to a USB and boot from it if it is a hybrid ISO, i. e. an ISO that starts with a MBR or GPT partition table, and whose content is laid out that it has both a traditional filesystem and an ISO filesystem where the same file names point to the same files. (Also the bootloader has to detect that case and boot from USB or CD properly depending on what drive is present).
Solution 2:
As you have exactly the same USB drive, the easiest recovery would be to copy an MBR
from the good one to the broken one. First, copy the good MBR
to a file:
dd if=/dev/sdX of=usb.mbr bs=512 count=1
then copy the saved MBR
to the broken one:
dd of=/dev/sdX if=usb.mbr; sync
then reinsert that USB stick being repaired and inspect the configuration with fdisk
- it must be OK now.
Recreate a vfat
file system on the existing partition.