Aydan
Posts: 729
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

[SOLVED] shell script problem

Fri Mar 14, 2014 9:34 pm

I'm trying to run the raspberry form an LVM root, and got it sort of working, but the LVM doesn't come up at boot by itself. I have to start is in the console manually.
I've narrowed it down to the lvm2 script that is supposed to activate the lvm. But it doesn't.
Here's the script:

Code: Select all

#!/bin/sh

PREREQ="mdadm mdrun multipath"

prereqs()
{
        echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
        prereqs
        exit 0
        ;;
esac

activate_vg()
{
        local dev="$1"

        # Make sure that we have a non-empty argument
        if [ -z "$dev" ]; then
                echo dev is empty
                return 1
        fi
        echo $dev

        # Take care of lilo boot arg, risky activating of all vg
        case "$dev" in
        fe[0-9]*)
                lvm vgchange -aly --ignorelockingfailure
                echo whatever1
                exit 0
                ;;
        # FIXME: check major
        /dev/root)
                lvm vgchange -aly --ignorelockingfailure
                echo whatever2
                exit 0
                ;;
        esac

        # Make sure that we have a d-m path
        dev="${dev#/dev/mapper/}"
        echo "dev is $dev and arg 1 is $1"
        if [ "$dev" = "$1" ]; then
                echo "returning 1"
                return 1
        fi

        eval $(dmsetup splitname --nameprefixes --noheadings --rows "$dev")
        echo "$DM_VG_NAME"
        echo "$DM_LV_NAME"

        if [ "$DM_VG_NAME" ] && [ "$DM_LV_NAME" ]; then
                lvm lvchange -aly --ignorelockingfailure "$DM_VG_NAME/$DM_LV_NAME"
                rc=$?
                if [ $rc = 5 ]; then
                        echo "Unable to find LVM volume $DM_VG_NAME/$DM_LV_NAME"
                fi
        fi
}

if [ ! -e /sbin/lvm ]; then
        echo "no /sbin/lvm"
        exit 0
fi

echo modprobing dm-mod
modprobe -q dm-mod

activate_vg "$ROOT"
activate_vg "$resume"

exit 0
The reason is that the line

Code: Select all

dev="${dev#/dev/mapper/}"
and the subsequent

Code: Select all

 if [ "$dev" = "$1" ]
is always true.

So the syntax of

Code: Select all

dev="${dev#/dev/mapper/}"
eludes me.

I think it's supposed to concatenate /dev/mapper to $dev, but the result is only $dev but $dev is the same as $1 so the subsequent activateion of the volume never gets called.
Is it that busybox behaves differently than other shells or what is going on here?

Regards
Aydan
Last edited by Aydan on Fri Mar 14, 2014 10:20 pm, edited 1 time in total.

Aydan
Posts: 729
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: shell script problem

Fri Mar 14, 2014 10:19 pm

OK, I figured out a solution.
I was trying to mount /dev/lvmroot/root as root but that would screw up the lvm script because it wants a path starting with /dev/mapper.
mounting /dev/mapper/lvmroot-root works.
And I figured out what dev="${dev#/dev/mapper/}" does. It gives the remainder of $dev without /dev/mapper/

Regards
Aydan

Return to “General discussion”