How can I get back the data of my USB on Ubuntu 16.04.1 LTS?

Overview

The data are important. This means that you should not mount this drive (only connect it). Then you should clone it to a drive of at least the same size, and do the recovery work on the cloned copy. This method will reduce the risk (that the recovery attempts will destroy data, than are possible to recover).

There are several helpful pages and several tools available via the internet. I wrote the following short page with tips and links to tools, that have worked for me.

Repair the partition table and file system of a pendrive

Details about cloning

Clone a drive to another drive of at least the same size. The drives are represented as block devices.

1. According to example 1 in 'info ddrescue'

Boot from a 'third' drive, for example the internal drive or another USB boot drive with linux.

Install ddrescue

sudo apt-get install gddrescue

It is a two-step procedure, where the second step is only necessary when there are 'difficult' or bad blocks on the source device (the USB drive)

sudo ddrescue -f -n source-device target-device log-file
sudo ddrescue -d -f -r3 source-device target-device log-file

for example

sudo ddrescue -f -n /dev/sdd /dev/sde log-file
sudo ddrescue -d -f -r3 /dev/sdd /dev/sde log-file

but check very carefully and modify the device letters to your particular case.

2. mkusb

If you find this too difficult or risky, we can hope that there are no bad blocks in the source device. Then it is possible to do this with mkusb. It will help you select the target device in order to avoid writing to the wrong one and overwrite valuable data.

Install mkusb:

If you run standard Ubuntu, you 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

Run mkusb like this:

sudo -H mkusb source-device

To match the example above we assume

sudo -H mkusb /dev/sdd

and mkusb will display information about all devices and later the possible target devices to let you select it via a menu, where additional data is displayed.

01-clone-a-device-overview

mkusb will filter the devices, and only show what are suitable target devices with numbers to help you select the correct one, in this example a Sandisk Extreme pendrive at /dev/sde

02-select-target-device

03-final-checkpoint

04-progress.png

05-work-done

Check in the terminal window, that the whole device was read and all data written (cloned)!

...
99
100
1962864+0 records in
1962864+0 records out
8039890944 bytes (8,0 GB, 7,5 GiB) copied, 440,371 s, 18,3 MB/s
Done
do_n_show: Work done
---------------------------------------------------------------------------
Syncing the device ...
Done :-)
Cleanup after mkusb finished :-)
---------------------------------------------------------------------------
Total time used [by mkusb] = 886 s; 00:14:46

(In this case there was extra total time because I made screenshots.)