Quick and dirty notes from the original AWS Documentation.
[[ ! -z $(sudo file -s /dev/xvdf | grep -e 'data$') ]] && sudo mkfs -t ext4 /dev/xvdf
[[ ! -z $(sudo file -s /dev/xvdg | grep -e 'data$') ]] && sudo mkfs -t ext4 /dev/xvdg
sudo mkdir -p /mnt/{data,tmplog}
sudo mount /dev/xvdf /mnt/data
sudo mount /dev/xvdg /mnt/tmplog
echo -e "/dev/xvdf\t/mnt/data\text4\tdefaults,nofail\t0\t2" | sudo tee --append /etc/fstab
echo -e "/dev/xvdg\t/mnt/tmplog\text4\tdefaults,nofail\t0\t2" | sudo tee --append /etc/fstab
sudo mount -a
NOTE: this assumes two volumes, one to be used for data and the other for logs and tmp that are uninitialized. We're checking first if the is a filesystem on the volume to then initialize it with a new filesystem.
Attach your volumes to the instance using the names /dev/xvdf
, /dev/xvdg
and so on.
Use the lsblk
command to check the attached volumes.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
`-xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 20G 0 disk
xvdg 202:96 0 20G 0 disk
Before you can actually use it you must get it ready with a filesystem on it.
For each volume run the command sudo file -s /dev/xvdf
to inspect if it is raw or was previously initialized.
[ec2-user ~]$ sudo file -s /dev/xvdf
/dev/xvdf: data
raw
[ec2-user ~]$ sudo file -s /dev/xvda1
/dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=1701d228-e1bd-4094-a14c-8c64d6819362 (needs journal recovery) (extents) (large files) (huge files)
already initialized
You will use mkfs
to get a filesystem on it.
sudo mkfs -t ext4 /dev/xvdf
Create a mounting point and mount it there
sudo mkdir -p /mnt/data
mount /dev/xvdf /mnt/data
To allow the system to automatically mount the volumes on reboot you must add the following lines to the /etc/fstab
file.
/dev/xvdf /data ext4 defaults,nofail 0 2
/dev/xvdg /tmplog ext4 defaults,nofail 0 2
Right after that you must check if the file is ok by running the following command:
sudo mount -a