加大VirtualBox Image大小的办法

转:https://blog.jyore.com/2013/06/virtualbox-increase-size-of-rhelfedoracentosscientificos-guest-file-system/

VirtualBox: Increase Size of RHEL/Fedora/CentOS/Scientific Guest File System

Tired of running out of space on your VM and running through complicated steps in order to get your VM resized?  This article provides the steps to take without you having to boot live CDs, clone VDI’s, or anything else complicated or time consuming.  We will simply leverage VirtualBox manager commands on our host and system commands on the guest.

E:\Oracle\VirtualBox>VBoxManage modifyhd "D:\VirtualBox VMs\development\development.vdi" --resize 20480
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

First, shutdown the VM you plan to work on.  Then we will run the manager tool. the

1
2
3
cd /path/to/vm
VBoxManage modifyhd vm.vdi --resize <size>
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

The <size> parameter should be the desired size to make your VDI, in MB.  For example, if you wish to resize your 10GB disk to 25GB, then you would use 25600 (1024*25). This should resize the VDI appropriately, however, if you boot up your VM, you will soon see that you are still at your original disk space.

1
2
3
cd /path/to/vm
VBoxManage modifyhd vm.vdi --resize 25600
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

If you open a partition tool, such as gparted, you can easily see that there is the extra available disk available, but it is set to unallocated.  If your guest OS is using LVM (this is all of the Red Hat flavors), then you cannot simply extend the volume as it will be locked.  Other volume managers may let you resize the partition.  Some may let you if you boot from a live CD.

With LVM we can actually make all these changes to the logical volume on a live file system.  It never hurts to backup your filesystem, or at least anything important, but it is not required.

The following steps will allow you to resize your partition.  In a terminal run the following commands in bold (you need root permissions to run fdisk):

  • df
    • Take note of the logical volume mapping (ex. /dev/mapper/fedora-root)
  • fdisk -l
    • Take note of the filesystem partition of your physical volume sits (ex. /dev/sda2)
  • fdisk /dev/sda
    • Run fdisk of this phyisical volume
  • d
    • Delete a partition
  • 2
    • Select your partition (we are using 2 from /dev/sda2)
  • n
    • Create a new partition
  • p
    • Make it a primary partition
  • 2
    • The partition number to make it on (same as we deleted)
  • <return>
    • Set the starting block (keep the default as it is usually correct)
  • <return>
    • Set the ending block (keep the default as it is fine for our use case)
  • w
    • Write the partition (will also exit fdisk shell)
  • reboot
    • We must reboot in order to have the new partition table loaded
  • pvresize /dev/sda2
    • Resizes the physical volume
  • pvscan
    • Use to verify the new size
  • lvextend -l +100%FREE /dev/mapper/fedora-root
    • Extend the logical volume to take all free space
  • resize2fs /dev/mapper/fedora-root
    • Resize the file system
  • df
    • See your newly sized volume

And that is it! With the last df command, you should see that your volume increased! In our example, let’s say you had 9GB of the 10GB disk and you resized it to 25GB.  In the first dfcommand, you would have seen 90% full.  After the resize, you should see the system as only 36% full, thus verifying the resize success!

The commands are reposted below for easier reference:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
df
fdisk -l
fdisk /dev/sda
d
2
n
p
2
< return >
< return >
w
reboot
pvresize /dev/sda2
pvscan
lvextend -l +100%FREE /dev/mapper/fedora-root
resize2fs /dev/mapper/fedora-root
df
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值