EBS Multi Attach NVME Persistent Preservation on Nitro EC2 EBS Optimized
You can install nvme-cli
from your distribution's package manager. For instance, on Fedora, CentOS, or similar:
sudo dnf install nvme-cli
On Amazon Linux 2:
sudo yum install nvme-cli
After installing nvme-cli for your distribution, you can explore your NVMe drive. There is no man page for nvme-cli, but you can get lots of help by entering:
nvme help
The output will provide you with a list of available sub-commands and their usage.
To list all NVMe devices and namespaces on your machine, use the following command:
sudo nvme list
The output will provide information about the NVMe drive, including its serial number, model, namespace, usage, format, and firmware revision.
You can obtain even more information about the drive and the features it supports by using the id-ctrl subcommand. For example:
sudo nvme id-ctrl /dev/nvme0n1
This command will display detailed information about the NVMe controller, including vendor ID, serial number, model name, and various controller attributes.
You can check the overall health of a drive with the smart-log subcommand:
sudo nvme smart-log /dev/nvme0n1
The output will provide information about the drive's temperature, available spare capacity, power-on hours, and more.
You can format an NVMe drive using nvme-cli, but be cautious, as it will erase all data on the drive. Backup important data before proceeding. Use the format subcommand, replacing 'X' with the appropriate location as listed in the results of nvme list:
sudo nvme format /dev/nvme0nX
When preparing to sell or dispose of your NVMe computer, securely erase the drive, but remember to back up important data first. This command erases all data:
sudo nvme sanitize /dev/nvme0nX
To read data from an NVMe drive starting from block 1000 and reading 10 blocks with a data size of 1:
sudo nvme read /dev/nvme1n1 --start-block=1000 --block-count=10 --data-size 1
sudo nvme write /dev/nvme1n1 -s 0 -c 1 -z 4096
To SSH into EC2 instances that have been configured with the above script, you can use the following commands for node1 and node2:
ssh -i "nvme-key.pem" ec2-user@ec2-52-221-202-154.ap-southeast-1.compute.amazonaws.com
ssh -i "nvme-key.pem" ec2-user@ec2-54-169-183-116.ap-southeast-1.compute.amazonaws.com
- The script is intended for EC2 instances that belong to the "compute optimized" instance families. This includes instance types such as C5, C5a, C5ad, C5d, C5n, C6a, C6g, C6gd, C6gn, C6i, C6id, C6in, C7a, C7g, C7gd, C7gn, C7i, Hpc6a, Hpc7g, and Hpc7a.
- It is recommended to use an instance type like c5.large and ensure EBS optimization.
Here are some additional NVMe commands and related operations you might find useful:
You can check the NVMe modules using the following command:
ls /sys/module/ | grep nvme
To find the EBS volume ID for an NVMe device (e.g., /dev/nvme1n1), use the following command:
sudo /sbin/ebsnvme-id /dev/nvme1n1
sudo nvme resv-register -n 1 --crkey=0x0 --nrkey=0xa1 --rrega=0 /dev/nvme1n1
sudo nvme resv-acquire -n 1 --crkey=0xa1 --rtype=1 --racqa=0 /dev/nvme0n1
sudo nvme resv-release /dev/nvme1n1 -n 1 -t 1
sudo nvme resv-release /dev/nvme1n1
sudo nvme resv-report /dev/nvme1n1 -n1 -e 1 -o normal
sudo nvme resv-acquire -n 1 --crkey=0xb1 --rtype=2 --racqa=0 /dev/nvme1n1
Here are the definitions for different values of persistent reservations:
0h: Reserved
1h: Write Exclusive Reservation
2h: Exclusive Access Reservation
3h: Write Exclusive - Registrants Only Reservation
4h: Exclusive Access - Registrants Only Reservation
5h: Write Exclusive - All Registrants Reservation
6h: Exclusive Access - All Registrants Reservation
07h-FFh: Reserved
You can perform various disk operations using commands like sudo fdisk -l, sudo mkfs.ext4 /dev/nvme1n1p1, sudo mkdir /shared, sudo mount /dev/nvme1n1p1 /shared, and sudo ls /shared.
To check the health of an NVMe drive, you can use:
sudo nvme id-ctrl /dev/nvme1n1 -H
To determine the filesystem type of a device (e.g., /dev/nvme1n1p1), you can use:
sudo file -s /dev/nvme1n1p1