Skip to content

AWS: resolve root EBS DeviceName from AMI metadata instead of hardcoding /dev/sda1 #332

Description

@mrizwan93

AWSProvider.create_server() hardcodes /dev/sda1 in BlockDeviceMappings:

"BlockDeviceMappings": [
    {
        "DeviceName": "/dev/sda1",
        "Ebs": ebs,
    },
],

On EC2, the root volume DeviceName is AMI-specific. AWS documents that for HVM instances it is often /dev/sda1 or /dev/xvda (Device names for volumes on Amazon EC2 instances).

When overriding root volume properties at launch (VolumeSize, DeleteOnTermination), DeviceName must match the AMI’s root device mapping. A mismatch can:

Apply VolumeSize to the wrong volume (root disk not resized)
Attach an extra EBS volume instead of overriding the root mapping
This is especially important now that mrack supports configurable root volume size via disksize (see PR #331).

Proposed solution
In create_server(), after get_image(specs):

Read ami.root_device_name when available
Otherwise use the first EBS entry from ami.block_device_mappings
Fall back to /dev/sda1 only if neither is present (backward compatibility)
Example helper:

@staticmethod
def _get_root_device_name(ami):
    root_name = getattr(ami, "root_device_name", None)
    if root_name:
        return root_name
    for mapping in getattr(ami, "block_device_mappings", None) or []:
        device = mapping.get("DeviceName")
        if device and mapping.get("Ebs"):
            return device
    return "/dev/sda1"

Use the resolved name in BlockDeviceMappings[].DeviceName.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions