Llinux system (Centos/Ubuntu/Debian) elastic cloud system disk expansion method
Published: 2015-03-18
For windows system, please refer to: https://www.west.cn/faq/list.asp?unid=2220
For windows data disk expansion, please refer to:https://www.west.cn/faq/list.asp?unid=512
For linux data disk expansion, please refer to:https://www.west.cn/faq/list.asp?unid=587
Warning:
1. If you have adjusted the partition management method, such as lvm management, please ignore this tutorial.
2. The ubuntu18 system does not currently support script expansion. Please expand manually. Refer to the ubuntu18 section below and use parted.
Automatic script processing (recommended)
SSH login to the server and download the automatic execution script (Note: Do not execute in the BT Panel terminal):
wget -O auto_expansion.sh http://downinfo.myhostadmin.net/vps/auto_expansion.sh && bash auto_expansion.sh && rm -rf auto_expansion.sh
Manual processing method
Red is the command you need to type, green is the content to note, blue is the description
Special reminder: After deleting a partition, you must first create a partition and then save. Clicking save after deletion will cause data loss. If you are not familiar withlinux, it is recommended to submit a maintenance ticket and our company will handle it manually; the fee is 100yuan.This operation is risky. To avoid data loss caused by misoperation, please back up your important data before operation!
centos6 uses gdisk tool
Centos:
[root@ebs-89713 ~]yum -y install gdisk //install partitioning tool
[root@ebs-89713 ~]gdisk /dev/vda //operate on the root partition disk
Command (? for help): p //view partitions
Disk /dev/vda: 104857600 sectors, 50.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): B7172F0B-2C30-4535-981D-F0ED8B4A6065
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 104857566
Partitions will be aligned on 2048-sector boundaries
Total free space is 41945021 sectors (20.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 62914559 30.0 GiB 8300 Linux filesystem //note this value
Command (? for help): d //delete partition
Using 1
Command (? for help): 1
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-104857566, default = 2048) or {+-}size{KMGTP}: 2048 //the value just recorded
Last sector (2048-104857566, default = 104857566) or {+-}size{KMGTP}: //press Enter directly
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): //press Enter directly
Changed type of partition to 'Linux filesystem'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/vda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[root@ebs ~]#reboot //restart to make the partition take effect
[root@ebs ~]#resize2fs -f /dev/vda1 //start expanding the root partition; if it is centos8.x system, use this command: xfs_growfs /dev/vda1
resize2fs -f /dev/vda1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/vda1 to 13106939 (4k) blocks.
The filesystem on /dev/vda1 is now 13106939 blocks long.
[root@ebs ~]#df -vh //done, check the new root partition size
centos7,centos8 use fdisk tool
[root@ebs-89713 ~]# fdisk /dev/vda
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): p
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c1d0e
Device Boot Start End Blocks Id System
/dev/vda1 2048 83886079 41942016 83 Linux
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): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@ebs-89713 ~]# reboot //restart to make the partition take effect
After restart, log in to the server again
Execute on centos7 system:
[root@ebs-89713 ~]# resize2fs -f /dev/vda1 //start expanding the root partition
Execute on centos8 system:
[root@ebs-89713 ~]# xfs_growfs /dev/vda1 //start expanding the root partition
[root@ebs-89713 ~]# df -vh //done, check the new root partition size
Ubuntu16,Ubuntu20,debian8,debian9 use parted tool
[root@ebs-89713 ~] parted /dev/vda
(parted) unit b
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 107374182400B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start: End Size Type File system Flags
1 1048576B 32211206143B 32210157568B primary ext4 boot
(parted) rm 1 //delete partition 1, record the start of 1; delete partition 2, record the start of partition 2
Warning: Partition /dev/vda1 is being used. Are you sure you want to continue?
Yes/No? yes
Error: Partition(s) 1 on /dev/vda have been written, but we have been unable to inform the kernel of the change,
probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot
now before making further changes.
Ignore/Cancel? I
(parted) mkpart
Partition type? primary/extended? p
File system type? [ext2]?
Start? 1048576B //delete partition 1, record the start of 1; delete partition 2, record the start of partition 2
End? 100%
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 107374182400B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start: End Size Type File system Flags
1 1048576B 107374182399B 107373133824B primary ext4
(parted) quit
Information: You may need to update /etc/fstab.
[root@ebs-89713 ~]# reboot //restart to make the partition take effect
After restart, log in to the server again
[root@ebs-89713 ~]# resize2fs -f /dev/vda1 //start expanding the root partition
[root@ebs-89713 ~]# df -vh //done, check the new root partition size
ubuntu18 (the system disk has two partitions vda1,vda2) uses parted tool
root@ebs-89713:~# parted /dev/vda
GNU Parted 3.2
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit b
(parted) print
Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue
with the current setting?
Fix/Ignore? Fix
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 42949672960B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1048576B 2097151B 1048576B bios_grub
2 2097152B 32211206143B 32209108992B ext4
(parted) rm 2
Warning: Partition /dev/vda2 is being used. Are you sure you want to continue?
Yes/No? Yes
Error: Partition(s) 2 on /dev/vda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a
result, the old partition(s) will remain in use. You should reboot now before making further changes.
Ignore/Cancel? I
(parted) mkpart
Partition name? []? //press Enter directly
File system type? [ext2]? //press Enter directly
Start? 2097152B //the start position in number 2 above
End? 100%
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 42949672960B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1048576B 2097151B 1048576B bios_grub
2 2097152B 42948624383B 42946527232B ext2
(parted) quit
root@ebs-89713:~# reboot //restart to make the partition take effect
After restart, log in to the server again
root@ebs-89713:~# resize2fs -f /dev/vda2 //start expanding the root partition
root@ebs-89713:~# df -vh //done, check the new root partition size
