一、前提:硬盘分区为lvm格式
二、新增硬盘刷新(vmware下,不关机新增硬盘,fdisk -l 无法看到,通过刷新可以实现)
1、查看有几个host
[root@localhost scsi_host]# ll /sys/class/scsi_host/ total 0 lrwxrwxrwx. 1 root root 0 Jun 13 20:58 host0 -> ../../devices/pci0000:00/0000:00:07.1/ata1/host0/scsi_host/host0 lrwxrwxrwx. 1 root root 0 Jun 13 20:58 host1 -> ../../devices/pci0000:00/0000:00:07.1/ata2/host1/scsi_host/host1 lrwxrwxrwx. 1 root root 0 Jun 13 20:58 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2
2、有几个,刷新几个,即可识别。
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host0/scan [root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host1/scan [root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host2/scan [root@localhost scsi_host]# ls /sys/class/scsi_device/ 1:0:0:0 2:0:0:0 2:0:1:0 [root@localhost scsi_host]# echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/rescan [root@localhost scsi_host]# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan [root@localhost scsi_host]# echo 1 > /sys/class/scsi_device/2\:0\:1\:0/device/rescan [root@localhost scsi_host]# fdisk -l
三、fdisk /dev/sdb 为linux lvm格式,方便下一步进行格式化
[root@template scsi_host]# fdisk /dev/sdc
注:如果磁盘分区格式默认是gpt的,那么在执行t后,需要选择15才为linux lvm
四、新增硬盘的lvm创建及挂载
1、创建pv
[root@localhost /]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created.
2、创建vg
[root@localhost /]# vgcreate vg_data /dev/sdb1 Volume group "vg_data" successfully created
3、创建lv(创建时不需要进行lvm的刷新,在对lv进行扩容时需要刷下,见三中的扩容实例)
[root@localhost /]# lvcreate -L 49.99G -n lv_data /dev/vg_data Rounding up size to full physical extent 49.99 GiB Logical volume "lv_data" created. 或:创建剩余全部的vg组的数据 lvcreate -l 100%FREE -n lv_oracle /dev/vg_oracle
4、给新增lv_data,创建文件系统
(1)centos 6及以下创建:[root@template ~]# mkfs.ext4 /dev/vg_oracle/lv_oracle
(2)centos 7创建:
[root@localhost /]# mkfs.xfs /dev/vg_data/lv_data meta-data=/dev/vg_data/lv_data isize=512 agcount=4, agsize=3276288 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=13105152, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=6399, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
5、挂载文件系统到\data
[root@localhost /]# mount /dev/vg_data/lv_data /data
6、查看df -h
[root@localhost /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_system-lv_root 37G 1.2G 36G 4% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.5M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 139M 876M 14% /boot tmpfs 379M 0 379M 0% /run/user/0 /dev/mapper/vg_data-lv_data 50G 33M 50G 1% /data
三、扩容硬盘的lvm创建及挂载(针对于vmware虚拟机,扩容硬盘方式,由原50G扩容至60G)
1、先将扩容的硬盘容量识别到,默认fdisk -l 只识别50G,新增容量需要刷新识别。进入scsi_disk,对新扩容硬盘进行echo '1'>device/rescan
[root@localhost scsi_host]# cd /sys/class/scsi_disk/ [root@localhost scsi_disk]# ll total 0 lrwxrwxrwx. 1 root root 0 Jun 13 20:58 2:0:0:0 -> ../../devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/scsi_disk/2:0:0:0 lrwxrwxrwx. 1 root root 0 Jun 13 20:58 2:0:1:0 -> ../../devices/pci0000:00/0000:00:10.0/host2/target2:0:1/2:0:1:0/scsi_disk/2:0:1:0 lrwxrwxrwx. 1 root root 0 Jun 14 04:09 2:0:2:0 -> ../../devices/pci0000:00/0000:00:10.0/host2/target2:0:2/2:0:2:0/scsi_disk/2:0:2:0 [root@localhost scsi_disk]# cd 2\:0\:1\:0/ [root@localhost 2:0:1:0]# echo '1'>device/rescan [root@localhost 2:0:1:0]# fdisk -l
2、扩容硬盘:
扩容硬盘后,查看fdisk /dev/sdb——m——p,会出现linux lvm 变为GPT的情况,更改为linux lvm测试,同时将新分区改为linux lvm模式,保存。
保存后会出现如下问题:
解决:使用partx
[root@template 2:0:0:0]# partx -a /dev/sda
解决:[root@localhost 2:0:1:0]# partprobe /dev/sdb
3、扩容分区:
(1). pvcreate
[root@localhost 2:0:1:0]# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created.
(2).vgextend
[root@localhost 2:0:1:0]# vgextend vg_data /dev/sdb2 Volume group "vg_data" successfully extended
(3).lvextend
[root@localhost 2:0:1:0]# lvextend -L +4.99G /dev/vg_data/lv_data Rounding size to boundary between physical extents: 4.99 GiB. Size of logical volume vg_data/lv_data changed from 59.99 GiB (15358 extents) to 64.98 GiB (16636 extents). Logical volume vg_data/lv_data successfully resized.
(4).刷新文件系统(xfs 在线扩容,使用xfs_growfs),完成扩容
centos 6及以下,进行刷新lv resize2fs 用于ext2,ext3,ext4的,才能挂载: SRMQAS:/sys/class/scsi_disk # resize2fs /dev/sapvg/lv_ora
centos 7,以后,默认使用xfs,刷新文件系统使用xfs_growfs
[root@localhost 2:0:1:0]# xfs_growfs /dev/vg_data/lv_data meta-data=/dev/mapper/vg_data-lv_data isize=512 agcount=4, agsize=3931648 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=15726592, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=7679, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 15726592 to 17035264
如果扩容swap,上述(3)完成后,需要执行 以下语句
[root@localhost /]# swapoff /dev/cl/swap
[root@localhost /]# mkswap /dev/cl/swap
mkswap: /dev/cl/swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 33550332 KiB
no label, UUID=53944263-b10b-4486-ac73-01c4526cfc27
[root@localhost /]# swapon /dev/cl/swap
五、删除lv,vg,pv
1、删除lv,vg,pv
[root@localhost /]# lvremove /dev/vg_data/lv_data Do you really want to remove active logical volume vg_data/lv_data? [y/n]: y Logical volume "lv_data" successfully removed [root@localhost /]# vgremove /dev/vg_data Volume group "vg_data" successfully removed [root@localhost /]# pvremove /dev/sdb1 Labels on physical volume "/dev/sdb1" successfully wiped.
2、完成上述1,进入fdisk /dev/sdb,可以直接删除分区了。
3、执行完成后,执行[root@localhost /]# partprobe 即可
六、lvreduce 缩减磁盘卷
缩小一个逻辑卷(逻辑卷的缩小操作必须离线执行,要卸载逻辑卷)
1、卸载已经挂载的逻辑卷 umount /dev/zq/mylv
----2、缩小文件系统(会提示需要运行fsck检查文件系统)resize2fs /dev/zq/mylv 1G 切记先缩小文件系统跟扩展的时候恰恰相反,缩小为1g
2、缩小LV lvreduce -L -1G /dev/zq/mylv
3、查看缩小后的LV lvdispaly
4、挂载 mount /dev/zq/mylv /mnt
文章评论