VirtualBox下扩容vdi文件

版本:VirtualBox 5.0.14

之前VirtualBox创建的虚拟机的vdi文件过小,无法满足新的实验需求,扩容vdi文件的方法如下:

比如我这里将RHEL6_Primary12cRAC2.vdi文件扩容到60000M大小,方法如下:

VBoxManage modifyhd E:\Vbox\Primary12cRAC2\RHEL6_Primary12cRAC2.vdi --resize 60000

实际执行过程:

  1. c:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd E:\Vbox\Primary12cRAC2\RH
  2. EL6_Primary12cRAC2.vdi --resize 60000
  3. 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

至此虚拟机层面的操作就算完成了。

但是这个时候启动虚拟机会发现大小没有变化:

  1. [root@jydb2 ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/vg_linuxbase-lv_root 28G 2.0G 24G 8% /
  4. tmpfs 3.9G 0 3.9G 0% /dev/shm
  5. /dev/sda1 485M 39M 421M 9% /boot

实际上这是因为我这里的环境使用的lvm,而对应的根分区使用的是磁盘的一个分区,而扩容的vdi对应的是/dev/sda磁盘,下面继续来看详细情况:

  1. [root@jydb2 ~]# fdisk -l /dev/sda
  2. Disk /dev/sda: 62.9 GB, 62914560000 bytes
  3. 255 heads, 63 sectors/track, 7648 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Sector size (logical/physical): 512 bytes / 512 bytes
  6. I/O size (minimum/optimal): 512 bytes / 512 bytes
  7. Disk identifier: 0x00047a24
  8. Device Boot Start End Blocks Id System
  9. /dev/sda1 * 1 64 512000 83 Linux
  10. Partition 1 does not end on cylinder boundary.
  11. /dev/sda2 64 3917 30944256 8e Linux LVM

可以看到/dev/sda已经成功扩容,现在只需要把扩容的空间新建成一个分区:

  1. [root@jydb2 ~]# fdisk /dev/sda
  2. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  3. switch off the mode (command 'c') and change display units to
  4. sectors (command 'u').
  5. Command (m for help): p
  6. Disk /dev/sda: 62.9 GB, 62914560000 bytes
  7. 255 heads, 63 sectors/track, 7648 cylinders
  8. Units = cylinders of 16065 * 512 = 8225280 bytes
  9. Sector size (logical/physical): 512 bytes / 512 bytes
  10. I/O size (minimum/optimal): 512 bytes / 512 bytes
  11. Disk identifier: 0x00047a24
  12. Device Boot Start End Blocks Id System
  13. /dev/sda1 * 1 64 512000 83 Linux
  14. Partition 1 does not end on cylinder boundary.
  15. /dev/sda2 64 3917 30944256 8e Linux LVM
  16. Command (m for help): n
  17. Command action
  18. e extended
  19. p primary partition (1-4)
  20. p
  21. Partition number (1-4): 3
  22. First cylinder (3917-7648, default 3917):
  23. Using default value 3917
  24. Last cylinder, +cylinders or +size{K,M,G} (3917-7648, default 7648):
  25. Using default value 7648
  26. Command (m for help): p
  27. Disk /dev/sda: 62.9 GB, 62914560000 bytes
  28. 255 heads, 63 sectors/track, 7648 cylinders
  29. Units = cylinders of 16065 * 512 = 8225280 bytes
  30. Sector size (logical/physical): 512 bytes / 512 bytes
  31. I/O size (minimum/optimal): 512 bytes / 512 bytes
  32. Disk identifier: 0x00047a24
  33. Device Boot Start End Blocks Id System
  34. /dev/sda1 * 1 64 512000 83 Linux
  35. Partition 1 does not end on cylinder boundary.
  36. /dev/sda2 64 3917 30944256 8e Linux LVM
  37. /dev/sda3 3917 7648 29975280 83 Linux
  38. Command (m for help): w
  39. The partition table has been altered!
  40. Calling ioctl() to re-read partition table.
  41. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
  42. The kernel still uses the old table. The new table will be used at
  43. the next reboot or after you run partprobe(8) or kpartx(8)
  44. Syncing disks.
  45. [root@jydb2 ~]# partprobe
  46. Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.

新加的分区需要重启才能生效。

重启虚拟机之后就可以将新加的分区创建成pv加入到vg,最终扩容lv即可,可以分为4个步骤,具体如下:

1.创建pv

  1. [root@jydb2 ~]# pvcreate /dev/sda3
  2. Physical volume "/dev/sda3" successfully created
  3. [root@jydb2 ~]# pvs
  4. PV VG Fmt Attr PSize PFree
  5. /dev/sda2 vg_linuxbase lvm2 a-- 29.51g 0
  6. /dev/sda3 lvm2 a-- 28.59g 28.59g

2.扩容vg

  1. [root@jydb2 ~]# vgs
  2. VG #PV #LV #SN Attr VSize VFree
  3. vg_linuxbase 1 2 0 wz--n- 29.51g 0
  4. [root@jydb2 ~]# vgextend -h
  5. vgextend: Add physical volumes to a volume group
  6. vgextend
  7. [-A|--autobackup y|n]
  8. [--restoremissing]
  9. [-d|--debug]
  10. [-f|--force]
  11. [-h|--help]
  12. [-t|--test]
  13. [-v|--verbose]
  14. [--version]
  15. [-y|--yes]
  16. [ PHYSICAL DEVICE OPTIONS ]
  17. VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
  18. [root@jydb2 ~]# vgextend vg_linuxbase /dev/sda3
  19. Volume group "vg_linuxbase" successfully extended
  20. [root@jydb2 ~]# vgs
  21. VG #PV #LV #SN Attr VSize VFree
  22. vg_linuxbase 2 2 0 wz--n- 58.09g 28.58g

3.扩容lv

  1. [root@jydb2 ~]# lvs
  2. LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
  3. lv_root vg_linuxbase -wi-ao---- 27.54g
  4. lv_swap vg_linuxbase -wi-ao---- 1.97g
  5. [root@jydb2 ~]# vgdisplay
  6. --- Volume group ---
  7. VG Name vg_linuxbase
  8. System ID
  9. Format lvm2
  10. Metadata Areas 2
  11. Metadata Sequence No 5
  12. VG Access read/write
  13. VG Status resizable
  14. MAX LV 0
  15. Cur LV 2
  16. Open LV 2
  17. Max PV 0
  18. Cur PV 2
  19. Act PV 2
  20. VG Size 58.09 GiB
  21. PE Size 4.00 MiB
  22. Total PE 14871
  23. Alloc PE / Size 7821 / 30.55 GiB
  24. Free PE / Size 7050 / 27.54 GiB
  25. VG UUID 41Wk3c-fuD0-SKcX-RqNQ-7uIP-e2xD-1mWaUd
  26. [root@jydb2 ~]# lvresize -l +7050 /dev/mapper/vg_linuxbase-lv_root
  27. Extending logical volume lv_root to 56.12 GiB
  28. Logical volume lv_root successfully resized
  29. [root@jydb2 ~]# vgdisplay
  30. --- Volume group ---
  31. VG Name vg_linuxbase
  32. System ID
  33. Format lvm2
  34. Metadata Areas 2
  35. Metadata Sequence No 6
  36. VG Access read/write
  37. VG Status resizable
  38. MAX LV 0
  39. Cur LV 2
  40. Open LV 2
  41. Max PV 0
  42. Cur PV 2
  43. Act PV 2
  44. VG Size 58.09 GiB
  45. PE Size 4.00 MiB
  46. Total PE 14871
  47. Alloc PE / Size 14871 / 58.09 GiB
  48. Free PE / Size 0 / 0
  49. VG UUID 41Wk3c-fuD0-SKcX-RqNQ-7uIP-e2xD-1mWaUd
  50. [root@jydb2 ~]# df -h
  51. Filesystem Size Used Avail Use% Mounted on
  52. /dev/mapper/vg_linuxbase-lv_root 29G 2.0G 25G 8% /
  53. tmpfs 3.9G 0 3.9G 0% /dev/shm
  54. /dev/sda1 485M 39M 421M 9% /boot

4.resize2fs lv

  1. [root@jydb2 ~]# resize2fs /dev/mapper/vg_linuxbase-lv_root
  2. resize2fs 1.41.12 (17-May-2010)
  3. Filesystem at /dev/mapper/vg_linuxbase-lv_root is mounted on /; on-line resizing required
  4. old desc_blocks = 2, new_desc_blocks = 4
  5. Performing an on-line resize of /dev/mapper/vg_linuxbase-lv_root to 14711808 (4k) blocks.
  6. The filesystem on /dev/mapper/vg_linuxbase-lv_root is now 14711808 blocks long.
  7. [root@jydb2 ~]# df -h
  8. Filesystem Size Used Avail Use% Mounted on
  9. /dev/mapper/vg_linuxbase-lv_root 56G 2.0G 51G 4% /
  10. tmpfs 3.9G 0 3.9G 0% /dev/shm
  11. /dev/sda1 485M 39M 421M 9% /boot

至此,已成功扩容了该虚拟机的系统根目录。

VirtualBox下扩容vdi文件的更多相关文章

  1. Mac环境下扩容 .vmdk 镜像容量

    参考: Resizing a VirtualBox Disk Image (.vmdk) on a Mac Mac环境下扩容 .vmdk 镜像容量 在安装虚拟机时,原有的vmdk镜像容量只有20G,在 ...

  2. VirtualBox 复制vdi文件和修改vdi的uuid

    1.复制vdi文件:VBoxManage clonehd 因为VirtualBox不允许注册重复的uuid,而每个vdi文件都有一个唯一的uuid.所以要想拷贝一份vdi文件再次在VBOX中注册,简单 ...

  3. VirtualBox 导入.vdi文件时报“uuid is exists”错误

    解决办法: 1.要安装的.vdi文件所在目录:D:\developTools\vm\RedHatLinux1.vdi 2.找到VirtualBox的安装目录,这里是D:\Program Files\O ...

  4. 【转】VIRTUALBOX导入已有.VDI文件步骤

    原文网址:http://blog.csdn.net/wanghai__/article/details/6703923 1.安装SUN VIRTUALBOX 2.新建,进入到“新建虚拟电话”对话框,下 ...

  5. 使用VirtualBox把IMG文件转换为VDI文件

    使用VirtualBox把IMG文件转换为VDI文件 首先确保已安装VirtualBox. 需要使用的命令: 语法:$ VBoxManage convertdd input.img output.vd ...

  6. VirtualBox虚拟机怎么导入已经存在的vdi文件

    VirtualBox虚拟机怎么导入已经存在的vdi文件 第一章 1.原因 早上一不小心将virtualBox 卸载了,(不知道怎么了, 里面得虚拟机全部都没有了,但是vdi文件还在) 2.解决办法 直 ...

  7. 【原创】VirtualBox 磁盘扩容教程

    问题和环境说明 环境: 主机:Ubuntu 15.10 客户机:Windows 7 x64 VirtualBox:5.0.10 虚拟机磁盘类型:VDI(VirtualBox磁盘映像) 问题: 在虚拟机 ...

  8. VirtualBox修改现有VDI虚拟磁盘大小

    之前创建的虚拟磁盘10G,现需要更大的空间,而又不想使用新增虚拟磁盘的方法. 通过查看资料发现VirtulBox提供的VBoxManage modifyhd命令可以解决,该命令的具体用法: VBoxM ...

  9. VirtualBox虚拟机扩容

    1. 在VBox下增加储存 如图,未扩容前是40G 打开cmd命令行(win+r  输入cmd打开) 将目录切换到virtual的安装目录 cd C:\Program Files\Oracle\Vir ...

随机推荐

  1. 在VMware中使用Nat方式设置静态IP, 宿主机可以 ssh

    坑很多:  麻痹,  主要还是要先 防火墙关掉,永久关掉.  seliux 也永久关掉. 临时关闭防火墙:systemctl stop firewalld    开机不启动: systemctl di ...

  2. Elasticsearch全文检索实战小结

    一.项目概述 这是一个被我称之为“没有枪.没有炮,硬着头皮自己造”的项目.项目是和其它公司合作的三个核心模块开发. 使用ES的目的是: 1).采集数据.网站数据清洗后存入ES: 2).对外提供精确检索 ...

  3. JQuery中数组的创建与使用

    一.创建数组的方式: 1.定义并赋值 var str = ['java', 'php', 'c++', 'c#', 'perl', 'vb', 'html', 'css']; 2.用{}定义后赋值: ...

  4. 小心踩雷,一次Java内存泄漏排查实战

    1.使用 jstack pid > jstack.log 保存了线程栈的现场,使用 jmap -dump:format=b,file=heap.log pid 保存了堆现场: https://m ...

  5. OCR技术(光学字符识别)

    什么是OCR? OCR英文全称是optical character recognition,中文叫光学字符识别.它是利用光学技术和计算机技术把印在或者写在纸上的 文字读取出来,并转换成一种计算机能够接 ...

  6. 图->连通性->有向图的强连通分量

    文字描述 有向图强连通分量的定义:在有向图G中,如果两个顶点vi,vj间(vi>vj)有一条从vi到vj的有向路径,同时还有一条从vj到vi的有向路径,则称两个顶点强连通(strongly co ...

  7. jquery基础学习之DOM篇(二)

    在此之前请牢记,jquery 是一个合集对象!!!! 1.节点创建 js创建方法: 创建元素:document.createElement 设置属性:setAttribute 添加文本:innerHT ...

  8. HBase系列文章(转)

    HBase概念学习(一)基本架构 HBase概念学习(二)JAVA API操作概览 HBase概念学习(三)Java API之CRUD(增查改删) HBase概念学习(四)Java API之扫描和过滤 ...

  9. 对线程发送signal

    学习对线程 发送 signal #include <stdio.h> #include <stdlib.h> #include <string.h> #includ ...

  10. python中由于中文路径引起的os.path.isfile(imgpath) == False问题

    昨天在用python脚本处理文件的时候,遇到了题述问题,明明文件时存在的,但是在用os.path.isfile(imgpath) == False进行判断的时候总是成立,在一开始以为是正反斜杠wind ...