Home >Operation and Maintenance >Linux Operation and Maintenance >How to expand a data disk and make the expanded capacity available

How to expand a data disk and make the expanded capacity available

坏嘻嘻
坏嘻嘻Original
2018-09-18 10:49:552648browse

Based on the introduction, this article focuses on how to expand the data disk and make the expanded capacity available, focusing on the specific operation steps.

Expand data disk_Linux

As your business grows, your data disk capacity may not be able to meet the needs of data storage. In this case, you can use the disk expansion function to expand the data disk.

Note

The data disk mounted on the instance can only be expanded when the instance is in the Running or Stopped state. Expanding this type of data disk requires restarting the instance on the console for the expanded capacity to take effect. Restarting the instance will stop the instance and interrupt your business, so please operate with caution.

It is recommended to manually create a snapshot to back up the data before expanding the data disk.

Regardless of whether the status of the data disk is pending mounting or in use, the disk expansion operation can be performed.

If a subscription instance has been renewed and downgraded, the subscription cloud disk on the instance does not support disk expansion operations during the remaining period of the current billing cycle.

If the data disk is creating a snapshot, the operation of expanding the data disk is not allowed.

The disk expansion function can only expand the data disk, but cannot expand the system disk or local disk (local SSD disk, etc.).

This article takes an efficient cloud disk data disk and an ECS instance running CentOS 7.3 64-bit as an example to explain how to expand the data disk and make the expanded capacity available.

You can complete the expansion operation by following the following steps:

Step 1. Expand the disk space of the data disk on the console

Step 2. Log in to the instance to expand the file system

Step 1. Expand the disk space of the data disk on the console

Follow the following steps to expand the disk space of the data disk on the console:

Log in to the ECS management console.

In the left navigation bar, select Storage > Cloud Disk.

Description

If the data disk you need to expand has been mounted on an instance, you can click the instance, find the corresponding instance, enter the instance details page, and click this instance disk.

Select a region.

Find the disk that needs to be expanded, and in the Operation column, select More > Disk expansion.

On the Disk Expansion page, set the expanded capacity, which is 30 GiB in this example. The capacity after expansion can only be larger than the current capacity.

After the cost information is displayed on the page, click to confirm the expansion.

Description

After the expansion is successful, the expanded capacity will be displayed in the disk list. However, if your data disk has been mounted to the instance, you can only see the new disk space capacity after logging in to the instance after restarting the instance on the console.

After expanding the disk space of the data disk on the console,

If the data disk has been mounted to the instance, you must perform Step 2. Log in to the instance to expand the file system.

If the data disk is not mounted to the instance, you must first mount the data disk (see Mounting a Cloud Disk), and then perform different operations based on the actual situation of the data disk:

If This is an unformatted data disk. You must format the data disk. For details, see Formatting and Mounting Data Disks in Linux.

If this data disk has been formatted and partitioned before, you must step 2. Log in to the instance to expand the file system.

Step 2. Log in to the instance to expand the file system

After completing the disk expansion on the ECS console, the file system of each partition of the disk will be Not expanded. You need to log in to the instance to expand the file system.

In this example, it is assumed that the data disk is mounted on a Linux instance. The operating system of the instance is CentOS 7.3 64-bit. The data disk before expansion has only one primary partition (/dev/vdb1, ext4 file system), the mount point of the file system is /resizetest. After the file system expansion is completed, the data disk still has only one primary partition.

Use username and password authentication to connect to the Linux instance.

Run the umount command to unmount the primary partition.

umount /dev/vdb1

Description

Use df -h to check whether the uninstallation is successful. If you cannot see the information of /dev/vdb1, it means the uninstallation is successful. The following is a sample output.

[root@iXXXXXX ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.5G 36G 4% /
devtmpfs 487M 0 487M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 312K 496M 1% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/0

Use the fdisk command to delete the original partition and create a new partition:

Note

If you use the parted tool to operate the partition, it cannot be used cross-functionally with fdisk, otherwise it will cause partitioning The starting sectors are inconsistent. Instructions for using the parted tool can be found here.

Run the command fdisk -l to list the partition information and record the final capacity and first sector position of the data disk before expansion.

Run the command fdisk [data disk device name] to enter the fdisk interface. In this example, the command is fdisk /dev/vdb.

Enter d and press Enter to delete the original partition.

Note

Deleting a partition will not cause data loss in the data disk.

Enter n and press Enter to start creating a new partition.

输入 p 并按回车键,选择创建主分区。因为创建的是一个单分区数据盘,所以只需要创建主分区。

说明

如果要创建4个以上的分区,您应该创建至少一个扩展分区,即选择 e。

输入分区编号并按回车键。因为这里仅创建一个分区,所以输入 1。

输入第一个可用的扇区编号:为了保证数据的一致性,First sector需要与原来的分区保持一致。在本示例中,按回车键采用默认值。

说明

如果发现First sector显示的位置和之前记录的不一致,说明之前可能使用 parted 来分区,那么就停止当前的 fdisk 操作,使用 parted 重新操作。

输入最后一个扇区编号:因为这里仅创建一个分区,所以按回车键采用默认值。

输入 wq 并按回车键,开始分区。

[root@iXXXXXX ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-62914559, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Using default value 62914559
Partition 1 of type Linux and of size 30 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

说明

如果您使用的是 parted 工具,进入 parted 界面后,输入 p 罗列当前的分区情况。如果有分区,则使用 rm+ 序列号来删除老的分区表,然后使用 unit s 定义起始位置,单位使用扇区个数计量,最后使用 mkpart 命令来创建即可,如下图所示。

How to expand a data disk and make the expanded capacity available

部分操作系统里,修改分区后可能会重新自动挂载文件系统。建议先执行 df -h 重新查看文件系统空间和使用情况。如果文件系统重新被挂载,执行 umount [文件系统名称] 再次卸载文件系统。

检查文件系统,并变更文件系统大小。

e2fsck -f /dev/vdb1 # 检查文件系统
resize2fs /dev/vdb1 # 变更文件系统大小

说明

使用 e2fsck 时,由于系统需要检查并订正文件系统元数据,所以速度较慢、耗时较长,请耐心等待。

正确使用 e2fsck 和 resize2fs 指令,不会造成原有数据丢失。

以下为示例输出结果。

[root@iXXXXXX ~]# e2fsck -f /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 11/1835008 files (0.0% non-contiguous), 159218/7339776 blocks
[root@iXXXXXX ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 7864064 (4k) blocks.
The filesystem on /dev/vdb1 is now 7864064 blocks long.

将扩容完成的文件系统挂载到原来的挂载点(如本示例中的 /resizetest)。

mount /dev/vdb1 /resizetest

查看文件系统空间和使用情况:运行命令 df -h。如果出现扩容后的文件系统信息,说明挂载成功,可以使用扩容后的文件系统了。

说明

挂载操作完成后,不需要在控制台上重启实例即可开始使用扩容后的文件系统。

以下为示例输出结果。

[root@iXXXXXX ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.5G 36G 4% /
devtmpfs 487M 0 487M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 312K 496M 1% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/0
/dev/vdb1 30G 44M 28G 1% /resizetest

The above is the detailed content of How to expand a data disk and make the expanded capacity available. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn