VBOX修改vhd/vdi存储空间大小

进入命令行,以Windows系统为例

(特别注意空格和中文)

1.启动CMD命令行,进入VirtualBox的安装目录。如

运行:cmd

C:\Users\Administrator\>D:

D:\> cd  "\Program Files\Oracle\VirtualBox"

D:\Program Files\Oracle\VirtualBox> VBoxManage.exe modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

D:\Program Files\Oracle\VirtualBox>

其中参数 YOUR_HARD_DISK.vdi 是您要修改的 VirtualBox 虚拟硬盘镜像文件。而参数 SIZE_IN_MB 是指修改后的硬盘容量,单位是MB。 

3. 调整磁盘空间为15G:

比如下面这行命令将会把名为" ubuntu.vdi "的  VirtualBox  硬盘容量修改为15*1024MB。

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "E:\dds\VirtualBox VMs\linux\linux-bak.vdi" --resize 15360

 

0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%.

 

D:\Program Files\VirtualBox >

 

 

注意:如果路径中包含空格或中文,整个路径要用英文状态引号"括起来,在WIN7的CMD下可以输入部分路径然后按TAB键补全,CMD监测到路径中有空格会自动为路径名加引号的,如:

D:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "F:\VirtualBox\my ubuntu.vdi"--resize 15360

D:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "F:\虚拟机\my ubuntu.vdi"--resize 15360

 

另,VBOX好像对MS的文件系统,比如NTFS的可能无法更改大小,一网友测试没成功,相对来说对Linux系的支持更好一些

 

 

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "E:\dds\VirtualBox VMs\linux-bak\linux-bak.vdi" --resize 20480

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

 

C:\Program Files\Oracle\VirtualBox>cd E:\dds\VirtualBox VMs

 

4.查看新的磁盘空间

  重新启动虚拟机,查看磁盘情况。

  [root@aimin ~]# fdisk -l /dev/sda

  Disk /dev/sda: 15.7 GB, 15728640000 bytes 255 heads, 63 sectors/track, 1912 cylinders

  可以看到磁盘空间已经扩展到15G,但这时还不可以使用。

  5.Enable新增加的空间

  使用 fdisk 将虚拟磁盘的空闲空间创建为一个新的分区。注意要使用代表 Linux LVM 的分区号 8e 来作为 ID。

  # fdisk /dev/sda     ---用root用户操作

  n {new partition}   

  p {primary partition}

  3 {partition number}

[这时会提示修改大小,选择默认直接回车即可]

   ---  此时再一次 fdisk /dev/sda

  t {change partition id}   ---这个的目的是将ID 修改成8e的类型,即LVM

  3 {partition number}  

  8e {Linux LVM partition}

  w

  ------

  如果中间有设置大小之类的提示,就直接回车。

  完成后,如果提示:

  WARNING: Re-reading the partition table failed with error 16:设备或资源忙。 The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)

  就重启一下系统。

  6.查看新增加的sda3是否标记为LVM,如果没有需要reboot

  #fdisk -l /dev/sda

 

7.调整LVM大小

  先看一下Volume Group名称

  [root@aimin ~]# vgdisplay --- Volume group --- VG Name vg_dds

  vg_dds是我的VolumeGroup的名称,实际操作时,需要使用实际显示的名称。

 

8.把新分配的空间创建一个新的物理

  #pvcreate /dev/sda3

 

9.然后使用新的物理卷来扩展 LVM 的 VolGroup,

  # vgextend vg_dds /dev/sda3

 

  10.然后扩展 LVM 的逻辑卷 vg_dds-lv_root,

  # lvextend /dev/mapper/vg_dds-lv_root /dev/sda3

  11.调整逻辑卷的大小

  #resize2fs /dev/mapper/vg_dds-lv_root

  到这里就完成了空间的扩展。

  12.查看效果

  [root@aimin ~]# df -h文件系统 容量 已用 可用 已用%% 挂载点/dev/mapper/vg_dds-lv_root 12G 5.2G 6.2G 46% /tmpfs 499M 80K 499M 1% /dev/shm/dev/sda1 485M 33M 427M 8% /boot

 

可能会出现的问题:

resize2fs: Bad magic number in super-block while trying to open /dev/centos/root Couldn't find valid filesystem superblock

检查 /dev/centos/root 文件系统,发现是xfs,如下;

# mount |grep root
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)

xfs的文件系统重新定义大小用如下命令:

# xfs_growfs /dev/mapper/centos-root 
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 39336960

重新进行df -h查看挂载点,发现大小已经更改。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值