Skip to content

Instantly share code, notes, and snippets.

@flyemsafe
Created August 18, 2019 15:48
Show Gist options
  • Save flyemsafe/b73ce356d978b04bb70ad1f53b6aafac to your computer and use it in GitHub Desktop.
Save flyemsafe/b73ce356d978b04bb70ad1f53b6aafac to your computer and use it in GitHub Desktop.

Configure USB device

  • Ensure all required packages are installed
dnf install grub2-efi shim gdisk grub2-efi-modules grub2-efi-x64-modules
  • Define USB device varaible
USB_DEVICE=/dev/sdb
  • Delete paritions from the device
# delete all paritions on the USB
sudo dd if=/dev/zero of="${USB_DEVICE}" bs=$((1024*1024)) count=1000

# Tell the OS the paritions has change
sudo partprobe

# Display informaiton about the device to ensure the paritions are removed
sudo lsblk -f "${USB_DEVICE}"

# Put GPT label on USB device
sudo parted "${USB_DEVICE}" mklabel gpt

# Show the GPT labe
sudo parted "${USB_DEVICE}" p
  • Partition the USB device
# This script run creates two paritions with gdisk
# - partition 1: vfat 500M
# - partition 2: Linux the rest of the disk
cat > /tmp/gdisk <<ELM
#!/bin/bash

TGTDEV=$1

sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | gdisk ${TGTDEV}
  n     # new partition
        # default 1
        # default start sector
  +500M
  ef00  # EFI System Partition
  n     # new partition
        # default 2
        # default start sector
        # default end sector
        # default type (Linux)
  w     # write
  y     # save
EOF
ELM

# Run the script
sudo sh /tmp/disk "${USB_DEVICE}"
sudo gdisk "${USB_DEVICE}" -l
  • Create the filesystemd and mount the devices
# These next two steps must be done is this order

# (1) Create the XFS filesystem
sudo mkfs.xfs "${USB_DEVICE}2"   
sudo mkdir -p /mnt/qubiusb/
sudo mount "${USB_DEVICE}2" /mnt/qubiusb/

# (2) Create the vfat filesystem for EFI
sudo mkfs.vfat "${USB_DEVICE}1" 
sudo mkdir -p /mnt/qubiusb/boot/efi
sudo mount "${USB_DEVICE}1" /mnt/qubiusb/boot/efi

# Verify mounts
sudo lsblk -f "${USB_DEVICE}"
  • Install grub on the usb device
# Install Grub

sudo grub2-install --boot-directory=/mnt/qubiusb/boot --efi-directory=/mnt/qubiusb/boot/efi --target=x86_64-efi --bootloader-id=qubinode --removable -v "${USB_DEVICE}"

# create grub2.cfg
sudo grub2-mkconfig -o /mnt/qubiusb/boot/grub2/grub.cfg
  • Replace /mnt/qubiusb/boot/grub2/grub.cfg with this

This needs further customerization to remove all the extra unwanted config directives.

You need to update these variables in the provided grub2.conf before using it.

  • set ISO="/rhel-server-7.6-x86_64-dvd.iso" #shouldn't need to change this
  • set KS="/qubinode-rhel7.6.ks" # the name of your kickstart file
  • set FSUUID="d6d40496-9b69-4c13-9f3f-8bfac5c732c7"

To get the FSUUID, run the below command to and grab the UUID

sudo lsblk -f "${USB_DEVICE}" | grep xfs

IMPORTANT

Make sure your copy the RHEL iso and your kickstart file to to where parition 2 is mounted, which should /mnt/qubiusb/ based on the above instructions.

#
# QUBINODE-INSTALLER grub2.conf
#


### BEGIN /etc/grub.d/00_header ###
set pager=1

if [ -f ${config_directory}/grubenv ]; then
  load_env -f ${config_directory}/grubenv
elif [ -s $prefix/grubenv ]; then
  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="${saved_entry}"
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 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 loadfont unicode ; then
  set gfxmode=1280x720x32,1024x768x32,auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
set tuned_initrd=""
### END /etc/grub.d/00_tuned ###

### BEGIN /etc/grub.d/01_menu_auto_hide ###
if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then
  set last_boot_ok=1
else
  set last_boot_ok=0
fi

# Reset boot_indeterminate after a successful boot
if [ "${boot_success}" = "1" ] ; then
  set boot_indeterminate=0
# Avoid boot_indeterminate causing the menu to be hidden more then once
elif [ "${boot_indeterminate}" = "1" ]; then
  set boot_indeterminate=2
fi
set boot_success=0
save_env boot_success boot_indeterminate

if [ x$feature_timeout_style = xy ] ; then
  if [ "${menu_show_once}" ]; then
    unset menu_show_once
    save_env menu_show_once
    set timeout_style=menu
    set timeout=60
  elif [ "${menu_auto_hide}" -a "${last_boot_ok}" = "1" ]; then
    set orig_timeout_style=${timeout_style}
    set orig_timeout=${timeout}
    if [ "${fastboot}" = "1" ]; then
      # timeout_style=menu + timeout=0 avoids the countdown code keypress check
      set timeout_style=menu
      set timeout=0
    else
      set timeout_style=hidden
      set timeout=1
    fi
  fi
fi
### END /etc/grub.d/01_menu_auto_hide ###

### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
  source ${prefix}/user.cfg
  if [ -n "${GRUB2_PASSWORD}" ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
fi
### END /etc/grub.d/01_users ###

### BEGIN /etc/grub.d/10_linux ###
menuentry '[QUBINODE] RHEL 7.6 Kickstart' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-a6984e62-9f65-4c00-884f-18a3884867cb' {
       set ISO="/rhel-server-7.6-x86_64-dvd.iso"
       set KS="/qubinode-rhel7.6.ks"
       set FSUUID="d6d40496-9b69-4c13-9f3f-8bfac5c732c7"
       search --fs-uuid --set=root $FSUUID
       loopback loop $ISO
       load_video
       set gfxpayload=keep
       insmod gzio
       insmod part_gpt
       insmod xfs
       linuxefi (loop)/isolinux/vmlinuz inst.stage2=hd:UUID=$FSUUID:$ISO inst.repo=hd:UUID=$FSUUID:$ISO inst.ks=hd:UUID=$FSUUID:$KS rhgb quiet
       initrdefi (loop)/isolinux/initrd.img
}

menuentry '[ISO] rhel-server-7.6-x86_64-dvd' --class rhel fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-a6984e62-9f65-4c00-884f-18a3884867cb' {
       set ISO="/rhel-server-7.6-x86_64-dvd.iso"
       set FSUUID="d6d40496-9b69-4c13-9f3f-8bfac5c732c7"
       search --fs-uuid --set=root $FSUUID
       loopback loop $ISO
       load_video
       set gfxpayload=keep
       insmod gzio
       insmod part_gpt
       insmod xfs
       linuxefi (loop)/isolinux/vmlinuz inst.stage2=hd:UUID=$FSUUID:$ISO inst.repo=hd:UUID=$FSUUID:$ISO rhgb quiet
       initrdefi (loop)/isolinux/initrd.img
}

menuentry "Boot from next device"  {
 load_video
 exit
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_ppc_terminfo ###
### END /etc/grub.d/20_ppc_terminfo ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
menuentry 'System setup' $menuentry_id_option 'uefi-firmware' {
	fwsetup
}
### 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 ###

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment