Linux下VBOX扩展虚拟机磁盘空间及扩展根目录空间
###1.说明由于安装虚拟机之前没有规划好空间,导致oracle安装好后空间太紧张了,隔三岔五去删个日志才行。特别是对于Oracle 12c及以上版本的oracle来说非常吃空间,起码要搞个100G来玩,要不运行不了几天空间就没了。由于VBOX是按照在Linux上的,所以这里仅以linux环境为示例来演示如何扩展虚拟机磁盘空间。还有一种就是在VBOX界面上点击两下就可以了。方法都是通用的,界面..
###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。
请参考:
###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
至此根目录空间已经成功扩展。
更多推荐
所有评论(0)