diff options
Diffstat (limited to 'server/modules/hdd-boot/opt')
-rw-r--r-- | server/modules/hdd-boot/opt/openslx/hdd-boot/grub.cfg | 146 | ||||
-rwxr-xr-x | server/modules/hdd-boot/opt/openslx/scripts/systemd-hdd_boot | 116 |
2 files changed, 262 insertions, 0 deletions
diff --git a/server/modules/hdd-boot/opt/openslx/hdd-boot/grub.cfg b/server/modules/hdd-boot/opt/openslx/hdd-boot/grub.cfg new file mode 100644 index 00000000..611b3785 --- /dev/null +++ b/server/modules/hdd-boot/opt/openslx/hdd-boot/grub.cfg @@ -0,0 +1,146 @@ +# +# DO NOT EDIT THIS FILE +# +# It is automatically generated by grub-mkconfig using templates +# from /etc/grub.d and settings from /etc/default/grub +# + +### BEGIN /etc/grub.d/00_header ### +if [ -s $prefix/grubenv ]; then + set have_grubenv=true + load_env +fi +if [ "${next_entry}" ] ; then + set default="${next_entry}" + set next_entry= + save_env next_entry + set boot_once=true +else + set default="0" +fi + +if [ x"${feature_menuentry_id}" = xy ]; then + menuentry_id_option="--id" +else + menuentry_id_option="" +fi + +export menuentry_id_option + +if [ "${prev_saved_entry}" ]; then + set saved_entry="${prev_saved_entry}" + save_env saved_entry + set prev_saved_entry= + save_env prev_saved_entry + set boot_once=true +fi + +function savedefault { + if [ -z "${boot_once}" ]; then + saved_entry="${chosen}" + save_env saved_entry + fi +} +function recordfail { + set recordfail=1 + if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi +} +function load_video { + if [ x$feature_all_video_module = xy ]; then + insmod all_video + else + insmod efi_gop + insmod efi_uga + insmod ieee1275_fb + insmod vbe + insmod vga + insmod video_bochs + insmod video_cirrus + fi +} + +if [ x$feature_default_font_path = xy ] ; then + font=unicode +else +insmod part_msdos +insmod lvm +insmod ext2 +set root='lvmid/ZvOK2H-W5xA-QoO2-zy2n-Sjr7-cpu8-M3zL6F/FzLrNP-IhMk-pB8d-vEEW-Jxxk-ujc7-NWSegg' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint='lvmid/ZvOK2H-W5xA-QoO2-zy2n-Sjr7-cpu8-M3zL6F/FzLrNP-IhMk-pB8d-vEEW-Jxxk-ujc7-NWSegg' 0bec626d-2d44-417d-acfd-83acbbcf2b34 +else + search --no-floppy --fs-uuid --set=root 0bec626d-2d44-417d-acfd-83acbbcf2b34 +fi + font="/usr/share/grub/unicode.pf2" +fi + +if loadfont $font ; then + set gfxmode=auto + load_video + insmod gfxterm + set locale_dir=$prefix/locale + set lang=pt_PT + insmod gettext +fi +terminal_output gfxterm +if [ "${recordfail}" = 1 ] ; then + set timeout=-1 +else + if [ x$feature_timeout_style = xy ] ; then + set timeout_style=menu + set timeout=10 + # Fallback normal timeout code in case the timeout_style feature is + # unavailable. + else + set timeout=10 + fi +fi +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/05_debian_theme ### +set menu_color_normal=white/black +set menu_color_highlight=black/light-gray +### END /etc/grub.d/05_debian_theme ### + +### BEGIN /etc/grub.d/06_mint_theme ### +set menu_color_normal=white/black +set menu_color_highlight=white/light-gray +### END /etc/grub.d/06_mint_theme ### + +### BEGIN /etc/grub.d/10_linux ### +### END /etc/grub.d/10_linux ### + +### BEGIN /etc/grub.d/10_lupin ### +### END /etc/grub.d/10_lupin ### + +### BEGIN /etc/grub.d/20_linux_xen ### + +### END /etc/grub.d/20_linux_xen ### + +### BEGIN /etc/grub.d/20_memtest86+ ### +### END /etc/grub.d/20_memtest86+ ### + +### BEGIN /etc/grub.d/30_os-prober ### +set timeout_style=menu +if [ "${timeout}" = 0 ]; then + set timeout=10 +fi +### END /etc/grub.d/30_os-prober ### + +### BEGIN /etc/grub.d/30_uefi-firmware ### +### END /etc/grub.d/30_uefi-firmware ### + +### BEGIN /etc/grub.d/40_custom ### +# This file provides an easy way to add custom menu entries. Simply type the +# menu entries you want to add after this comment. Be careful not to change +# the 'exec tail' line above. +### END /etc/grub.d/40_custom ### + +### BEGIN /etc/grub.d/41_custom ### +if [ -f ${config_directory}/custom.cfg ]; then + source ${config_directory}/custom.cfg +elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then + source $prefix/custom.cfg; +fi +### END /etc/grub.d/41_custom ### + diff --git a/server/modules/hdd-boot/opt/openslx/scripts/systemd-hdd_boot b/server/modules/hdd-boot/opt/openslx/scripts/systemd-hdd_boot new file mode 100755 index 00000000..f975b697 --- /dev/null +++ b/server/modules/hdd-boot/opt/openslx/scripts/systemd-hdd_boot @@ -0,0 +1,116 @@ +#!/bin/bash +set -x +# Downloading all in SLX_BASE_PATH to /boot Example: Ubuntu_1404_x64 +# wget -N, update if the file has been changed +boot_download () { + echo "Downloading $SLX_BASE_PATH ................." + wget -P /boot -N -r --tries=3 --timeout=5 --quiet -nH -l1 --no-parent --reject="index.html*" --reject="$SLX_BASE_PATH.*" $SLXSRV/$SLX_BASE_PATH #<---- ok =), but try with -nc too + RET=$? + [ $RET != 0 ] && { echo "Error - downloading 'http://$SLXSRV/$SLX_BASE_PATH/' via wget failed."; exit 1; } ||{ echo "Successfully downloaded 'http://$SLXSRV/$SLX_BASE_PATH' via wget."; return 0; } +} + +# Getting informations from cmdline +read KCL < "/proc/cmdline" +for opts in ${KCL}; do + case "${opts}" in + slxbase=*) # BASE_PATH Example Ubuntu_1404_x64 + SLX_BASE_PATH=${opts#slxbase=} ;; + slxsrv=*) + #SLX IP server info + SLXSRV=${opts#slxsrv=} ;; + BOOT_IMAGE=*) + BOOT_IMAGE=${opts} ;; + initrd=*) + initrd=${opts} ;; + esac +done +KCL=$(echo "$KCL" | sed "s|SLX_BASE_PATH|$SLX_BASE_PATH|g;s|$BOOT_IMAGE||g;s|$initrd||g") + +# Scan vm-store dir for vmware image xmls and copy +if [ -d /cache/export/dnbd3 -a -d /mnt/vmstore ]; then + [ ! -d /boot/vmstore ] && mkdir /boot/vmstore + for FILE in $(find /cache/export/dnbd3 -iname "*.vmdk*" ! -iname "*map"); do + [ -e "${FILE}.map" ] && continue + image_name=$(echo $(basename "$FILE") | cut -d "." -f1) + cd /mnt/vmstore + for XML in $(grep -rIl --include "*.xml" "$image_name" .); do + xmldir=$(dirname $XML) + mkdir -p /boot/vmstore/${xmldir} + cp $XML /boot/vmstore/${xmldir}/ + done + cd - >/dev/null + done +fi + +# Bind mount available vmstore in /boot to /mnt/vmstore if not already present +if ! grep -qs '/mnt/vmstore' /proc/mounts; then + [ ! -d /mnt/vmstore ] && mkdir -p /mnt/vmstore + [ -d /boot/vmstore ] && mount --bind /boot/vmstore /mnt/vmstore +fi + +# if SLX_BASE_PATH already exists, just update. Does not make the menu again. +[ -d /boot/$SLX_BASE_PATH ] && { boot_download; echo "$SLX_BASE_PATH updated"; } || { boot_download; echo "New base $SLX_BASE_PATH downloaded to HDD"; } + +# Installing GRUB + +#Find disk of /boot +BOOT_DISK=$(df | grep /boot | awk '{print $1}' | tr -d '[0-9]' | cut -c 6-) +BOOT_PART=$(df | grep /boot | awk '{print $1}' | tr -dc '[0-9]') +[ -z "$BOOT_DISK" ] && { echo "BOOT DISK could not be found, exiting."; exit 1; } + +#Check if disk is msdos or GPT +if sgdisk /dev/$BOOT_DISK | grep -qs 'invalid GPT'; then + BOOT_TYPE='msdos' +else + BOOT_TYPE='gpt' +fi + +if [ ! -d /boot/grub ]; then + + grub-install --boot-directory=/boot /dev/$BOOT_DISK + update-grub-gfxpayload + + RET=$? + [ $RET != 0 ] && { echo "Could not install GRUB"; exit 1; } || echo "GRUB successfully installed" + + # First, copy grub.cfg + [ -e /opt/openslx/hdd-boot/grub.cfg ] && cp -r /opt/openslx/hdd-boot/grub.cfg /boot/grub/ +fi + +#Add new base to grub.cfg +if ! grep -qs "menuentry '$SLX_BASE_PATH'" /boot/grub/grub.cfg; then + + #GRUB ok, so lets make the menu + echo "BOOT DISK is $BOOT_DISK" #Just for test + case $BOOT_DISK in + sda) GRUB_DISK=hd0 ;; + sdb) GRUB_DISK=hd1 ;; + sdc) GRUB_DISK=hd2 ;; + sdd) GRUB_DISK=hd3 ;; + sde) GRUB_DISK=hd4 ;; + *) echo "GRUB_DISK was not found" + exit 1 ;; + esac + + [ -e /boot/grub/grub.cfg ] || { echo "Could not find grub.cfg"; exit 1; } + +cat <<EOF >> /boot/grub/grub.cfg +######################### + menuentry '$SLX_BASE_PATH' { + linux ($GRUB_DISK,${BOOT_TYPE}$BOOT_PART)/$SLX_BASE_PATH/kernel hdd_boot=${BOOT_DISK}$BOOT_PART $KCL + initrd ($GRUB_DISK,${BOOT_TYPE}$BOOT_PART)/$SLX_BASE_PATH/initramfs-stage31 +} +######################### +EOF + +fi + +true + + + + + + + + |