function strcontains { set str="$1" set pattern="$2" if regexp ".*${pattern}.*" "$str"; then return 0; else return 1; fi } function scan_disk { # Scan the disk and create a menuentry to boot it if it contains a linux # install disk=$1 if [ -e $disk/etc/lsb-release ]; then probe -s uuid -u $disk source $disk/etc/lsb-release menuentry "Discovered: $DISTRIB_ID $DISTRIB_RELEASE $disk" $disk $uuid { set root=$2 linux /vmlinuz root=UUID=$3 initrd /initrd.img } fi } # Load modules insmod all_video insmod ext2 insmod gfxterm insmod linux insmod normal insmod part_gpt insmod part_msdos insmod png insmod probe insmod regexp insmod serial # Set up display set gfxmode=auto terminal_output gfxterm terminal_input console # Set boot type if [ x$grub_platform = xefi ]; then set boottype=efi else set boottype=bios fi # Try to set up serial serial --unit=0 --speed=9600 terminal_output --append serial terminal_input --append serial # Set up appearance loadfont /boot/grub/unicode.pf2 regexp -s install_disk 'hd([0-9]+)' $root # Scan all disks except for current root for disk in (*); do if ! strcontains "$disk" $install_disk; then scan_disk $disk fi done # Create menuentry for installer menuentry "Boot Installer - Graphical Console" { set root=(hd0,msdos2) linux /vmlinuz ro root=LABEL=cloudimg-rootfs overlayroot=device:dev=LABEL=overlay-rootfs console=ttyS0 console=tty0 quiet splash initrd /initrd.img } menuentry "Boot Installer - Serial Console" { set root=(hd0,msdos2) linux /vmlinuz ro root=LABEL=cloudimg-rootfs overlayroot=device:dev=LABEL=overlay-rootfs console=tty0 console=ttyS0 initrd /initrd.img } set default=0 set timeout=50