Operation and maintenance practice: Linux system expands the partition where Oracle database is located

Time:2021-9-12

The production environment often encounters insufficient disk space. Next, let’s introduce the solution of LVM volume expansion.
Operation and maintenance practice: the Linux system extends the partition where the Oracle database is located. Operation and maintenance practice: the Linux system extends the partition where the Oracle database is located
Experimental environment:
System: centos7
The installation adopts LVM volume partition, and the Oracle database is deployed in / home / Oracle partition. In the later stage, it is found that there is not enough disk space, so a new hard disk is added to expand the partition / home / oracle.

View system space usage
[[email protected] ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 10G 0 lvm /
├─centos-swap 253:1 0 4G 0 lvm [SWAP]
└─centos-home 253:2 0 5G 0 lvm /home
sr0 11:0 1 4.2G 0 rom
It can be seen that LVM partition is adopted. If it is not LVM partition, it cannot be expanded in this way. The directory where Oracle is located is 5g in size.
/Dev / SDB is a new hard disk

Add a hard disk and change the partition to LVM format
[[email protected] ~]# fdisk /dev/sdb
Welcome to fdisk (util Linux 2.23.2).

The changes remain in memory until you decide to write the changes to disk.
Think twice before using the write command.

Device does not contain a recognized partition table
Create a new DOS disk label using the disk identifier 0xd10b295e.

Command (enter m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
Start sector (2048-20971519, 2048 by default):
The default value 2048 will be used
Last sector, + sector or + size {K, m, G} (2048-20971519, the default is 20971519): + 5g
Partition 1 is set to Linux type and size is set to 5 gib

Command (enter m for help): t
Partition 1 Selected
Hex code (enter l to list all codes): 8e
Changed the type of partition ‘Linux’ to ‘Linux LVM’

Command (enter m for help): P

Disk / dev / SDB: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sector of 1 * 512 = 512 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (min / best): 512 bytes / 512 bytes
Disk label type: DOS
Disk identifier: 0xd10b295e

Device boot start end blocks ID system
/dev/sdb1 2048 10487807 5242880 8e Linux LVM

Command (enter m for help): W
The partition table has been altered!

Calling ioctl() to re-read partition table.
Synchronizing disks.
The newly added hard disk is initialized as a physical volume
[[email protected] ~]# pvcreate /dev/sdb1
Physical volume “/dev/sdb1” successfully created.
Viewing volume groups
[[email protected] ~]# vgdisplay
— Volume group —
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.00 GiB
PE Size 4.00 MiB
Total PE 4864
Alloc PE / Size 4864 / 19.00 GiB
Free PE / Size 0 / 0
VG UUID sNqtMh-Yg2a-Y2gb-RZh6-yVJg-gVQH-6n2bxz
Therefore, the volume group name is CentOS and the size is 19g

Adding a new physical volume to a volume group
[[email protected] ~]# vgextend centos /dev/sdb1
Volume group “centos” successfully extended
View volume groups again
[[email protected] ~]# vgdisplay
— Volume group —
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size <24.00 GiB
PE Size 4.00 MiB
Total PE 6143
Alloc PE / Size 4864 / 19.00 GiB
Free PE / Size 1279 / <5.00 GiB
VG UUID sNqtMh-Yg2a-Y2gb-RZh6-yVJg-gVQH-6n2bxz
The volume group size becomes 24g

Increase logical volume size 4G
[[email protected] ~]# lvresize -L +4G /dev/centos/home
Size of logical volume centos/home changed from 5.00 GiB (1280 extents) to 9.00 GiB (2304 extents).
Logical volume centos/home successfully resized.
disk size viewing
[[email protected] ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 10G 0 lvm /
├─centos-swap 253:1 0 4G 0 lvm [SWAP]
└─centos-home 253:2 0 9G 0 lvm /home
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 5G 0 part
└─centos-home 253:2 0 9G 0 lvm /home
sr0 11:0 1 4.2G 0 rom
At this point, you can see that CentOS home becomes 9g

DF – H view disk size
[[email protected] ~]# df -h
File system capacity used% mount point available
/dev/mapper/centos-root 10G 927M 9.1G 10% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.8M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/mapper/centos-home 5.0G 33M 5.0G 1% /home
/dev/sda1 197M 103M 95M 53% /boot
tmpfs 98M 0 98M 0% /run/user/0
At this time, it is found that / dev / mapper / CentOS home is still 5g

Resize file system
[[email protected] ~]# xfs_growfs /dev/centos/home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=327680 blks

     =                       sectsz=512   attr=2, projid32bit=1
     =                       crc=1        finobt=0 spinodes=0

data = bsize=4096 blocks=1310720, 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 1310720 to 2359296
If XFS, use XFS_ Growfs if ext4, use resize 2fs

View again
[[email protected] ~]# df -h
File system capacity used% mount point available
/dev/mapper/centos-root 10G 927M 9.1G 10% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.8M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/mapper/centos-home 9.0G 33M 9.0G 1% /home
/dev/sda1 197M 103M 95M 53% /boot
tmpfs 98M 0 98M 0% /run/user/0
In this way, the / home / home partition is really expanded.

summary
In this way, the expansion of production environment space is completed.