虚拟机下扩展磁盘空间

    技术2025-02-11  45

    把现有硬盘的容量增加,本来是4G的硬盘扩充到8G,32G。。。。,其命令为:vmware-vdiskmanager.exe -x size mydisk.vmdk//示例如下:主系统Windows XP SP3,假设vmware虚拟机Ubuntu8.04安装在E分区,运行cmdD:/>cd "Program Files"D:/Program Files>cd VMwareD:/Program Files/VMware>cd "VMware Workstation"D:/Program Files/VMware/VMware Workstation>vmware-vdiskmanager -x 10Gb "E:/Ubuntu 8.04/Ubuntu 8.04.vmdk"  Grow: 100% done.Disk expansion completed successfully.WARNING: If the virtual disk is partitioned, you must use a third-party         utility in the virtual machine to expand the size of the         partitions. For more information, see:         http://www.vmware.com/support/kb/enduser/std_adp.php?p_faqid=1647需要强调的一点是,调整硬盘大小之后的效果,相当于增加了原来物理硬盘的柱面数目,因此,文件系统并不会自动增长。需要重新调整文件系统的大小。这一步不同的系统有不同的方法。比如1. 如果guest  OS为win系列,可以通过partion magic来实现2. 如果guest  OS为Linux系列,可以通过resize2fs来扩大ext2/3格式的文件系统。一般来说主要有两个工具,resize2fs和parted。不过使用resize2fs /dev/sda1 10GB的时候,会显示请求的size过大,因为之前扩大的硬盘容量并没有添加任何的文件系统,可以说是没有格式化吧。使用parted提示需要将sda1 卸载了才能操作。后来选择了用fdisk的笨办法来扩容,详解见下。3. 如果guset OS为其他Unix系统,可以通过向文件树中新增加分区,来扩充原文件系统。启动虚拟机系统,用root登录(后续所有步骤都应以root用户身份登录操作),在命令行用fdisk -l查看。由于这里是直接修改了原始空间大小,因此可以看到/dev/sda空间改变为10.7 GB。

    # fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x000b2cce   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1         922     7405933+  83  Linux/dev/sda2             923        1044      979965   82  Linux swap / Solaris# fdisk /dev/sda  //然后依次选择m,p,n,e,3,p,n,l,p,w

    以下是我执行的过程

    [root@localhost ~]# fdisk /dev/hda4

    The number of cylinders for this disk is set to 3916.There is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs(e.g., DOS FDISK, OS/2 FDISK)

    Command (m for help): p

    Disk /dev/hda4: 32.2 GB, 32212254720 bytes255 heads, 63 sectors/track, 3916 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x000bc363

    Device Boot Start End Blocks Id System/dev/hda1 * 1 25 200781 83 Linux/dev/hda2 26 1958 15526822+ 8e Linux LVM/dev/hda3 1959 2610 5237190 8e Linux LVM

    Command (m for help): nCommand actione extendedp primary partition (1-4)pSelected partition 4First cylinder (2611-3916, default 2611): Using default value 2611Last cylinder or +size or +sizeM or +sizeK (2611-3916, default 3916): Using default value 3916

    Command (m for help): tPartition number (1-4): 4Hex code (type L to list codes): 8eChanged system type of partition 4 to 8e (Linux LVM)

    Command (m for help): p

    Disk /dev/hda: 32.2 GB, 32212254720 bytes255 heads, 63 sectors/track, 3916 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x000bc363

    Device Boot Start End Blocks Id System/dev/hda1 * 1 25 200781 83 Linux/dev/hda2 26 1958 15526822+ 8e Linux LVM/dev/hda3 1959 2610 5237190 8e Linux LVM/dev/hda4 2611 3916 10490445 8e Linux LVM

    Command (m for help): wThe 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.Syncing disks.

    (注:建议重启一下CentOS系统)

    # mkfs.ext3 /dev/sda5# mkdir -p /data# cp /etc/fstab /etc/fstab.bak修改文件/etc/fstab,挂载/dev/sda5到/data下/dev/sda5            /data            ext3       defaults              1 1# reboot //重启# df -h

     

     

    系统磁盘空间大小更改成功

     

    最新回复(0)