]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Adds extlinux support, which is not working for the custom method at kvmx-create
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 2 Apr 2017 13:45:15 +0000 (10:45 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 2 Apr 2017 13:45:15 +0000 (10:45 -0300)
kvmx-create
kvmxfile

index dacab4aa174cef6b30a9cdaca9af017f908f6ee8..7f20585790d74be7d6d23b6855fa7af1f27ce25e 100755 (executable)
@@ -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
index 988157c28d49baf8f6ade244bf742dfa7276b092..bb27893893aaa12652f03fc3a9eceb6718ad8639 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -81,3 +81,6 @@ ssh_support="y"
 #
 # This setting is used during virtual machine bootstrapping by kvmx-create.
 ssh_custom="y"
+
+# Bootloader (used only during bootstrapping by kvmx-create).
+bootloader="grub"