Add a command line option to specify which bootloader use: grub or syslinux

This commit is contained in:
Timothy Redaelli 2015-06-30 17:04:23 +02:00
parent bcf8cda4be
commit 70991d1f4e

View file

@ -94,7 +94,8 @@ delete_all() {
} }
install_packages() { install_packages() {
local packages="base grub openssh" local packages="base openssh"
[ "$bootloader" != "none" ] && packages="$packages $bootloader"
# You can't use chroot_exec here, because the root filesystem was deleted! # You can't use chroot_exec here, because the root filesystem was deleted!
"/root.$cpu_type/usr/bin/busybox" chroot "/root.$cpu_type" /usr/bin/pacstrap -M /mnt $packages "/root.$cpu_type/usr/bin/busybox" chroot "/root.$cpu_type" /usr/bin/pacstrap -M /mnt $packages
cp -L "/root.$cpu_type/etc/resolv.conf" /etc cp -L "/root.$cpu_type/etc/resolv.conf" /etc
@ -122,15 +123,18 @@ configure_bootloader() {
/dev/mapper/*) needs_lvm2=1 ;; /dev/mapper/*) needs_lvm2=1 ;;
esac esac
# If you are still using eth* as interface name, disable "strange" ifnames if [ $needs_lvm2 -eq 1 ]; then
if grep -q '^[[:space:]]*eth' /proc/net/dev; then # Some distro doesn't use lvmetad by default
sed -i.bak 's/GRUB_CMDLINE_LINUX_DEFAULT="/&net.ifnames=0 /' /etc/default/grub sed -i.bak 's/use_lvmetad = 1/use_lvmetad = 0/g' /etc/lvm/lvm.conf
fi fi
if [ "$bootloader" = "grub" ]; then
# If you are still using eth* as interface name, disable "strange" ifnames
grep -q '^[[:space:]]*eth' /proc/net/dev && \
sed -i.bak 's/GRUB_CMDLINE_LINUX_DEFAULT="/&net.ifnames=0 /' /etc/default/grub
if [ $needs_lvm2 -eq 1 ]; then if [ $needs_lvm2 -eq 1 ]; then
local vg local vg
# Some distro doesn't use lvmetad by default
sed -i.bak 's/use_lvmetad = 1/use_lvmetad = 0/g' /etc/lvm/lvm.conf
vg=$(lvs --noheadings $root_dev | awk '{print $2}') vg=$(lvs --noheadings $root_dev | awk '{print $2}')
root_dev=$(pvs --noheadings | awk -v vg="$vg" '($2 == vg) { print $1 }') root_dev=$(pvs --noheadings | awk -v vg="$vg" '($2 == vg) { print $1 }')
fi fi
@ -145,6 +149,12 @@ configure_bootloader() {
for root_dev in $root_devs; do for root_dev in $root_devs; do
grub-install --target=i386-pc --recheck --force "$root_dev" grub-install --target=i386-pc --recheck --force "$root_dev"
done done
elif [ "$bootloader" = "syslinux" ]; then
# If you are still using eth* as interface name, disable "strange" ifnames
grep -q '^[[:space:]]*eth' /proc/net/dev && tmp="net.ifnames=0"
syslinux-install_update -ami
sed -i "s;\(^[[:space:]]*APPEND.*\)root=[^[:space:]]*;\1root=$root_dev${tmp:+ $tmp};" /boot/syslinux/syslinux.cfg
fi
if [ $needs_lvm2 -eq 1 ]; then if [ $needs_lvm2 -eq 1 ]; then
mv /etc/lvm/lvm.conf.bak /etc/lvm/lvm.conf mv /etc/lvm/lvm.conf.bak /etc/lvm/lvm.conf
@ -181,7 +191,7 @@ finalize() {
Hi, Hi,
your VM has successfully been reimaged with Arch Linux. your VM has successfully been reimaged with Arch Linux.
This script configured grub as bootloader and systemd-networkd for networking. This script configured $bootloader as bootloader and systemd-networkd for networking.
When you are finished with your post-installation, you'll need to reboot the VM the rough way: When you are finished with your post-installation, you'll need to reboot the VM the rough way:
# sync ; reboot -f # sync ; reboot -f
@ -192,10 +202,18 @@ finalize() {
EOF EOF
} }
bootloader=grub
mirrors= mirrors=
while getopts ":m:h" opt; do while getopts ":b:m:h" opt; do
case $opt in case $opt in
b)
if ! [ "$OPTARG" = "grub" -o "$OPTARG" = "syslinux" -o "$OPTARG" = "none" ]; then
echo "Invalid bootloader specified" >&2
exit 1
fi
bootloader="$OPTARG"
;;
m) m)
mirrors="${mirrors:+$mirrors }$OPTARG" mirrors="${mirrors:+$mirrors }$OPTARG"
;; ;;
@ -204,6 +222,7 @@ while getopts ":m:h" opt; do
usage: ${0##*/} [options] usage: ${0##*/} [options]
Options: Options:
-b (grub|syslinux) Use the specified bootloader. When this option is omitted, it defaults to grub.
-m mirror Use the provided mirror (you can specify this option more than once). -m mirror Use the provided mirror (you can specify this option more than once).
-h Print this help message -h Print this help message