You are not logged in.
Pages: 1
i'm creating script for generating chainload entries to /boot/grub/grub.cfg
so some testing and suggestions for optimization are welcome.
# cat /etc/grub.d/40_chainloader.sh
#!/bin/bash
blkid | sort | while read line
do
DEV=$(echo $line | sed 's/:.*//')
# skip if part. is mounted as root /
[ -n "$(mount -l | grep " / " | grep "$DEV")" ] && continue
# skip if part. hasnt boot flag (*)
[ -z "$(fdisk -l | grep "*" | grep "$DEV")" ] && continue
# vars used later
DEV=$(echo $DEV | sed 's/\/dev\///')
LABEL=$(echo $line | grep 'LABEL=' | sed 's/.*LABEL="//' | sed 's/".*//')
#if [ -n "$LABEL" ]; then LABEL=" [$LABEL]"; fi
[ -n "$LABEL" ] && LABEL=" [$LABEL]"
FS=$(echo $line | grep 'TYPE=' | sed 's/.*TYPE="//' | sed 's/".*//')
DEV_NR=$(echo ${DEV:2:1})
# ex sdb6 => b
DEV_NR=$(echo $DEV_NR | sed 's/a/0/' | sed 's/b/1/' | sed 's/c/2/')
DEV_NR=$(echo $DEV_NR | sed 's/d/3/' | sed 's/e/4/' | sed 's/f/5/')
#PART_NR=${DEV:3:1}
# output print
echo "menuentry \"Chainload $DEV$LABEL\" {"
echo " # insmod $FS"
# insmod isnt checked (hfsplus, iso9660, ntfs ...) , so its commented out
echo " set root=(hd$DEV_NR,${DEV:3:1})"
echo " chainloader +1"
echo "}"
done
Offline
DEV_NR=$(echo $DEV_NR | sed 's/a/0/' | sed 's/b/1/' | sed 's/c/2/') DEV_NR=$(echo $DEV_NR | sed 's/d/3/' | sed 's/e/4/' | sed 's/f/5/')
You can replace this with
DEV_NR=$(echo $DEV_NR | tr abcdef 012345)
You can use here-docs instead of a bunch of echo's one after the other:
cat <<EOF
menuentry "Chainload $DEV$LABEL" {
set root=(hd$DEV_NR,${DEV:3:1})
chainloader +1
}
EOF
You can also write it in perl. Hah j/k.
Offline
Thanks!
#!/bin/bash
blkid | sort | while read line
do
DEV_PATH=$(echo $line | sed 's/:.*//')
# skip if partition is mounted as root /
[ -n "$(mount -l | grep " / " | grep "$DEV_PATH")" ] && continue
# skip if partition hasnt boot flag (*)
[ -z "$(fdisk -l | grep "*" | grep "$DEV_PATH")" ] && continue
# vars used later
DEV=$(echo $DEV_PATH | sed 's/\/dev\///')
LABEL=$(echo $line | grep 'LABEL=' | sed 's/.*LABEL="//' | sed 's/".*//')
[ -n "$LABEL" ] && LABEL=" [$LABEL]"
FS=$(echo $line | grep 'TYPE=' | sed 's/.*TYPE="//' | sed 's/".*//')
DEV_NR=$(echo ${DEV:2:1} | tr abcdefgh 01234567)
#PART_NR=${DEV:3:1}
# output print
echo "Found boot flag on $DEV_PATH$LABEL" >&2
# insmod isnt tested (hfsplus, iso9660, ntfs ...) , so its commented out
cat <<EOF
menuentry "Chainload 2 $DEV$LABEL" {
# insmod $FS
set root=(hd$DEV_NR,${DEV:3:1})
chainloader +1
}
EOF
done
Offline
Pages: 1