VirtualBox增大硬盘容量(guest为Linux)


如果virtualbox中的guest系统出现磁盘空间不足的情况,最方便的方法就是将已有硬盘变大。网上能找到不少guest为windows时的扩大硬盘容量的方法,但在guest为linux时又略有不同。其实方法不止一种,下面以virtualbox自带的调整工具为例进行说明。
 
 
 
第一步:
 
如guest系统的vdi为debian_work.vdi,原大小为10G,现在想要扩大到20G,则到virtualbox安装路径下运行:
 
vboxmanage modifyhd debian_work.vdi --resize 20000
 
注:
 
1. 只有当vdi创建时选的动态扩展才有效。
 
2. 参数resize后以M为单位,只能比原来的空间大。
 
3. 实际当中vdi可能会需要加路径。
 
这是官方文档上的一段说明:
 
"The --resize option allows you to expand the capacity of an existing image; this increases thelogical size of a virtual disk without affecting the physical size much.[32] This currently works only for the VDI and VHD formats, and only for the dynamically expanding variants. For example, if you originally created a 10G disk which is now full, you can use the --resize command to add more space to the virtual disk without having to create a new image and copy all data from within a virtual machine."
 
 
 
第二步:
 
如果第一步成功了的话会在virtualbox的管理界面里看到该vdi文件的虚拟大小为20G,但实际大小为10G不到。到guest系统(Linux)中执行
 
# fdisk -l
 
会发现/dev/sda中有一块空间是没有分配的,执行
 
# fdisk /dev/sda
 
进行分配,根据说明依次输入
 
n(新建), p(主分区), x(数字,代表/dev/sdax),起末位置一般默认即可,最后w保存退出。
 
 
 
第三步:
 
重启后看到新建分区(如/dev/sda3),然后将之挂载到某一目录(如/workspace)。先运行
 
#blkid
 
得到新建分区/dev/sda3的UUID,然后编辑/etc/fstab,加上
 
UUID=xxxxxx    /workspace   ext3   errors =remount-ro  0   1
 
当中实际的参数请根据需要填写。以后重启完了就可以通过/workspace访问新扩大的磁盘了。
 
 
 
摘自 金卓军的博客

相关内容

    暂无相关文章