how to check and repair a 2fs filesystem-in-a-file

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
miriam
Posts: 373
Joined: Wed 06 Dec 2006, 23:46
Location: Queensland, Australia
Contact:

how to check and repair a 2fs filesystem-in-a-file

#1 Post by miriam »

I spent much of today working on a Puppy installation on a thumbdrive. Everything was going great until something went wrong and it was damaged somehow. I couldn't reboot into it and I was looking at many hours of work wasted.

After unsuccessfully spending a while looking around on the net for a solution, I started writing out a plea for help on this forum, but halfway through writing I realised the ridiculously simple solution. There may be an even easier solution, but here is what I came up with. If you know of an easier way please let me (and everyone else) know.

The problem with using fsck to check an sfs file is that until the sfs file is mounted it is just a file on some other filesystem. But you can't mount it because fsck requires the device name and that the device not be mounted. Unfortunately I couldn't work out how to give an sfs file a device name without mounting it.

And then it hit me...

Go to your /etc/fstab file and enter something like this into it:

Code: Select all

/mnt/sdh1/pupsave.2fs	/mnt/sdh1/pupsave  ext2  defaults 0 0
In this instance my thumbdrive is mounted on /mnt/sdh1 and the sfs file I want to repair is called pupsave.2fs.

Save the fstab file. Puppy will notice and now think that there is a device /mnt/sdh1/pupsave.2fs that is mounted as /mnt/sdh1/pupsave which is type ext2.
NOTE: I previously made the type "squashfs", and that worked, but after reading and considering Amigo's comments below and researching more on the web, I think it is safer for the type to be ext2.

Now open a terminal and use fsck to repair it like this:

Code: Select all

e2fsck /mnt/sdh1/pupsave.2fs
I used e2fsck because this sfs is ext2 internally.

If it refuses to do anything, and says the filesystem is clean, you can force it using the -f option:

Code: Select all

e2fsck -f /mnt/sdh1/pupsave.2fs
Read the manual to find out what other options there are.

When you're done, delete or comment out the line in your fstab. I commented out mine by putting a # character at the beginning of the line. Then if calamity befalls me again, all I need do is edit the relevant parts of the line and re-use it.

I only use ext2 filesystem inside an sfs file because journals add many more writes, shortening the lifespan of a flash memory device. Also I never use encryption because I have a crap memory for passwords. :)
NOTE: DO NOT do this with an encrypted sfs filesystem. I expect it will totally screw it.

But as watchdog mentions below there is a way to handle encryption. It is arguably simpler than my way of working on the 2fs file:

Code: Select all

losetup-FULL -E 1 /dev/loop2 /mnt/sdh1/pupsave.2fs 
or for normal, unencrypted 2fs files:

Code: Select all

