I want to be able to increase the size of the /var filesystem of my EC2 instance "possibly" without having to detach the volume, and creating new volume and attach.
- list block devices
$lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 2.4T 0 disk ├─xvda1 202:1 0 487M 0 part /boot └─xvda2 202:2 0 2T 0 part ├─ami-home 253:0 0 10G 0 lvm /home ├─ami-opt 253:1 0 20G 0 lvm /opt ├─ami-tmp 253:2 0 10G 0 lvm /tmp ├─ami-var 253:3 0 30G 0 lvm /var ├─ami-var_tmp 253:4 0 10G 0 lvm /var/tmp ├─ami-var_log 253:5 0 30G 0 lvm /var/log ├─ami-var_log_audit 253:6 0 20G 0 lvm /var/log/audit └─ami-root 253:7 0 19.5G 0 lvm /
- disk free ( as we can see, /var is 100% full )
$df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ami-root 20G 1.8G 18G 9% / devtmpfs
7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 17M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0%
/sys/fs/cgroup /dev/mapper/ami-var 30G 30G 53M 100% /var
/dev/mapper/ami-opt 20G 330M 20G 2% /opt
/dev/mapper/ami-home 10G 39M 10G 1% /home
/dev/mapper/ami-var_log 30G 72M 30G 1% /var/log
/dev/mapper/ami-tmp 10G 54M 10G 1% /tmp
/dev/mapper/ami-var_log_audit 20G 488M 20G 3% /var/log/audit
/dev/mapper/ami-var_tmp 10G 33M 10G 1% /var/tmp
/dev/xvda1 484M 162M 323M 34% /boot tmpfs
1.6G 0 1.6G 0% /run/user/1000
- get the existing size of the volume ( since I know the instance id )
$aws ec2 describe-volumes --volume-ids vol-007310f0c754b2598
> { > "Volumes": [ > { > "AvailabilityZone": "us-east-1c", > "Attachments": [ > { > "AttachTime": "2018-08-02T15:47:47.000Z", > "InstanceId": "i-047fa3b2aea60f7b3", > "VolumeId": "vol-007310f0c754b2598", > "State": "attached", > "DeleteOnTermination": true, > "Device": "/dev/xvda" > } > ], > "Encrypted": false, > "VolumeType": "gp2", > "VolumeId": "vol-007310f0c754b2598", > "State": "in-use", > "Iops": 720, > "SnapshotId": "snap-00a77e9f750429974", > "CreateTime": "2018-08-02T15:47:47.023Z", > "Size": 240 > } > ] }
increase the size of the partition
$aws ec2 modify-volume --region us-east-1 --volume-id vol-007310f0c754b2598 --size 2400 --volume-type gp2
result:
{
"VolumeModification": {
"TargetSize": 2400,
"TargetVolumeType": "gp2",
"ModificationState": "modifying",
"VolumeId": "vol-007310f0c754b2598",
"TargetIops": 7200,
"StartTime": "2018-08-06T06:57:21.000Z",
"Progress": 0,
"OriginalVolumeType": "gp2",
"OriginalIops": 720,
"OriginalSize": 240
}
}
- xfs_growfs -d /var does not modify the var
Error: data size unchanged, skipping
references:
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-initialize.html
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/cli-modify.htmlenter link description here
So i tried:
$lvextend -l +200%FREE /dev/mapper/ami-var
New size (7680 extents) matches existing size (7680 extents).
but:
> xfs_growfs -d /dev/mapper/ami-var meta-data=/dev/mapper/ami-var
> isize=512 agcount=4, agsize=1966080 blks
> = sectsz=512 attr=2, projid32bit=1
> = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=7864320, imaxpct=25
> = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=3840, version=2
> = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0,
> rtextents=0 data size unchanged, skipping