Steps I followed were:
- Check whether your USB device is detected using "lsusb" command
- Finding where the device is located (using fdisk)
- Guess PC-type hard disk partitions using gpart
- Manipulate partitions using gparted (Gnome partition editor)
- Scan and repair disk partitions (using testdisk)
- Finding bad blocks using badblocks
- Copy zeros to starting locations (using dd)
Followings are the details those steps with the commands and the output of each.
1. Check whether your USB device is detected using "lsusb" command
lsusb is a command used to list all USB devices found in a system$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
...
Bus 002 Device 008: ID 0930:6544 Toshiba Corp. Kingston DataTraveler 2.0 Stick (2GB)
...
Above command lists the connected USB devices, and my Kingston DataTraveler 2.0 Stick is also shown. So it is clear that the USB flash drive is correctly connected.
2. Finding where the device is located (using fdisk)
"fdisk" command can be used to find details about the device.$ sudo fdisk -l
....
Disk /dev/sdc: 8010 MB, 8010194944 bytes
247 heads, 62 sectors/track, 1021 cylinders, total 15644912 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: 0xd0e2392f
Disk /dev/sdc doesn't contain a valid partition table
So this device size is correctly identified as 8010MB (8GB) and is located at /dev/sdc. Interestingly, fdisk has reported that this device is not having a valid partition table. So something has happened to the partition table and I wanted to fix it with the help of fdisk command as follows.
$ sudo fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x4c9b7827.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Error closing file
As shown above, fdisk has tried to alter the partition table, but failed. So I tried to add a partition as below, which again failed with the same error message.
# sudo fdisk /dev/sdc
...
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Partition type:
primary (0 primary, 0 extended, 4 free)
extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-15644911, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-15644911, default 15644911):
Using default value 15644911
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Error closing file
So it seemed fdisk can not help further in resolving this issue.
3. Guess PC-type hard disk partitions using gpart
I used gpart to find details of the existing partitions, and following was the outcome.$ sudo gpart /dev/sdc
Begin scan...
End scan.
Checking partitions...
Ok.
Guessed primary partition table:
Primary partition(1)
type: 000(0x00)(unused)
size: 0mb #s(0) s(0-0)
chs: (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r
Primary partition(2)
type: 000(0x00)(unused)
size: 0mb #s(0) s(0-0)
chs: (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r
Primary partition(3)
type: 000(0x00)(unused)
size: 0mb #s(0) s(0-0)
chs: (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r
Primary partition(4)
type: 000(0x00)(unused)
size: 0mb #s(0) s(0-0)
chs: (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r
As per the above findings, there is no correct partition in the device.
4. Manipulate partitions using gparted (Gnome partition editor)
I used "gparted" tool to add a partition table. As shown in above image, gparted shows this device at /dev/sdc with Partition=unallocated and FileSystem=unallocated, so it also identified that there was an issue. So I tried adding a partition table [by Device -> Create Partition Table...] of msdos type, but GUI displayed an error message as "Error while creating partition table". Command line also had some issues listed as below.
$ sudo gparted
======================
libparted : 2.3
======================
/dev/sdc: unrecognised disk label
/dev/sdc: unrecognised disk label
Input/output error during write on /dev/sdc
Error fsyncing/closing /dev/sdc: Input/output error
/dev/sdc: unrecognised disk label
So gparted also failed to resolve this for me.
5. Scan and repair disk partitions (using testdisk)
I tried "testdisk" tool to analyze and repair the disk. Following devices were identified by the tool.$ sudo testdisk
TestDisk 6.13, Data Recovery Utility, November 2011
....
Select a media (use Arrow keys, then press Enter):
...
Disk /dev/sdc - 8010 MB / 7639 MiB - Kingston DT 101 G2
Partition details of this /dev/sdc were shown as below.
Disk /dev/sdc - 8010 MB / 7639 MiB - CHS 1021 247 62
Current partition structure:
Partition Start End Size in sectors
P Unknown 0 0 1 1021 150 18 15644912
Disk /dev/sdc - 8010 MB / 7639 MiB - CHS 1021 247 62
Partition Start End Size in sectors
No partition found or selected for recovery
As per the above, there is no partitions in this disk.
Also I tried to use this tool to create a new MBR record, and the command resulted as below.
Write a new copy of MBR code, confirm ? (Y/N)
TestDisk exited normally.
You have to reboot for the change to take effect.
However even after reconnecting the device, the issue was not resolved.
6. Finding bad blocks using badblocks
Finally I suspected whether the pen drive was having bad blocks, so tried the badblocks utility to check for those as follows.$ badblocks -vws /dev/sdc
Checking for bad blocks in read-write mode
From block 0 to 7822455
Testing with pattern 0xaa: 0.03% done, 34:50 elapsed. (0/0/0 errors)
However this tool was taking much longer time to run. As shown above only 0.03 was completely in 34.50 minutes, which means around 80 days to complete. Obviously, I was not going to wait that longer to fix the pen drive.
7. Copy zeros to starting locations (using dd)
I tried "dd" tool to write zeros to the device in case there were some inconsistency in the partition table creation space. So 8MB of zeros were written to pen drive successfully.$ sudo dd if=/dev/zero of=/dev/sdc bs=8M count=1
1+0 records in
1+0 records out
8388608 bytes (8.4 MB) copied, 2734.83 s, 3.1 kB/s
However even after dd was successful, I tried to add a partition table with gparted as explained in step 4 above, but it continued to fail.
Summary
Finally after all these operations, partition table creation was not successful even though I was able to write some data into this pen drive with 'dd' tool. Hence it is not possible to boot and mount inside an operation system. I assumed this was due to a hardware failure of the device.Hope these details will help someone (including me) when resolving issues with USB pen drives in future.
Thnx for compiling a list of such useful tools. Will help someone surely.
ReplyDeletetry HP USB Disk Storage Format Tool on windows
ReplyDelete@2 - Thanks for the helpful information. I will give it a try and update you all.
ReplyDelete