Pages by Andreas B. M. Hofmeier
An-H
email Impressum/Note Privacy
http[s]://www.abmh.de/en/papers/ls/Flash-Restore.html

Like to be free? ... then: Fight for Freedom

Flash-Restore/Recover

From Linux Solutions

Jump to: navigation, search

One reason that flashs (USB Sticks or Storage) are not working anymore is, that the partetion-table was damaged. Here is, what you could do about it:

Contents

Try to Mount the Flash

If there is data on it, you want to save, you can try to mount the file system with offset:

determine, were file-system starts

look for the VFAT-file-system-signature

dd if=/dev/sda bs=1M count=1 | hexdump /dev/stdin -C | grep -i "55 AA  "

You will get something like this:

000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............Uª|
000041f0  00 41 bb 00 07 80 7e 02  0e e9 40 ff 00 00 55 aa  |.A»...~..é@ÿ..Uª|
00007df0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............Uª|
00007ff0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............Uª|
000089f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............Uª|
1+0 records in
1+0 records out
1048576 bytes transferred in 0.331127 seconds (3166688 bytes/sec)

The first number on each line gives you the offset in hexadecimal. This offset is wrong for 0x1F0, so you have to subtract this number. Do not forget, that this numbers are hexadecimal values, you have to convert them into decimal numbers:

echo $[0xHEXADECIMALNUMBER]

try mounting the filesystem with

mount /dev/sda /mnt -o ro,offset=$[0x00007df0-0x1F0]


You may need to try the offsets of all lines which where found. Here a typical offset was given as example. The part in brackets specifies the offset. Just put "0x" (Zero+x) and the offset you want to try (first number of eacht line of the last command) and than "-0x1F0" to correct the little error.

Then try to look into /mnt. If you data is there, copy it. If not, do not forget

umount /mnt

and then try the next one.

The file-system is mounted read-only!

After you saved you data, you should format the flash!

Format the Flash

Creating Partetion Table

with cfdisk

cfdisk /dev/sda

This program controlled by the keyboard only. Use the arrow-keys to select a command.

  1. There should be a lot of Free Space. If not, just select "Delete" to delete existing partitions.
  2. Just select "New",
    1. than "Primary",
    2. then enter the size of the partition (the biggest possible size is the default value, so you can just press Enter if you want just one partition).
  3. Then you should set the type of the Partition to FAT.
    1. Just select "Type",
    2. and then enter "0B". Before you can enter this, you may have to press enter, because the program lists all possible types.
  4. After all you have to save you changes with "Write",
    1. you have to confirm this with entering "Yes".

with fdisk

fdisk /dev/sda
  1. You can alway list the partitions with "p"
  2. Use "d" to delete partitions if there are some
  3. Use "n" for a new partition
    1. than "p" for a primary one
    2. then "1" for the first one
    3. then enter for the default start sector (first possible)
    4. then enter again for the last possible sector (biggest possible size)
  4. Change partition type to "W95 FAT32": use "t"
    1. then enter "b"
  5. Write your changes with "w"

After this remove the flash and put it in again.

Now create a vfat-file-system with

mkdosfs /dev/sda1

or

mkfs.msdos /dev/sda1

or also: You could use a windows computer to format the flash at this point.

If there are may be some broken sectors on the flash, add the parameter -c for doing a sector-test as well.


Pages by Andreas B. M. Hofmeier
An-H
email Impressum/Note Privacy
http[s]://www.abmh.de/en/papers/ls/Flash-Restore.html
Creative Commons License
(c) Andreas B. M. Hofmeier
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Germany License