Browse Source

- skel-root/hd51: rework mdev-mmcblk script to mount swap- and storage-partition

master
vanhofen 6 years ago
parent
commit
ab30d1d574
  1. 103
      skel-root/armbox/hd51/lib/mdev/fs/mdev-mmcblk

103
skel-root/armbox/hd51/lib/mdev/fs/mdev-mmcblk

@ -11,55 +11,46 @@ K_PARTNAME=""
ROOTFSDEV=""
R_PARTNAME=""
ROOTSUBDIR=""
NEWLAYOUT=0
# to use partnames in old layout, set it to 1
SUBDIRBOOT=0
# to use partition names in non-subdirboot layout, set it to 1
USE_PARTNAMES=0
#
check_mmcblk()
{
devname=""
partname=""
for i in $BLOCKS;do
if [ "$i" != "$BLOCKS" ];then
devname=$(cat $i | grep DEVNAME | cut -d '=' -f 2)
if [ "$devname" == "$MDEV" ];then
partname=$(cat $i | grep PARTNAME | cut -d '=' -f 2)
if [ -n "$(echo $partname | grep 'kernel')" ];then
KERNELDEV=$devname
K_PARTNAME=$partname
# check partition names
DEVNAME=""
PARTNAME=""
for i in $BLOCKS; do
if [ "$i" != "$BLOCKS" ]; then
DEVNAME=$(cat $i | grep DEVNAME | cut -d '=' -f 2)
if [ "$DEVNAME" == "$MDEV" ]; then
PARTNAME=$(cat $i | grep PARTNAME | cut -d '=' -f 2)
if [ -n "$(echo $PARTNAME | grep 'kernel')" ]; then
KERNELDEV=$DEVNAME
K_PARTNAME=$PARTNAME
break
elif [ -n "$(echo $partname | grep 'rootfs')" ];then
ROOTFSDEV=$devname
R_PARTNAME=$partname
if [ -n "$(echo $partname | grep 'linuxrootfs')" ];then
NEWLAYOUT=1
elif [ -n "$(echo $PARTNAME | grep 'rootfs')" ]; then
ROOTFSDEV=$DEVNAME
R_PARTNAME=$PARTNAME
if [ -n "$(echo $PARTNAME | grep 'linuxrootfs')" ]; then
R_PARTNAME="linuxrootfs1"
SUBDIRBOOT=1
fi
break
elif [ -n "$(echo $partname | grep 'userdata')" ];then
ROOTFSDEV=$devname
R_PARTNAME=$partname
NEWLAYOUT=1
elif [ -n "$(echo $PARTNAME | grep 'userdata')" ]; then
ROOTFSDEV=$DEVNAME
R_PARTNAME=$PARTNAME
SUBDIRBOOT=1
break
fi
fi
fi
done
[ "$partname" == "swap" -o "$partname" == "swapdata" ] && exit 0
[ "$NEWLAYOUT" == "1" -o "$USE_PARTNAMES" == "1" ] && MOUNTPOINT="$MOUNTBASE/$R_PARTNAME"
}
#
read_cmdline()
{
for param in $(cat /proc/cmdline);do
if [ -n "$(echo $param | grep rootsubdir)" ];then
ROOTSUBDIR=$(echo $param | cut -d '=' -f 2)
break
fi
done
}
# check partition names
check_mmcblk
if [ "$SUBDIRBOOT" == "1" -o "$USE_PARTNAMES" == "1" ]; then
MOUNTPOINT="$MOUNTBASE/$R_PARTNAME"
elif [ "$PARTNAME" == "storage" ]; then
MOUNTPOINT="$MOUNTBASE/$PARTNAME"
fi
# do not add or remove root device again...
[ "$ROOTDEV" = "$MDEV" -a "$R_PARTNAME" != "userdata" ] && exit 0
@ -71,12 +62,18 @@ fi
case "$ACTION" in
add)
# do not mount kernel partitions
if [ "$KERNELDEV" == "$MDEV" ];then
if [ "$KERNELDEV" == "$MDEV" ]; then
LOGINFO "[$ACTION] /dev/$MDEV is a kernel partition [$K_PARTNAME] - not mounting."
exit 0
fi
# TODO: check for partitions
if [ "$NEWLAYOUT" == "1" ];then
if [ "$PARTNAME" == "swap" ]; then
mkswap /dev/$MDEV
swapon /dev/$MDEV
exit 0
fi
if [ "$SUBDIRBOOT" == "1" ]; then
if grep -q $MOUNTPOINT /proc/mounts; then
LOGINFO "/dev/$MDEV already mounted [$R_PARTNAME] - not mounting again"
exit 0
@ -85,16 +82,22 @@ case "$ACTION" in
mount -t auto /dev/$MDEV /tmp/$MDEV 2>&1 >/dev/null
RET=$?
[ $RET != 0 ] && LOGWARN "mount /dev/$MDEV to /tmp/$MDEV failed with $RET" && rmdir /tmp/$MDEV
if [ "$R_PARTNAME" == "linuxrootfs1" ];then
if [ "$R_PARTNAME" == "linuxrootfs1" ]; then
LOGINFO "mounting /dev/$MDEV [$R_PARTNAME] to $MOUNTPOINT"
mkdir -p $MOUNTPOINT
mount --bind /tmp/$MDEV/linuxrootfs1 $MOUNTPOINT
elif [ "$R_PARTNAME" == "userdata" ];then
elif [ "$R_PARTNAME" == "userdata" ]; then
# parse cmdline for rootsubdir
read_cmdline
for i in /tmp/$MDEV/*;do
if [ -n "$(echo $i | grep linuxrootfs)" ];then
if [ "$ROOTSUBDIR" == "$(basename $i)" ];then
for param in $(cat /proc/cmdline); do
if [ -n "$(echo $param | grep rootsubdir)" ]; then
ROOTSUBDIR=$(echo $param | cut -d '=' -f 2)
break
fi
done
for i in /tmp/$MDEV/*; do
if [ -n "$(echo $i | grep linuxrootfs)" ]; then
if [ "$ROOTSUBDIR" == "$(basename $i)" ]; then
LOGINFO "/dev/$MDEV rootsubdir [$ROOTSUBDIR] is already mounted as root"
continue
fi
@ -128,8 +131,8 @@ case "$ACTION" in
mount -t auto /dev/$MDEV $MOUNTPOINT 2>&1 >/dev/null
RET=$?
if [ $RET != 0 ]; then
LOGWARN "mount /dev/$MDEV $MOUNTPOINT failed with $RET"
LOGWARN " $OUT1"
LOGWARN "mount /dev/$MDEV $MOUNTPOINT failed with $RET"
LOGWARN " $OUT1"
rmdir $MOUNTPOINT
fi
fi

Loading…
Cancel
Save