V
V
VN2021-12-17 13:40:04
linux
VN, 2021-12-17 13:40:04

How to corrupt a file in Linux?

I want to test the operation of the gddrescue utility. But, in order not to copy the entire partition, I want to test only on part of the file system.
I'm trying to write a few zeros to the middle of the file using dd

dd if=/dev/zero of=/backup/version_project_2_20_11_20.zip bs=1 count=1 seek=7 conv=notrunc

But after that, the archive continues to open.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hint000, 2021-12-17
@kavabangaungava

I want to test the operation of the gddrescue utility
It doesn't work like that.
ddrescue doesn't do any magic to recover a file. And by writing garbage to a file, you won't damage the disk so you can test reading it with ddrescue.
From a physically healthy disk, ddrescue will copy exactly the same thing as regular dd (ie, it will copy a neatly corrupted file with zeros in the middle).
To test ddrescue, you need to bang the hard drive against the wall, :) and not write zeros in the middle of the file.

P
pfg21, 2021-12-17
@pfg21

archive index intact - when opening an archive, an intact index is read and displayed.
while everything is ok.
but when unpacking the archive, the program will stumble upon "wrong" blocks and start throwing errors or turn off altogether.
run a test of this archive - you'll see.

A
Alexey Cheremisin, 2021-12-17
@leahch

1) You do not need to damage the insides of the file, but the file system .
2) It is not necessary to do this on a real file system, you can use a small file of 500 megabytes and connect it as a disk device through loopback
And already damage it as you please.
truncate -s 500M my-file-system.img- create a file
mkfs.ext4 my-file-system.img- create a file system on it
mount -o loop my-file-system.img /mnt- mount
df -h /mnt- check size
umount /mnt- unmount

[email protected] /h/leah# truncate -s 500M my-file-system.img
[email protected] /h/leah# mkfs.ext4 my-file-system.img 
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done                            
Creating filesystem with 128000 4k blocks and 128000 inodes
Filesystem UUID: ada9f825-92d5-4410-b186-eda1ef2edfeb
Superblock backups stored on blocks: 
  32768, 98304

Allocating group tables: done                            
Сохранение таблицы inod'ов: done                            
Создание журнала (4096 блоков): готово
Writing superblocks and filesystem accounting information: готово

[email protected] /h/leah# mount -o loop /home/leah/my-file-system.img /mnt
[email protected] /h/leah# df -h /mnt
Файл.система   Размер Использовано  Дост Использовано% Cмонтировано в
/dev/loop26      469M         768K  433M            1% /mnt
[email protected] /h/leah# umount /mnt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question