Volume groups on 8GB AWS AMI
5 years 9 months ago #77
The Amazon Linux AMI comes with a 8GB root device. Best practice would be to create logical volumes for /var and /home and so one would allocate an additional EBS storage device to create these volumes. This would leave you with an 8GB root device of which in most cases at least 6GB will never be used. Here are the steps we took to allocate this otherwise wasted space into logical volumes.
In this example we resize the root partition to 2GB and create 3 logical volumes, 1GB for swap, 1GB for /home and the remainder 4GB for /var.
To get started, attach the root volume to another AWS instance system using the AWS console, say as /dev/sdg
Check root filesystem: e2fsck -f /dev/sdg1
Resize root filesystem: resize2fs -p /dev/sdg1 2G
Check filesystem once more after resizing: e2fsck -f /dev/sdg1
Use parted or fdisk on /dev/sdg,
Take note of the start block number of the root partition,
Delete the root partition,
Recreate the root partition with same start block number as before and a size of +2G
Create a second partition /dev/sdg2 and claim the free space. Do this before attaching to the target system because otherwise growroot will claim back the free space for the root partition at startup
Use parted to rename the root partition to Linux
e2fsck -f /dev/sdg1
Attach the volume back to the target system as /dev/xvda
Create a new physical volume of /dev/xvda2: pvcreate /dev/xvda2
Create a volume group, for example vg1: vgcreate vg1 /dev/xvda2
Create logical volumes:
for swap: lvcreate -L 1G -n lv1 vg1
for /home: lvcreate -L 1G -n lv2 vg1
for /var: lvcreate -l 100%FREE -n lv3 vg1
Make file systems for /home and /var: mkfs.ext4 /dev/vg1/lv2 and mkfs.ext4 /dev/vg1/lv3
Copy data for /var: mount /dev/vg1/lv2 /mnt and then cp -a /var/* /mnt/
umount /mnt before you do the same for /home:
Copy data for /home: mount /dev/vg1/lv3 /mnt and then cp -a /home/* /mnt/
Add both file systems to /etc/fstab:
/dev/vg1/lv2 /var ext4 defaults 0 0
/dev/vg1/lv3 /var ext4 defaults 0 0
Make swap of lv1: mkswap /dev/vg1/lv1
Add swap to /etc/fstab: /dev/vg1/lv1 swap swap defaults 0 0
Last Edit: 5 years 9 months ago by Arnaud.
The administrator has disabled public write access.