When you launch an EC2 instance, it goes through a boot process similar to physical computers, but with some cloud-specific twists.
Understanding this boot process can help you troubleshoot and optimize your EC2 instances more effectively.
Infrastructure Allocation
When you start or create an EC2 instance, AWS allocates the necessary infrastructure resources to make your instance available.
Once the instance is allocated, the boot process begins. At the same time, AWS starts monitoring status checks 🔗 , including system, instance, and volume. If any of these checks fail, the EC2 instance will not start successfully.
Firmware Initialization
After resource allocation your EC2 instance boots up and relies on the firmware installed on the underlying hardware (motherboard chip). This firmware is the first software that runs, initializing the platform so that the operating system on the instance can start.
There are two main types of firmware:
- UEFI: A newer version, UEFI offers more features, like support for larger hard drives and faster boot times.
- Legacy BIOS: An older firmware standard, still used in some cases, particularly for older hardware that doesn’t support UEFI.
You can check this in the Boot Mode parameter of the AMI. This parameter can have one of three values: uefi
, legacy-bios
, or uefi-preferred
.
If the value is empty, the instance will use the default boot mode for the selected instance type.
- Graviton instance types: Use UEFI by default.
- Intel and AMD instance types: Use Legacy BIOS by default.
The firmware performs its Power-On Self-Test (POST), it checks essential hardware components like the CPU, memory, storage devices, and other basic functionalities to ensure they’re working correctly.
Bootloaders
After the firmware completes its POST, it detects the bootloader, a program responsible for loading the operating system into memory. The bootloader is typically located on the root device where the system image is installed.
GRUB is one of the most common bootloaders used in Linux. It allows you to select from multiple kernel versions. However, not all AMIs use GRUB. Some might use simpler bootloaders that automatically load the default kernel without giving you a choice.
If your AMI uses the GRUB bootloader, you can access it through the EC2 serial console.
Once the bootloader is detected, it loads the Linux kernel, the core operating system, into memory.
Kernel Loading
At first, when the kernel is loaded, it doesn’t know how to interact with storage devices or file systems.
To fix this, the kernel loads a temporary file system, either initrd
or initramfs
(a more advanced version). These contain the essential drivers needed to access hard drives, initialize hardware, and mount the root file system, which contains the core files necessary for the operating system to boot.
Service Initialization with init and systemd
Once the root file system is mounted, the kernel starts the first user-space program, called init
. This program is responsible for setting up and managing all the necessary services and processes to get the system running smoothly.
In older systems, init
starts services sequentially, one after another, based on a series of shell scripts located in directories like /etc/init.d/
.
However, modern systems use systemd
, a more advanced init
system that can start services in parallel. systemd
uses unit files, which are located in directories like /etc/systemd/system/
.
They handle essential services like networking, logging, and device management.
At this point, your user-data scripts (if configured) get executed. These scripts typically run as part of cloud-init
and are an important part of instance configuration.
You can view the system and boot logs from the EC2 console using the Instance System Log or Screenshot options. These are useful tools for debugging when an EC2 instance fails to start.
User Environment
After the core services are up, the system either displays a graphical login screen (GUI) or a text-based login prompt, depending on the system configuration. Once you log in, you can access the operating system and start using it.
I would love to hear your feedback in the comments below!
Thanks for reading,
-Alon