`
winhyt
  • 浏览: 107308 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

虚拟机VMare扩容

阅读更多
参考文档(感谢如下文档的作者):
http://www.linuxidc.com/Linux/2010-12/30811.htm
http://hi.baidu.com/jackli00/blog/item/4f399bd2c64e2738970a16e2.html



   随着随着Linux虚拟机的不断使用,在VMware中经常遇到 预先装好的 linux 虚拟机的硬盘空间过小 的问题,造成很多软件不能安装, 而重新装一个,又挺麻烦。于是,上网搜了下关于 vmware 硬盘扩容的方法。 总结如下:
    1、创建完分区的挂载点必须是一个目录。
    2、一个分区挂载在一个已存在的目录上,这个目录可以不为空,但挂载后这个目录下以前的内容将不可用。
   
一、首先使用VMware工具进行扩容分配的硬盘空间
    1 、 vmware 提供一个命令行工具, vmware-vdiskmanager.exe ,位于 vmware 的安装目录下,比如:F:\VMware-workstation-5.5.1-19175。切记,该工具是命令行工具,需要在Windows中的dos窗口内操作,切换到vmware-vdiskmanager.exe 所在的目录下。执行    2、扩容命令是:
       F:\VMware-workstation-5.5.1-19175>vmware-vdiskmanager.exe 
        -x20Gb  "F:\ThreeLinuxOrcle9i\Red Hat Enterprise Linux 4.vmdk"
        Using log file
        C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\vmware-                     Administrator\vdiskmanager.log
    注: 要扩容的系统这时不能在运行 ,参数 "-x" 表示要扩展虚拟机硬盘空间,紧随其后的数字是要扩展到的大小 ( 本例为扩展到 20GB ,这是一个磁盘总量,包含了原先的磁盘容量 ) 。 最后是指定要操作的虚拟机磁盘的具体文件,要是路径名中有空格,必须以双引号括起来。按回车键开始执行,执行完毕,退出命令提示符窗口。重启 VMware ,会发现虚拟机硬盘空间已变成 20GB 了。
    我们重启虚拟机后,发现虚拟机的硬盘是变成 20GB 了,但进入 linux 系统后,用 "df -lh" 查看发现硬盘空间还是原先那么大。 虽然已经扩大了磁盘,但是由于还没有经过分区,指定文件系统,所以 linux 操作系统无法识别(其实就相当于你的硬盘虽然大了,但是你并没有对其进行分区是一个道理)。下面我们进行分区处理。

二、使用linux命令分区
    1、首先进入linux,通过命令fdisk -l 列出磁盘情况。
       [root@linuxoracle ~]# fdisk -l

       Disk /dev/sda: 21.4 GB, 21474836480 bytes
       255 heads, 63 sectors/track, 2610 cylinders
       Units = cylinders of 16065 * 512 = 8225280 bytes

       Device Boot      Start         End      Blocks   Id  System
       /dev/sda1   *           1        1044     8385898+  83  Linux
      /dev/sda2            1045        1305     2096482+  82  Linux swap
     其中 Disk /dev/sda: 21.4 GB, 21474836480 bytes
          255 heads, 63 sectors/track, 2610 cylinders
       说明了sda硬盘共21GB,2610个磁道, 如果你有多个硬盘,应该会有sdb, sdc等
可以看出 已经用了 1~1305磁道, 还有2610-1305=1305个磁道未用, 已经有10G已经分区,还有10G未分区。其中现有的10G被分为了2个区,  一个是 linux分区 一个是 linux swap(交换分区)。
    2、查看现有分区的磁盘使用情况以及挂载情况
       [root@linuxoracle ~]# df -h
       Filesystem            Size  Used Avail Use% Mounted on
       /dev/sda1             7.9G  7.3G  254M  97% /
       none                  506M     0  506M   0% /dev/shm
可以看到现有的10G分区已经基本上被使用玩。/dev/sda1分区是被挂载在了"/"根目录下, 还剩3%的剩余容量.
    3、把剩余的未使用的10G空间进行分区,并给其挂载到一个目录
        [root@linuxoracle ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
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): m --此处输入m命令Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p  --此处输入p命令 表示 选择创建主分区
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1044     8385898+  83  Linux
/dev/sda2            1045        1305     2096482+  82  Linux swap

Command (m for help): n  --此时输入n表示添加一个新的分区Command action
   e   extended
   p   primary partition (1-4)
primary partition   --需要输入全称:primary partition,直接输入 p 变成了打印的命令,切记Partition number (1-4): 3  --主分区(编号 1 到 4 ),逻辑分区 (编号从 5 开始)。输入数字后,一路回车,就把剩余的空间全部利用啦,
First cylinder (1306-2610, default 1306):
Using default value 1306
Last cylinder or +size or +sizeM or +sizeK (1306-2610, default 2610):
Using default value 2610

--等待出现下面的命令或者出现上面的提示,说明创建分区结束啦。
Command (m for help):
Command (m for help): p  --输入p命令
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1044     8385898+  83  Linux
/dev/sda2            1045        1305     2096482+  82  Linux swap
/dev/sda3            1306        2610    10482412+  83  Linux

--说明分区创建成功
--此时键入: w " 保存所有并退出,分区划分完毕 "
如下:
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.
Syncing disks.

注意,
1)这里虽然通过fdisk -l能看到新增的分区,但是要重启后才能写入分区表, 重启系统后,新的分区就能正常使用了

[root@linuxoracle ~]# reboot  --重新启动系统2)新的分区必须经过格式化之后才能挂载。
[root@linuxoracle ~]# mkfs.ext3 /dev/sda3 ,关于格式化的命令如果你需要其它的 
3)将分区挂接到一个已存在的不为空的目录上。但挂载后这个目录下以前的内容将不可用。
第一遍跟别人做的:
   我们想挂到/home下,所以先备份下/home, 再挂载,挂完后再copy回来。
   cd /
    mv /home /home2
  mkdir /home
   mount /dev/sda3 /home
  cp /home2/* /home/ --此处出错啦,不知道为啥 呵呵 不管啦 反正能用
4)查看结果, 查看各个分区的挂载目录以及分区的磁盘占用情况
   [root@linuxoracle home2]# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda1     ext3    7.9G  7.3G  254M  97% /
none         tmpfs    506M     0  506M   0% /dev/shm
/dev/sda3     ext3    9.9G   55M  9.3G   1% /home

成功啦。 真的成功了么? 当时我也是这么认为的,不过等我虚拟机系统重启之后,用df -Th命令查看,发现原来的挂载的分区不见啦,可是用 fdisk -l 命令查看,确实是存在的,这是怎么回事啊?
经过从晚上查询资料,发下系统确实已经扩容成功,并且成功挂载,只是系统在自动启动的时候,没有加载我们扩展的分区,需要手动将扩展的分区配置到系统加载文件里面去,废话不多说啦,看下面
    基本上所有Linux发行版在启动系统时都是根据/etc/fstab文件的配置来挂载分区的.关于/etc/fstab文件文件的描述的讲解,网上也有,有时间在整理。在此文件中我们需要将我们新增的分区,按照指定的格式,加入里面
    /dev/sda3                /home                   ext3    defaults        1 1
到此,通过命令查看,我们会看到分区已经挂载,reboot系统后,再次查看就会发现,系统也正常加载分区啦。
分享到:
评论
1 楼 DLFSEEIT 2014-04-30  
写得很详细 很多细节多注意到了 

相关推荐

Global site tag (gtag.js) - Google Analytics