

 AWS Cloud9 は新規顧客には利用できなくなりました。 AWS Cloud9 の既存のお客様は、通常どおりサービスを引き続き使用できます。[詳細はこちら](https://aws.amazon.com/blogs/devops/how-to-migrate-from-aws-cloud9-to-aws-ide-toolkits-or-aws-cloudshell/)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 環境で使用されている Amazon EBS ボリュームのサイズ変更
<a name="move-environment-resize"></a>

このステップでは、Amazon EBS ボリュームのサイズを変更する方法を説明します。

1. サイズを変更したい Amazon EBS ボリュームの Amazon EC2 インスタンスに関連付けられている環境を開きます。

1. 環境の AWS Cloud9 IDE で、次の内容のファイルを作成し、そのファイルを 拡張子 `.sh` (例: ) で保存します`resize.sh`。
**メモ**  
このスクリプトは、AL2023、Amazon Linux 2、Amazon Linux、または Ubuntu サーバーを実行する EC2 インスタンスに接続した Amazon EBS ボリュームに対して有効であり、IMDSv2 を使用するように設定されています。  
このスクリプトは、Nitro ベースのインスタンスで NVMe ブロックデバイスとして公開される Amazon EBS ボリュームのサイズも変更します。Nitro システムをベースにしたインスタンスリストについては、「*Amazon EC2 ユーザーガイド*」の「[Nitro ベースのインスタンス](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances)」を参照してください。

   ```
   #!/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.
   TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
   INSTANCEID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null)
   REGION=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/placement/region 2> /dev/null)
   
   # 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 \
     --region $REGION)
   
   # 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 [[ -e "/dev/xvda" && $(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're on AL2 or AL2023
     STR=$(cat /etc/os-release)
     SUBAL2="VERSION_ID=\"2\""
     SUBAL2023="VERSION_ID=\"2023\""
     if [[ "$STR" == *"$SUBAL2"* || "$STR" == *"$SUBAL2023"* ]]
     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 or AL2023
     STR=$(cat /etc/os-release)
     SUBAL2="VERSION_ID=\"2\""
     SUBAL2023="VERSION_ID=\"2023\""
     if [[ "$STR" == *"$SUBAL2"* || "$STR" == *"$SUBAL2023"* ]]
     then
       sudo xfs_growfs -d /
     else
       sudo resize2fs /dev/nvme0n1p1
     fi
   fi
   ```

1. IDE のターミナルセッションから、`resize.sh` ファイルが格納されているディレクトリに移動します。それから次のコマンドを実行し、`20` を Amazon EBS ボリュームのリサイズとして希望する Gib 単位のサイズに置き換えます。
   + 

     ```
     bash resize.sh 20
     ```
   + 

     ```
     chmod +x resize.sh
     ./resize.sh 20
     ```