Need to corrupt an ext4 filesystem to performance test ext4

Issues related to applications and software problems
Post Reply
kvashishta
Posts: 66
Joined: 2015/02/15 18:35:55

Need to corrupt an ext4 filesystem to performance test ext4

Post by kvashishta » 2015/09/01 18:33:48

Team,

I need to corrupt an ext4 filesystem in order to test the performance of fsck.
Googling led me to sg3_utils which I installed, it is however not working out for me. Please suggest how to use the sg3_utils or any new approach to corrupt an ext4 filesystem.
The attempts at using sg3_utils are documented below. As always all patronage is appreciated.

[root@system tmp]# sg_write_long -v -w -l 16384 /dev/sdf1
sg_write_long: issue write long to device /dev/sdf1
xfer_len= 0 (0x0), lba=16384 (0x4000)
cor_dis=0, wr_uncor=1, pblock=0
Write Long (10) cmd: 3f 40 00 00 40 00 00 00 00 00
write long(10): pass through os error: Inappropriate ioctl for device
SCSI WRITE LONG (10): Sense category: -1


[root@system tmp]# sg_write_long -v -w -l 16384 /dev/sdf
sg_write_long: issue write long to device /dev/sdf
xfer_len= 0 (0x0), lba=16384 (0x4000)
cor_dis=0, wr_uncor=1, pblock=0
Write Long (10) cmd: 3f 40 00 00 40 00 00 00 00 00
write long(10): Fixed format, current; Sense key: Illegal Request
Additional sense: Invalid command operation code
Sense Key Specific: Error in Command: byte 0
SCSI WRITE LONG (10): Illegal request, invalid opcode sense key
[root@system tmp]#

[root@system tmp]# lsscsi -g
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0 /dev/sg0
[2:0:0:0] disk VMware Virtual disk 1.0 /dev/sda /dev/sg1
[2:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb /dev/sg2
[2:0:2:0] disk VMware Virtual disk 1.0 /dev/sdc /dev/sg3
[2:0:3:0] disk VMware Virtual disk 1.0 /dev/sdd /dev/sg4
[2:0:4:0] disk VMware Virtual disk 1.0 /dev/sde /dev/sg5
[2:0:5:0] disk VMware Virtual disk 1.0 /dev/sdf /dev/sg6
[root@system tmp]#

[root@system tmp]# sg_write_long -v -w /dev/sg6
sg_write_long: issue write long to device /dev/sg6
xfer_len= 0 (0x0), lba=0 (0x0)
cor_dis=0, wr_uncor=1, pblock=0
Write Long (10) cmd: 3f 40 00 00 00 00 00 00 00 00
write long(10): Fixed format, current; Sense key: Illegal Request
Additional sense: Invalid command operation code
Sense Key Specific: Error in Command: byte 0
SCSI WRITE LONG (10): Illegal request, invalid opcode sense key
[root@system tmp]#

Regards,

Kartik Vashishta

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: Need to corrupt an ext4 filesystem to performance test e

Post by avij » 2015/09/01 18:42:12

You can use dd if=/dev/urandom of=/dev/sdf1 bs=4096 seek=somerandomnumber to write random data to the specified location on the hard disk. You can also use /dev/zero if you're so inclined. However, chances are that doing this will not corrupt any critical ext4 directory data, but will "only" silently corrupt your files, which fsck won't notice. If you end up writing that random block of data to an unallocated part of the hard disk, nothing bad will happen.

kvashishta
Posts: 66
Joined: 2015/02/15 18:35:55

Re: Need to corrupt an ext4 filesystem to performance test e

Post by kvashishta » 2015/09/01 19:24:47

Thanks for the response, it is much appreciated. I have filled up the file system, df -kh shows it at 100% (is this accurate enough), so, having filled up the filesystem will dd still not corrupt the filesystem or will it?

Regards,

Kartik Vashishta

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: Need to corrupt an ext4 filesystem to performance test e

Post by avij » 2015/09/01 19:38:25

In your case dd is likely to corrupt your data, but as ext4 does not calculate any sort of checksums of the data, running fsck on the modified filesystem will not notice any errors.

You would need to be either a) really lucky to hit a block that contains ext4 internal data (superblock, inode information, block bitmap, extent trees, directory blocks, journal etc), or b) somehow determine where those ext4 internal data blocks are. For the latter, the ext4 filesystem tools may be useful. It has been a while since I've last done anything at this level, but perhaps some of the utils listed in man -k ext4 help.

kvashishta
Posts: 66
Joined: 2015/02/15 18:35:55

Re: Need to corrupt an ext4 filesystem to performance test e

Post by kvashishta » 2015/09/01 19:53:48

Thanks again. Here we go:

[root@system tmp]# mke2fs -n /dev/mapper/500gtestvg-500gbvol
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131069952 blocks
6553497 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
4000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000

Could you please give me the exact command to type in? I need to corrupt this good. Regards,

Kartik Vashishta

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: Need to corrupt an ext4 filesystem to performance test e

Post by avij » 2015/09/01 20:42:11

Oh, I forgot that you'd probably need to add count=1 to the dd command line as well. Otherwise dd would write random data to the hard disk from the specified point onwards until the end of the disk.

I would expect that if you run dd if=/dev/urandom of=/dev/mapper/500gtestvg-500gbvol bs=4096 seek=32768 count=1 you would corrupt the first superblock backup block. Repeat as needed.

kvashishta
Posts: 66
Joined: 2015/02/15 18:35:55

Re: Need to corrupt an ext4 filesystem to performance test e

Post by kvashishta » 2015/09/01 21:12:57

Thank you very much. I am somewhat surprised at the lack of tools to simulate file system corruption. I appreciate your help. Regards,

Kartik Vashishta

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: Need to corrupt an ext4 filesystem to performance test e

Post by gerald_clark » 2015/09/02 01:06:40

Journaled filesystems got to great lengths to avoid filesystem corruption and the necessity to run fsck.
Depending on your filesystem size and available RAM it may not be possible to fsck the filesystem.

kvashishta
Posts: 66
Joined: 2015/02/15 18:35:55

Re: Need to corrupt an ext4 filesystem to performance test e

Post by kvashishta » 2015/09/11 12:54:00

I tried dd but could not corrupt the filesystem.
my fstab looks like this:
/dev/500gtestvg/500gbvol /500GBFS ext4 defaults 0 2

I rebooted and the filesystem mounted without issues, I did not notice anything unusual on the console either.

Please advise.

Post Reply