SRJ
SRJ

Reputation: 2806

Mounting an Additional EBS volume to AMI with EC2 Image Builder

I am using EC2 Image Builder Service to build golden AMIs.

Use Case :

I want to attach additional EBS volume in the instance and there i will do all the installation of third party components and store everything there rather than doing everything to my root device. Thereafter i want to build the AMI for the same and so i am currently using EC2 Image Builder Service.

Problem Statement :

I want to mount an additional EBS volume to instance(which is building AMI). To achieve that i have included mounting device commands and included them in custom build component.

name: DeployComponents
description: This is to deploycomponents.
schemaVersion: 1.0
phases:
  - name: build
    steps:
      - name: DeploymentStep
        action: ExecuteBash
        inputs:
          commands:
            - echo "Attaching Additional EBS Volume."
            - lsblk
            - sudo useradd -m abc -p abc
            - sudo groupadd cloud
            - sudo usermod -a -G cloud cloud
            - sudo umount -f /dev/sdb
            - sudo mkfs -t ext4 /dev/sdb
            - sudo mkdir /cloud
            - mount /dev/sdb /cloud
            - echo /dev/sdb /cloud ext4 defaults,nofail 0 2 >> /etc/fstab
            - sed -i 's+/opt/mount1+/cloud+' /etc/fstab
            - sudo chown -R cloud:cloud /cloud

Also included the same device in the recipe i.e. /dev/sdb.

When i look at the EC2 Image Builder logs then i am seeing this :

Logs :

umount: /dev/sdb: mountpoint not found
mke2fs 1.42.9 (28-Dec-2013)
Could not stat /dev/sdb --- No such file or directory

The device apparently does not exist; did you specify it correctly?
mount: special device /dev/sdb does not exist
umount: /dev/sdb: mountpoint not found
mke2fs 1.42.9 (28-Dec-2013)
Could not stat /dev/sdb --- No such file or directory

The device apparently does not exist; did you specify it correctly?
mount: special device /dev/sdb does not exist

What am i missing ?

Any help is appreciated.

Many Thanks in Advance.

Upvotes: 0

Views: 1712

Answers (1)

SRJ
SRJ

Reputation: 2806

I figured out the issue.

It was due to naming convention of devices on AWS

I ran lsblk command on machine(which will be used to create AMI) and output was like this

NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1     259:1    0  100G  0 disk 
└─nvme0n1p1 259:2    0  100G  0 part /
nvme1n1     259:0    0  100G  0 disk 

And there i figured out naming convention for /dev/sdb will be /dev/nvme1n1

References :

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

Upvotes: 0

Related Questions