###1.說明
由于安裝虛拟機之前沒有規劃好空間,導緻oracle安裝好後空間太緊張了,隔三岔五去删個日志才行。特别是對于Oracle 12c及以上版本的oracle來說非常吃空間,起碼要搞個100G來玩,要不運作不了幾天空間就沒了。
由于VBOX是按照在Linux上的,是以這裡僅以linux環境為示例來示範如何擴充虛拟機磁盤空間。還有一種就是在VBOX界面上點選兩下就可以了。方法都是通用的,界面方式更為友善。
###2.開始
####2.1.界面方式
點選“檔案”中“虛拟媒體管理”

然後找到要修改的vdi檔案,然後點選修改,确認即可。
####2.2.指令方式
首先定位到虛拟機所使用的VDI檔案的位置,可以通過VBOX檢視,如:
[root@storage2 Oracle 12c R2 RAC1]# ll Oracle/ 18c/ RAC1.vdi
-rw------- 1 root root 52791607296 Nov 22 01:42 Oracle 18c RAC1.vdi --就是這個檔案
目前該檔案大小為50G
[root@storage2 Oracle 12c R2 RAC1]# du -sh Oracle/ 18c/ RAC1.vdi
50G Oracle 18c RAC1.vdi
下面通過VBOX指令将該檔案擴充為100G
[root@storage2 Oracle 12c R2 RAC1]# VBoxManage modifymedium disk Oracle/ 18c/ RAC1.vdi --resize 102400
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
####2.3.驗證
打開虛拟驗證一下
[root@rac1 ~]# fdisk -l /dev/sda
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000b2e8b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
剩下就是擴充根目錄分區VLM。
請參考:
https://www.cndba.cn/Expect-le/article/109
###3.擴充根目錄分區
首先檢視空間
[root@rac1 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size <49.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12543
Free PE 1 --已經沒有空間了
Allocated PE 12542
PV UUID J1e1lG-Vddf-kR4y-WyD2-IIAV-CT07-7fvgFE
####3.1.建立新分區
将已經擴大的磁盤/dev/sda再劃分一個新分區出來。
[root@rac1 ~]# 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): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000b2e8b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
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): 3 --分區号
First sector (104857600-209715199, default 104857600): --起始扇區,使用預設值
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-209715199, default 209715199): --終止扇區,這裡我把空間全部劃分給新分區。
Using default value 209715199
Partition 3 of type Linux and of size 50 GiB is set
Command (m for help): wq --儲存退出
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.
然後重新開機,或執行partprobe指令生效
[root@rac1 ~]# partprobe
[root@rac1 ~]# ll /dev/sda*
brw-rw---- 1 root disk 8, 0 Nov 22 15:12 /dev/sda
brw-rw---- 1 root disk 8, 1 Nov 22 15:12 /dev/sda1
brw-rw---- 1 root disk 8, 2 Nov 22 15:12 /dev/sda2
brw-rw---- 1 root disk 8, 3 Nov 22 15:12 /dev/sda3 --新分區
–新分區大小
[root@rac1 ~]# fdisk -l /dev/sda3
Disk /dev/sda3: 53.7 GB, 53687091200 bytes, 104857600 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
####3.2.建立PV
在新分區上建立新PV
[root@rac1 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
再次檢視PV資訊
[root@rac1 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size <49.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12543
Free PE 1
Allocated PE 12542
PV UUID J1e1lG-Vddf-kR4y-WyD2-IIAV-CT07-7fvgFE
"/dev/sda3" is a new physical volume of "50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ieuNtj-uppY-EfbH-FoiV-B7sp-pL8D-y8gacC
####3.3.擴充VG
–檢視vg資訊
[root@rac1 ~]# vgdisplay
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 1 / 4.00 MiB ---擴充前空間大小
VG UUID 91mq0N-nI9f-XZq5-toJa-hbS9-mieJ-jpyNfd
–擴充
[root@rac1 ~]# vgextend rhel /dev/sda3
Volume group "rhel" successfully extended
–再次檢視vg資訊
[root@rac1 ~]# vgdisplay
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 98.99 GiB
PE Size 4.00 MiB
Total PE 25342
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 12800 / 50.00 GiB --空閑大小
VG UUID 91mq0N-nI9f-XZq5-toJa-hbS9-mieJ-jpyNfd
####3.4.LV擴充
通過lvextend指令将根目錄的邏輯卷空間擴大
[root@rac1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 45G 40G 4.4G 91% / --需要使用到該資訊
devtmpfs 4.8G 0 4.8G 0% /dev
tmpfs 10G 1.4G 8.7G 14% /dev/shm
tmpfs 4.9G 17M 4.8G 1% /run
tmpfs 4.9G 0 4.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 178M 837M 18% /boot
tmpfs 984M 12K 984M 1% /run/user/42
tmpfs 984M 0 984M 0% /run/user/0
tmpfs 984M 0 984M 0% /run/user/54322
–擴充
[root@rac1 ~]# lvextend -l +12800 /dev/mapper/rhel-root
Size of logical volume rhel/root changed from 44.05 GiB (11278 extents) to 94.05 GiB (24078 extents).
Logical volume rhel/root successfully resized.
–檢視檔案系統格式
[root@rac1 ~]# cat /etc/fstab | grep rhel-root
/dev/mapper/rhel-root / xfs defaults 0 0
–xfs_growfs擴充xfs格式的檔案系統
[root@rac1 ~]# xfs_growfs /dev/mapper/rhel-root
meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=2887168 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=11548672, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5639, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11548672 to 24655872
You have new mail in /var/spool/mail/root
[root@rac1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 95G 40G 55G 43% /
devtmpfs 4.8G 0 4.8G 0% /dev
tmpfs 10G 1.4G 8.7G 14% /dev/shm
tmpfs 4.9G 17M 4.8G 1% /run
tmpfs 4.9G 0 4.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 178M 837M 18% /boot
tmpfs 984M 12K 984M 1% /run/user/42
tmpfs 984M 0 984M 0% /run/user/0
tmpfs 984M 0 984M 0% /run/user/54322