Changing Instance Types In AWS For SLES 12 SP2 And SLES 12 SP3 Based HVM Instances (and later)
Ever tried to switch instance types from lets say t2 to m5 on SLES 12 SP3 (including SLES For SAP)? Well if you did you were in for a bad surprise in that your instance would no longer boot. Switching the instance type back away from the newer instance types c5, m5, m5d…. and restarting the instance would get everything working again. That’s of course not the way we want things to behave.
The issue has been fixed in images with a date stamp later then 20180810. For running instances addressing the issue is reasonably straight forward.
Yeah well the issue was fixed in images after 20180810. But then We dropped the config when SLE 15 was released and with the kernel change in SLE 12 SP5 the virtio module disappeared from the kernel. However, not until SLE 15 SP2 did dracut trigger an error and thus generate an insufficient initrd for type switching. Meaning is you are running an instance based on SLE 15 or later from an image with a date stamp prior to 20210107 you need to check if /etc/dracut.conf.d/07-aws-type-switch.conf exists. If it does not exist create it with the content shown below. If it does exist, at least 2 image refreshes were pushed out that contained virtio you want to fix it before you attempt to switch instance types between Nitro and Xen based instance types.
And now I get to claim again, instances started from images with a date stamp later than 20210107 require no action for instance type switching.
End Update 2021-01-07:
As root run:
For SLES 12 SP4 and earlier based instances:
echo 'add_drivers+=" ena ext4 nvme nvme-core virtio virtio_scsi xen-blkfront xen-netfront "' >> /etc/dracut.conf.d/07-aws-type-switch.conf && mkinitrd
For SLES 12 SP5 and later based instances
echo 'add_drivers+=" ena ext4 nvme nvme-core xen-blkfront xen-netfront "' >> /etc/dracut.conf.d/07-aws-type-switch.conf && mkinitrd
End Update 2021-01-07:
Newer instance types present the root volume to the guest instance from NVMe devices, while older instance types present the root device as a virtual block device. While all SLES 12 SP2 and SP3 images boot on either instance type, during initial boot the initrd gets regenerated to fit the instance type. This has the effect that when booting on the older instance types drivers needed to boot on newer instance types get removed from the initrd and vice-versa. The config change above simply makes sure that the necessary drivers for both instance types get included in the initrd when it gets regenerated and thus the problem is fixed.
What if your running instance has a longer history? Meaning way back when you started with a SLES 11 based instance or anything in between and you have been migrating your instances. Well as far as the EC2 framework is concerned you are still running an instance of the image you started and older images do not support the new instance type. Therefore EC2 will not let you switch.