前提:
备份系统数据,虚拟机做快照。
确定可扩容时间。
升级失败后,可利用快照进行恢复,如快照不能恢复,可利用备份软件进行前一天的数据恢复。
1、查看原磁盘状态:
[root@spczdb11 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_db11-LogVol00 125G 14G 106G 12% /
tmpfs 7.8G 72K 7.8G 1% /dev/shm
/dev/sda1 1008M 62M 895M 7% /boot
/dev/mapper/vg_db11-LogVol01 138G 35G 97G 27% /home
/dev/mapper/vg_db12-LogVol00 493G 418G 50G 90% /oradata
[root@spczdb11 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sdb 8:16 0 500G 0 disk
`-sdb1 8:17 0 500G 0 part
`-vg_db12-LogVol00 (dm-1) 253:1 0 500G 0 lvm /oradata
sda 8:0 0 300G 0 disk
|-sda1 8:1 0 1G 0 part /boot
|-sda2 8:2 0 32G 0 part [SWAP]
`-sda3 8:3 0 267G 0 part
|-vg_db11-LogVol00 (dm-0) 253:0 0 127G 0 lvm /
`-vg_db11-LogVol01 (dm-2) 253:2 0 140G 0 lvm /home
2、添加一块新的磁盘,容量为2T,系统下FDISK 可能看不到,需要重启操作系统,不重启方法:
[root@spczdb11 ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 01 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
[root@spczdb11 ~]# echo "scsi add-single-device 2 0 2 0">/proc/scsi/scsi
[root@spczdb11 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sdb 8:16 0 500G 0 disk
`-sdb1 8:17 0 500G 0 part
`-vg_db12-LogVol00 (dm-1) 253:1 0 500G 0 lvm /oradata
sda 8:0 0 300G 0 disk
|-sda1 8:1 0 1G 0 part /boot
|-sda2 8:2 0 32G 0 part [SWAP]
`-sda3 8:3 0 267G 0 part
|-vg_db11-LogVol00 (dm-0) 253:0 0 127G 0 lvm /
`-vg_db11-LogVol01 (dm-2) 253:2 0 140G 0 lvm /home
sdc 8:32 0 2T 0 disk
3、磁盘分区 格式为 8E
[root@spczdb11 ~]# fdisk -l
Disk /dev/sdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006614a
Device Boot Start End Blocks Id System
/dev/sdb1 1 65271 524286976 8e Linux LVM
Disk /dev/sda: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000341ce
Device Boot Start End Blocks Id System
/dev/sda1 * 1 131 1048576 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 131 4309 33554432 82 Linux swap / Solaris
/dev/sda3 4309 39163 279968768 8e Linux LVM
Disk /dev/mapper/vg_db11-LogVol00: 136.3 GB, 136314880000 bytes
255 heads, 63 sectors/track, 16572 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_db12-LogVol00: 536.9 GB, 536866717696 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_db11-LogVol01: 150.4 GB, 150369992704 bytes
255 heads, 63 sectors/track, 18281 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdc: 2199.0 GB, 2199023255552 bytes
255 heads, 63 sectors/track, 267349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@spczdb11 ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd98e85a6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-267349, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-267349, default 267349):
Using default value 267349
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdc: 2199.0 GB, 2199023255552 bytes
255 heads, 63 sectors/track, 267349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd98e85a6
Device Boot Start End Blocks Id System
/dev/sdc1 1 267349 2147480811 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
4、创建PV:
[root@spczdb11 ~]# pvcreate /dev/sdc1
dev_is_mpath: failed to get device for 8:33
Physical volume "/dev/sdc1" successfully created
[root@spczdb11 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 vg_db11 lvm2 a-- 267.00g 0
/dev/sdb1 vg_db12 lvm2 a-- 500.00g 0
/dev/sdc1 lvm2 a-- 2.00t 2.00t
5、查看vg 及lv:
[root@spczdb11 ~]# vgdisplay
--- Volume group ---
VG Name vg_db12
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 500.00 GiB
PE Size 4.00 MiB
Total PE 127999
Alloc PE / Size 127999 / 500.00 GiB
Free PE / Size 0 / 0
VG UUID tu0ePT-5wEd-eH1f-Obw3-fg6L-B1X8-acLjb5
--- Volume group ---
VG Name vg_db11
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 267.00 GiB
PE Size 4.00 MiB
Total PE 68351
Alloc PE / Size 68351 / 267.00 GiB
Free PE / Size 0 / 0
VG UUID 7ablFQ-AEia-B5P8-8KFc-TjCl-CBwa-DO2tT9
===================================================================================================================================
[root@spczdb11 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_db12/LogVol00
LV Name LogVol00
VG Name vg_db12
LV UUID fOFLti-ZPu8-Cqvc-JaJa-TzRu-fq75-FoaSXN
LV Write Access read/write
LV Creation host, time spczdb11, 2018-04-19 04:35:35 +0800
LV Status available
# open 1
LV Size 500.00 GiB
Current LE 127999
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/vg_db11/LogVol01
LV Name LogVol01
VG Name vg_db11
LV UUID 9IJk70-TSZI-XwUA-HeLT-9gW2-mu32-t2vk6B
LV Write Access read/write
LV Creation host, time spczdb11, 2018-04-19 04:35:14 +0800
LV Status available
# open 1
LV Size 140.04 GiB
Current LE 35851
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg_db11/LogVol00
LV Name LogVol00
VG Name vg_db11
LV UUID PhcvMG-Kv8j-d5dB-0Zcg-43mU-9M54-AyS6Ip
LV Write Access read/write
LV Creation host, time spczdb11, 2018-04-19 04:35:24 +0800
LV Status available
# open 1
LV Size 126.95 GiB
Current LE 32500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
6、扩容VG:
[root@spczdb11 ~]# vgextend vg_db12 /dev/sdc1
Volume group "vg_db12" successfully extended
[root@spczdb11 ~]# vgdisplay
--- Volume group ---
VG Name vg_db12
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 2.49 TiB
PE Size 4.00 MiB
Total PE 652286
Alloc PE / Size 127999 / 500.00 GiB
Free PE / Size 524287 / 2.00 TiB 剩余空间为2TB
VG UUID tu0ePT-5wEd-eH1f-Obw3-fg6L-B1X8-acLjb5
--- Volume group ---
VG Name vg_db11
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 267.00 GiB
PE Size 4.00 MiB
Total PE 68351
Alloc PE / Size 68351 / 267.00 GiB
Free PE / Size 0 / 0
VG UUID 7ablFQ-AEia-B5P8-8KFc-TjCl-CBwa-DO2tT9
[root@spczdb11 ~]# lvextend -L +2T /dev/vg_db12/LogVol00
Extending logical volume LogVol00 to 2.49 TiB
Insufficient free space: 524288 extents needed, but only 524287 available 只能添加 524287 个扇区 ,所以选择添加1.99T。(具体换算太麻烦,没有必要那么精确)
[root@spczdb11 ~]# lvextend -L +1.99T /dev/vg_db12/LogVol00
Rounding size to boundary between physical extents: 1.99 TiB
Extending logical volume LogVol00 to 2.48 TiB
Logical volume LogVol00 successfully resized
[root@spczdb11 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_db12/LogVol00
LV Name LogVol00
VG Name vg_db12
LV UUID fOFLti-ZPu8-Cqvc-JaJa-TzRu-fq75-FoaSXN
LV Write Access read/write
LV Creation host, time spczdb11, 2018-04-19 04:35:35 +0800
LV Status available
# open 1
LV Size 2.48 TiB 再次查看LV size 为 2.48TB ,(新添加的2T 加上 原有的500GB )
Current LE 649666
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/vg_db11/LogVol01
LV Name LogVol01
VG Name vg_db11
LV UUID 9IJk70-TSZI-XwUA-HeLT-9gW2-mu32-t2vk6B
LV Write Access read/write
LV Creation host, time spczdb11, 2018-04-19 04:35:14 +0800
LV Status available
# open 1
LV Size 140.04 GiB
Current LE 35851
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg_db11/LogVol00
LV Name LogVol00
VG Name vg_db11
LV UUID PhcvMG-Kv8j-d5dB-0Zcg-43mU-9M54-AyS6Ip
LV Write Access read/write
LV Creation host, time spczdb11, 2018-04-19 04:35:24 +0800
LV Status available
# open 1
LV Size 126.95 GiB
Current LE 32500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
7、扩容LV后,df查看空间没有增加,需要重新定义分区 大小。(对文件系统进行扩容)
[root@spczdb11 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_db11-LogVol00 125G 14G 106G 12% /
tmpfs 7.8G 72K 7.8G 1% /dev/shm
/dev/sda1 1008M 62M 895M 7% /boot
/dev/mapper/vg_db11-LogVol01 138G 35G 97G 27% /home
/dev/mapper/vg_db12-LogVol00 493G 418G 50G 90% /oradata
[root@spczdb11 ~]#
[root@spczdb11 ~]#
[root@spczdb11 ~]# resize2fs /dev/mapper/vg_db12-LogVol00 ### 如果是XFS文件系统要会执行附录中的命令来更新文件系统
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_db12-LogVol00 is mounted on /oradata; on-line resizing required
old desc_blocks = 32, new_desc_blocks = 159
Performing an on-line resize of /dev/mapper/vg_db12-LogVol00 to 665257984 (4k) blocks.
The filesystem on /dev/mapper/vg_db12-LogVol00 is now 665257984 blocks long.
[root@spczdb11 ~]# df -h 重新定义完成后查看空间
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_db11-LogVol00 125G 14G 106G 12% /
tmpfs 7.8G 72K 7.8G 1% /dev/shm
/dev/sda1 1008M 62M 895M 7% /boot
/dev/mapper/vg_db11-LogVol01 138G 35G 97G 27% /home
/dev/mapper/vg_db12-LogVol00 2.5T 418G 2.0T 18% /oradata
8、扩容完成,删除虚拟机快照,免去备份报错。
[root@RackShift ~]# mount | grep root #查看 文件系统
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
[root@RackShift ~]# xfs_growfs /dev/mapper/centos-var
meta-data=/dev/mapper/centos-var 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 14365696
[root@RackShift ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 60G 12G 49G 20% /
/dev/sda1 197M 132M 66M 67% /boot
/dev/mapper/centos-home 10G 33M 10G 1% /home
/dev/mapper/centos-var 55G 4.7G 51G 9% /var
tmpfs 781M 0 781M 0% /run/user/0