Building up from this other answer.
There are two solutions depending on the cloud-init version
- cloud-init >= 24.2, using
device_aliases
, disk_setup
, fs_setup
and mounts
with x-systemd.device-timeout
- cloud-init < 24.2, using
disk_setup
and mounts
with x-systemd.device-timeout
and x-systemd.makefs
(this options make a substitute for fs_setup
not working with nvme partition on cloud-init < 24.2)
cloud-init >= 24.2
If you can use cloud-init 24.2 (released July 2024) you can partition, format and mount EBS volumes (that are exposed as NVMe in AWS Nitro instances, see Amazon EBS and NVMe) like this (tested on Fedora 41 Rawhide 20240711):
#cloud-config
device_aliases:
disk1: /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0a250869ccd411b30
disk_setup:
disk1:
table_type: gpt
layout: [50,25,25]
overwrite: false
fs_setup:
- label: disk1-earth
filesystem: xfs
device: disk1
partition: 1
- label: disk1-mars
filesystem: xfs
device: disk1
partition: 2
- label: disk1-venus
filesystem: xfs
device: disk1
partition: 3
mounts:
- [ LABEL=disk1-earth, /earth, xfs, "defaults,nofail,x-systemd.device-timeout=30"]
- [ LABEL=disk1-mars, /mars, xfs, "defaults,nofail,x-systemd.device-timeout=30"]
- [ LABEL=disk1-venus, /venus, xfs, "defaults,nofail,x-systemd.device-timeout=30"]
mounts_default_fields: [ None, None, "auto", "defaults,nofail", "0", "2"]
cloud-init 24.2 is required if you want to partition the disk since previous versions do not work with NVMe (see #5246 that was fixed by #5263 and released on cloud-init 24.2)
If you don't need several partitions you can use any reasonably recent cloud-init.
The x-systemd.device-timeout=30
in the mount options tells mount
to wait 30 seconds for the device to become available providing the delay requested by the OP.
You can verify the proper partitioning, formatting and mount afterwards with the following commands
sudo blkid -s LABEL
lsblk -o name,size,mountpoint,label
findmnt --fstab
cloud-init < 24.2
If your distro does not have cloud-init 24.2, you can't use fs_setup
for NVMe with partitions (see bug #5246 that was fixed by #5263 and released on cloud-init 24.2.
Since you can't use fs_setup
, you need to use x-systemd.makefs
on the mount options. fs_setup
did also serve to assign a disk partition label and that you can't do via mount options, so you "lose" the ability of giving it a label.
#cloud-config
device_aliases:
disk1: /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0a250869ccd411b30
disk_setup:
disk1:
table_type: gpt
layout: [50,25,25]
overwrite: false
fs_setup:
- label: disk1-earth
filesystem: xfs
device: disk1
partition: 1
- label: disk1-mars
filesystem: xfs
device: disk1
partition: 2
- label: disk1-venus
filesystem: xfs
device: disk1
partition: 3
mounts:
- [ /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0a250869ccd411b30-part1, /earth, xfs, "defaults,nofail,x-systemd.device-timeout=30s,x-systemd.makefs"]
- [ /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0a250869ccd411b30-part2, /mars, xfs, "defaults,nofail,x-systemd.device-timeout=30s,x-systemd.makefs"]
- [ /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0a250869ccd411b30-part3, /venus, xfs, "defaults,nofail,x-systemd.device-timeout=30s,x-systemd.makefs"]
mounts_default_fields: [ None, None, "auto", "defaults,nofail", "0", "2"]
You can verify the proper partitioning, formatting and mount afterwards with the following commands
lsblk -o name,size,mountpoint,label
findmnt --fstab