Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
lvm init.d shutdown prob
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
nordic bro
Guru
Guru


Joined: 25 Oct 2003
Posts: 585

PostPosted: Thu Oct 24, 2013 9:02 pm    Post subject: lvm init.d shutdown prob Reply with quote

I built a new gentoo amd64 system ~month ago including lvm2 (lvm2-2.02.97-r1). it's using the stock init.d/lvm where everything seems fine except on shutdown.

wrt runscript or sh syntax I'm not so good and am a little afraid to run any of these shutdown-related lvm cmds while I'm logged in trying to troubleshoot it manually - the problem is at the end of this section:

Code:
stop() {
   for lvm_path in /bin/lvm /sbin/lvm ; do
      [ -x "$lvm_path" ] && break
   done
   if [ ! -x "$lvm_path" ]; then
      eerror "Cannot find lvm binary in /sbin or /bin!"
      return 1
   fi
# Stop LVM2
if [ -x /sbin/vgs ] && \
   [ -x /sbin/vgchange ] && \
   [ -x /sbin/lvchange ] && \
   [ -f /etc/lvmtab -o -d /etc/lvm ] && \
   [ -d /proc/lvm  -o "`grep device-mapper /proc/misc 2>/dev/null`" ]
then
   einfo "Shutting down the Logical Volume Manager"
   

        VGS=$($lvm_path vgs --config "${config}" -o vg_name --noheadings --nosuffix 2> /dev/null)

        if [ "$VGS" ]
        then
            ebegin "  Shutting Down LVs & VGs"
         #still echo stderr for debugging
ebegin "  lv cmd1 start"
         lvm_commands="#! ${lvm_path} --config '${config}'\n"
         # Extra PV find pass because some devices might not have been available until very recently
ebegin "  lv cmd2 start"
         lvm_commands="${lvm_commands}lvchange --sysinit -a ln ${VGS}\n"
         # Now make the nodes
ebegin "  lv cmd3 start"
         lvm_commands="${lvm_commands}vgchange --sysinit -a ln\n"
         # Order of this is important, have to work around dash and LVM readline
         printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null
         eend $? "Failed"
        fi

   einfo "Finished Shutting down the Logical Volume Manager"
fi
}


watching shutdown the error msg comes after " lv cmd3 start". the msg flashes kind of quick on screen but it's close to this:

Shutting Down LVs & VGs
lv cmd1 start
lv cmd2 start
lv cmd3 start
command failed "2"
no such command, try help

would anyone know what's the matter? somehow the "2" from redirection ends up being interpreted as part of the cmd string or something?

at the top of the script $config is this:

config='global { locking_dir = "/run/lock/lvm" }'

/run/lock/lvm exists.

/etc/conf.d/lvm has just this:

RC_AFTER="mdraid"

thanks.

incidentally most/all of my lvm partitions were created ages ago under older revs of lvm so don't know if that has something to do with this. I just keep reusing them w/newer lvm releases since I've never had trouble before plus I don't recall seeing any emerge notices about having to do something w/them after installing a new lvm pkg.
Back to top
View user's profile Send private message
nordic bro
Guru
Guru


Joined: 25 Oct 2003
Posts: 585

PostPosted: Sat Oct 26, 2013 4:29 pm    Post subject: Reply with quote

pretty important change, the shutdown msg is this:

Shutting Down LVs & VGs
lv cmd1 start
lv cmd2 start
lv cmd3 start
Command failed with status code 2
No such command. Try "help"

obv that's substantially different from op, apologies.

I may be able to figure this out myself now but wanted to update my post before making somebody waste their time with the wrong error msg.

fwiw the msg disappears pretty quickly, thought I had recorded it correctly initially then last night noticed it was quite a bit different.
Back to top
View user's profile Send private message
Zentoo
Apprentice
Apprentice


Joined: 18 Nov 2002
Posts: 195
Location: /dev/console

PostPosted: Fri Nov 15, 2013 1:26 pm    Post subject: Reply with quote

To debug init script, use this:

Code:
/etc/init.d/lvm restart --debug


if you get the same problem that I got right now, you should notice the error come from this executed part:

Code:
+ /sbin/lvm /proc/self/fd/0 --config 'global { locking_dir = "/run/lock/lvm" }'
  Command failed with status code 2.
  No such command.  Try 'help'.
+ eend 2 Failed
 * Failed                                                                                                               [ !! ]
+ einfo 'Finished Shutting down the Logical Volume Manager'

_________________
Kernel 5.14.15-zen | Gcc 11.2 | Glibc 2.34
Core i7 6700K @ 4.6GHz | 32Gb
ACCEPT_KEYWORDS="~amd64"
CFLAGS="-march=native -O2 -pipe"
Back to top
View user's profile Send private message
pigsboss
n00b
n00b


