在我的 CentOS 7 服务器中,有一个磁盘和一个分区(sda、sda1)。现在它已满,我要求服务器提供商添加新磁盘(sdb),然后我创建了一个 LVM 类型的分区 sdb1。如何合并 sda1 和 sdb1 而不丢失数据或启动损坏?
fdisk -l 输出:
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000ab236
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 83886079 41942016 83 Linux
Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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: 0x09a86f50
Device Boot Start End Blocks Id System
/dev/sdb1 2048 62914559 31456256 8e Linux LVM
df-h输出:
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 188M 1.7G 10% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 40G 40G 623M 99% /
tmpfs 381M 0 381M 0% /run/user/54321
tmpfs 381M 0 381M 0% /run/user/0
答案1
您可以使用vgextend
扩展卷组并lvextend
扩展现有的逻辑卷。假设 sdb1 已创建为 LWM:
# pvcreate <<newly created partition>>, or in our case
pvcreate /dev/sdb1
# Listing of curent volume group.
# We will use later VG Name - so remember it somewhere (or copy-paste)
vgdisplay
# vgextend <<VG Name>> <<newly created partition>>, or in our case
vgextend cl_centos7 /dev/sdb1
# Scanning for psychical volumes (please notice our with 120GB)
pvscan
# Listing of logical volumes.
# We want to extend this with name root and important info for us is LV path
lvdisplay
# Logical volume extending
# lvextend <<LV path>> <<newly created partition>>, or in our case
lvextend /dev/cl_centos7/root /dev/sdb1
# Logical volume extending for free space which we added by new disk
# resize2fs <<LV path>>, or in our case
resize2fs /dev/cl_centos7/root
或者,您可以使用最后 2 个命令来将现有的 ДМ 路径扩展至磁盘空间的 100%:
# lvextend -l +100%FREE /dev/cl_centos7/root