KVM:如何通过LVM调整访客VM磁盘的大小

在Debian主机nl-ams02c-kvm02上有CentOS访客虚拟机nl-ams02c-ispbgp02。

我调整了相应的LVM,如:

root@nl-ams02c-kvm02:~# lvextend -L +10000G /dev/raid50/nl-ams02c-ispbgp02 root@nl-ams02c-kvm02:~# lvdisplay /dev/mapper/raid50-nl--ams02c--ispbgp02 --- Logical volume --- LV Path /dev/raid50/nl-ams02c-ispbgp02 LV Name nl-ams02c-ispbgp02 VG Name raid50 LV UUID uzftwI-kf3a-R0jl-hZXq-vSP3-MDBt-o8iXTW LV Write Access read/write LV Creation host, time nl-ams02c-kvm02, 2015-07-30 16:12:48 +0200 LV Status available # open 1 LV Size 9.81 TiB Current LE 2572500 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:4 

现在磁盘正确显示了生效的上升

 root@nl-ams02c-kvm02:~# fdisk /dev/mapper/raid50-nl--ams02c--ispbgp02 -l Disk /dev/mapper/raid50-nl--ams02c--ispbgp02: 9.8 TiB, 10789847040000 bytes, 21073920000 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 524288 bytes Disklabel type: dos Disk identifier: 0x0009ede3 Device Boot Start End Sectors Size Id Type /dev/mapper/raid50-nl--ams02c--ispbgp02p1 * 2048 1026047 1024000 500M 83 Linux /dev/mapper/raid50-nl--ams02c--ispbgp02p2 1026048 102399999 101373952 48.3G 8e Linux LVM root@nl-ams02c-kvm02:~# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name raid50 PV Size 21.83 TiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 5723048 Free PE 3041700 Allocated PE 2681348 PV UUID j9Je9z-G1AN-JX7O-W03E-91l9-l80g-7Cys0V 

问题将是;

在客人nl-ams02-ispbgp02(xfs文件系统)

我如何调整它? 你能否就build议的步骤和方法提供build议?

我必须首先安装(?),然后用xfs_growfs(?)增长它

从客人的angular度来看,这是:

 [root@nl-ams02c-ispbgp02 ~]# partprobe [root@nl-ams02c-ispbgp02 ~]# fdisk -l Disk /dev/vda: 52.4 GB, 52428800000 bytes, 102400000 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: 0x0009ede3 Device Boot Start End Blocks Id System /dev/vda1 * 2048 1026047 512000 83 Linux /dev/vda2 1026048 102399999 50686976 8e Linux LVM Disk /dev/mapper/centos-root: 46.6 GB, 46615494656 bytes, 91045888 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 /dev/mapper/centos-swap: 5242 MB, 5242880000 bytes, 10240000 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 [root@nl-ams02c-ispbgp02 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 43.41g swap centos -wi-ao---- 4.88g [root@nl-ams02c-ispbgp02 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 44G 1.9G 42G 5% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 8.3M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/vda1 497M 204M 294M 41% /boot [root@nl-ams02c-ispbgp02 ~]# fdisk -l /dev/vda Disk /dev/vda: 52.4 GB, 52428800000 bytes, 102400000 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: 0x0009ede3 Device Boot Start End Blocks Id System /dev/vda1 * 2048 1026047 512000 83 Linux /dev/vda2 1026048 102399999 50686976 8e Linux LVM [root@nl-ams02c-ispbgp02 ~]# dmesg | egrep vda [ 1.280952] vda: vda1 vda2 [ 3.645818] XFS (vda1): Mounting V4 Filesystem [ 4.411333] XFS (vda1): Ending clean mount 

看起来你有一台主机将LV输出到guest虚拟机,然后再使用LVM为文件系统创build一个LV。

现在你已经有了一个大的虚拟磁盘,里面有一对较小的分区。 有两种select:增加形成访客PV的主分区的大小,或将新分区作为PV添加到访客VG。 就个人而言,我会和前者一起做,因为它更简洁,但是如果您是LVM的新手,那么稍后可能会更安全一些,大部分都可以在线完成:

  1. 或者:
    • 在客人: partprobe拿起新的大小。 使用fdisk进行validation。
    • 如果partprobe失败:重新启动guest,以便获取新的磁盘大小。
  2. login到客人
  3. 使用fdisk创build一个新的扩展分区。 接受build议的开始和结束。 types是:83。
  4. 在新部件上创build新的pv: pvcreate /dev/vda5 (用适当的磁盘和/或分区replace
  5. 向VG添加新的部分: vgextend centos /dev/vda5 (用实际的guest虚拟机名称replace<centos>
  6. 扩展你所需的FS的LV: lvextend -l +100%FREE /dev/centos/root
  7. 将你的FS增加到新的LV的大小: xfs_growfs /dev/centos/root (假设/或root)