how to save a ext4 FS state before attempt to fix it ?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to save a ext4 FS state before attempt to fix it ?
Hi there !
I have a 1T disk with valuable information and no backup. Yes, I know but it is my personal computer and I don't have tapes and making backups on another disk is too expensive, since I have 2x3T + 1x1T(this one) and making backups of 4T in a domestic environment it is not a easy or cheap task.
Anyway...
The FS is corrupted. Not the media, just the FS.
I want to preserve the current FS state before any attempt to fix it.
If I had a 1T spare disk, I would duplicate it to have a copy to try another thing if the first attempted failed. (As I would do in a forensic analyses)
The question: It is possible to save on a file a few blocks of the begging of the device, ran fsck and if it not worked, copy back those blocks and try again with different answers ?
I know I can save the first 512bytes of a disk to preserve the bootstrap and partition table, so I was wondering if something similar could be done with a ext4 FS....
I am not sure about the layout of a ext4 FS. If it put all information about the files on the beginning (or end) of disk it should work...in this case, how much I should copy to preserve the current state of a ext4 FS ?
Staples has 1TB disk for around $75. I guess your data is not that valuable? Or if you have 1TB free make an LVM, copy the disk, and try to fix the copy. Leave the original disk intact.
There is no basis for assuming that the problem is in the first few blocks or that only the first few blocks will be touched by a repair.
You can use e2image to create a file with the ext2/3/4 metadata, and that same program can restore that metadata back to the original filesystem. See the manpage for e2image and especially the "RAW IMAGE FILES" section. You can run fsck.ext4 on such a raw image file and see what it does without ever touching the original filesystem.
Staples has 1TB disk for around $75. I guess your data is not that valuable? Or if you have 1TB free make an LVM, copy the disk, and try to fix the copy. Leave the original disk intact.
There is no basis for assuming that the problem is in the first few blocks or that only the first few blocks will be touched by a repair.
Yup, You are right. Buying a new disk for this purpose is the safest move.
Even so, I am curious about another options.
You can use e2image to create a file with the ext2/3/4 metadata, and that same program can restore that metadata back to the original filesystem. See the manpage for e2image and especially the "RAW IMAGE FILES" section. You can run fsck.ext4 on such a raw image file and see what it does without ever touching the original filesystem.
Hey ! Thanks ! I didn't know about this fellow. I will try !
You can use e2image to create a file with the ext2/3/4 metadata, and that same program can restore that metadata back to the original filesystem. See the manpage for e2image and especially the "RAW IMAGE FILES" section. You can run fsck.ext4 on such a raw image file and see what it does without ever touching the original filesystem.
No, it didn't worked.
Looks like the FS cannot be corrupted or damaged...
Code:
root@38Y46W1-x:~# e2image -r /dev/mapper/newprivatearea /home/system-extra/sdh1.img
e2image 1.42.13 (17-May-2015)
e2image: Bad magic number in super-block while trying to open /dev/mapper/newprivatearea
Couldn't find valid filesystem superblock.
No, it didn't worked.
Looks like the FS cannot be corrupted or damaged...
Code:
root@38Y46W1-x:~# e2image -r /dev/mapper/newprivatearea /home/system-extra/sdh1.img
e2image 1.42.13 (17-May-2015)
e2image: Bad magic number in super-block while trying to open /dev/mapper/newprivatearea
Couldn't find valid filesystem superblock.
Apparently that program does not look for backup super blocks and can't get started if the primary one is damaged. Oh, well ... .
I am not sure about the layout of a ext4 FS. If it put all information about the files on the beginning (or end) of disk it should work...in this case, how much I should copy to preserve the current state of a ext4 FS ?
An ext4 FS creates its control blocks called inodes at intervals throughout the partition. Finding the physical location of the inode in question would be daunting unless it is given in the error message you got. Anyway I would trust fsck to repair the damaged inode before I would trust myself to try it by hand.
I suggest that you buy a backup drive and make a dd backup. The backup will have the same problems as the original. Then run fsck with the -n option which tells fsck to report the problems that it finds but not to try to repair any problems.
Then if you are comfortable with fsck run in one of two modes. Use the -r mode if you only have a few errors. The -r mode asks you for permission to repair each err as it goes. Use the -a mode if you have a lot of errors. The -a mode
will not ask you for permission to make each change.
If fsck finds any file fragments without a file name fsck will number each fragment and put them into lost+found. You might be able to figure out the file name from the contents of the numbered file.
An ext4 FS creates its control blocks called inodes at intervals throughout the partition. Finding the physical location of the inode in question would be daunting unless it is given in the error message you got. Anyway I would trust fsck to repair the damaged inode before I would trust myself to try it by hand.
I suggest that you buy a backup drive and make a dd backup. The backup will have the same problems as the original. Then run fsck with the -n option which tells fsck to report the problems that it finds but not to try to repair any problems.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.