728x90
Note

The following topic walks you through the process of extending XFS and Ext4 file systems for Linux. For information about other file systems, see their documentation for instructions.


After you increase the size of an EBS volume, you must use file system–specific commands to extend the file system to the new, larger size. You can do this as soon as the volume enters the optimizing state.

To extend a file system on Linux, you need to:

  1. Extend the partition, if your volume has one.
  2. Extend the file system.

Before you begin

이 부분에 대해서 조금 더 설명하자면, Volume 에 대해서 modifications 를 거치는 경우에는 modification - optimizing - completed state 까지를 거치는데 이 부분에서 Cooldown period 가 적용되기 때문에 약 6시간에서 24시간을 거친 이후에야 volume 수정을 재시도를 할 수 있다.

추가적으로 Volume 사이즈는 늘리는 것은 가능해도, 줄이는 것은 안되니께 굉장히 유의해야한다.

 

Extend the file system of EBS volumes

Use the following procedure to extend the file system for a resized volume.

Note that device and partition naming differs for Xen instances and Nitro instances. To determine whether your instance is Xen-based or Nitro-based, use the describe-instance-types AWS CLI command as follows:

 

AWS CLI 에서 반드시 이부분을 확인하고 넘어가야한다. 부가적으로 설명하자면 t2 ~ t3 급에서 m5 급이나 c5 급 등으로 올라오게 되면 변경점이 생기기 때문이다

[ec2-user ~]$ aws ec2 describe-instance-types --instance-type instance_type --query "InstanceTypes[].Hypervisor"

nitro indicates that your instance in Nitro-based. xen or xen-on-nitro indicates that your instance is Xen-based.

 

To extend the file system of EBS volumes

  1. Connect to your instance.
  2. Resize the partition, if needed. To do so
    1. Check whether the volume has a partition. Use the lsblk command.

      Nitro Instance Example
      In the following example output, the root volume (nvme0n1) has two partitions (nvme0n1p1 and nvme0n1p128), while the additional volume (nvme1n1) has no partitions.
[ec2-user ~]$ sudo lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0   8G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

Xen Instance Example

In the following example output, the root volume (xvda) has a partition (xvda1), while the additional volume (xvdf) has no partition.

[ec2-user ~]$ sudo lsblk                
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  16G  0 disk
└─xvda1 202:1    0   8G  0 part /
xvdf    202:80   0  24G  0 disk

If the volume has a partition, continue the procedure from the following step (2b). If the volume has no partitions, skip steps 2b, 2c, and 2d, and continue the procedure from step 3.

 

이러한 부분에서 swap disk 를 생성해주려고 하는 경우에는 Instance 변경에 따라 문제가 생길 수 있기 때문에 option 으로 nvme 를 가져가게 된다

 

Troubleshooting tip

If you do not see the volume in the command output, ensure that the volume is attached to the instance, and that it is formatted and mounted.

 


Check whether the partition needs to be extended. In the lsblk command output from the previous step, compare the partition size and the volume size.

If the partition size is smaller than the volume size, continue to the next step. If the partition size is equal to the volume size, the partition can't be extended.

 

Troubleshooting tip

If the volume still reflects the original size, confirm that the volume modification succeeded.


Extend the partition. Use the growpart command and specify the partition to extend.

 

Nitro Instance Example

For example, to extend a partition named nvme0n1p1, use the following command.

[ec2-user ~]$ sudo growpart /dev/nvme0n1 1

 

Xen Instance Example

For example, to extend a partition named xvda1, use the following command.

 

Important

Note the space between the device name (xvda) and the partition number (1).

 

[ec2-user ~]$ sudo growpart /dev/xvda 1
Troubleshooting tips
  • mkdir: cannot create directory ‘/tmp/growpart.31171’: No space left on device FAILED: failed to make temp dir: Indicates that there is not enough free disk space on the volume for growpart to create the temporary directory it needs to perform the resize. Free up some disk space and then try again.
  • must supply partition-number: Indicates that you specified an incorrect partition. Use the lsblk command to confirm the partition name, and ensure that you enter a space between the device name and the partition number.
  • NOCHANGE: partition 1 is size 16773087. it cannot be grown: Indicates that the partition already extends the entire volume and can't be extended. Confirm that the volume modification succeeded.

 

Verify that the partition has been extended. Use the lsblk command. The partition size should now be equal to the volume size.

 

확장된 부분에 대한 확인사살을 하면 된다

 

Nitro 인스턴스의 경우에는 아래처럼 1부터 파티션 128까지 붙을 수 있다

[ec2-user ~]$ sudo lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0  16G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

 

아래의 경우는 Xen Instance 의 경우이다

[ec2-user ~]$ df -hT
Filesystem      Type   Size    Used   Avail   Use%   Mounted on
/dev/xvda1      ext4   8.0G    1.9G   6.2G    24%    /
/dev/xvdf1      xfs    24.0G   45M    8.0G    1%     /data
...

The commands to extend the file system differ depending on the file system type. Choose the following correct command based on the file system type that you noted in the previous step.

  • [XFS file system] Use the xfs_growfs command and specify the mount point of the file system that you noted in the previous step.

Nitro and Xen instance Example

[ec2-user ~]$ sudo xfs_growfs -d /
Troubleshooting tips
  • xfs_growfs: /data is not a mounted XFS filesystem: Indicates that you specified the incorrect mount point, or the file system is not XFS. To verify the mount point and file system type, use the df -hT command.
  • data size unchanged, skipping: Indicates that the file system already extends the entire volume. If the volume has no partitions, confirm that the volume modification succeeded. If the volume has partitions, ensure that the partition was extended as described in step 2.

[Ext4 file system] Use the resize2fs command and specify the name of the file system that you noted in the previous step.

 

Nitro instance example

For example, to extend a file system mounted named /dev/nvme0n1p1, use the following command.

[ec2-user ~]$ sudo resize2fs /dev/nvme0n1p1

Xen instance example

For example, to extend a file system mounted named /dev/xvda1, use the following command.

[ec2-user ~]$ sudo resize2fs /dev/xvda1
 
Troubleshooting tips
  • resize2fs: Bad magic number in super-block while trying to open /dev/xvda1: Indicates that the file system is not Ext4. To verify file the system type, use the df -hT command.
  • open: No such file or directory while opening /dev/xvdb1: Indicates that you specified an incorrect partition. To verify the partition, use the df -hT command.
  • The filesystem is already 3932160 blocks long. Nothing to do!: Indicates that the file system already extends the entire volume. If the volume has no partitions, confirm that the volume modification succeeded. If the volume has partitions, ensure that the partition was extended, as described in step 2.

[Other file system] See the documentation for your file system for instructions.

  1. Verify that the file system has been extended. Use the df -hT command and confirm that the file system size is equal to the volume size.

'Cloud > AMAZON' 카테고리의 다른 글

AWS CLI install and update instructions  (0) 2023.12.02
[AWS EC2] EC2 에서 Swap Volume 생성하기  (0) 2023.08.16
Make an AMI public  (0) 2023.08.12
[AWS CLI] modify-image-attribute  (0) 2023.08.12
[Trouble Shooting] Instance Check Failed issue  (0) 2023.08.08

+ Recent posts