bootinst linux boot installer

This commit is contained in:
Tomas M
2012-10-09 14:47:46 -05:00
parent 39335c407f
commit 796a925a5f
3 changed files with 40 additions and 7 deletions
+32
View File
@@ -0,0 +1,32 @@
#!/bin/sh
# Setup booting from disk (USB or harddrive)
# Requires: extlinux, fdisk, df, tail, tr, cut, cat, sed
set -e
# change working directory to dir from which we are started
CWD="$(pwd)"
BOOT="$(dirname "$0")"
cd "$BOOT"
# find out device and mountpoint
PART="$(df . | tail -n 1 | tr -s " " | cut -d " " -f 1)"
DEV="$(echo "$PART" | sed -r "s:[0-9]+\$::" | sed -r "s:([0-9])[a-z]+\$:\\1:i")" #"
# install syslinux bootloader
extlinux --install $BOOT
if [ "$DEV" != "$PART" ]; then
# Setup MBR on the first block
cat "$BOOT/mbr.bin" > "$DEV"
# Toggle a bootable flag
PART="$(echo "$PART" | sed -r "s:.*[^0-9]::")"
(
fdisk -l "$DEV" | fgrep "*" | fgrep "$DEV" | cut -d " " -f 1 \
| sed -r "s:.*[^0-9]::" | xargs -I '{}' echo -ne "a\n{}\n"
echo -ne "a\n$PART\nw\n"
) | fdisk $DEV >/dev/null 2>&1
fi
echo "Boot installation finished."
cd "$CWD"