Ubuntu 16.04虚拟机/ XenServer存储扩展问题

首先,我应该说我是服务器pipe理和虚拟化领域的新手。 在检查了几个关于它的教程之后,我尝试扩展在XenServer中创build的虚拟机的存储,并从另一个虚拟机获取快照。 首先,我通过XenCenterclosures了VM并将存储从40 GB扩展到了80 GB。 然后,我启动VM并inputfdisk:

sudo fdisk /dev/xvda 

然后我打印分区表:

 Device Boot Start End Sectors Size Id Type /dev/xvda1 2048 999423 997376 487M 83 Linux /dev/xvda2 1001470 83884031 82882562 39.5G 5 Extended /dev/xvda5 1001472 83884031 82882560 39.5G 8e Linux LVM 

在任何教程中我都没有看到类似的分区表。 这就是为什么我试图创build类似于这个表的新的分区表。 首先我删除5和2,然后我创build了一个新的扩展分区(2),我创build了一个Linuxtypes的分区(5)。 最后,我把5的types改成了Linux LVM。 最终分区表如下所示:

 Device Boot Start End Sectors Size Id Type /dev/xvda1 2048 999423 997376 487M 83 Linux /dev/xvda2 999424 167772159 166772736 79.5G 5 Extended /dev/xvda5 1001472 167772159 166770688 79.5G 8e Linux LVM 

检查表后,我写了表到磁盘并重新启动虚拟机。 虚拟机启动没有任何问题。 我用sudo df -h检查磁盘空间,这里是输出:

 Filesystem Size Used Avail Use% Mounted on udev 12G 0 12G 0% /dev tmpfs 2.4G 8.7M 2.4G 1% /run /dev/mapper/dbvmviduio--vg-root 35G 1.7G 32G 6% / tmpfs 12G 0 12G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 12G 0 12G 0% /sys/fs/cgroup /dev/xvda1 472M 101M 347M 23% /boot tmpfs 100K 0 100K 0% /run/lxcfs/controllers tmpfs 2.4G 0 2.4G 0% /run/user/1000 

毕竟,我试图像教程中所写的那样运行resize2fs 。 首先,我不知道在xvda2或xvda5上运行resize2fs,我尝试了他们两个,我得到了这些错误。

 sudo resize2fs /dev/xvda2 resize2fs 1.42.13 (17-May-2015) resize2fs: Attempt to read block from filesystem resulted in short read while trying to open /dev/xvda2 Couldn't find valid filesystem superblock. sudo resize2fs /dev/xvda5 resize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda5 Couldn't find valid filesystem superblock. 

分区表有什么问题吗? 我怎样才能克服这些问题?

注意:当我无法解决这些问题时,我尝试创build一个Linuxtypes的分区(没有扩展),重启后VM不启动。 (之后我恢复了快照)。

我不确定你所遵循的是什么步骤,但是下面的三件事情需要增加一个Linux VM可用的磁盘:

  • 在XenCenter中增加可用于VM的磁盘大小。
  • 增加VM分区表中VM分区的大小。
  • 增加虚拟机中ext3文件系统的大小

以下是给定示例中涉及的步骤。

第1步:增加XenCenter中的磁盘空间

你已经做到了。

步骤2:更改VM中的分区表

接下来,启动虚拟机,因为您需要使用fdisk来增加linux /分区的大小。 分开的实用程序应该允许您调整分区大小,并且更加智能化,并且还可以移动文件系统数据,但是分开后不允许您编辑正在运行的分区。 在这种情况下,因为我们想要编辑例如:/ dev / xvda3这是我们的/分区,它在虚拟磁盘的末尾,所以我只需要扩大分区的大小,而不是移动它。 在运行的VM上使用fdisk来增加/分区(/ dev / xvda3):

 # fdisk /dev/xvda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/xvda: 12.9 GB, 12884901888 bytes 255 heads, 63 sectors/track, 1566 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000928ad Device Boot Start End Blocks Id System /dev/xvda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/xvda2 26 281 2048000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/xvda3 281 1045 6134784 83 Linux Command (m for help): d Partition number (1-4): 3 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (281-1566, default 281): 281 Last cylinder, +cylinders or +size{K,M,G} (281-1566, default 1566): 1566 Command (m for help): p Disk /dev/xvda: 12.9 GB, 12884901888 bytes 255 heads, 63 sectors/track, 1566 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000928ad Device Boot Start End Blocks Id System /dev/xvda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/xvda2 26 281 2048000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/xvda3 281 1566 10325071 83 Linux 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. # 

第3步:重启虚拟机

现在最后的警告是准确的,您需要重新启动虚拟机,以便内核能够获取对分区几何体的更改。 但是,重新启动不会更改/分区的可用磁盘空间大小:

 # df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda3 5.8G 829M 4.7G 15% / tmpfs 497M 0 497M 0% /dev/shm /dev/xvda1 194M 45M 140M 25% /boot 

你可以通过在正在运行的虚拟机中运行resize2fs来解决这个问题,它会自动注意到分区几何和文件系统的大小之间的差异,并将文件系统扩展到最大尺寸:

 # resize2fs /dev/xvda3 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/xvda3 is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/xvda3 to 2581267 (4k) blocks. The filesystem on /dev/xvda3 is now 2581267 blocks long. # df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda3 9.7G 830M 8.4G 9% / tmpfs 497M 0 497M 0% /dev/shm /dev/xvda1 194M 45M 140M 25% /boot # 

特别感谢 http://www.simonhiggs.com/articles/xenserver-6.2-extending-disk-on-a-linux-vm.html

在启动resize2fs之前,您应该执行一些其他的操作…调整分区大小后,请执行以下步骤:

在resize的分区上调整物理卷大小:

 sudo lvm pvresize /dev/xvda3 

重新扫描您的卷组:

 sudo lvm vgscan 

激活虚拟组:

 sudo lvm vgchange -ay 

显示逻辑卷:

 sudo lvdisplay 

存储您的根卷的名称。 它应该是这样的:/ dev / vm-name-vg / root

将逻辑卷调整为所有额外的可用空间(不要忘记用上一个命令中的真实卷名replace“/ dev / vm-name-vg / root”):

 sudo lvm lvresize /dev/vm-name-vg/root -l +100%FREE 

那你可以做

 resize2fs /dev/xvda3 

它应该现在工作。

我无法让自己的方式工作,并find为什么我的方式不起作用,但我发现一个解决方法感谢这个video 。

  1. 我closures了虚拟机并增加了硬盘
  2. 然后启动VM并运行fdisk /dev/xvda
  3. 使用n (第4部分,/ dev / xvda4)创build新的Linux LVMtypes,具有可用空间的主分区
  4. 写了w并保存了新的分区表
  5. 重新启动虚拟机
  6. 重启后,用pvcreate /dev/xvda4创build新的分区
  7. vgdisplay看看我的VG名称是什么(这是dbvmviduio-vg)
  8. 通过运行vgextend dbvmviduio-vg /dev/xvda4扩展dbvmviduio-vg vgextend dbvmviduio-vg /dev/xvda4
  9. 通过运行lvextend -L+40G /dev/dbvmviduio-vg/root增加容量
  10. 最后,我运行了resize2fs /dev/dbvmviduio-vg/root并选中了df -h