losetup-FULL /dev/loop2 /mnt/sdh1/pupsave.2fs 
In this case the device is obviously /dev/loop2 which, although unlikely, it would probably be smart to ensure is not already being used by something (use the df command to see which are in use. And after you no longer need it you can remove the loop setup with:

Code: Select all

losetup-FULL -d /dev/loop2
Last edited by miriam on Fri 05 Sep 2014, 01:11, edited 3 times in total.
[color=blue]A life! Cool! Where can I download one of those from?[/color]

watchdog
Posts: 2021
Joined: Fri 28 Sep 2012, 18:04
Location: Italy

#2 Post by watchdog »

I think the following commands could also work:

Code: Select all

losetup-FULL /dev/loop2 /mnt/sdh1/pupsave.2fs
e2fsck /dev/loop2
losetup-FULL -d /dev/loop2
If the pupsave.2fs is lightencrypted than:

Code: Select all

losetup-FULL -E 1 /dev/loop2 /mnt/sdh1/pupsave.2fs
e2fsck /dev/loop2
losetup-FULL -d /dev/loop2
If the pupsave.2fs is heavily encrypted than:

Code: Select all

losetup-FULL -e aes /dev/loop2 /mnt/sdh1/pupsave.2fs
e2fsck /dev/loop2
losetup-FULL -d /dev/loop2
Be careful testing.

EDIT: read the following warning for old puppies:

http://www.murga-linux.com/puppy/viewto ... 187#798187
Last edited by watchdog on Sat 06 Sep 2014, 07:56, edited 3 times in total.

User avatar
miriam
Posts: 373
Joined: Wed 06 Dec 2006, 23:46
Location: Queensland, Australia
Contact:

#3 Post by miriam »

Very cool, watchdog! I hadn't heard of the losetup command before. That does seem to be an easy way to do it. Bonus that it's able to handle encryption as well. Neat!
[color=blue]A life! Cool! Where can I download one of those from?[/color]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#4 Post by amigo »

Uh, your thread title is misleading, because a *.2fs is not the same as a *.sfs file(system). There is no repair tool for squashfs (sfs) as it is only available as an image -it's not a normal block-based file system.

User avatar
miriam
Posts: 373
Joined: Wed 06 Dec 2006, 23:46
Location: Queensland, Australia
Contact:

#5 Post by miriam »

Thanks Amigo. I didn't realise the difference until your comment prompted me to look further into it.

I've altered the subject title accordingly and have added a note that perhaps the type in my fstab entry should have been ext2 rather than squashfs... though squashfs did seem to work. Perhaps 2fs files might be better seen as a special variant of squashfs? Are 2fs files compressed internally? I need to learn more and experiment more with this.
[color=blue]A life! Cool! Where can I download one of those from?[/color]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#6 Post by amigo »

No, 2fs files are ext2 filesystem which do not feature compression -they are a 'normal' file system image. That is, ext2 is a normal block-based filesystem which can be written to or deleted from and can be repaired with fsck. Normally such FS's are used on a partition, but can also be used as a mountable FS image.
squashsfs can only be used as an FS image -you can't format a partition with squashfs and a squashfs image can't be altered or damaged since they are read-only.

Mayou

Test

#7 Post by Mayou »

# losetup-FULL /dev/loop2 /mnt/home/slackosave-bugGens.2fs
losetup-FULL: /dev/loop2: device is busy
# e2fsck /dev/loop2
e2fsck 1.41.14 (22-Dec-2010)
/dev/loop2 has gone 427 days without being checked, check forced.
Pass 1: Checking inodes, blocks, and sizes
Deleted inode 8348 has zero dtime. Fix<y>? yes

Deleted inode 8349 has zero dtime. Fix<y>? yes

Deleted inode 8353 has zero dtime. Fix<y>?

An what does that mean ? pleeease...

watchdog
Posts: 2021
Joined: Fri 28 Sep 2012, 18:04
Location: Italy

Re: Test

#8 Post by watchdog »

Mayou wrote:# losetup-FULL /dev/loop2 /mnt/home/slackosave-bugGens.2fs
losetup-FULL: /dev/loop2: device is busy
Your /dev/loop2 is occupied. Type in console:

Code: Select all

losetup
to search for a free loop device (one not listed 0-9). Say it is /dev/loop9; then change the command:

Code: Select all

losetup-FULL /dev/loop9 /mnt/home/slackosave-bugGens.2fs 

Code: Select all

e2fsck /dev/loop9
losetup-FULL -d /dev/loop9
If you are using slacko 5.7 then you should alternatively consider to boot your slackosave with boot option "pfix=fsck".

Mayou

Pmount

#9 Post by Mayou »

Thanks sir. I just come back from my breakfast.
I was testing with pmount , that is new. But it's only one pupsave which has problems.
So i will go further using your method.

Nevertheless here are the results with pmount
Attachments
pmount.jpg
(50.93 KiB) Downloaded 1033 times

Mayou

I suppose my pupsave must be in unmounted partition

#10 Post by Mayou »

# losetup
/dev/loop0: 0 /mnt/tmpfs/puppy_slacko_5.3.2.9.sfs
/dev/loop1: 0 /mnt/dev_save/slackosave-bugGens.2fs
# losetup-FULL /dev/loop9 /mnt/home/slackosave-bugGens.2fs
# e2fsck /dev/loop9
e2fsck 1.41.14 (22-Dec-2010)
/dev/loop9 was not cleanly unmounted, check forced.

I suppose my pupsave must be in unmounted partition ? In that case i have to copy it on another pendrive... One second; I reboot on the second pupsave....
Last edited by Mayou on Thu 22 Jan 2015, 08:44, edited 1 time in total.

Mayou

It's and old pendrive

#11 Post by Mayou »

# losetup-FULL /dev/loop9 /mnt/home/slackosave-bugGens.2fs
# e2fsck /dev/loop9
e2fsck 1.41.14 (22-Dec-2010)
/dev/loop9 has gone 427 days without being checked, check forced.
Pass 1: Checking inodes, blocks, and sizes
Deleted inode 8353 has zero dtime. Fix<y>? yes

In fact, i can redo a pupsave. MY doubt was about the health of this usb stick.
What is your opinion ?

# losetup
/dev/loop0: 0 /mnt/tmpfs/puppy_slacko_5.3.2.9.sfs
/dev/loop1: 0 /mnt/dev_save/slackosave-LotusNotes.2fs
/dev/loop9: 0 /initrd/mnt/dev_save/slackosave-bugGens.2fs
# losetup-FULL /dev/loop9 /mnt/home/slackosave-bugGens.2fs
losetup-FULL: /dev/loop9: device is busy
#
I am on slackosave_LotusNotes.2fs !
Attachments
loop.png
(72.36 KiB) Downloaded 1007 times

watchdog
Posts: 2021
Joined: Fri 28 Sep 2012, 18:04
Location: Italy

#12 Post by watchdog »

You can't check a pupsave in use. Use this method from a live session or another pupsave. The pupsave to be checked must be in a mounted partition. Don't forget to free the loop device after check:

Code: Select all

losetup_FULL -d /dev/loopx
In my opinion you are doing your job in a complicated manner. This method is obsolete for recent puppies which check the pupsave booting with option "pfix=fsck" even when the pupsave is an encrypted one.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#13 Post by amigo »

Actually, you should be able to run fsck on the filesystem image and/or the partition it resides on -as long as they are mounted *read-only* during the operation. You can achieve that by using the command 'mount -o remount ...' -I guess on Puppy that menas the real command would be mount-FULL .... or something like that.
You can run 'mount' without any options to see the mount information and figure out the full remount command based on that. Here's an example:

Code: Select all

# mount
/dev/sda2 on / type ext3 (rw,relatime,errors=continue,barrier=1,data=ordered)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
/dev/sda5 on /usr/src type ext3 (rw)
Say I want to check /dev/sda5, but it needs to remain mounted because some program is running from there. As you can see it is mounted read-write, but I can change that like this:
'mount -o remount,ro /dev/sda5'
Now I could run fsck on that partition even while mounted. Nearly all Linux systems boot with the root partition mounted read-only at first. Then, they are able to check the root partition before later using the remount option to make it writable for the later init processes.

Post Reply