Provides various official and user-released code examples and code reference. You are welcome to exchange and learn. As your business grows, your cloud disk capacity is insufficient. Therefore, we need to expand the capacity. Resizing is not as easy as adding cloud disks. To be formatted. I am taking a note here to facilitate future queries.
Before resizing
We recommend that you manually create a snapshot before resizing the disk to back up data.
If a snapshot is being created on the disk, resizing is not allowed.
Only resize the disk capacity, not the file system.
Supports expansion of general disks, but does not support expansion of local disks (local disks and local SSD disks.
A data disk attached to an instance can be resized only when the instance is Running or Stopped.
After resizing
After you use the ECS console or Open API to resize a disk, you must restart the instance on the ECS console or by using Open API.
After the expansion takes effect, you still need to manually format the extended storage space.
Procedure
This document uses Ubuntu 14.04 as an example to describe how to resize a disk. Operations on other Linux systems are similar.
In this instance, we select the initial disk size as 63 GB and resize it to 70 GB.
Log on to the ECS console.
Click instances in the left-side navigation pane. Select the region at the top of the page.
First, go to the disk list page and click More> resize disk. Note that this option is available only for data disks. To resize a system disk, you must replace the system disk.
On the resize page, enter the disk capacity after resizing and click resize.
You can also directly use OpenAPI for resizing:
ResizeDisk -- DiskId = d-94tomxanq -- NewSize = 70
Restart the server. Go to the instance list page, click more, and choose restart.
Or use OpenAPI to restart:
RebootInstance --InstanceId=i-94lw423m7
Log on to the ECS instance.
If the disk was previously mounted on the server, umount the disk first.
umount /mnt/dev1
Delete the original partition and create a new partition.
Some users use the parted tool to operate partitions, but parted and fdisk cannot be used in combination. Otherwise, the starting sector of the partition may be inconsistent. Therefore, when you delete the original partition and create a new partition, follow these steps:
1) Use fdisk-l to list the partition information and record the final Capacity and start sector position of the disk to be resized.
2) run the fdisk command and enter d to delete the original partition.
3) Input n, p, and 1 in sequence to create a partition.
4) When you select sector, in this example, press enter to select the default value. You can also choose as needed. To ensure data consistency, we recommend that the First sector be consistent with the previous partition.
The following is an example of using fdisk:
"
root@iZ94lw423m7Z:~# fdisk /dev/xvdb
Command (m for help): d
Selected partition 1
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-146800639, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-146800639, default 146800639):
Using default value 146800639
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
"
If we find that the location of the First sector is inconsistent with that recorded earlier, it means that we may have used parted for partitioning. Then we will stop the current fdisk operation and use parted to perform the operation again.
Run the parted command and enter p to list the current partition information. If yes, use rm + serial number to delete the old partition table, and use unit s to define the start position and unit to calculate the number of sectors, finally, use the mkpart command to create the file, as shown in.
9 format the disk.
When using e2fsck, because the system needs to check and correct the file system metadata, it is slow and time-consuming. Please wait patiently.
If you use the e2fsck and resize2fs commands correctly, the original data will not be lost.
"
e2fsck -f /dev/xvdb1
resize2fs /dev/xvdb1
"
10. Mount the resized disk to the original mount point.
"
mount /dev/xvdb1 /mnt/dev1
"
11 use the df-TH command to view the disk information.
"
df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvda1 ext4 22G 1.4G 19G 7% /
none tmpfs 4.1k 0 4.1k 0% /sys/fs/cgroup
udev devtmpfs 510M 4.1k 510M 1% /dev
tmpfs tmpfs 105M 381k 104M 1% /run
none tmpfs 5.3M 0 5.3M 0% /run/lock
none tmpfs 521M 0 521M 0% /run/shm
none tmpfs 105M 0 105M 0% /run/user
/dev/xvdb1 ext4 74G 55M 71G 1% /mnt/dev1
"
Conclusion: My first operation failed. Of course, the data will not be lost. Because formatting or operations as per the tutorial will not lose data. Of course, just in case, it is better to create a snapshot.
I 'd like to describe something that is more prone to errors. Fdisk/dev/xvdb. Note that there is no 1 in this step. Here, e2fsck-f/dev/xvdb1 resize2fs/dev/xvdb1 has 1. Otherwise it will be ineffective.
If you have any questions, leave a message or add my QQ164418960
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB