How to cleanly unmount your filesystem on shutdowns

How to do things, solutions, recipes, tutorials
Message
Author
User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

How to cleanly unmount your filesystem on shutdowns

#1 Post by Patriot »

Hmmm .....

This is a quick how-to for achieving a clean "filesystem" unmount on shutdowns (Updated 5-July-2010). Currently tested for full hdd installs (ext2, PUPMODE=2), frugal installs (ext2, PUPMODE=12) and frugal ataflash installs (ext2, PUPMODE=13) only.

Primary work was done on puppy412 and further tests were later done on puppy421 and puppy431. If you're using a different frugal install mode (CF/usb/etc) then I'm still keen to know your result.

There are now two (2) different method suitable for different needs:
1. If you're basically using full hdd installs or frugals on vfat then method 1 is sufficient. This is the easiest with minimal changes.
2. If you want a complete unmount then method 2 is what you need. This requires initrd.gz minor surgery and substantial changes to the shutdown script.
  • -----------------------------------------------
    METHOD 1 : HDD OR SAVEFILE UNMOUNT
    -----------------------------------------------
1. Edit /etc/rc.d/rc.shutdown in your favorite editor

2. Look for this code block at the end of rc.shutdown (this sample is from puppy412)

Code: Select all

#v2.13 menno suggests this improvement...
STRAYPARTD="`cat /proc/swaps | grep "/dev/" | cut -f 1 -d " " | tr "\n" " "`"
for ONESTRAY in $STRAYPARTD
do
 echo "Swapoff $ONESTRAY"
 swapoff $ONESTRAY
done
sync
3. Add this code block right after the code block above:

Code: Select all

# Stop udev & loggers
killall udevd &>/dev/null
killall klogd &>/dev/null
killall syslogd &>/dev/null

# Patriot's lame "unmount of rootfs"
if [ $PUPMODE -ne 5 ]; then
  case $PUPMODE in
	2)	pupFS=$(awk '/\/dev\/root/ {print $3}' /proc/mounts)
		mount -o remount,ro -t $pupFS /dev/root /
		sync
		;;

	*)	uniFS=$(awk '/unionfs/ {print $3}' /proc/mounts)
		pupFS=$(awk '/pup_rw/ {print $3}' /proc/mounts)
		if [ "$uniFS" -a "$pupFS" != "tmpfs" ]; then
		  mkdir -p /tmp/unrootfs
		  sync
		  mount -o remount,prepend:/tmp/unrootfs,xino=/tmp/unrootfs/xino -t $uniFS / /
		  sync
		fi
		mount -o remount,ro /initrd${SAVE_LAYER}
		sync
		;;
  esac
fi
4. Save it.

5. You must now manually fsck your savefile (or hdd) by either :
  • a) doing a pfix=fsck on your next reboot (for frugals)
    b) boot puppy in ram (pfix=ram) and do a e2fsck of your savefile or hdd
    c) whatever fsck method that you're comfy with
From now onwards, normal shutdowns (reboot/poweroff) should be able to unmount your savefiles (on vfat) or full hdd installs cleanly.
  • ---------------------------------------------------------------------------
    METHOD 2 : ROOTFS COMPLETE-THRU-THE-LAYERS UNMOUNT
    ---------------------------------------------------------------------------
Notes:
This is a quick how-to for a complete-thru-the-layers clean unmount on shutdowns. I have done some confidence testing with these scripts but they have not gone through any rigorous testing cycle (confidence testing only includes booting with pup_x.sfs, pup_x.sfs+zdrv to pup_x.sfs+zdrv+devx+ksrc). I am using it now on my daily systems and I believe that the core logics are pretty stable by now.

The affected files are init in initrd.gz, /sbin/poweroff, /sbin/reboot, /etc/rc.d/rc.shutdown, /etc/profile, ~/.bashrc

Changelog:
06-June-2010: first published
11-June-2010: fix for stray process on puppyfs (thanks to gyro)
12-June-2010: improvements and fixes for command line interface (CLI).
15-June-2010: adjustments for fresh setup (PUPMODE=5)
05-July-2010: fix for loop device detach list (thanks to gyro)


