How to cleanly unmount your filesystem on shutdowns

How to do things, solutions, recipes, tutorials
Message
Author
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