How to fix GRUB initramdisk

From HyperSecurity Wiki
Revision as of 06:24, 19 January 2017 by 70.79.46.50 (talk) (Redhat Systems)
Jump to: navigation, search

Using System Rescue CD/DVD

When converting a physical live machine to vmware using vmware converter, there can be issues with booting due to how vmware recreates the initrd and grub.cfg. To fix this, do the following:

System Rescue CD Download

Boot the live CD and press option "E" to boot the / (root) parition

Once booted to a full OS, login to the OS as root and run the following in order:

update-initramfs -t -k all -u
update-grub 

This will update the initramfs as well as the grub.cfg file to match the new initrd. Reboot to confirm grub and booting is fixed.

Debian/Ubuntu broken init

Source

First boot with Debian Live CD/DVD. Once booted, become root:

sudo su -

Once root, mount the root partion to mnt. sdaX for non software RAID. mdX for software RAID.

mount /dev/sdaX /mnt

Next mount the boot partion to /mnt/boot if you multi partions

mount /dev/sdaX /mnt/boot

Copy over the /boot dir contents to /mnt/boot for a working kernel and initrd:

copy /boot/* /mnt/boot

Then bind mount the following partitions:

mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

Chroot the /mnt directory:

chroot /mnt /bin/bash

Update the Grub:

update-initramfs -t -k all -u
update-grub 

Exit Chroot and reboot:

exit && reboot && eject

Redhat Systems

https://wiki.centos.org/TipsAndTricks/CreateNewInitrd


Helpful commands:

  1. List UUID of all disks:
    • ls /dev/disk/by-uuid -lt
  2. Add CDROM to apt:
    • apt-cdrom add
  3. Rebuild software RAID
    • mdadm --assemble --scan
  4. List Software RAID details
    • mdadm -D /dev/md0

Grub2 Boot Example

Top half:

set root='mduuid/{md2UUID}' 
if [ x$feature_platform_search_hint = xy ]; then
 search --no-floppy --fs-uuid --set=root --hint='mduuid/{md2UUID}'  {MD2}
else
 search --no-floppy --fs-uuid --set=root {MD2}

Bottom half:

set linux_gfx_mode=
export linux_gfx_mode
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-{MD2}' {
       load_video
       insmod gzio
       if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
       insmod part_msdos
       insmod part_msdos
       insmod diskfilter
       insmod mdraid1x
       insmod ext2
       set root='mduuid/{md0UUID}'
       if [ x$feature_platform_search_hint = xy ]; then
         search --no-floppy --fs-uuid --set=root --hint='mduuid/{md0UUID}'  {MD0}
       else
         search --no-floppy --fs-uuid --set=root {MD0}
       fi
       echo    'Loading Linux 3.16.0-4-686-pae ...'
       linux   /vmlinuz-3.16.0-4-686-pae root=UUID={MD2} ro ipv6.disable=1 quiet
       echo    'Loading initial ramdisk ...'
       initrd  /initrd.img-3.16.0-4-686-pae
}