How to Update kernel in Amazon EC2 Instances
Update kernel Amazon EC2 is not the easy way and sometimes leads to worse your instance by not connecting to your system. I have faced and as fast as I can, I have shared the problem with you. I work with gentoo.
DISCLAIMER: DO AT YOUR OWN RISK.
Update Kernel Amazon EC2
This process has been described in EC2 Official Page: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedKernels.html
Gentoo Update Kernel
It is also in: https://wiki.gentoo.org/wiki/Kernel/Upgrade
The main problem is the New Kernel is not boot even grub is updated.
Solution
Go to boot dir by /boot
$ cd /boot
This boot will display the following
And you will see the softlinks to kernel and initramfs and even System.map
You have to replace these softlinks by
rm /boot/System.map /boot/initramfs /boot/kernel
ln -s /boot/initramfs-5.4.38-gentoo-x86_64.img /boot/initramfs
ln -s /boot/vmlinux-5.4.38-gentoo-x86_64 /boot/kernel
ln -s /boot/System.map-5.4.38-gentoo-x86_64 /boot System.map
After that reboot your machine.
How to Rescue when kernel not work
You can find detail in this YouTube Link: https://www.youtube.com/watch?v=QiMpJi2YWxA
When you boot your machine and take system screenshot and the following error may occurs:
* Bringing up interface eth0
* Caching network module dependencies
* ERROR: interface eth0 does not exist
* Ensure that you have loaded the correct kernel module for your hardware
* ERROR: net.eth0 failed to start
* ERROR: cannot start netmount as net.eth0 would not start
You can stop machine forcefully and detach and attach on another EC2 Instances
For example, if you mount with xvdf, you should mount like this
mount /xvdf1 /mnt
mount -o bind /dev /mnt/dev
mount -o bind /dev/shm /mnt/dev/shm
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
chroot /mnt
Your old Gentoo installation will occur in these area. You can type with the following exact command.
touch /etc/udev/rules.d/80-net-name-slot.rules
According to this.