How to cleanly unmount your filesystem on shutdowns

How to do things, solutions, recipes, tutorials
Message
Author
gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#41 Post by gyro »

Patriot,

I checked that my initrd.gz included your mods.
I did a fresh cut & paste of your mods to rc.shutdown.

I did a fresh frugal install from vfat SD card (USB storage).
On reboot, after creating the savefile, I got a couple of "umount device busy" messages. But the pupsave.2fs is good

Code: Select all

# ./bin/fsckmount-mnt-data.sh /mnt/sdc1/pupsave.2fs 
fsck 1.41.9 (22-Aug-2009)
e2fsck 1.41.9 (22-Aug-2009)
/mnt/sdc1/pupsave.2fs: clean, 337/32768 files, 11459/131072 blocks
After the reboot, now in pupmode=13, I did another reboot, and got no error messages. But the pupsave.2fs is not quite perfect

Code: Select all

# ./bin/fsckmount-mnt-data.sh /mnt/sdc1/pupsave.2fs 
fsck 1.41.9 (22-Aug-2009)
e2fsck 1.41.9 (22-Aug-2009)
Superblock last mount time (Fri Jun 18 05:12:37 2010,
	now = Thu Jun 17 19:16:48 2010) is in the future.
Fix? yes

/mnt/sdc1/pupsave.2fs was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/mnt/sdc1/pupsave.2fs: ***** FILE SYSTEM WAS MODIFIED *****
/mnt/sdc1/pupsave.2fs: 392/32768 files (0.3% non-contiguous), 11905/131072 blocks
What I find intriguing is that even though it says "not cleanly unmounted", it doesn't find any errors.
The release rc.shutdown produced a pupsave file that was not only "not cleanly unmounted", but fsck always reported some errors.

gyro

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#42 Post by gyro »

Patriot,

Tried your busybox.
Works fine except no "ipcalc" applet.
In puppy 431, rc.network uses "ipcalc" when setting up static IP addresses. So I've reverted to the release busybox.

gyro

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#43 Post by Patriot »

Hmmm .....
gyro wrote:

Code: Select all

# ./bin/fsckmount-mnt-data.sh /mnt/sdc1/pupsave.2fs 
fsck 1.41.9 (22-Aug-2009)
e2fsck 1.41.9 (22-Aug-2009)
Superblock last mount time (Fri Jun 18 05:12:37 2010,
	now = Thu Jun 17 19:16:48 2010) is in the future.
Fix? yes .....
What I find intriguing is that even though it says "not cleanly unmounted", it doesn't find any errors. .....
The only error there is the unmount time stamp. When the savefile is last mounted/unmounted, the time is Fri Jun 18 05:12:37 2010 but the time is now Thu Jun 17 19:16:48 2010 ... The filesystem itself is fine, this is what I call an "administrative" error .... :lol:

Nope, it's not caused by the clean unmount code blocks. This is a wider problem (TZ/UTC/localtime/whatever) that seems to affect many puppy versions. Will need a bit of time to look into ... and thanks for the busybox test report. I've uploaded a new copy of busybox with ipcalc added (minus watchdog). If you find any critical applet missing, just let me know.


Rgds

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#44 Post by gyro »

Patriot,
I do understand that the "mount time in the future" error message, is unrelated to rc.shutdown doing the right thing. I think it's got something to do with the mount in init being done before the localtime stuff is sorted out.
Patriot wrote:thanks for the busybox test report. I've uploaded a new copy of busybox with ipcalc added (minus watchdog). If you find any critical applet missing, just let me know.
Thanks for the new busybox, now I can use your upgraded busybox, and still configure static IP addresses in puppy 431. I haven't missed watchdog yet.

gyro

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

bug in init code??

#45 Post by gyro »

Patriot,

I was just reviewing my code changes to the init script in initrd.gz, and I noticed something odd with your code:

Code: Select all

# Patriot: init from tmpfs
mkdir -p /pup_new/mnt/unrootfs
mount -t tmpfs tmpfs /pup_new/mnt/unrootfs -o size=4m
cp /bin/busybox /pup_new/mnt/unrootfs/init
if [ "$(readlink /pup_new/sbin/init)" != "/mnt/unrootfs/init" ]; then
  ln -sf /mnt/unrootfs/init /pup_new/sbin/init
fi
sync
should it be

Code: Select all

