LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 07-02-2017, 09:39 AM   #1
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
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 ?

best regards.
 
Old 07-02-2017, 09:54 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
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.
 
1 members found this post helpful.
Old 07-02-2017, 09:57 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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.
 
1 members found this post helpful.
Old 07-02-2017, 11:16 AM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
Quote:
Originally Posted by smallpond View Post
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.

thansk
 
Old 07-02-2017, 11:18 AM   #5
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
Quote:
Originally Posted by rknichols View Post
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 !

best regards,
 
Old 07-02-2017, 11:25 AM   #6
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
Quote:
Originally Posted by rknichols View Post
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.
 
Old 07-02-2017, 12:08 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by marozsas View Post
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 ... .
 
Old 07-02-2017, 12:53 PM   #8
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by marozsas View Post
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.


---------------------------
Steve Stites
 
Old 07-02-2017, 02:12 PM   #9
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
Quote:
Originally Posted by jailbait View Post
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.

...

---------------------------
Steve Stites
Yes, I am already doing that. Thank you !
 
  


Reply

Tags
corrupted, ext4



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Linux with save state? NeoGenesisRevo Linux - Distributions 6 08-30-2015 06:11 PM
Save and retrieve the state of a signal anuRV Programming 0 07-19-2013 12:45 AM
CISPA: The latest attempt to establish a massive surveillance state, sign open letter lugoteehalt General 12 04-27-2012 10:04 AM
How to disable save state across sessions in Gnome? freekamail Linux - Software 2 04-26-2006 08:40 AM
How do -you- save STATE across web applications? lowpro2k3 Programming 2 05-23-2005 05:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration