VMware虛擬機擴容

做者:金良(golden1314521@gmail.com) csdn博客:http://blog.csdn.net/u012176591node

用了一段Linux虛擬機,發現安裝虛擬機時分配的空間不夠用,又不捨得刪掉虛擬機重裝,畢竟辛辛苦苦在上面裝了好多軟件,我可不想再爲這些配置折騰一番。android

怎麼辦呢,固然是虛擬機擴容面試

1.虛擬機所在磁盤空間不夠,可以把虛擬機複製到還有一塊磁盤裏。ubuntu

2.進入VMware的安裝文件夾,在命令提示符後輸入"vmware-vdiskmanager",什麼參數也不加直接按回車鍵,可顯示這一命令的說明。
ide

3.這一步要關閉虛擬機才行:ui

擴容命令:C:\Program Files\VMware\VMware Workstation>vmware-vdiskmanager -x 40Gb "D:\Program Files\Virtual Machines\Ubuntu\Ubuntu.vmdk"
this

參數 "-x" 表示要擴展虛擬機硬盤空間,緊隨其後的數字是要擴展到的大小 ( 擴展到 40GB ,包括了原先的磁盤容量 ) 。 spa


 從新啓動 VMware ,會發現虛擬機硬盤空間已變成 40GB 了.net


4.運行命令 df -ah查看磁盤狀況,發現磁盤空間和擴容前同樣,還是20G:code


5.查看分區,運行命令:

fdisk -l
如下是當前的磁盤分區表截圖,這時咱們可以看到磁盤的總量的確添加�到 40GB 了,但是分區僅僅有曾經的那幾個原有的分區。

添加�分區過程截圖:


從新啓動後格式化該分區:


發現一個問題,我命名擴增了20G,爲何新增的分區容量這麼小,以致於格式化時提示「Filesystem too small for a journal」

再看虛擬機配置,截圖:


圖上顯示的是:眼下此虛擬硬盤的大小(current size)是19.8G,最大是(maximum size)40G。但是怎麼得到這個最大磁盤容量呢?


而後我用了還有一種方法擴容:

與以前的思路不一樣,本方法不是擴大原來的虛擬磁盤的容量,而是另加一個虛擬磁盤來擴充容量。

第一步、退出Linux虛擬機系統,經過在VMware上對虛擬機進行設置來添加�一塊虛擬硬盤。

附截圖:






第二步、從新啓動Linux虛擬機,對這塊虛擬硬盤進行分區、格式化和掛載。

看下磁盤分區狀況:

root@ubuntu:/home/now/android4.0.1# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e4e09

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    39845887    19921920   83  Linux
/dev/sda2        39847934    41940991     1046529    5  Extended
/dev/sda5        39847936    41940991     1046528   82  Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

這裏可以看到/dev/sdb 就是咱們新加入�的硬盤,咱們需要給新的硬盤分區。

步驟例如如下(看提示):

root@ubuntu:/home/now/android4.0.1# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9d6a9772.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): 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): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9d6a9772

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

再看磁盤分區,已達到咱們想要的結果:

root@ubuntu:/home/now/android4.0.1# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e4e09

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    39845887    19921920   83  Linux
/dev/sda2        39847934    41940991     1046529    5  Extended
/dev/sda5        39847936    41940991     1046528   82  Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
213 heads, 34 sectors/track, 5791 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9d6a9772

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   83  Linux

咱們把新加的磁盤/dev/sdb1 掛載到根分區

root@ubuntu:/home/now# mount /dev/sdb1 /
mount: you must specify the filesystem type

系統提示需要明白的文件類型,即咱們需要對其進行格式化。

如下是格式化操做:

root@ubuntu:/home/now# mkfs -t ext3 /dev/sdb1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   
而後掛載,成功:

root@ubuntu:/home/now# mount /dev/sdb1 /
root@ubuntu:/home/now# 

查看掛載狀況,可以看到/dev/sdb1掛載到了根分區:

root@ubuntu:/home/now# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       19478204 16257028   2208696  89% /
udev              503544        4    503540   1% /dev
tmpfs             102472     1108    101364   2% /run
none                5120        0      5120   0% /run/lock
none              512352      152    512200   1% /run/shm
/dev/sdb1       19478204 16257028   2208696  89% /

可以看到這不是咱們想要的結果,這是因爲「掛載點」必須是一個已經存在的文件夾,這個文件夾可以不爲空,但掛載後這個文件夾下曾經的內容將不可用,只是umount之後會恢復正常。

使用卸載命令,發現不能卸載:

root@ubuntu:/# umount /dev/sdb1
umount: /: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

好在使用mount掛載系統的一個特色是一旦系統從新啓動以後就失效,需要又一次掛載。因此咱們從新啓動就能卸載掉磁盤/dev/sdb1了。

系統從新啓動後,在根文件夾下新建一個子文件夾(因爲所有的文件夾都是掛載到根文件夾下的),而後把磁盤/dev/sdb1掛載在此文件夾下:

root@ubuntu:/home/now# cd /
root@ubuntu:/# mkdir /storehouse
root@ubuntu:/# mount /dev/sdb1 /storehouse

查看存儲空間利用狀況:

root@ubuntu:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        19G   16G  2.2G  88% /
udev            492M  4.0K  492M   1% /dev
tmpfs           101M  956K  100M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            501M  152K  501M   1% /run/shm
/dev/sdb1        20G  173M   19G   1% /storehouse

看到了吧,最後一行就是咱們掛載的文件夾。

使用下面試試,往裏面拷貝一個壓縮文件:

root@ubuntu:/# cp  /home/now/android4.0.1.tar.gz  /storehouse
root@ubuntu:/# ls /storehouse/
android4.0.1.tar.gz  lost+found

而後查看存儲空間利用狀況:

root@ubuntu:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        19G   16G  2.2G  88% /
udev            492M  4.0K  492M   1% /dev
tmpfs           101M  968K  100M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            501M  152K  501M   1% /run/shm
/dev/sdb1        20G  1.9G   17G  11% /storehouse

能夠看到能夠正常使用。

改動/etc/fstab文件,開機本身主動掛載:

如圖,紅色方框是咱們加入�的

相關文章
相關標籤/搜索