summaryrefslogtreecommitdiff
path: root/stale/boot_kernel.sh
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2024-04-21 13:52:26 +0200
committerCarlos Maiolino <[email protected]>2024-04-21 13:52:26 +0200
commit47b7016ed5ac6dd8efc041060d62e632e937a6d2 (patch)
tree2540760186b400288565c2d2f67dd3c3e93bcfe0 /stale/boot_kernel.sh
Initial commit
Diffstat (limited to 'stale/boot_kernel.sh')
-rw-r--r--stale/boot_kernel.sh91
1 files changed, 91 insertions, 0 deletions
diff --git a/stale/boot_kernel.sh b/stale/boot_kernel.sh
new file mode 100644
index 0000000..a29f8a0
--- /dev/null
+++ b/stale/boot_kernel.sh
@@ -0,0 +1,91 @@
+#!/bin/bash
+
+#This script is used to start-up a KVM-based virtual machine with a specific
+#kernel, specified via command line with -k option
+
+#--------------------------------------------------#
+
+#virt-xml <domain> --edit --boot kernel=args=<args>
+VIRTXML_BIN=`which virt-xml 2> /dev/null`
+DEFAULT_OPS="ro vconsole.font=latarcyrheb-sun16 LANG=en_CA.UTF-8 console=ttyS0
+crashkernel=128M"
+
+# Display usage help function
+usage() {
+ echo
+ echo "boot_kernel.sh: start a virtual machine with a direct kernel"
+ echo
+ echo "Usage: boot_kernel.sh -d <vm_name> -k <kernel> -r <root_dev> -o \"<kernel_opts>\""
+ echo
+ echo "-d: Specify the virtual machine name (domain name)"
+ echo "-k: Kernel executable path to be loaded in the virtual machine"
+ echo "-o: Kernel Options command line arguments (please use \"\")"
+ echo "-r: Root device, partition where rootfs is stored inside VM"
+ echo "-h: Show this help"
+}
+
+
+if [ -z $VIRTXML_BIN ]; then
+ echo "virt-xml executable not found..."
+ echo "Please make sure your system has virt-install package installed"
+ echo
+ exit
+fi
+
+add_kernel_to_xml() {
+ echo $VIRTXML_BIN --edit --boot kernel=$KERNEL_PATH kernel_args=$KERNEL_OPS
+}
+
+
+while getopts "d:hk:o:r:" ARG; do
+ case $ARG in
+ d) #domain name
+ DOMAIN_NAME=$OPTARG
+ ;;
+ h)
+ #help menu
+ usage
+ ;;
+ k) #kernel path
+ KERNEL_PATH=$OPTARG
+ ;;
+ o)
+ #kernel_ops
+ KERNEL_OPS=$OPTARG
+ ;;
+ r)
+ #root_device
+ ROOT_DEV=$OPTARG
+ ;;
+ *)
+ usage
+ exit
+ ;;
+
+ esac
+done
+
+#Ensure $KERNEL_PATH is valid
+if [ -z $KERNEL_PATH ]; then
+ echo "Kernel image not specified..."
+ usage
+ exit 1
+fi
+
+if [ ! -f $KERNEL_PATH ]; then
+ echo "Kernel image not found...exiting"
+ exit 1
+fi
+
+#add_kernel_to_xml
+$VIRTXML_BIN $DOMAIN_NAME --edit --boot kernel=$KERNEL_PATH
+
+#Set kernel_args
+if [ -z "$KERNEL_OPS" ]; then
+ $VIRTXML_BIN $DOMAIN_NAME --edit --boot kernel_args="root=$ROOT_DEV $DEFAULT_OPS"
+else
+ $VIRTXML_BIN $DOMAIN_NAME --edit --boot kernel=$KERNEL_PATH --boot kernel_args="root=$ROOT_DEV ro $KERNEL_OPS"
+fi
+
+#Starting VM
+virsh start $DOMAIN_NAME