VMware下LINUX的虚拟机增长磁盘空间

VMware6.7安装目录下有一个命令行工具vmware-vdiskmanager.exe 程序,可用来修改虚拟机硬盘的大小。方法以下:node

方法一:linux

  1. 关闭虚拟机;启动Windows下的命令提示符界面;app

  2. 命令进入VMware的安装目录(如:D:\VMware),输入“vmware-vdiskmanager”后按回车键,可显示关于该命令的说明。ide

  3. 执行以下命令:vmware-vdiskmanager -x 15Gb "G:\VMware Space\Red Hat Enterprise Linux 5.vmdk"参数-x表示要扩展虚拟机硬盘空间;紧随其后的数字指要扩展的大小(如15Gb,表示磁盘总量,包含原来的磁盘容量);最后是要操做的虚拟机Linux的具体文件。若路径名中有空格,必须以双引号括起来。工具

  等待约10分钟,执行完毕,退出命令提示符窗口,重启VMware,这时虚拟机硬盘空间已变成15GB了。这个过程当中,已安装的Linux系统不会被破坏。this

  若是原来的虚拟机硬盘已被分红了多个分区,那么在经过 vmware-vdiskmanager.exe扩大了硬盘空间后,还须要在虚拟机系统中将增长的分区划分、格式化。spa

方法二:先关闭虚拟机电源,作以下设置:“ 虚拟机”--“虚拟机设置”--“应用实例”--“增长磁盘空间”,能够随意添加你须要增到到的磁盘大小(如15Gb,表示磁盘总量,包含原来的磁盘容量); 再重启电源进入系统作以下步骤设置。.net

4. 启动虚拟机系统,用root登陆(后续全部步骤都应以root用户身份登陆操做),在 命令行用fdisk -l查看。因为这里是直接修改了原始空间大小,所以能够看到/dev/sda空间改变为16.1GB(原磁盘空间从10G增长到15G)。若是是从VMware菜单里增长虚拟硬盘,则会多出一个/dev/sd?,这里的?表明硬盘编号,第一个硬盘编号为a即sda,第二个就是sdb,第三个是sdc,以此类推,通常来讲,若是之前没有增长过硬盘,那么原来的硬盘就是sda,经过VMware菜单增长的虚拟硬盘编号就是sdb。若是添加的第二块硬盘是IDE硬盘,就应该看到hdb,若是是 SCSI硬盘,看到的就应该是sdb。命令行

5. 使用fdisk /dev/sda进入菜单项,m是列出菜单,p是列出分区表,n是增长分区,w是保存并推出。因为这里增长的磁盘只有5G,所以5G划为一个区。
[root@localhost ~]# 
fdisk -lorm

Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1305    10377990   8e  Linux LVM

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

The number of cylinders for this disk is set to 1958.
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/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1305    10377990   8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1306-1958, default 1306): +1306
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): +1958
Value out of range.
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): 
Using default value 1958

Command (m for help): p

Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1305    10377990   8e  Linux LVM
/dev/sda3            1306        1958     5245222+  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: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
/dev/sda3            1306        1958     5245222+  83  Linux

[root@localhost ~]# reboot                              #需reboot一下机器继续以下步骤

[root@localhost ~]# df -h                                                                #挂载前的分区状况
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                      8.6G  2.8G  5.4G  35% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm

6.  使用mkfs.ext3 /dev/sda3    格式化分区

[root@localhost ~]# mkfs.ext3 /dev/sda3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
656000 inodes, 1311305 blocks
65565 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1346371584
41 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@localhost ~]# cd /
[root@localhost /]# 
mkdir /cm                       #增长一个/cm

[root@localhost /]# mount /dev/sda3 /cm           #挂载分区到   /cm         
[root@localhost /]# df -h                                     #挂载后的分区状况
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                      8.6G  2.8G  5.4G  35% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/sda3             5.0G  139M  4.6G   3% /cm

7.设置开机自动加载     

建立加载点:mkdir /cm 挂载以后,      修改vi /etc/fstab  分区表文件,

在文件最后加上      /dev/sda3  /cm   ext3    defaults    0 0     而后保存,重启便可。  

(注意:修改分区表若是有误,将致使进不了linux桌面系统,但这时系统会进入commandline模式,咱们能够在commandline模式下对有误的fstab进行修复更改,不过默认状况下这个commandline模式会是Read-Only file system,这意味着你的任何修改操做都是不容许的,但能够经过命令 mount / -o remount,rw  来解除这个限制)。

相关文章
相关标签/搜索