Personal computing discussed

Moderators: renee, SecretSquirrel, notfred

 
mxmaniac
Gerbil
Topic Author
Posts: 17
Joined: Fri Jun 27, 2014 12:34 pm

Can you intentionally corrupt disks/files to practice recove

Sat Apr 11, 2015 10:54 pm

I am pretty new to Linux, but I would like to be able to practice recovering disks and files, especially in RAID arrays. Basically I would like to simulate various types of disk failures that may happen in a RAID array.

Is there any easy way to intentionally corrupt various things like the filesystem, or corrupt a few files on a single disk of a raid array? That way I can practice using tools like ****, mdadm and whatever other ones are out there to try and repair the damage?

I be doing all of this in virtual machines, so no worry about messing up the PC.

edit - the tool name above that got censored out is supposed to be the f s c k tool
 
Yan
Gerbil XP
Posts: 349
Joined: Fri Dec 21, 2012 9:37 pm
Location: Ottawa

Re: Can you intentionally corrupt disks/files to practice re

Sun Apr 12, 2015 5:21 am

The man page for the command that cannot be named suggests one way to deliberately corrupt a file system:

Note that in general it is not safe to run e2f s ck on mounted filesystems. The only exception is if the -n option is specified, and -c, -l, or -L options are not specified. However, even if it is safe to do so, the results printed by e2f s ck are not valid if the filesystem is mounted. If e2f s ck asks whether or not you should check a filesystem which is mounted, the only correct answer is ''no''. Only experts who really know what they are doing should consider answering this question in any other way.


Banning "f s c k" on a tech site is silly, obviously.
 
notfred
Maximum Gerbil
Posts: 4610
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: Can you intentionally corrupt disks/files to practice re

Sun Apr 12, 2015 9:14 am

I've asked to get f-s-c-k removed from the word filtering list.

To corrupt files you could work out where on the disk has the file and then overwrite bits of it with dd. Remember the disks are accessible as raw data e.g. /dev/sda1
 
LoneWolf15
Gerbil Elite
Posts: 963
Joined: Tue Feb 17, 2004 8:36 am
Location: SW Meecheegan

Re: Can you intentionally corrupt disks/files to practice re

Sun Apr 12, 2015 10:03 am

To the OP: Are you testing the repair tools for development, or something else?

If this is for disaster recovery (not dev stuff), usually I'd test file/folder/baremetal restoration of backups. A good backup beats a file system repair tool and high hopes any day.
i9-9900K @4.7GHz, GIGABYTE Z390 Aorus Pro WiFi, 2 x 16GB G.Skill RipJaws V PC3000
Corsair 650D, Seasonic 1Kw Platinum PSU
2x HP EX920 1TB NVMe, Samsung 850 Pro 512GB 2.5", NEC 7200 DVDRW
Gigabyte RTX 2080 Super Gaming OC, Dell S2719DGF 27" LCD
 
just brew it!
Administrator
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: Can you intentionally corrupt disks/files to practice re

Sun Apr 12, 2015 1:47 pm

Well, for starters you could just disconnect the data cable of a drive in the array while the array is running, and practice recovering the array after this simulated drive failure.

Beyond that, you've got a number of possibilities:

- The dd tool allows you to read and write arbitrary blocks of data to/from any file or device. You can use this to intentionally corrupt and read back data on the underlying block devices.

- The debugfs tool allows you to interactively look at the file system's internal data structures.

- The dmsetup tool allows you to set up a "loopback device" (essentially a device driver filter) which allows you to simulate in software (via the table option) blocks which have read errors. If you build your RAID device on top of a set of loopback devices, you will be able to simulate bad blocks.

- The hdparm tool, via the --make-bad-sector option, allows you to instruct a hard drive to intentionally create a bad sector on the media. This sector will then behave like it has a permanent read error. (This is reversible, via the --repair-sector option.)

- You can use a hex editor (e.g. bless, hexedit) to view and edit bytes on a raw device.

- You may want to consider using a VM (VMware or VirtualBox) to practice in. This will make it easier to simulate various configurations of RAID arrays without needing a pile of physical hard drives, and also eliminates the risk of corrupting the file system of your desktop if you accidentally select the wrong device for one of your simulated failures. (Not sure if the bad sector feature of hdparm is supported on virtual disks... all the other stuff I've mentioned should work though.)
Nostalgia isn't what it used to be.
 
mxmaniac
Gerbil
Topic Author
Posts: 17
Joined: Fri Jun 27, 2014 12:34 pm

Re: Can you intentionally corrupt disks/files to practice re

Sun Apr 12, 2015 3:39 pm

Thanks so much for the advice. I have not had a chance to try these yet, but I will be trying all of these methods soon.

Using dd was mentioned a couple of times, and its actually the first tool that came to my mind. Although I've used it a few times for certain things like writing blank files, speed tests, writing iso files, etc., I'm not quite sure how to use it to selectively corrupt a certain part of a drive or file. Can anyone give an example?

This is how my virtual machine is currently setup, I have /dev/sdb through /dev/sdf in one 5 disk array, and these are actual virtual hard disks through VM Ware, so the system thinks they are real hard drives.

I also have a second array using the losetup loopback tool to make some virtual disks in another 10 disk array using /dev/loop0 through /dev/loop9

I've placed about 1000 very small text files in each volume.

Can anyone give an example of the correct syntax or procedure to use the DD tool to specifically corrupt the filesystem/files/drive, say for example on /dev/sdc or /dev/loop7?
 
Yan
Gerbil XP
Posts: 349
Joined: Fri Dec 21, 2012 9:37 pm
Location: Ottawa

Re: Can you intentionally corrupt disks/files to practice re

Mon Apr 13, 2015 2:12 pm

mxmaniac wrote:
Can anyone give an example of the correct syntax or procedure to use the DD tool to specifically corrupt the filesystem/files/drive, say for example on /dev/sdc or /dev/loop7?


The Wikipedia page on dd gives several good examples.

To deliberately overwrite the first megabyte of partition /dev/sda1:

dd if=/dev/zero of=/dev/sda1 bs=1k count=1024

To deliberately overwrite the first kilobyte of a file:

dd if=/dev/zero of=/tmp/test bs=1k count=1 conv=notrunc

A superfluous warning stating the obvious: the dd command can corrupt your data if used incorrectly.

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On