Joined: 27 Dec 2011
Posts: 20

PostPosted: Mon Mar 24, 2014 10:18 am    Post subject: Reply with quote

Are you using multiple VGs? If so the /etc/init.d/lvm script needs to be modified a little.

Here is the original one:
Code:

#!/sbin/runscript
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/lvm2/files/lvm.rc-2.02.95-r2,v 1.2 2013/04/09 11:00:26 ssuominen Exp $

depend() {
   use dmeventd
   before checkfs fsck
   after dmeventd modules device-mapper
}

config='global { locking_dir = "/run/lock/lvm" }'

dm_in_proc() {
   local retval=0
   for x in devices misc ; do
      grep -qs 'device-mapper' /proc/${x}
      retval=$((${retval} + $?))
   done
   return ${retval}
}

start() {
   # LVM support for /usr, /home, /opt ....
   # This should be done *before* checking local
   # volumes, or they never get checked.
   
   # NOTE: Add needed modules for LVM or RAID, etc
   #       to /etc/modules.autoload if needed
   for lvm_path in /bin/lvm /sbin/lvm ; do
      [ -x "$lvm_path" ] && break
   done
   if [ ! -x "$lvm_path" ]; then
      eerror "Cannot find lvm binary in /sbin or /bin!"
      return 1
   fi
   if [ -z "${CDBOOT}" ] ; then
      if [ -e /proc/modules ] && ! dm_in_proc ; then
         modprobe dm-mod 2>/dev/null
      fi
      if [ -d /proc/lvm ] || dm_in_proc ; then
         ebegin "Setting up the Logical Volume Manager"
         #still echo stderr for debugging
         lvm_commands="#! ${lvm_path} --config '${config}'\n"
         # Extra PV find pass because some devices might not have been available until very recently
         lvm_commands="${lvm_commands}pvscan\n"
         # Now make the nodes
         lvm_commands="${lvm_commands}vgscan --mknodes\n"
         # And turn them on!
         lvm_commands="${lvm_commands}vgchange --sysinit -a ly\n"
         # Order of this is important, have to work around dash and LVM readline
         printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null
         eend $? "Failed to setup the LVM"
      fi
   fi
}

stop() {
   for lvm_path in /bin/lvm /sbin/lvm ; do
      [ -x "$lvm_path" ] && break
   done
   if [ ! -x "$lvm_path" ]; then
      eerror "Cannot find lvm binary in /sbin or /bin!"
      return 1
   fi
# Stop LVM2
if [ -x /sbin/vgs ] && \
   [ -x /sbin/vgchange ] && \
   [ -x /sbin/lvchange ] && \
   [ -f /etc/lvmtab -o -d /etc/lvm ] && \
   [ -d /proc/lvm  -o "`grep device-mapper /proc/misc 2>/dev/null`" ]
then
   einfo "Shutting down the Logical Volume Manager"
   

        VGS=$($lvm_path vgs --config "${config}" -o vg_name --noheadings --nosuffix 2> /dev/null)
        if [ "$VGS" ]
        then
            ebegin "  Shutting Down LVs & VGs"
         #still echo stderr for debugging
         lvm_commands="#! ${lvm_path} --config '${config}'\n"
         # Extra PV find pass because some devices might not have been available until very recently
         lvm_commands="${lvm_commands}lvchange --sysinit -a ln ${VGS}\n"
         # Now make the nodes
         lvm_commands="${lvm_commands}vgchange --sysinit -a ln\n"
         # Order of this is important, have to work around dash and LVM readline
         printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null
         eend $? "Failed"
        fi

   einfo "Finished Shutting down the Logical Volume Manager"
fi
}

# vim:ts=4


Pay attention to the stopping part of this script. The variable VGS is assigned as
Code:

VGS=$($lvm_path vgs --config "${config}" -o vg_name --noheadings --nosuffix 2> /dev/null)

If you have two VGs, say, vg01 and vg02, the variable VGS would be
Code:

vg01
vg02

after the assignment. The names of the two VGs are separated by a newline.
Then go to the following line:
Code:

         printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null

All literal '\n' in string variable lvm_commands are interpreted as newlines. But the newline between vg01 and vg02 are still there.
So while executing this command, the script would encounter a failure, since a line of the command is started with vg02, which definitely is not a executable command but the name of a VG.

So the assignment of variable VG should be modified as
Code:

VGS=$($lvm_path vgs --config "${config}" -o vg_name --noheadings --nosuffix --rows 2> /dev/null)

so that vg01 and vg02 are separated by a space instead of a newline.
_________________
Pig's Boss / 猪头
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum