XenServer 虚拟机(centos7.2)扩容LVM磁盘分区的方法
说明:XenServer(6.2)里面安装的虚拟机(centos7),分区的时候采用的是LVM磁盘分区,文件系统格式为xfs
需求:现在需要扩容虚拟机根分区/
具体操作:
使用XenCenter增大虚拟机磁盘容量,如下图所示
增大当前磁盘到80GB
注意:必须在虚拟机关机状态下进行
[root@node03 ~]# df -h #硬盘容量还是没有增加 文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 28G 7.3G 21G 27% /devtmpfs 484M 0 484M 0% /devtmpfs 494M 0 494M 0% /dev/shmtmpfs 494M 6.6M 488M 2% /runtmpfs 494M 0 494M 0% /sys/fs/cgroup/dev/xvda1 497M 124M 373M 25% /boottmpfs 99M 0 99M 0% /run/user/0[root@node03 ~]# fdisk -l磁盘 /dev/xvda:85.9 GB, 85899345920 字节,167772160 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0x000747b6 设备 Boot Start End Blocks Id System/dev/xvda1 * 2048 1026047 512000 83 Linux/dev/xvda2 1026048 62914559 30944256 8e Linux LVM磁盘 /dev/mapper/centos-root:29.5 GB, 29490151424 字节,57597952 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节[root@node03 ~]# fdisk /dev/xvda 欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。命令(输入 m 获取帮助):p #查看当前分区磁盘 /dev/xvda:85.9 GB, 85899345920 字节,167772160 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0x000747b6 设备 Boot Start End Blocks Id System/dev/xvda1 * 2048 1026047 512000 83 Linux/dev/xvda2 1026048 62914559 30944256 8e Linux LVM命令(输入 m 获取帮助):n #创建新分区Partition type: p primary (2 primary, 0 extended, 2 free) e extendedSelect (default p): Using default response p分区号 (3,4,默认 3):起始 扇区 (62914560-167772159,默认为 62914560):将使用默认值 62914560Last 扇区, +扇区 or +size{K,M,G} (62914560-167772159,默认为 167772159):将使用默认值 167772159分区 3 已设置为 Linux 类型,大小设为 50 GiB命令(输入 m 获取帮助):t #改变分区类型分区号 (1-3,默认 3):Hex 代码(输入 L 列出所有代码):8e已将分区“Linux”的类型更改为“Linux LVM”命令(输入 m 获取帮助):p #重新查看分区磁盘 /dev/xvda:85.9 GB, 85899345920 字节,167772160 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0x000747b6 设备 Boot Start End Blocks Id System/dev/xvda1 * 2048 1026047 512000 83 Linux/dev/xvda2 1026048 62914559 30944256 8e Linux LVM/dev/xvda3 62914560 167772159 52428800 8e Linux LVM #已新增分区命令(输入 m 获取帮助):w #保存分区The partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)正在同步磁盘。[root@node03 ~]# reboot #重启 pvdisplay #查看已经存在的pv(物理卷) [root@node03 ~]# mkfs.xfs /dev/xvda3 #格式xvda3为xfs meta-data=/dev/xvda3 isize=256 agcount=4, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@node03 ~]# pvcreate /dev/xvda3 #创建一个新的LVM分区 WARNING: xfs signature detected on /dev/xvda3 at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/xvda3. Physical volume "/dev/xvda3" successfully created [root@node03 ~]# pvdisplay #查看LVM分区 --- Physical volume --- PV Name /dev/xvda2 VG Name centos PV Size 29.51 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 7554 Free PE 11 Allocated PE 7543 PV UUID HmuCM1-FxAF-H3B8-IhWE-Rv1l-aHGh-WuOt2x "/dev/xvda3" is a new physical volume of "50.00 GiB" --- NEW Physical volume --- PV Name /dev/xvda3 VG Name PV Size 50.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 22C1HW-lKKM-q586-IV3U-YEpB-GDHp-QWvkiG [root@node03 ~]# vgdisplay #查看当前已经存在的vg(逻辑卷组)为centos --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 29.51 GiB PE Size 4.00 MiB Total PE 7554 Alloc PE / Size 7543 / 29.46 GiB Free PE / Size 11 / 44.00 MiB VG UUID BVTF97-nxZW-XjpL-8ATa-cuAE-cLfk-RR467T [root@node03 ~]# lvdisplay #查看已经存在的lv(逻辑卷)/dev/centos/root --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID Z1jslP-JTGa-N3fc-f2XB-icIF-PqVS-kS5L6F LV Write Access read/write LV Creation host, time node03, 2017-02-08 10:36:40 +0800 LV Status available # open 2 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID 0EVGDC-Vwvw-TLqC-7iOC-DOQI-iPHf-N5E2Kz LV Write Access read/write LV Creation host, time node03, 2017-02-08 10:36:41 +0800 LV Status available # open 1 LV Size 27.46 GiB Current LE 7031 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@node03 ~]# vgextend centos /dev/xvda3 #把/dev/xvda3加入与/目录相同的vg(逻辑卷组)centos Volume group "centos" successfully extended [root@node03 ~]# lvextend -L +50GB -n /dev/centos/root #扩容lv(逻辑卷)root Size of logical volume centos/root changed from 27.46 GiB (7031 extents) to 77.46 GiB (19831 extents). Logical volume root successfully resized. [root@node03 ~]# xfs_growfs /dev/centos/root #/dev/centos/root生效 meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1799936 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=7199744, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=3515, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 7199744 to 20306944
注意:由于CentOS6和CentOS7在默认根文件系统的文件系统格式存在差异,需要判断是否为xfs,如果是xfs则应该使用xfs_growfs而不是一味的使用resize2fs。
使用resize2fs扩展ext2、ext3、ext4格式的文件系统,使用xfs_growfs扩展xfs格式的文件系统
转载于:https://blog.51cto.com/daisywei/1897487