aboutsummaryrefslogtreecommitdiff
path: root/kvmx-create
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-04-02 10:45:15 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-04-02 10:45:15 -0300
commitfdd9554377cb7a686107603799dbde8e891b290e (patch)
treeb6ec829ec1bffb489b97a8108eecd92f0b7f24c9 /kvmx-create
parent03f94939b1405c9fffd690d764fc08106d88d8ca (diff)
downloadkvmx-fdd9554377cb7a686107603799dbde8e891b290e.tar.gz
kvmx-fdd9554377cb7a686107603799dbde8e891b290e.tar.bz2
Adds extlinux support, which is not working for the custom method at kvmx-create
Diffstat (limited to 'kvmx-create')
-rwxr-xr-xkvmx-create54
1 files changed, 40 insertions, 14 deletions
diff --git a/kvmx-create b/kvmx-create
index dacab4a..7f20585 100755
--- a/kvmx-create
+++ b/kvmx-create
@@ -123,6 +123,7 @@ function kvmx_config {
kvmx_user_config size 3G "Image size"
kvmx_user_config format qcow2 "Image format: raw or qcow2"
kvmx_user_config method custom "Bootstrap method: custom or vmdeboostrap"
+ kvmx_user_config bootloader grub "Bootloader: grub or extlinux"
}
# Load config file
@@ -156,10 +157,15 @@ function kvmx_create_vmdebootstrap {
formt=""
fi
+ if [ "$booloader" == "grub" ]; then
+ boot_option="--grub"
+ else
+ boot_option=""
+ fi
+
# Run
kvmx_sudo_run vmdebootstrap --verbose --image=$image --size=$size --distribution=$version \
- --mirror=$mirror --arch=$arch --hostname=$hostname.$domain \
- --grub $format
+ --mirror=$mirror --arch=$arch --hostname=$hostname.$domain $boot_option $format
# Fix permissions
kvmx_sudo_run chown -R `whoami`. `dirname $image`
@@ -283,21 +289,41 @@ allow-hotplug ens3
iface ens3 inet dhcp
EOF
- # GRUB
+ # Mount auxiliary filesystems needed by the bootloader
kvmx_sudo_run mount none -t proc $WORK/proc
kvmx_sudo_run mount none -t sysfs $WORK/sys
kvmx_sudo_run mount -o bind /dev/ $WORK/dev
- $APT_INSTALL grub-pc -y
- # GRUB install is not working for jessie and this was an attempt to fix it
- # Consider fixing this or moving to extlinux.
- # https://superuser.com/questions/130955/how-to-install-grub-into-an-img-file
- # http://www.grulic.org.ar/~mdione/glob/posts/create-a-disk-image-with-a-booting-running-debian/
- # http://www.syslinux.org/wiki/index.php?title=EXTLINUX
- # https://packages.debian.org/jessie/grub-firmware-qemu
- #kvmx_sudo_run sed -i -e 's|^#GRUB_DISABLE_LINUX_UUID=true|GRUB_DISABLE_LINUX_UUID=true|' $WORK/etc/default/grub
- #kvmx_sudo_run grub-install --boot-directory=$WORK/boot $image
- kvmx_sudo_run chroot $WORK/ update-grub
- kvmx_sudo_run chroot $WORK/ grub-install $device
+
+ if [ "$bootloader" == "grub" ]; then
+ # Possible alternative: https://packages.debian.org/jessie/grub-firmware-qemu
+ $APT_INSTALL grub-pc
+ # GRUB install is not working for jessie and this was an attempt to fix it
+ #kvmx_sudo_run sed -i -e 's|^#GRUB_DISABLE_LINUX_UUID=true|GRUB_DISABLE_LINUX_UUID=true|' $WORK/etc/default/grub
+ kvmx_sudo_run chroot $WORK/ update-grub
+ kvmx_sudo_run chroot $WORK/ grub-install $device
+ # Alternative: install from the host directly into the image
+ # https://superuser.com/questions/130955/how-to-install-grub-into-an-img-file
+ #kvmx_sudo_run grub-install --boot-directory=$WORK/boot $image
+ elif [ "$bootloader" == "extlinux" ]; then
+ # http://www.grulic.org.ar/~mdione/glob/posts/create-a-disk-image-with-a-booting-running-debian/
+ # http://www.syslinux.org/wiki/index.php?title=EXTLINUX
+ # http://www.syslinux.org/wiki/index.php?title=Mbr
+ $APT_INSTALL extlinux
+ kvmx_sudo_run chroot $WORK/ extlinux --install /boot
+ kvmx_sudo_run dd bs=440 count=1 conv=notrunc if=$WORK/usr/lib/EXTLINUX/gptmbr.bin of=$device
+ cat <<-EOF | $SUDO tee $WORK/boot/syslinux.cfg > /dev/null
+default linux
+timeout 1
+
+label linux
+say Booting linux...
+linux /vmlinuz
+append root=/dev/vda1 ro
+initrd /initrd.img
+EOF
+ fi
+
+ # Umount auxiliary filesystems
kvmx_sudo_run umount $WORK/proc
kvmx_sudo_run umount $WORK/sys
kvmx_sudo_run umount $WORK/dev