In this article, we prioritize the safety of your data. First, you’ll see how you can back up your flash drive’s contents and then proceed to various fixes for the problem at hand. This way, if an attempt at fixing the problem ends up making it worse, you may still be able to revert to the snapshot of the current state of your flash drive.
Take a Compressed Full Backup Image
In Linux, there are many tools for backing up any storage device. However, the tried-and-tested approach relies on dd and GunZip (better known as gzip).
- To make a backup of your flash drive, first connect it to your computer. Fire up your favorite terminal (or press CTRL+Alt+T).
- Locate your flash drive:
- To back up your flash drive to an image file compressed with ZIP in a single command, use:
- To restore the backup, you’ll have to reverse the two commands’ sequence and define your flash drive as the output device. The full command will look like this:
Fix Corrupted Filesystem with FSCK
With the flash drive’s contents backed up, it’s time to try fixing it. For that, you can turn to fsck. This tool is great for removing bad file blocks, as most (if not all) corruption and unreadability comes from problems like this. For this command, you’ll have to define the partition instead of the full drive. You’ll find it with a similar name as your device by issuing: Then, run fsck on it with: In this command:
sudo fsck runs the fixing tool with administrative rights.-v tells it to show us detailed information about the proceedings.-a states we want it to automatically try repairing any errors it finds./dev/disk… is the partition that will be checked for errors.
Format USB Drive with Fdisk/MKFS from the Terminal
If fsck didn’t manage to repair the device’s filesystem, you can try to format it to use it as if it is new.
- The first step is to erase any existing filesystem structures and recreate them from scratch. You can use fdisk for this. Run it with sudo on your device with:
- Press o followed by Enter to create a new DOS partition table on it to have your USB drive readable everywhere. If you only want to use it on your modern computer and OS, you can replace o with g to create a new GPT partition table instead.
- Press n followed by Enter to make a new partition, then p to make it a primary one. If you used e instead of p, it would be created as an extended partition, but there’s no point in doing so if you aren’t planning to create more than three partitions on the drive. Then, you can just press Enter when asked about the partition’s number, first and last sectors, to accept the defaults and have the partition span the whole USB drive.
- Press p and then Enter to check out the new storage structure in your USB drive. Then, press w followed by Enter to write the changes to the USB drive and exit fdisk.
- Your partition will be unformatted, and since it won’t have a filesystem yet, it will be unusable. To create a filesystem, you can use one of the mkfs tools that come with all modern Linux distributions. To format your partition as FAT32, usable by most devices, use:
- To format your partition with NTFS, for use with modern versions of Windows, or with EXT4, for use only with Linux, use: or
The GUI Way to Check and Fix USB Drive with Disks
If you don’t like typing commands, you can turn to the Disks tool for checking and formatting your USB drive. Disks is pre-installed on Ubuntu.
- Visit your apps menu and search for “disks.” Launch the app when you locate it.
- Choose your USB drive from the list on the left and click on the icon with the two cogs. Choose “Repair Filesystem” and follow the steps of the wizard to fix the filesystem.
- In our case, we weren’t dealing with a hardware problem but with filesystem corruption. Although the issue was beyond repair, we could reformat our USB drive and keep using it. To do that with disks, with the USB drive selected, click on the icon with the two cogs again and choose “Format Partition … “
- Enter a name for your USB drive in the Volume Name field and choose from the three most popular filesystems for it:
Ext4 for use with LinuxNTFS for use with modern versions of WindowsFAT for use with both, as well as other types of devices (from smartphones to gaming consoles)
- Note the “Erase” option. Leave it disabled for a quick format. Flick it to On for a complete format that will fully erase your device’s contents. When dealing with corrupted devices that could also have some bad blocks, it’s better to go for the full erase option.
Rejuvenated USB Drive
Now that you have repaired your corrupted USB drive, you can use it again like a brand new drive. And if you are looking to create a Linux Live USB drive, follow the instructions here.