扩展oracle VM VirtualBox硬盘容量

1.首先对于box的扩展,只支持VDI VHD两种格式
DOC下,访问到vbox安装目录下:

//VirtualBox  的安装目录
cd D:\Oracle\VirtualBox  
d:

如果硬盘是vmdk格式,首先需要克隆并转格式,命令如下:
VDI:

VBoxManage clonehd "C:\Users\pactera\VirtualBox VMs\centos\centos.vmdk" "C:\Users\pactera\VirtualBox VMs\centos\centos.vdi" --format VDI

VHD:

VBoxManage clonehd "C:\Users\pactera\VirtualBox VMs\centos\centos.vmdk" "C:\Users\pactera\VirtualBox VMs\centos\centos.vhd" --format VHD

其他实用命令:

删除
VBoxManage closemedium disk “D:\tool\Oracle\VirtualBox VMs\centos7-03\centos7-03.vmdk” --delete
浏览
D:\Oracle\VirtualBox>VBoxManage.exe list hdds

2、修改硬盘大小
示例为:15G即25600M

VBoxManage modifyhd "C:\Users\pactera\VirtualBox VMs\centos\centos.vhd" --resize 25600

3、用新增的空间新建分区

[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): nPartition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): p
Selected partition 4
No free sectors available

Command (m for help): xfs_growfs /dev/mapper/centos-root 

enter后输入w再enter

4、用以下命令可以看到 多了一个/dev/sda3的分区

[root@localhost ~]# fdisk -l
Disk /dev/sda: 26.8 GB, 26843545600 bytes, 52428800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d51e5

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
/dev/sda3 20971520 52428799 15728640 83 Linux

Disk /dev/mapper/centos-root: 24.7 GB, 24687673344 bytes, 48218112 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

c . reboot 重启,然后格式化/dev/sda3
mkfs.ext3 /dev/sda3

5、创建物理卷
[root@localhost ~]# pvcreate /dev/sda3
Physical volume “/dev/sda3” successfully created

使用新增物理卷扩展vg
[root@localhost ~]# vgextend centos /dev/sda3
Volume group “centos” successfully extended

[root@localhost ~]#xfs_growfs /dev/mapper/centos-root

6、lvresize -l +100%FREE /dev/mapper/centos-root

Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 22.99 GiB (5886 extents).
Logical volume centos/root successfully resized.

7、最后扩展在线扩展文件系统:
[root@localhost ~]#xfs_growfs /dev/mapper/centos-root

说明: 很多资料是说这个: resize2fs -f /dev/mapper/centos-root
但是报错,因为centOS默认文件系统是xfs的只能用,NND坑了我好久(直到看到别人的http://blog.itpub.net/24486203/viewspace-1790666)才知道要用这个:xfs_growfs
/dev/mapper/centos-root

[root@localhost ~]#df -h

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 23G 3.6G 20G 16% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.7M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 1014M 125M 890M 13% /boot
tmpfs 100M 0 100M 0% /run/user/0

/dev/sda3 20971520 52428799 15728640 83 Linux

报错:
1>操作过程如果有报错:
WARNING: Re-reading the partition table failed with error 22:
执行:
[root@localhost ~]#/sbin/kpartx -a /dev/sda3
后继续操作

参考文章:
主:http://blog.csdn.net/laiyangwen1120/article/details/51036404
其他:
http://blog.163.com/zhu329599788@126/blog/static/66693350201731521131776/

http://blog.csdn.net/weiguang1017/article/details/52252448

https://zhidao.baidu.com/question/468894513.html

你可能感兴趣的:(VM)