:: Re: [DNG] runit: unclean shutdown?
Top Pagina
Delete this message
Reply to this message
Auteur: Didier Kryn
Datum:  
Aan: dng
Onderwerp: Re: [DNG] runit: unclean shutdown?
Le 13/03/2023 à 03:47, Steve Litt a écrit :
> Henry Jensen via Dng said on Sun, 12 Mar 2023 15:18:52 +0100
>
>> Hello,
>>
>> I switched form sysvinit to runit with runit-init on Devuan chimaera.
>> Since then at every boot I see the message "recovering journal" for
>> the root partition. This indicates, that at the last shutdown the
>> partition wasn't unmounted.
> The preceding is a bad sign. Let's fix it...
>
>> I don't see this message when using sysvinit. The root partition
>> reports "clean" at boot then, which is the normal condition.
>>
>> I added "sleep 10" at the end of runit stage 3 script to see, if there
>> is a problem at shutdown, but couldn't see any.
>>
>> How can I examine this problem further?
> Hi Henry,
>
> To start, I'll post my 3 shellscript, and perhaps you'll see something
> mine has that yours doesn't. Unfortunately, mine has all sorts of if
> statements in case it's shutting down a qemu VM...
>
> ===================================================================
> #!/bin/sh
> # vim: set ts=4 sw=4 et:
>
> PATH=/usr/bin:/usr/sbin
>
> . /etc/runit/functions
> detect_virt
> [ -r /etc/rc.conf ] && . /etc/rc.conf
>
> echo
> msg "Waiting for services to stop..."
> sv force-stop /var/service/*
> sv exit /var/service/*
>
> [ -x /etc/rc.shutdown ] && /etc/rc.shutdown
>
> if [ -z "$VIRTUALIZATION" ]; then
>      msg "Saving random number generator seed..."
>      seedrng
> fi
>
> if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then
>      hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z
> a-z)} fi
>
> halt -w  # for wtmp
>
> if [ -z "$VIRTUALIZATION" ]; then
>      msg "Stopping udev..."
>      udevadm control --exit
> fi
>
> msg "Sending TERM signal to processes..."
> pkill --inverse -s0,1 -TERM
> sleep 1
> msg "Sending KILL signal to processes..."
> pkill --inverse -s0,1 -KILL
>
> if [ -z "$VIRTUALIZATION" ]; then
>      msg "Unmounting filesystems, disabling swap..."
>      swapoff -a
>      umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
>      msg "Remounting rootfs read-only..."
>      mount -o remount,ro /
> fi
>
> sync
>
> if [ -z "$VIRTUALIZATION" ]; then
>      deactivate_vgs
>      deactivate_crypt
>      if [ -e /run/runit/reboot ] && command -v kexec >/dev/null; then
>          msg "Triggering kexec..."
>          kexec -e 2>/dev/null
>          # not reached when kexec was successful.
>      fi
> fi
> ===================================================================
>
> In the preceding, note that [ -z "$VIRTUALIZATION" ] means the
> $VIRTUALIZATION environment variable has zero length, indicating *no*
> virtualization. I think the lines pertinent to your issue are the ones
> that happen right after all processes have been terminated and the ones
> that don't terminate are killed. This includes the following:
>
> swapoff -a
>
> The preceding prevents swapping from changing any disk content...
>
> umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
>
> The preceding recursively unmounts all disk filesystems (as opposed to
> /sys, /proc, etc.)
>
> mount -o remount,ro /
>
> The preceding remounts the root partition as read-only, so further
> changes cannot be made to it, but its executables can still be used to
> perform the final shutdown tasks. Note that if /usr is a separate
> partition and there's no /sbin, those executables won't be available.
> You'll need to do some fancy copying before the mass unmount. Oh,
> Lennart!
>
> sync
>
> The preceding confuses me a little because my first instinct would be
> that sync wouldn't work on a read-only filesystem, because what sync
> does is write cached disk writes to disk. A quick web search yielded
> nothing on this subject. But perhaps sync *does* work on readonly
> filesystems. If that's the case, leaving out the sync would leave
> cached writes and perhaps would trigger a journal recovery on the next
> reboot. So if you haven't yet, but a sync command after you've
> unmounted all disk partitions and set the root partition read-only.
>
> SteveT


    Hi Steve.

    I'm pretty sure umount flushes the write buffers associated to the
given partition and, therefore, there is no need for sync before it. For
what concerns 'mount -o remount,ro' , there is still the issue of file
metadata being modified if you don't specify noatime. I would  do 'mount
-o remount,ro,noatime'

     I don't know for the f. acls. For my own systems, all partitions
are always mounted with noacl; therefore I would also add it in the remount.

--     Didier