https://wiki.centos.org/TipsAndTricks/CreateNewInitrd
If you have changed a motherboard or moved a disk to a different system it may fail to boot due to the lack of appropriate drivers in the initial RAM disk image (initramfs for CentOS 6, initrd for CentOS 5).
Boot in Rescue Mode#
- Boot from a CentOS installation disc (for example, CD #1 or DVD).
- Type "linux rescue" at the "boot:" prompt.
- Mount all filesystems in read-write mode.
Create the New Initramfs or Initrd#
Change root to real root ('/') on your hard disk and make the new initramfs or initrd.
1mount --bind /proc /mnt/sysimage/proc
2mount --bind /dev /mnt/sysimage/dev
3mount --bind /sys /mnt/sysimage/sys
4chroot /mnt/sysimageFor CentOS 7 and multipathed root ('/') issue the following before chroot-ing to '/mnt/sysimage':
1mount --bind /run /mnt/sysimage/run
2systemctl start multipathd.serviceFor CentOS 6:
Create a backup copy of the current initramfs:
1cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bakNow create the initramfs for the current kernel:
1dracut -fIf you need to build it for a specific kernel version (replace the version appropriately):
1dracut -f /boot/initramfs-2.6.32-358.el6.x86_64.img 2.6.32-358.el6.x86_64One useful option you might want to add is -H (--hostonly). With this option dracut installs only what is needed for booting your system. Otherwise dracut by default adds many drivers to the initramfs making its size larger than necessary. Many other options may be exercised. Please see man dracut, man dracut.conf and the upstream Deployment Guide.
For CentOS 5:
Create a backup copy of the current initrd:
1cp -p /boot/initrd-$(uname -r).img /boot/initrd-$(uname -r).img.bakNow create the initrd for the current kernel:
1mkinitrd -f -v /boot/initrd-$(uname -r).img $(uname -r)If you need to build it for a specific kernel version (replace the version appropriately):
1mkinitrd -f -v /boot/initrd-2.6.18-371.el5.img 2.6.18-371.el5If you are migrating a physical machine to a virtual one using the Xen hypervisor, replace the last command above with:
1mkinitrd --with-xenblk initrd-2.6.18-371.el5xen.img 2.6.18-371.el5xenMany other options may be exercised, such as adding non-loaded modules manually. See man mkinitrd for details. It may be necessary to modify /boot/grub/grub.conf and/or /etc/fstab depending on the details of your installation. This depends on your use of LABEL and/or UUID versus physical devices in the files, and is too complex an issue to get into in any detail in a TipsAndTricks article.
Reboot
1cd /
2sync
3telinit 6This page was created by PhilSchaffner. Other Wiki contributors are invited to make corrections, additions, or modifications.
The page was inspired by this forum thread. Please see the thread for additional discussion.