1. Modify /sbin/reboot to :

Code: Select all

#!/bin/sh
[ "$PPID" = "1" ] && exec /etc/rc.d/rc.shutdown reboot
echo -e "\nTo reboot, select \e[0;36m[Reboot]\e[0m from the main menu or"
echo -e "use \e[0;36m'wmreboot'\e[0m from within a shell/script.\n"
2. Modify /sbin/poweroff to :

Code: Select all

#!/bin/sh
[ "$PPID" = "1" ] && exec /etc/rc.d/rc.shutdown poweroff
echo -e "\nTo poweroff, select \e[0;36m[Poweroff]\e[0m from the main menu or"
echo -e "use \e[0;36m'wmpoweroff'\e[0m from within a shell/script.\n"
3. Edit /etc/profile and look for alias vi=e3vi and add the 3 additional alias lines (fix for CLI shutdowns):

Code: Select all

#v4.00 run e3vi whenever vi excuted...
alias vi=e3vi

# Part of clean-unmount-on-shutdowns CLI requirement
alias poweroff="exec poweroff"
alias reboot="exec reboot"
alias xwin="exec xwin"

#v2.12
#xorgwizard creates this file, run once only...
if [ ! -f /tmp/bootcnt.txt ];then
 [ -f /etc/resolutionfix ] && eval `cat /etc/resolutionfix`
fi
4. Edit ~/.bashrc (ie. /root/.bashrc) and add the unalias and alias lines after . /etc/profile line. (Applicable X & CLI fixes):

Code: Select all

. /etc/profile

# unalias for vt
unalias poweroff reboot

# Prevent X recursions in vt
alias X='echo -e "\nX-windows is \e[1;31malready running.\e[0m\n"'
alias Xorg=X
alias Xvesa=X
alias xwin=X
5. Edit /etc/rc.d/rc.shutdown :

- The first added block is at the beginning of the script, before the clear statement

Code: Select all

...
...
...
if [ -z "$1" ]; then
  exit 1
else
  case $1 in
	poweroff|reboot)
	  applet=$1
	  shtty=$(tty)
	  ;;
	*)
	  exit 2
	  ;;
  esac
fi

clear
exec 1>/dev/null 2>&1
echo "System is shutting down ..." >/dev/console
- The next addition is at the end of the script, after the swapoff code block
- Everything past exec /cleanup can be commented or removed

Code: Select all

...
...
...
#v2.13 menno suggests this improvement...
STRAYPARTD="`cat /proc/swaps | grep "/dev/" | cut -f 1 -d " " | tr "\n" " "`"
for ONESTRAY in $STRAYPARTD
do
 echo "Swapoff $ONESTRAY"
 swapoff $ONESTRAY
done
sync

# Stop udevd & logs daemon
killall udevd klogd syslogd &>/dev/null

# Unload modules
for ((i=1; i<=8; i++))
do
  modlist=$(lsmod | awk '($3 == "0") {print $1}')
  [ -z "$modlist" ] && break
  for onemod in $modlist
  do
	rmmod $onemod
  done
done

# Patriot's not too lame unmount of rootfs layers
if [ ! -d /initrd -o $PUPMODE -eq 2 ]; then
  # Unmount code block for full hdd install
  devFS=$(awk '/\/dev\/root/ {print $3}' /proc/mounts)
  busybox mount -o remount,ro -t $devFS /dev/root /
  sync
  busybox umount -ar 2>/dev/null
  exec /bin/busybox $applet
fi

# Setup unrootfs, if none
if [ $(df | grep -c ' /mnt/unrootfs$') -eq 0 ]; then
  mkdir -p /mnt/unrootfs
  busybox mount -t tmpfs tmpfs /mnt/unrootfs -o size=4m
  sync
fi

# Preset, if fresh setup
[ -z "$SAVE_LAYER" ] && SAVE_LAYER="/pup_rw"

# aufs branch switcheroo ...
uniFS=$(awk '/unionfs / {print $3}' /proc/mounts)
busybox mount -o remount,prepend:/mnt/unrootfs=rw,noxino -t $uniFS / /
sync
busybox mount -o remount,ro /initrd${SAVE_LAYER}
sync

