Working GRUB
GNU GRUB is the bootloader of choice for most Linux distributions, offering massive flexibility to boot a multitude of operating systems. With GRUB version 2, configuration remains straightforward, but can be largely auto-generated with modern tools. It also retains the full flexibility to modify the boot configuration at run-time.
Configuration
It always pays to make backups:
cd /boot/grub2 cp -a grub.cfg grub.cfg.backup
In order to generate grub2 configuration:
grub2-mkconfig -o /boot/grub2/grub.cfg
The tool will probe the system looking for partitions containing vmlinuz and initramfs images, and build configuration appropriately. Administrator tunables that affect the process are stored in /etc/default/grub. Example config:
GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved # GRUB_TERMINAL="serial console" # GRUB_SERIAL_COMMAND="serial --unit=0 --speed=9600" GRUB_CMDLINE_LINUX="quiet rhgb" GRUB_DISABLE_RECOVERY="true"
Configuration is best built from within the intended root of the Linux system, and the tool can be run on a live system with no issues. If the system is in a state where this is unattainable, it is possible to build a clean environment by assembling the necessary mounts in rescue mode. Do not select “find drives automatically,” we will do so manually:
mkdir /mnt/sysimage vgchange -ay mount /dev/mapper/Volume00-root mount /dev/sda1 /mnt/sysimage/boot mount --bind /proc /mnt/sysimage/proc mount --bind /dev /mnt/sysimage/dev mount --bind /sys /mnt/sysimage/sys chroot /mnt/sysimage
NOTE: Devices holding boot and root will vary from system to system.
Now run grub2-mkconfig.
Run-Time Changes
Hitting “e” at the grub menu allows one to peruse and change configuration. This is probably most commonly used to alter kernel command-line arguments, such as adding “single” to boot to single-mode, but any aspect of the configuration can be changed before boot.
For example, we may wish to attempt to boot an alternate root volume. While in this mode, we need simply find the kernel we wish to boot and alter its command-line arguments, one being the selection of the intended root:
linux /vmlinuz-3.12.8-300.fc20.i686 ro root=/dev/sda2
NOTE: Add/remove other arguments such as quiet, rhgb, or rd.* as necessary.
We may also have a need to load an alternate initramfs image:
initrd /initramfs-3.12.8-300.fc20.i686.img.backup
When satisfied with the changes, hit F10 to boot.
Grub Prompt
It is actually entirely possible to attempt boot with no grub configuration at all, whether dropping voluntarily or involuntarily to the grub prompt. Given all the same assumptions:
grub> ls (hd0) (hd0,1) (hd0,2) (hd0,3) grub> set root=(hd0,1) grub> linux /vmlinuz-3.12.8-300.fc20.i686 ro root=/dev/sda2 grub> initrd /initramfs-3.12.8-300.fc20.i686.img.20140608 grub> boot
NOTE: The partition nomenclature is different in grub, but we are specifying the partition containing vmlinuz and initrd images (eventually known as sda1 and mounted at /boot by linux). Also note that tab-completion thankfully works.
Resources
- http://tuxers.com/main/instigating-a-manual-boot-from-the-grub-prompt
Leave a comment