我有一个Linux VM需要装Oracle数据库,之前的根盘是vmdk类型的,只有20G,想扩充到40G。
VDI(VirtualBox Disk Image)是VIrtualBox自己的磁盘格式,虽然不如VMDK普及,但支持磁盘扩展等高级功能。因此我需要将以前模板中的VMDK磁盘装换为VDI格式。
步骤如下:
- 从虚拟机模板(.ova)导入虚拟机
- 将vmdk格式的磁盘转换为vdi格式。(参考)
PS C:\Program Files\Oracle\VirtualBox> .\VBoxManage clonehd --format VDI E:\TEST\DB12c\OL7U4-disk001.vmdk E:\TEST\DB12c\
OL7U4-rootdisk.vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'VDI'. UUID: 24126d4e-bc59-4c4b-a650-3e7eb024af4b
- 在Media Manager中,将VDI磁盘从20G扩充到40G
- 在虚拟机中,取消关联之前的VMDK磁盘,然后关联新生成的VDI磁盘
- 启动虚机,扩展磁盘和文件系统
[root@10 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─ol-root 249:0 0 17G 0 lvm /
└─ol-swap 249:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
# 在增加的空间上建立分区sda3
[root@10 ~]# 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): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (41943040-83886079, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079):
Using default value 83886079
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.
[root@10 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─ol-root 249:0 0 17G 0 lvm /
└─ol-swap 249:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
# 运行partprobe,重新读取分区表
[root@10 ~]# partprobe /dev/sda
[root@10 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 19G 0 part
│ ├─ol-root 249:0 0 17G 0 lvm /
│ └─ol-swap 249:1 0 2G 0 lvm [SWAP]
└─sda3 8:3 0 20G 0 part
sr0 11:0 1 1024M 0 rom
[root@10 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@10 ~]# vgdisplay -s
"ol" <19.00 GiB [<19.00 GiB used / 0 free]
[root@10 ~]# vgextend ol /dev/sda3
Volume group "ol" successfully extended
[root@10 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/ol/swap
LV Name swap
VG Name ol
LV UUID RRH8RC-5MNd-lsbJ-pDlb-qpsE-QEQ2-PbQFN2
LV Write Access read/write
LV Creation host, time localhost, 2017-12-06 17:07:48 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 249:1
--- Logical volume ---
LV Path /dev/ol/root
LV Name root
VG Name ol
LV UUID 8AP7ks-mRxu-4sqb-7yoK-J98z-ukmP-mux85E
LV Write Access read/write
LV Creation host, time localhost, 2017-12-06 17:07:49 +0800
LV Status available
# open 1
LV Size <17.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 249:0
# 将分区sda3上的空间全部补充到逻辑卷root上
[root@10 ~]# lvextend ol/root /dev/sda3
Size of logical volume ol/root changed from <17.00 GiB (4351 extents) to 36.99 GiB (9470 extents).
Logical volume ol/root successfully resized.
[root@10 ~]# lvdisplay ol/root
--- Logical volume ---
LV Path /dev/ol/root
LV Name root
VG Name ol
LV UUID 8AP7ks-mRxu-4sqb-7yoK-J98z-ukmP-mux85E
LV Write Access read/write
LV Creation host, time localhost, 2017-12-06 17:07:49 +0800
LV Status available
# open 1
LV Size 36.99 GiB
Current LE 9470
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 249:0
# 扩展文件系统,XFS是Linux 7默认的文件系统,可以看到,剩余空间从11G扩展到了31G
[root@10 ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ol-root 17G 6.9G 11G 41% /
[root@10 ~]# xfs_growfs ol/root
xfs_growfs: ol/root is not a mounted XFS filesystem
[root@10 ~]# xfs_growfs /dev/ol/root
meta-data=/dev/mapper/ol-root isize=256 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 9697280
[root@10 ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ol-root 37G 6.9G 31G 19% /
- 关机,保持虚拟机为模板
- 清理之前的VMDK文件