# Prep unrootfs
cd /mnt/unrootfs
rm -f init
mkdir -p bin dev etc lib mnt nroot proc sbin sys tmp var/run
sync

# Prep /bin
cp /bin/busybox /bin/grep /usr/bin/fuser bin/
bbApps=$(bin/busybox); bbApps=${bbApps##*functions:}
for bbLnk in $bbApps; do ln -s busybox bin/${bbLnk%,}; done
unset bbApps bbLnk
# Check for busybox umount option
loflag=$(bin/busybox umount 2>&1 | awk '/\t-d\t/ {print " "$1}')
# Prep /dev
cp -dR /dev/* dev/
# Prep /etc
ln -s /proc/mounts etc/mtab
cp /etc/passwd etc/
# Prep /lib
cp /lib/ld-linux.so.2 /lib/libc.so.6 /lib/libcrypt.so.1 /lib/libm.so.6 lib/
# Prep /sbin
ln -s /bin/busybox sbin/getty
sync

# Move recursions
function move_recursion()
{
  mkdir $2
  busybox mount -o move $1 $2
}
[ "$PUP_HOME" ] && move_recursion /initrd${PUP_HOME} mnt/mp1
[ "$SAVE_LAYER" ] && move_recursion /initrd${SAVE_LAYER} mnt/mp2
[ "$(grep '/mnt/tmpfs ' /proc/mounts)" ] && move_recursion /initrd/mnt/tmpfs mnt/mp3
[ "$(grep '/mnt/tmpfs2 ' /proc/mounts)" ] && move_recursion /initrd/mnt/tmpfs2 mnt/mp4
[ "$(grep ' /tmp ' /proc/mounts)" ] && busybox umount /tmp
busybox umount /dev/pts /proc/bus/usb
busybox mount -o move /proc proc
busybox mount -o move /sys sys
sync

# Switching to unrootfs
unset LANG
pivot_root . /mnt/unrootfs/nroot
sync
cd /

# Prep Cleanup
echo '#!/bin/sh
exec 0<'$shtty'
exec 1>'$shtty' 2>&1

# Terminate anything still on puppyfs
fuser -kms /nroot

# Find and unmount union branches
unibrs=$(mount | grep " aufs ")
if [ "$(echo $unibrs | grep dirs=)" ]; then
  # AUFS1
  unibrs=${unibrs##*dirs=}; unibrs=${unibrs%)*}; unibrs=${unibrs%%,*}
  for i in $(echo $unibrs | tr ":" " ")
  do
	case $i in
	  /=*|/mnt/mp2=*) continue ;;
	  *) unilist="${i%%=*} $unilist" ;;
	esac
  done
else
  # AUFS2
  unibrs=${unibrs##*si=}; unibrs=${unibrs%)*}; unibrs="/sys/fs/aufs/si_"${unibrs%%,*}
  for i in $(ls $unibrs/br*)
  do
	h=$(cat $i)
	case $h in
	  /=*|/mnt/mp2=*) continue ;;
	  *) unilist="${h%%=*} $unilist" ;;
	esac
  done
fi
for onebrs in $unilist
do
  mount -o remount,del:${onebrs} -t '$uniFS' /nroot /nroot
  sync
  umount'$loflag' $onebrs
  sync
done

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

# Final cleanup and unmount boot partition
[ -d /mnt/mp4 ] && umount'$loflag' /mnt/mp4
sync
[ -d /mnt/mp3 ] && umount'$loflag' /mnt/mp3
sync
umount'$loflag' /nroot
sync
[ -d /mnt/mp2 ] && umount'$loflag' /mnt/mp2
sync
[ -d /mnt/mp1 ] && umount /mnt/mp1

umount -ar 2>/dev/null
exec /bin/busybox '$applet'
' >/cleanup
chmod 755 /cleanup
exec /cleanup
6. Unpack initrd.gz and edit init script (at the end of the script):

Code: Select all

sync
umount /proc/bus/usb
umount /sys
umount /proc

# 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

#now using cpio archive for initramfs 'initial ramdisk'...
#exec switch_root -c /dev/console /pup_new /bin/busybox init 3
exec switch_root /pup_new /sbin/init

###END###
7. You must now manually fsck your savefile (or hdd) before checking your filesystem status.


Rgds

._.
Last edited by Patriot on Mon 26 Jul 2010, 17:32, edited 11 times in total.

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

#2 Post by Patriot »

here be dragons

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#3 Post by jemimah »

Excellent - I had a similar idea, though I hadn't gotten to looking up the syntax for aufs.

For Pupmode 13, I think there might be a way to remove the save file from the union, and it should copy up any open files to the RAM branch. I played with it on UnionFS but switched back to AUFS before I got very far.

That is what your code does right?

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

#4 Post by Patriot »

Hmmm .....
jemimah wrote:Excellent - I had a similar idea, though I hadn't gotten to looking up the syntax for aufs.

For Pupmode 13, I think there might be a way to remove the save file from the union, and it should copy up any open files to the RAM branch. I played with it on UnionFS but switched back to AUFS before I got very far.

That is what your code does right?
:lol: ..... Yes, initially I was also thinking of (it couldn't be that difficult to) fully removing the save file from the union, but apparently it's harder than it seems ... Further experiments shows that switching the save file to read-only (ro) mode also gives me the desired result. So, that's what the code block above will (try) to do. I think there's no worries with pupmode=13 updates as that's already being handled earlier by snapmergepuppy ...

Thanks for highlighting pupmode=13, I did several simulation runs with that mode and have made some adjustments to cater for it ...


Rgds

User avatar
MinHundHettePerro
Posts: 852
Joined: Thu 05 Feb 2009, 22:22
Location: SE

#5 Post by MinHundHettePerro »

Absolutely Brilliant :)!

Corrects the problem with uncleanly unmounted savefiles in lupu.

Thank you :)/
MHHP
[color=green]Celeron 2.8 GHz, 1 GB, i82845, many ptns, modes 12, 13
Dual Xeon 3.2 GHz, 1 GB, nvidia quadro nvs 285[/color]
Slackos & 214X, ... and Q6xx
[color=darkred]Nämen, vaf....[/color] [color=green]ln -s /dev/null MHHP[/color]

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#6 Post by big_bass »

Hey Patriot


great news !

I would like to do some testing for you
you said that you edited code based against 4.12
could you please post the diff against the official 4.12

just to be sure all is fine before placing it in my iso

thanks Joe

I'll throw in a simple dagNdrop xdialog diff making tool
you may find it to come in handy for all the stuff you do

Code: Select all

#!/bin/sh

# version 2 changed to *.patch
# just a simple diff tool for the lazy
# there are better but this is easy :D 
# Joe Arose 
# call this dnd_diff
# patched are auto made for you 
DIALOG=Xdialog

$DIALOG --title "The original for DIFF   " \
        --inputbox "Type in a value or Drag N drop.
         enter first file to diff now 
        the name will be given from the this file.patch
        and placed in root\n
" 0 0  2> /tmp/one.txt

retval=$?



input=`cat /tmp/one.txt`


case $retval in
  0)
    echo "Input string is '$input'";;
  1)
    echo "Cancel pressed."
    exit;;
  255)
    echo "Box closed."
    exit;;
esac

#----------------------------------
$DIALOG --title "The edited file for DIFF   " \
        --inputbox "Type in a value or Drag N drop.
        you enter second file to diff now\n
" 0 0 2>/tmp/two.txt

retval=$?

input2=`cat /tmp/two.txt`

case $retval in
  0)
    echo "Input string is '$input2'";;
  1)
    echo "Cancel pressed."
    exit;;
  255)
    echo "Box closed."
    exit;;
esac

diff -pruN $input $input2 >/root/`basename $input`.patch

#or you could do this if you have another editor installed 
$DEFAULTTEXTEDITOR  /root/`basename $input`.patch

#geany is the default editor change this if you have another editor
#geany /root/`basename $input`.patch

rm -f /tmp/two.txt
rm -f /tmp/one.txt


User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#7 Post by jemimah »

This is working good for cleanly unmounting the save file, but the partition that contains the save file is still not getting unmounted cleanly.

Any ideas how to fix that? How do other distros do it?

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

#8 Post by Patriot »

Hmmm .....
big_bass wrote:..... could you please post the diff against the official 4.12 .....
Hey there Big Joe ... Sure thing. Here ya go ...

Code: Select all

--- rc.shutdown.412	2008-11-02 05:43:37.000000000 +0800
+++ rc.shutdown	2010-05-31 00:27:09.191902581 +0800
@@ -843,6 +843,33 @@ do
 done
 sync
 
+# Stop udev & loggers
+killall udevd &>/dev/null
+killall klogd &>/dev/null
+killall syslogd &>/dev/null
+
+# Patriot's lame "unmount of rootfs"
+if [ $PUPMODE -ne 5 ]; then
+  case $PUPMODE in
+   2)   pupFS=$(awk '/\/dev\/root/ {print $3}' /proc/mounts)
+      mount -o remount,ro -t $pupFS /dev/root /
+      sync
+      ;;
+
+   *)   uniFS=$(awk '/unionfs/ {print $3}' /proc/mounts)
+      pupFS=$(awk '/pup_rw/ {print $3}' /proc/mounts)
+      if [ "$uniFS" -a "$pupFS" != "tmpfs" ]; then
+        mkdir -p /tmp/unrootfs
+        sync
+        mount -o remount,prepend:/tmp/unrootfs,xino=/tmp/unrootfs/xino -t $uniFS / /
+        sync
+      fi
+      mount -o remount,ro /initrd${SAVE_LAYER}
+      sync
+      ;;
+  esac
+fi 
+
 #rm -f /tmp/wmexitmode.txt
 
 #note, there is a problem with unmounting, especially ntfs as it cannot be remounted
jemimah wrote:This is working good for cleanly unmounting the save file, but the partition that contains the save file is still not getting unmounted cleanly.

Any ideas how to fix that? How do other distros do it?
Ah well, it didn't occur to me at the time as I'm on fat/ntfs all this while ... I'll do some experiments with frugals on ext2 later to see if there's any "easy-n-painless" way to achieve this. The way puppy is using the multi-layered FS sure borks any easy unmounting. I'm aware that Slax relies heavily on aufs but I don't recall seeing Slax using multiple layers like this ...

Well, let's see how it goes ...


Rgds

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#9 Post by jemimah »

The worst is when you're dual booting with ubuntu or something and it makes you wait through an fsck with every boot. :(

Thanks for tackling this problem. This will help a lot of people.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#10 Post by 8-bit »

I just tried your modification to the rc.shutdown script and it works very well. After a reboot to Puppy 431 SCSI, I checked the lupusave file for puppy lucid 500 and it came back clean.
That is the first time that has ever happened.
This modification should be passed on to Barry for inclusion in all the official Puppy versions!
Very good work and a problem solved. :D :D

don922
Posts: 433
Joined: Sat 19 Jan 2008, 07:58
Location: Nong Yai Buah

#11 Post by don922 »

Works great in Puppy 4.12 retro frugal install! :D

Doesn't work in Puppy 400 frugal install....:cry:

Is there any easy fix? I have no coding skills :oops:

I notice that you limited its use but the rc.shutdowns are about the same....
Patriot wrote: Subject description: puppy412, puppy421, puppy431
[color=green][i]Don -- Thailand[/i][/color]
[url=http://www.puppylinux.com][img]http://tinypic.com/4e0tojl.jpg[/img][/url]

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#12 Post by big_bass »

Hey Patriot

thanks for the added patch
I have to keep track of all
the stuff I add

It gives me great pleasure to post this code snippit

Code: Select all

 root@slaxer:~# e2fsck -av /mnt/hda2/pup_save-new2.2fs
/mnt/hda2/pup_save-new2.2fs: clean, 56364/262144 files, 908809/1048576 blocks

clean, clean, clean! :D
8) 8) 8)


-----------------------techno details --------------------------------------------

ahhh there's a little thing I want to clear up
I tested this booting in slackware 13
so as not to have any puppy symlink confusion

what happens testing the save file by mounting it you get a
broken symlink in /mnt/home pointing to /initrd/mnt/dev_save
which is a good thing


however if you boot in puppy it appears that /mnt/home is a mounted folder
which could be confusing while testing on puppy



-----------------------------------------------------------------

**if anyone needs to mount a pup_save outside of puppy
if you install ROX I wrote two simple scripts to do it I wrote an umount also but
rox can handle the unmount in the same way as puppy
so you dont need it

Code: Select all


#!/bin/sh
#simple drag and drop mounting  tool for
#sfs iso or ext3 /ext2 files  (2fs 3fs in puppy) 
#just drag and drop  on this script
#they will get mounted with the correct name
#at /mnt
#script by Joe Arose ...big_bass



#SFS
if echo `basename "$1" ` | grep -q '.sfs$'; then
                  mkdir -p /mnt/`basename $1`
mount -t squashfs -o loop,ro  $1 /mnt/`basename $1`
cd /mnt/`basename $1`
 rox -d /mnt/`basename $1`   
				  
				  
#EXT2				  
elif echo `basename "$1" ` | grep -q '.2fs$'; then
                  mkdir -p /mnt/`basename $1`
mount -t ext2 -o loop,ro  $1 /mnt/`basename $1`
cd /mnt/`basename $1`
 rox -d /mnt/`basename $1`   
					  
#EXT3				  
elif echo `basename "$1" ` | grep -q '.3fs$'; then
                  mkdir -p /mnt/`basename $1`
mount -t ext3 -o loop,ro  $1 /mnt/`basename $1`
cd /mnt/`basename $1`
 rox -d /mnt/`basename $1`   
				 	  		  

#ISO				  
elif echo `basename "$1" ` | grep -q '.iso$'; then
                  mkdir -p /mnt/`basename $1`
mount -t iso9600 -o loop,ro  $1 /mnt/`basename $1`
cd /mnt/`basename $1`
 rox -d /mnt/`basename $1`   
				  fi	  		  				  

Joe

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

#13 Post by Patriot »

Hmmm .....
don922 wrote: ..... Doesn't work in Puppy 400 frugal install....:cry:

Is there any easy fix? .....
Puppy 4.00 uses unionfs by default and my tests with that thingy gives inconsistent ummount result. Well, I do have a quick fix for puppy400 :

1. Edit your menu.lst and make puppy 4.00 use aufs (using kernel option layerfs=aufs), example:

Code: Select all

kernel (hd0,0)/puppy400/vmlinuz pmedia=idehd pdev1=hda1 psubdir=puppy400 layerfs=aufs
2. Modify /etc/rc.d/rc.shutdown as shown above in my first post, but with two additional lines as shown below:

Code: Select all

      if [ "$uniFS" -a "$pupFS" != "tmpfs" ]; then
        mount -t tmpfs tmpfs /tmp -o size=1m     # extra for puppy4.00
        mkdir -p /tmp/unrootfs
        sync
        mount -o remount,prepend:/tmp/unrootfs,xino=/tmp/unrootfs/xino -t $uniFS / /
        sync
        sleep 2        # maybe needed for puppy400
      fi
That's it. On your next puppy400 reboot, you will see the filesystem check running slightly faster (and yes, fsck is hardcoded to run on every boot in puppy400). The fsck log /initrd/tmp/chkret should now be showing a clean status.


Rgds
Last edited by Patriot on Tue 01 Jun 2010, 07:01, edited 1 time in total.

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

#14 Post by Patriot »

Hmmm .....

:D I have managed to manually unmount all mounted partitions, loop devices, the savefile and the aufs union successfully from a live frugal puppy412. The util lsof have been really really helpful in my "quest" .....

Tracing the whole thing have shown me obscure stuffs like "embedded" recursions (/initrd/mnt/dev_save + /initrd/pup_rw) and the real badass bugger, init itself. No wonder its tough un-mounting the darn frugal thingy.

However, there's no code to show yet as I need more time to code them properly and refine them to a minimum. I should warn whoever's interested with this that your puppy may require more than just a minor modification to initrd and the shutdown scripts ...


Rgds

don922
Posts: 433
Joined: Sat 19 Jan 2008, 07:58
Location: Nong Yai Buah

Puppy 400 still has problems

#15 Post by don922 »

@Patriot:

I have changed the menu.lst per your instructions and added the line to /etc/rc.d/rc.shutdown.

I shutdown puppy400, booted into puppy412 and ran e2fsck with the following results:

Code: Select all

[~] e2fsck -vp /mnt/home/puppy400/pup_save-400.2fs
/mnt/home/puppy400/pup_save-400.2fs: Superblock last mount time is in the future.  FIXED.
/mnt/home/puppy400/pup_save-400.2fs was not cleanly unmounted, check forced.

    3740 inodes used (5.71%)
     135 non-contiguous inodes (3.6%)
         # of inodes with ind/dind/tind blocks: 402/75/0
  105865 blocks used (40.38%)
       0 bad blocks
       0 large files

    3300 regular files
     374 directories
       4 character device files
       0 block device files
       0 fifos
       1 link
      51 symbolic links (51 fast symbolic links)
       2 sockets
--------
    3732 files
On the next boot into puppy400 I saw the following in the boot message:
Setting up the Unionfs layered file system
Performing a switch_root to the new Unionfs file system
I thought that the new menu.lst entry changed this.
Maybe puppy400 just won't cleanly unmount.
[color=green][i]Don -- Thailand[/i][/color]
[url=http://www.puppylinux.com][img]http://tinypic.com/4e0tojl.jpg[/img][/url]

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

Re: Puppy 400 still has problems

#16 Post by Patriot »

Hmmm .....

@don922

Please take a look at the amended code block above. I've added a sleep line to allow background stuffs to settle. Seems to help improve the remounting for puppy400 (only).
don922 wrote: ..... I shutdown puppy400, booted into puppy412 and ran e2fsck with the following results: .....
Ah yes, you should reboot back into puppy400 for the auto fsck to run first .... If you rebooted into puppy412 then you need to do a manual fsck ... After the fsck is done (plus a reboot), then only you check for unmount stats ...
don922 wrote:On the next boot into puppy400 I saw the following in the boot message:
Setting up the Unionfs layered file system
Performing a switch_root to the new Unionfs file system
I thought that the new menu.lst entry changed this.
Maybe puppy400 just won't cleanly unmount.
The boot message is hardcoded. A mount status in a terminal will show that the union layer is using aufs.


Rgds
Attachments
p400status.png
Checking puppy 4.00 previous unmount savefile status
(5.05 KiB) Downloaded 1876 times

don922
Posts: 433
Joined: Sat 19 Jan 2008, 07:58
Location: Nong Yai Buah

Puppy 400 must be jinxed

#17 Post by don922 »

I add the 2 lines for Puppy 400 /etc/rc.d/rc.shutdown, but I am still not getting it right.

I rebooted back into Puppy 400 and ran cat /initrd/tmp/chkret see the results below:
Attachments
umount.png
(81.24 KiB) Downloaded 2013 times
[color=green][i]Don -- Thailand[/i][/color]
[url=http://www.puppylinux.com][img]http://tinypic.com/4e0tojl.jpg[/img][/url]

User avatar
playdayz
Posts: 3799
Joined: Fri 25 Apr 2008, 18:57

#18 Post by playdayz »

Code: Select all

#v2.13 menno suggests this improvement...
STRAYPARTD="`cat /proc/swaps | grep "/dev/" | cut -f 1 -d " " | tr "\n" " "`"
for ONESTRAY in $STRAYPARTD
do
 echo "Swapoff $ONESTRAY"
 swapoff $ONESTRAY
done
sync

###should your code go here????

#rm -f /tmp/wmexitmode.txt

#note, there is a problem with unmounting, especially ntfs as it cannot be remounted
#ro (?). A ntfs part with ${DISTRO_FILE_PREFIX}save.2fs cannot be unmounted because of the mounted
#${DISTRO_FILE_PREFIX}save.2fs.
#at least, attempt to kill anything running in the ntfs partition...
#(i don't think anything will be, only /dev/loop1 (${DISTRO_FILE_PREFIX}save.2fs), but just in case)
ABSPUPHOME="" #100107
[ "$PUP_HOME" ] && ABSPUPHOME="/initrd${PUP_HOME}" #v2.16rc
[ ! "$ABSPUPHOME" ] && ABSPUPHOME="/initrd/mnt/dev_save" #v2.16rc
if [ "`busybox mount | grep "$ABSPUPHOME"`" != "" ];then
 #BADPIDS="`fuser -v -m $ABSPUPHOME | grep -v --extended-regexp 'kernel|COMMAND|^$' | tr -s ' ' | cut -f 3 -d ' ' | tr '\n' ' '`"
 BADPIDS="`fuser -m $ABSPUPHOME 2>/dev/null`" #100107
 for ONEBAD in $BADPIDS
 do
  echo "Killing process $ONEBAD..."
  kill $ONEBAD
  sleep 1
  kill -9 $ONEBAD 2>/dev/null
  sync
 done
 killzombies #v3.99
fi


#v2.16rc try this too... SAVE_LAYER defined in /etc/rc.d/PUPSTATE...
if [ "$SAVE_LAYER" ];then
 sync
 SAVEDEV="`mount | grep "/initrd${SAVE_LAYER}" | cut -f 1 -d ' '`"
 SAVEFS="`mount | grep "/initrd${SAVE_LAYER}" | cut -f 5 -d ' '`"
 busybox mount -t $SAVEFS -o remount,ro $SAVEDEV /initrd${SAVE_LAYER} 2>/dev/null
 umount-FULL -i -n -l /initrd/${SAVE_LAYER} 2>/dev/null #-l is lazy unmount.
fi

#v2.16 try one more thing for ntfs... lazy unmount, suggested by GuestToo...
MNTFUSE="`busybox mount | grep 'fuse' | head -n 1 | cut -f 3 -d ' '`"
if [ "$MNTFUSE" != "" ];then
 #v2.17 hairywill found the -u is required with -z...
 fusermount -z -u $MNTFUSE
#else
# if [ "$PDEV1" ];then #from PUPSTATE
#  APATTERN="/dev/$PDEV1 "
#  if [ "`busybox mount | grep "$APATTERN"`" != "" ];then
#   #[ "$PUP_HOME" ] && busybox mount -t $DEV1FS -o remount,ro /dev/$PDEV1 /initrd${PUP_HOME}
#   #...no, do not attempt ro remount, will prevent ${DISTRO_FILE_PREFIX}save clean shutdown if it didn't above.
#   umount-FULL -i -n -l /dev/$PDEV1
#  fi
# fi
fi

busybox umount -ar > /dev/null 2>&1

#the end#
There is a report in this thread that your shutdown fix works for lupu. I am going to put it into a development release toward 5.1 named lucid-202. Here is the end of rc.shutdown. Does it seem that it should still go where you said? Thank you.

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

#19 Post by Patriot »

Hmmm .....
playdayz wrote:........ There is a report in this thread that your shutdown fix works for lupu. I am going to put it into a development release toward 5.1 named lucid-202. Here is the end of rc.shutdown. Does it seem that it should still go where you said? Thank you.
I believe it should also work on quirky too ... :lol: ... and yes, the place you commented will do just fine ... You may want to take note that the shutdown fix here works fine for the savefiles only, not the partition it resides on (as pointed out earlier by jemimah).

Current progress:
Manual unmount of all the layers was already done. Putting it down into code started soon after but completion was delayed due to a borked partition. Don't ask me how 10GiB of my data got wiped out ..... already spent 3 days reconstructing the file tables .... :roll:

The complete-thru-the-layers-clean-unmount script is just about done and now it's going through some confidence testing on p412/p421/p431 ... :D


Rgds

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

#20 Post by Patriot »

Hmmm .....

I'm pleased to publish the complete-thru-the-layers clean-unmount-on-shutdowns script which can be found on the first post of this thread.

Also attached is busybox-1.16.1 static binary suitable as replacement for p412/p421/p431, if anyone's interested.


Rgds

Post Reply