Search This Blog

2014-08-14

Boot Directly into New Kernel After Kickstart Install

It is useful to be able to boot directly into your freshly installed linux box immediately after installation.

However there are multiple different methods to going about doing this, both depending on which version of GRUB you are running, because the information you will require to make the next kernel load will depend on what you plan on booting next.

Both instructions will require the use of post-install scripts to pull data from the filesystem about next boot parameters.

First off, it's a good idea to get some debug going on your console screen, which can be done via the following:
%post
exec < /dev/console > /dev/console
echo "# Running Post Configuration #"
#....Do stuff....
echo "End of post-install steps"
References: http://blog.mozilla.org/jv/2011/01/31/redirecting-kickstart-prepost-over-serial-console/

GRUB 0.97

In GRUB 0.97 its fairly easy, you just grab the cmdline options (arguments) from the /boot/grub/grub.conf
cmdline=$(awk /kernel.*console/'{$1=$2=""; print$0}' /boot/grub/grub.conf)                       
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initramfs-$(uname -r).img --append="${cmdline}"
sleep 2                                                                                          
kexec -e                                                                                         

GRUB 2

In GRUB 2 its a bit more challenging as each GRUB menu is dynamically generated from /etc/grub2.cfg which points to /etc/grub.d/* files which have scripts that parse the underlying filesystem to locate kernels to dynamically build the grub menu
ls -lah /etc/grub.d/
total 80K
drwx------.  2 root root 4.0K Aug 12 13:16 .
drwxr-xr-x. 99 root root 8.0K Aug 12 20:09 ..
-rwxr-xr-x.  1 root root 8.5K Jun 30 12:16 00_header
-rwxr-xr-x.  1 root root 9.3K Jun 30 12:16 10_linux
-rwxr-xr-x.  1 root root  11K Jun 30 12:16 20_linux_xen
-rwxr-xr-x.  1 root root 2.5K Jun 30 12:16 20_ppc_terminfo
-rwxr-xr-x.  1 root root  11K Jun 30 12:16 30_os-prober
-rwxr-xr-x.  1 root root  214 Jun 30 12:16 40_custom
-rwxr-xr-x.  1 root root  216 Jun 30 12:16 41_custom
-rw-r--r--.  1 root root  483 Jun 30 12:16 README

By default linux grub menus are generated via /etc/grub.d/10_linux and take the defaults for cmdline options from /etc/defaults/grub

Grabbing the cmdline

cmdline=$(awk -F '"' '/GRUB_CMDLINE_LINUX/{print$2}' /etc/default/grub)

Grabbing the root Volume

I haven't figured out a dynamic way of grabbing the root volume yet so I just manually stuff in /dev/mapper/(volume-group-lv) in

Putting GRUB2 all together to kexec the kernel

%post                                    
exec < /dev/console > /dev/console       
echo "# Running Post Configuration #"                                                                                    
cmdline=$(awk -F '"' '/GRUB_CMDLINE_LINUX/{print$2}' /etc/default/grub)                                               
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initramfs-$(uname -r).img --append="root=/dev/mapper/VolGrp-Vol1 ro {cmdline}"                                                                                                               
sleep 2                                                                                                               
echo "Loading new Kernel"                                                                                             
kexec -e 
%end

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.