作者:金良([email protected]) csdn博客:http://blog.csdn.net/u012176591
用了一段Linux虚拟机,发现安装虚拟机时分配的空间不够用,又不舍得删掉虚拟机重装,毕竟辛辛苦苦在上面装了好多软件,我可不想再为这些配置折腾一番。
怎么办呢,当然是虚拟机扩容。
1.虚拟机所在磁盘空间不够,可以把虚拟机拷贝到另一块磁盘里。
2.进入VMware的安装目录,在命令提示符后输入"vmware-vdiskmanager",什么参数也不加直接按回车键,可显示这一命令的说明。
3.这一步要关闭虚拟机才行:
扩容命令:C:\Program Files\VMware\VMware Workstation>vmware-vdiskmanager -x 40Gb "D:\Program Files\Virtual Machines\Ubuntu\Ubuntu.vmdk"
参数 "-x" 表示要扩展虚拟机硬盘空间,紧随其后的数字是要扩展到的大小 ( 扩展到 40GB ,包含了原先的磁盘容量 ) 。
重启 VMware ,会发现虚拟机硬盘空间已变成 40GB 了
4.执行命令 df -ah查看磁盘情况,发现磁盘空间和扩容前一样,仍是20G:
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))
系统重启后,在根目录下新建一个子目录(因为所有的目录都是挂载到根目录下的),然后把磁盘/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文件,开机自动挂载:
如图,红色方框是我们添加的