【转载】VMware下LINUX的虚拟机增加磁盘空间


转载自:http://space.itpub.net/24435147/viewspace-694200

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

方法一:

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

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

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

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

  如果原来的虚拟机硬盘已被分成了多个分区,那么在通过 vmware-vdiskmanager.exe扩大了硬盘空间后,还需要在虚拟机系统中将增加的分区划分、格式化。

方法二:

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,假如选的是hdb。

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

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 来解除这个限制)。

优质内容筛选与推荐>>
1、转:PureMVC示例 CafeTownsend
2、APK签名导出向导
3、[Leetcode]237. Delete Node in a Linked List -David_Lin
4、java 相等, 比较, 条件操作符(翻译自Java Tutorials)
5、JNDI:对java:comp/env的研究


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号