-2

I'm using CentOS release 6.6. Today, I wanted to test the disk write speed to a 500 GB disk at /dev/sdc.

I used this command:

fio -filename=/dev/sdc -direct=1 -iodepth 1 -thread -rw=randwrite \
    -ioengine=psync -bs=16k -size=1G -numjobs=5 -runtime=15 -group_reporting \
    -name=mytest

When I use the command df -h to look at the disk, I get

Filesystem            Size  Used Avail Use% Mounted on
 9.0Z  9.0Z     0 100% /data

and in /data, I use ls, but I can't see any data. The disk is ext4.

How can I recover it?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
taoyantu
  • 11
  • 1
  • Was `/dev/sdc` mounted at `/data`? Was it mounted at `/`? Because if so, specifying `-filename=/dev/sdc` and `-rw=randwrite` clobbered everything with random bits, making recovery nearly impossible. Sorry. – PaSTE Aug 07 '17 at 05:59
  • @PaSTE I `m mount /dev/sdc /data . Isn't there any hope for me ? o my god ! – taoyantu Aug 07 '17 at 06:05
  • Unmount the file system and then use grep on /dev/sdc to see if you can find any of the data that was on there before. If data is there, at least you can recover it onto another disk. – Raman Sailopal Aug 07 '17 at 08:52

1 Answers1

2

When you told fio to write to /dev/sdc with 1 GB of random data, you probably overwrote the partition table (and some significant portion of the first physical partition on the disk). More than likely, you'll never see that first 1GB ever again. But if you are careful and lucky, you might be able to recover the other 499 GB.

Before you start messing with the disk, you should back up the data as-is to some external drive and keep it safe. Use a tool like dd to make sure you copy the raw bits from the drive rather than trying to mount the drive as a block device in any way.

Recovery of the partition table is probably not possible through automatic means, but if you know how the disk was partitioned before, you can just repartition the disk the same way using parted. For example, if the entire disk contained a single ext4-formatted partition, you can do parted -s /dev/sdc -- mklabel gpt mkpart primary ext2 0 -1s.

Once the partition table has been rebuilt but BEFORE YOU FORMAT THE NEW PARTITION, try running fsck.ext4. You might need to specify the -b flag and point the program to a usable backup superblock, as more than likely the primary superblock lived somewhere in that first GB of disk that was overwritten. For most modern systems, the backup superblock is typically at block 32768, but ymmv.

As a last-ditch effort (and if you are feeling lucky), make a new ext4 filesystem on the partition with mkfs.ext4 -S to attempt to rebuild the superblocks without wiping anything.

And make sure to read the man pages, and keep that backup handy so you can start over if any of these suggestions don't work or lead to more data corruption!

PaSTE
  • 4,050
  • 18
  • 26