#Perform grub edits to login to superuser mode to recover a lost password.
#Press 'esc' while system is booting to enter into the grub edit mode and press 'e' and move to the 'linux16' line and append.
rd.break or init=/sysroot/bin/sh
mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit (twice)
Using insmod and grubcmd manage initramfs
#Grub2 Command Line.
grub>
insmod lvm
search.file /etc/fstab
lvm/vgos-root
set root=(lvm/vgos-root)
linux16 (hd0,msdos1)/vmlinuz -tab root=/dev/mapper/vgos-root
initrd (hd0,msdos1)/initramfs*
#System boot issues
Early debug shell can be activated by
systemctl enable debug-shell # A root shell will be spanned on TTY9, CTRL+ALT+F9)
#Corruption in grub.cfg
Mount the DVD, boot - choose the resuce media
#If vmlinuz is missing
Boot into rescue mode
chroot /mnt/sysimage
mount /dev/cdrom /tmp/mnt
cp /tmp/mnt/isolinux/vmlinuz /boot/vmlinuz-$(uname -r) or grub2-install /dev/vda1 --skip-fs-probe --force -v
cd /boot ; dracut initramfs-$(uname -r).img $(uname -r)
#Configure virtual terminals
/etc/systemd/logind.conf
#NOTE: (*IMPORTANT*)
Iff console doesn't come up even with rd.break or init=/sysroot/bin/sh add below to overide the console terminals.
rd.break console=tty1 or rd.break console=tty0 (or ttyS0) or enforcing=0
#Corruption in grub.cfg
Mount the DVD, boot - choose the resuce media
chroot /mnt/sysimage
grub2-install /dev/vda
yum reinstall grub2-tools
grub2-mkconfig -o /boot/grub2/grub.cfg
or
grub2-mkconfig -o /boot/grub2/efi/EFI/redhat/grub.cfg
-Example.
[root@lab11 default]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-d88dc0e9818b405383649087000b224a
Found initrd image: /boot/initramfs-0-rescue-d88dc0e9818b405383649087000b224a.img
done
Using kpartx , mount the image FS using /dev/loop and re-mount
[root@lab130a ~]# grep linux16 /boot/grub2/grub.cfg
linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/vgos-lvroot ro crashkernel=auto rd.lvm.lv=vgos/lvroot rhgb quiet LANG=en_US.UTF-8
linux16 /vmlinuz-0-rescue-6e490d5089bd459881a69cee25bb2294 root=/dev/mapper/vgos-lvroot ro crashkernel=auto rd.lvm.lv=vgos/lvroot rhgb quiet
[root@lab130a ~]# grubby --update-kernel /boot/vmlinuz-3.10.0-327.el7.x86_64 --args="console=tty0,ttyS0,115200"
[root@lab130a ~]# grep linux16 /boot/grub2/grub.cfg
linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/vgos-lvroot ro crashkernel=auto rd.lvm.lv=vgos/lvroot rhgb quiet LANG=en_US.UTF-8 console=tty0 console=ttyS0 console=ttyS0,115200
linux16 /vmlinuz-0-rescue-6e490d5089bd459881
# Try to get access to console
virsh console lab11
#Doesn't work until the console access is enabled. Enable via kpartx
root@panchajanya:~\> virsh domblklist lab11
Target Source
------------------------------------------------
vda /data/sdd01/vspd1/lab11.img
root@panchajanya:~\> kpartx -av /data/sdd01/vspd1/lab11.img
add map loop0p1 (253:14): 0 1048576 linear /dev/loop0 2048
add map loop0p2 (253:15): 0 20971520 linear /dev/loop0 1050624
add map loop0p3 (253:16): 0 1048576 linear /dev/loop0 22022144
root@panchajanya:~\> mount /dev/mapper/loop0p1 /mnt/
root@panchajanya:~\> cd /mnt/
root@panchajanya:/mnt\> ls
config-3.10.0-327.el7.x86_64 initrd-plymouth.img
grub symvers-3.10.0-327.el7.x86_64.gz
grub2 System.map-3.10.0-327.el7.x86_64
initramfs-0-rescue-d88dc0e9818b405383649087000b224a.img vmlinuz-0-rescue-d88dc0e9818b405383649087000b224a
initramfs-3.10.0-327.el7.x86_64.img vmlinuz-3.10.0-327.el7.x86_64
initramfs-3.10.0-327.el7.x86_64kdump.img
root@panchajanya:/mnt\> vi grub2/grub.cfg
root@panchajanya:/mnt\> grep console grub2/grub.cfg
terminal_output console
linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/vgos-lvroot ro crashkernel=auto rd.lvm.lv=vgos/lvroot rhgb quiet LANG=en_US.UTF-8 console=ttyS0
umount /dev/mapper/loop0p1
kpartx -dv /data/sdd01/vspd1/lab11.img