AWSのcloud9サービスでmysqlを導入しようとしたところ空き容量が足りなかった。
なので以下の方法を試した。
まずは $df
コマンドで空き容量を確認。
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 485132 0 485132 0% /dev
tmpfs 503448 0 503448 0% /dev/shm
tmpfs 503448 456 502992 1% /run
tmpfs 503448 0 503448 0% /sys/fs/cgroup
/dev/xvda1 10473452 10145328 328124 97% /
tmpfs 100692 0 100692 0% /run/user/1000
/dev/xvda1が97%埋まっています。
これを次のシェルスクリプト
#!/bin/bash
# Specify the desired volume size in GiB as a command-line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances \
--instance-id $INSTANCEID \
--query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \
--output text)
# Resize the EBS volume.
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE
# Wait for the resize to finish.
while [ \
"$(aws ec2 describe-volumes-modifications \
--volume-id $VOLUMEID \
--filters Name=modification-state,Values="optimizing","completed" \
--query "length(VolumesModifications)"\
--output text)" != "1" ]; do
sleep 1
done
#Check if we're on an NVMe filesystem
if [ $(readlink -f /dev/xvda) = "/dev/xvda" ]
then
# Rewrite the partition table so that the partition takes up all the space that it can.
sudo growpart /dev/xvda 1
# Expand the size of the file system.
# Check if we are on AL2
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/xvda1
fi
else
# Rewrite the partition table so that the partition takes up all the space that it can.
sudo growpart /dev/nvme0n1 1
# Expand the size of the file system.
# Check if we're on AL2
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/nvme0n1p1
fi
fi
resize.shとしてどこでもいいのでファイルを作成。
その後
$ sh resize.sh 30
をターミナルに打ってあげて完了。
Filesystem Inodes IUsed IFree IUse% Mounted on
devtmpfs 121283 284 120999 1% /dev
tmpfs 125862 2 125860 1% /dev/shm
tmpfs 125862 388 125474 1% /run
tmpfs 125862 16 125846 1% /sys/fs/cgroup
/dev/xvda1 1015248 358584 656664 36% /
tmpfs 125862 2 125860 1% /run/user/1000
36%の余裕ができました。☻