Skip to content

Instantly share code, notes, and snippets.

@timfoster
Created May 28, 2019 14:07
Show Gist options
  • Save timfoster/ac9a32f14eb95640b2cf0267ed900cd2 to your computer and use it in GitHub Desktop.
Save timfoster/ac9a32f14eb95640b2cf0267ed900cd2 to your computer and use it in GitHub Desktop.
A simple script to generate a pxe menu from a directory of SmartOS platform images
#!/bin/bash
DIR=/tank/archive/smartos
cd $DIR
LATEST=$(ls -1d */platform | grep -v tgz | sort -u | tail -1 | awk -F/ '{print $1}')
read -d '' HEADER << EOF
\#!ipxe
set smartos_latest $LATEST
set http_server http://puroto
:start
menu Welcome to iPXE's Boot Menu
item
item --gap -- ------------------------- Operating systems ------------------------------
item smartos_latest SmartOS-latest (\${smartos_latest})
item smartos_latest_debug SmartOS-latest, debug mode (\${smartos_latest})
EOF
read -d '' UTILS << EOF
item --gap -- ------------------------------ Utilities ---------------------------------
item shell Enter iPXE shell
item reboot Reboot
item
item exit Exit (boot local disk)
choose --default smartos-latest --timeout 5000 target && goto \${target}
:shell
echo Type exit to get the back to the menu
shell
set menu-timeout 5
goto start
:reboot
reboot
:exit
exit
EOF
read -d '' MENU_ITEMS << EOF
:smartos_latest_debug
kernel \${http_server}/smartos/\${smartos_latest}/platform/i86pc/kernel/amd64/unix -v -B console=text,noimport=true,smartos=true,root_shadow='$5$2HOHRnK3$NvLlm.1KQBbB0WjoP7xcIwGnllhzp2HnT.mDO7DpxYA'
initrd \${http_server}/smartos/\${smartos_latest}/platform/i86pc/amd64/boot_archive
boot
:smartos_latest
kernel \${http_server}/smartos/\${smartos_latest}/platform/i86pc/kernel/amd64/unix -B smartos=true
initrd \${http_server}/smartos/\${smartos_latest}/platform/i86pc/amd64/boot_archive
boot
EOF
LAST_ITEM="goto start"
echo "$HEADER"
PLAT_LIST=$(ls -1d *platform* | grep -v tgz | sort -r)
for item in $PLAT_LIST; do
entry=$(basename $item)
echo "item ${entry} ${entry}"
echo "item ${entry}_debug ${entry} - debug"
done
echo "$UTILS"
echo "$MENU_ITEMS"
for item in $PLAT_LIST; do
entry=$(basename $item)
echo ":${entry}"
echo "kernel \${http_server}/smartos/$entry/platform/i86pc/kernel/amd64/unix -B smartos=true"
echo "initrd \${http_server}/smartos/$entry/platform/i86pc/amd64/boot_archive"
echo "boot"
echo ""
echo ":${entry}_debug"
echo "kernel \${http_server}/smartos/$entry/platform/i86pc/kernel/amd64/unix -v -B console=text,noimport=true,smartos=true,root_shadow='$5$2HOHRnK3$NvLlm.1KQBbB0WjoP7xcIwGnllhzp2HnT.mDO7DpxYA'"
echo "initrd \${http_server}/smartos/$entry/platform/i86pc/amd64/boot_archive"
echo "boot"
echo ""
done
echo "$LAST_ITEM"
@timfoster
Copy link
Author

A Makefile that downloads and extract SmartOS platform images then runs this script is at https://gist.github.com/timfoster/ac9a32f14eb95640b2cf0267ed900cd2

@timfoster
Copy link
Author

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