本站文章总数为:165
Search Posts

linux云硬盘在线扩容分区,分配剩余空间到当前挂载目录(不丢失数据)

内容纲要
[root@s18vn-log ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  8.2G   11G  45% /
devtmpfs         32G     0   32G   0% /dev
tmpfs            32G     0   32G   0% /dev/shm
tmpfs            32G  8.6M   32G   1% /run
tmpfs            32G     0   32G   0% /sys/fs/cgroup
tmpfs           6.3G     0  6.3G   0% /run/user/997
/dev/vdb1        99G  1.8G   92G   2% /gldata1
tmpfs           6.3G     0  6.3G   0% /run/user/0
[root@s18vn-log ~]# fdisk -l

Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000cc280

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    41943039    20970496   83  Linux

Disk /dev/vdb: 1073.7 GB, 1073741824000 bytes, 2097152000 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: 0x48a6bfda

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209715199   104856576   83  Linux
[root@s18vn-log ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
vda    253:0    0   20G  0 disk 
└─vda1 253:1    0   20G  0 part /
vdb    253:16   0 1000G  0 disk 
└─vdb1 253:17   0  100G  0 part /gldata1
[root@s18vn-log ~]# cp -r /gldata1 /home/
[root@s18vn-log ~]# 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): p

Disk /dev/vdb: 1073.7 GB, 1073741824000 bytes, 2097152000 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: 0x48a6bfda

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209715199   104856576   83  Linux

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): p

Disk /dev/vdb: 1073.7 GB, 1073741824000 bytes, 2097152000 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: 0x48a6bfda

   Device Boot      Start         End      Blocks   Id  System

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): 
First sector (2048-2097151999, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151999, default 2097151999): 
Using default value 2097151999
Partition 1 of type Linux and of size 1000 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@s18vn-log ~]# partprobe /dev/vdb
[root@s18vn-log ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
vda    253:0    0   20G  0 disk 
└─vda1 253:1    0   20G  0 part /
vdb    253:16   0 1000G  0 disk 
└─vdb1 253:17   0 1000G  0 part /gldata1
[root@s18vn-log ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vdb1 is mounted on /gldata1; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 125
The filesystem on /dev/vdb1 is now 262143744 blocks long.

环境:centos 7.9  x64 原分区格式ext4

原来的云硬盘从100G扩容到1T,所以剩下的900G,想扩容到挂载的目录/gldata1

1 lsblk 查看总容量

2   fdisk  /dev/vdb 删除旧分区重新分区

d n 默认1 默认起始  默认结束  w写入

3 刷新分区表 partprobe /dev/vdb

4  扩容文件系统  resize2fs /dev/vdb1  (ext4文件系统使用此命令)

如果是xfs系统使用 xfs_groups /dev/vdb1扩容

 

参考原文:http://t.zoukankan.com/LincentLliang-p-13098834.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注