# Patriot: init from tmpfs
mkdir -p /pup_new/mnt/unrootfs
mount -t tmpfs tmpfs /pup_new/mnt/unrootfs -o size=4m
cp /bin/busybox /pup_new/mnt/unrootfs/init
if [ "$(readlink /pup_new/sbin/init)" != "/pup_new/mnt/unrootfs/init" ]; then
  ln -sf /pup_new/mnt/unrootfs/init /pup_new/sbin/init
fi
sync
i.e. adding "/pup_new" in "if" and "ln" lines?

gyro

nooby
Posts: 10369
Joined: Sun 29 Jun 2008, 19:05
Location: SwedenEurope

#46 Post by nooby »

I noticed now this one
"/pup_new/mnt/unrootfs/init"


Was there other differences too?
I use Google Search on Puppy Forum
not an ideal solution though

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

Re: bug in init code??

#47 Post by Patriot »

Hmmm .....
gyro wrote:Patriot,

I was just reviewing my code changes to the init script in initrd.gz, and I noticed something odd with your code: ........
That code block you were referring to should be read with the last line to receive enlightenment: 8)

Code: Select all

# Patriot: init from tmpfs
mkdir -p /pup_new/mnt/unrootfs
mount -t tmpfs tmpfs /pup_new/mnt/unrootfs -o size=4m
cp /bin/busybox /pup_new/mnt/unrootfs/init
if [ "$(readlink /pup_new/sbin/init)" != "/mnt/unrootfs/init" ]; then
  ln -sf /mnt/unrootfs/init /pup_new/sbin/init
fi
sync

exec switch_root /pup_new /sbin/init 
The link is checked/made before switching rootfs, so it took into account where (busybox) init is going to be afterwards. After rootfs switch, /pup_new will "automagically disappear". If you still believe its a bug, feel free to test out your theory ... just watch out for kernel panics ... :lol:


Rgds

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

Re: bug in init code??

#48 Post by gyro »

Patriot wrote:That code block you were referring to should be read with the last line to receive enlightenment:
Thanks for the explanation.
Sorry, my mistake. I was looking at the code in a "diff" file, and hence in isolation. All makes sense now.

gyro

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#49 Post by gyro »

Patriot,

Sorry to be a bother, but there is just 1 more thing.

In the cleanup script in "rc.shutdown" there is block of code starting with

Code: Select all

# Find and detach loop devices
for onelodev in $(losetup|tr -d " ")
that may have a difficulty.
In my puppy 431, a blank "losetup" command, will only display loop devices 0..9. I used to specifically use /dev/loop10 and had to issue "losetup /dev/loop10" to see the info for this device. Hence your code would not detach /dev/loop10 on my system.
Maybe something like the following, (based on load_sfs code):

Code: Select all

# Find and detach loop devices
current_loops=$(expr $(ls -1 /dev/loop* | wc -l) - 1)
for n in $(seq 0 $current_loops); do
  losetup -d /dev/loop${n} 2>/dev/null
done
might work more reliably on puppies using more than 10 loop devices.

gyro

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#50 Post by Patriot »

Hmmm .....

Ah yes, I've forgotten about busybox losetup limits of 10 devices. Ok, it's a simple fix:

Code: Select all

# Find and detach loop devices
for onelodev in $(grep "^/dev/loop" /proc/mounts | tr -s " " ":")
do
  losetup -d ${onelodev%%:*} 2>/dev/null
  sync
done
Quick test runs were done with 16 mounted loop devices.


Rgds

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#51 Post by gyro »

I've updated "rc.update-431.pet" to include this latest fix to rc.shutdown.

See my earlier post for download.

gyro

User avatar
AlexS
Posts: 47
Joined: Fri 24 Nov 2006, 10:22
Location: Munich

#52 Post by AlexS »

i've tried to follow this thread, but i have one question: can these fixes be applied to a ext2 encrypted pupsave? If not how could one implement that? I need encrypted pupsaves for real world usage.

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#53 Post by gyro »

AlexS wrote:i've tried to follow this thread, but i have one question: can these fixes be applied to a ext2 encrypted pupsave? If not how could one implement that? I need encrypted pupsaves for real world usage.
My guess is, yes. I would defer to Patriot on this, but I don't think having an encrypted pupsave should make any difference. Just change the scripts as outlined by Patriot.

gyro

User avatar
AlexS
Posts: 47
Joined: Fri 24 Nov 2006, 10:22
Location: Munich

#54 Post by AlexS »

ok, I went for the simple approach (the first suggested by patriot), I'll see how it works out over the next couple of days

Post Reply