Commit 86f52450 authored by Anton Midyukov's avatar Anton Midyukov

grub: generate grub.cfg for grub-efi and ieee1275boot

These changes allow you to create two independent config at the same time or separately. It will be possible to add support for grub-pc in the future.
parent 80e83624
default='linux' default='linux'
menuentry 'Install ALT @relname@' --hotkey 'i' --id 'linux' { menuentry 'Install ALT @relname@' --hotkey 'i' --id 'linux' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ vga=@bootvga@ @bootargs@ linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ vga=@bootvga@ @bootargs@
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'Install ALT @relname@ (headless with DHCP+VNC client) (edit to set server IP address)' --id 'vncconnect' { menuentry 'Install ALT @relname@ (headless with DHCP+VNC client) (edit to set server IP address)' --id 'vncconnect' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ showopts @bootargs@ headless no_alt_virt_keyboard vncconnect=IP linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ showopts @bootargs@ headless no_alt_virt_keyboard vncconnect=IP
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'Install ALT @relname@ (headless with DHCP+VNC) (password VNCPWD)' --id 'vncpasswd' { menuentry 'Install ALT @relname@ (headless with DHCP+VNC) (password VNCPWD)' --id 'vncpasswd' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ showopts @bootargs@ headless no_alt_virt_keyboard vncpassword=VNCPWD linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot automatic=method:cdrom ramdisk_size=@altinst_size@ showopts @bootargs@ headless no_alt_virt_keyboard vncpassword=VNCPWD
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'LiveCD (no hard disk needed)' --id 'live' { menuentry 'LiveCD (no hard disk needed)' --id 'live' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@live_size@ stagename=live showopts lowmem vga=@bootvga@ @bootargs@ linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@live_size@ stagename=live showopts lowmem vga=@bootvga@ @bootargs@
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'LiveCD with sessions support' --id 'session' { menuentry 'LiveCD with sessions support' --id 'session' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@live_size@ stagename=live showopts live_rw vga=@bootvga@ @bootargs@ linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@live_size@ stagename=live showopts live_rw vga=@bootvga@ @bootargs@
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'Rescue LiveCD' --id 'rescue' { menuentry 'Rescue LiveCD' --id 'rescue' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@rescue_size@ stagename=rescue splash=0 showopts @rescue_bootargs@ linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@rescue_size@ stagename=rescue splash=0 showopts @rescue_bootargs@
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'Rescue with sessions support' --id 'rescue_session' { menuentry 'Rescue with sessions support' --id 'rescue_session' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom,label:ALT* ramdisk_size=@rescue_size@ stagename=rescue splash=0 showopts @rescue_bootargs@ live_rw linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot live automatic=method:cdrom,label:ALT* ramdisk_size=@rescue_size@ stagename=rescue splash=0 showopts @rescue_bootargs@ live_rw
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'Forensic mode (leave disks alone)' --id 'rescue_forensic' { menuentry 'Forensic mode (leave disks alone)' --id 'rescue_forensic' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@rescue_size@ splash=0 showopts stagename=rescue @rescue_bootargs@ max_loop=16 forensic hash=@rescue_hash@ linux$linux_suffix @boot_path@/vmlinuz changedisk fastboot live automatic=method:cdrom ramdisk_size=@rescue_size@ splash=0 showopts stagename=rescue @rescue_bootargs@ max_loop=16 forensic hash=@rescue_hash@
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
menuentry 'Check this media for defects' --id 'mediachk' { menuentry 'Check this media for defects' --id 'mediachk' {
linux$linux_suffix /EFI/BOOT/vmlinuz changedisk live quiet lowmem automatic=method:cdrom mediacheck=1 stagename=mediacheck showopts @bootargs@ linux$linux_suffix @boot_path@/vmlinuz changedisk live quiet lowmem automatic=method:cdrom mediacheck=1 stagename=mediacheck showopts @bootargs@
initrd$linux_suffix /EFI/BOOT/full.cz initrd$linux_suffix @boot_path@/full.cz
} }
...@@ -19,7 +19,7 @@ ifndef GRUB_DIRECT ...@@ -19,7 +19,7 @@ ifndef GRUB_DIRECT
GRUB_CFG := $(GRUB_CFG) $(SUBPROFILE_DIRS) defaults GRUB_CFG := $(GRUB_CFG) $(SUBPROFILE_DIRS) defaults
endif endif
DSTDIR := $(BUILDDIR)/stage1/files/EFI/BOOT/.in DSTDIR := $(BUILDDIR)/stage1/files/boot/grub/.in
DSTCFGS := $(DSTDIR)/*.cfg DSTCFGS := $(DSTDIR)/*.cfg
# we can do GRUB_{CFG,MODULES,FILES} # we can do GRUB_{CFG,MODULES,FILES}
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
cd "$WORKDIR" cd "$WORKDIR"
cfgs="$(find EFI/BOOT -name '*.cfg')" [ -f boot/grub/grub.cfg -o -f EFI/BOOT/grub.cfg ] || exit 0
[ -n "$cfgs" ] || {
echo "${0##*/}: did not find any config under EFI/BOOT " >&2 cfgs=
exit 1 [ ! -f boot/grub/grub.cfg ] || cfgs+='boot/grub/grub.cfg '
} [ ! -f EFI/BOOT/grub.cfg ] || cfgs+='EFI/BOOT/grub.cfg'
# apply size census while looking for potential squashfs images # apply size census while looking for potential squashfs images
find -maxdepth 1 -type f -size +1M \ find -maxdepth 1 -type f -size +1M \
......
...@@ -5,10 +5,14 @@ ...@@ -5,10 +5,14 @@
cd "$WORKDIR" cd "$WORKDIR"
grep -qs "@rescue_hash@" EFI/BOOT/*.cfg || exit 0 [ -f boot/grub/grub.cfg -o -f EFI/BOOT/grub.cfg ] || exit 0
cfgs=
[ ! -f boot/grub/grub.cfg ] || cfgs+='boot/grub/grub.cfg '
[ ! -f EFI/BOOT/grub.cfg ] || cfgs+='EFI/BOOT/grub.cfg'
find -maxdepth 1 -type f -name rescue \ find -maxdepth 1 -type f -name rescue \
| while read image; do | while read image; do
rescue_hash="$(sha256sum -b "$image" | cut -f1 -d' ')" rescue_hash="$(sha256sum -b "$image" | cut -f1 -d' ')"
sed -i "s,@rescue_hash@,$rescue_hash," EFI/BOOT/*.cfg sed -i "s,@rescue_hash@,$rescue_hash," $cfgs
done done
...@@ -2,17 +2,23 @@ ...@@ -2,17 +2,23 @@
# gather grub configuration from snippets; # gather grub configuration from snippets;
# copy modules; see also this feature's generate.mk # copy modules; see also this feature's generate.mk
CFG="grub.cfg" CFG="$WORKDIR/boot/grub/grub.cfg"
CFG_EFI="$WORKDIR/EFI/BOOT/grub.cfg"
mkdir -p "$WORKDIR/EFI/BOOT" if [ -n "$GLOBAL_EFI_BOOTLOADER" -a ! "$GLOBAL_EFI_BOOTLOADER" = "grub-efi" ]; then
cd "$WORKDIR/EFI/BOOT" rm -fr "$WORKDIR/boot"
exit 0
fi
# validate just in case (see also stage1 Makefile) if [ -z "$GLOBAL_EFI_BOOTLOADER" ]; then
case "$GLOBAL_BOOTLOADER" in case "$GLOBAL_BOOTLOADER" in
isolinux|syslinux|ieee1275boot|grubaa64boot|grubx86boot) ;; ieee1275boot) ;;
*) echo "error: weird GLOBAL_BOOTLOADER: \`$GLOBAL_BOOTLOADER'" >&2; *) rm -fr "$WORKDIR/boot"
exit 1;; exit 0;;
esac esac
fi
cd "$WORKDIR/boot/grub"
# copy extra files, if any # copy extra files, if any
GRUB_FILES="$(cat .in/grub.list)" GRUB_FILES="$(cat .in/grub.list)"
...@@ -21,21 +27,47 @@ if [ -n "${GRUB_FILES% }" ]; then ...@@ -21,21 +27,47 @@ if [ -n "${GRUB_FILES% }" ]; then
fi fi
# number ordering sponsored by shell's pathname expansion # number ordering sponsored by shell's pathname expansion
grep -hv '^#' .in/[0-9][0-9]*.cfg > "$CFG" case "$GLOBAL_BOOTLOADER" in
ieee1275boot)
grep -hv '^#' $(find .in/*.cfg -not -name *_efi.cfg) > "$CFG" ;;
esac
if [ "$GLOBAL_EFI_BOOTLOADER" = "grub-efi" ]; then
mkdir -p "$WORKDIR/EFI/BOOT"
grep -hv '^#' $(find .in/*.cfg) > "$CFG_EFI"
fi
# there should be DEFAULT directive there (at least for alterator-netinst) # there should be DEFAULT directive there (at least for alterator-netinst)
if ! grep -i '^default' .in/[0-9][0-9]*.cfg; then default_change() {
DEFAULT="$(grep -i '\-\-id ' .in/[0-9][0-9]*.cfg | head -1 | rev| cut -f2 -d' ' |rev)" local CFG=$1
if ! grep -i '^default' "$CFG"; then
DEFAULT="$(grep -i '\-\-id ' "$CFG" | head -1 | rev| cut -f2 -d' ' |rev)"
if [ -n "$DEFAULT" ]; then if [ -n "$DEFAULT" ]; then
echo "default=$DEFAULT" >> "$CFG" echo "default=$DEFAULT" >> "$CFG"
else else
echo "error: no DEFAULT or UI directive and cannot guess" >&2 echo "error: no DEFAULT or UI directive and cannot guess for $CFG" >&2
exit 1 exit 1
fi fi
fi fi
}
if [ -f "$CFG" ]; then
default_change "$CFG"
sed -i 's,@boot_path@,/boot,g' "$CFG"
fi
if [ -f "$CFG_EFI" ]; then
default_change "$CFG_EFI"
sed -i 's,@boot_path@,/EFI/BOOT,g' "$CFG_EFI"
fi
# snippets are not going into the actual image # snippets are not going into the actual image
if [ "$DEBUG" != 2 ]; then rm -r .in/; fi if [ "$DEBUG" != 2 ]; then
rm -r .in/
cd $WORKDIR
[ -f "$CFG" ] || rm -r boot/grub
[ ! $(ls -A boot/ | wc -l) -eq 0 ] || rm -r boot/
fi
# NB: there will be final macro expansion based on actual image sizes # NB: there will be final macro expansion based on actual image sizes
# done by features.in/grub/scripts.d/20-propagator-ramdisk # done by features.in/grub/scripts.d/20-propagator-ramdisk
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment