您的位置:首页 > 其它

加大VirtualBox Image大小的办法

2016-04-30 20:06 274 查看


转: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

Posted on June
17, 2013 by Joey
Yore — 20
Comments ↓

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

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.

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:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: