1. 程式人生 > >Linux LVM線上擴容

Linux LVM線上擴容

lvm線上擴容 1、先增加硬碟(VMware虛擬化或其他環境),本文以VMware Workstation來操作,VMware Workstation中新增加一塊硬碟必須重啟伺服器才能識別到。VMware ESXi則不用 OS版本:Centos7.3

A、磁碟新增完成,進入系統,用fdisk -l查詢磁碟,但發現找不到,則進行查詢 輸入cat /proc/scsi/scsi

B、然後使用lsblk檢視系統只有兩塊盤。

C、第三塊的磁碟並未發現,使用echo “- - -” > /sys/class/scsi_host/host2/scan

注意: echo “- - -” > /sys/class/scsi_host/host0/scan //這個 scan 屬性支援以"-"作為萬用字元,如以下命令可以執行讓整個 scsi_host 進行重新搜尋,這個功能用於除錯某些對熱挺拔實現不 完善的 SCSI 驅動程式很有用 備註host0處是host1,還是host2,取決於 cat /proc/scsi/scsi 之後的 scsi 驅動器的號

2、找到新增加的盤 [[email protected] ~]# fdisk -l Disk /dev/sdb: 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: 0xb242c480

Device Boot Start End Blocks Id System /dev/sdb1 2048 209715199 104856576 83 Linux

Disk /dev/sda: 81.6 GB, 81604378624 bytes, 159383552 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: 0x000b6403

Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 159383551 78642176 8e Linux LVM

Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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 /dev/mapper/cl-root: 51.3 GB, 51308920832 bytes, 100212736 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 /dev/mapper/cl-swap: 4160 MB, 4160749568 bytes, 8126464 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 /dev/mapper/cl-home: 25.1 GB, 25052577792 bytes, 48930816 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 /dev/mapper/VolGroup1-lvData1: 107.4 GB, 107365793792 bytes, 209698816 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、硬碟分割槽 [[email protected] ~]# fdisk /dev/sdc 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.

Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xc8318816.

Command (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): 1 First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Partition 1 of type Linux and of size 20 GiB is set

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

Calling ioctl() to re-read partition table. Syncing disks. 4、建立PV [[email protected] ~]# pvcreate /dev/sdc1 Physical volume “/dev/sdc1” successfully created. 5、擴容到VG [[email protected] ~]# vgextend VolGroup1 /dev/sdc1 Volume group “VolGroup1” successfully extended 6、檢視vg [[email protected] ~]# vgdisplay — Volume group — VG Name VolGroup1 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 119.99 GiB PE Size 4.00 MiB Total PE 30718 Alloc PE / Size 25598 / 99.99 GiB Free PE / Size 5120 / 20.00 GiB VG UUID XPA6Ew-9acE-4bTq-8YRy-GE4D-FqBV-KPC82v

— Volume group — VG Name cl 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 75.00 GiB PE Size 4.00 MiB Total PE 19199 Alloc PE / Size 19198 / 74.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID vw5vsX-S9Sg-jaBl-Ak7F-DbWg-LoFA-fNsjyY

[[email protected] ~]# lvdisplay — Logical volume — LV Path /dev/VolGroup1/lvData1 LV Name lvData1 VG Name VolGroup1 LV UUID VZYKyQ-aUZB-3ee7-sWMd-9E8E-SXgy-SY44j3 LV Write Access read/write LV Creation host, time test2, 2017-09-06 09:07:28 +0800 LV Status available

open 1

LV Size 99.99 GiB Current LE 25598 Segments 1 Allocation inherit Read ahead sectors auto

  • currently set to 8192 Block device 253:3

— Logical volume — LV Path /dev/cl/swap LV Name swap VG Name cl LV UUID FZ9ePU-3Eu7-sJXv-ioQl-fb5w-eolt-rVc7as LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-08-31 07:08:56 +0800 LV Status available

open 2

LV Size 3.88 GiB Current LE 992 Segments 1 Allocation inherit Read ahead sectors auto

  • currently set to 8192 Block device 253:1

— Logical volume — LV Path /dev/cl/home LV Name home VG Name cl LV UUID 2OGF8n-xAiA-eM2T-TWQq-IGcE-anuA-VOayXN LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-08-31 07:08:56 +0800 LV Status available

open 1

LV Size 23.33 GiB Current LE 5973 Segments 1 Allocation inherit Read ahead sectors auto

  • currently set to 8192 Block device 253:2

— Logical volume — LV Path /dev/cl/root LV Name root VG Name cl LV UUID 1wiy6J-g4Rx-eD24-px1s-KgFd-2R2w-m7O0rQ LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-08-31 07:08:57 +0800 LV Status available

open 1

LV Size 47.79 GiB Current LE 12233 Segments 1 Allocation inherit Read ahead sectors auto

  • currently set to 8192 Block device 253:0 7、擴容lv [[email protected] ~]# lvresize -l +5120 /dev/VolGroup1/lvData1 Size of logical volume VolGroup1/lvData1 changed from 99.99 GiB (25598 extents) to 119.99 GiB (30718 extents). Logical volume VolGroup1/lvData1 successfully resized. [[email protected] ~]# vgdisplay — Volume group — VG Name VolGroup1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 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 119.99 GiB PE Size 4.00 MiB Total PE 30718 Alloc PE / Size 30718 / 119.99 GiB Free PE / Size 0 / 0 VG UUID XPA6Ew-9acE-4bTq-8YRy-GE4D-FqBV-KPC82v

— Volume group — VG Name cl 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 75.00 GiB PE Size 4.00 MiB Total PE 19199 Alloc PE / Size 19198 / 74.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID vw5vsX-S9Sg-jaBl-Ak7F-DbWg-LoFA-fNsjyY

[[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 48G 4.9G 43G 11% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 144K 1.9G 1% /dev/shm tmpfs 1.9G 9.0M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 148M 867M 15% /boot /dev/mapper/cl-home 24G 33M 24G 1% /home /dev/mapper/VolGroup1-lvData1 99G 61M 94G 1% /oracle tmpfs 378M 12K 378M 1% /run/user/0 8、擴容檔案系統 [[email protected] ~]# resize2fs /dev/VolGroup1/lvData1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/VolGroup1/lvData1 is mounted on /oracle; on-line resizing required old_desc_blocks = 13, new_desc_blocks = 15 The filesystem on /dev/VolGroup1/lvData1 is now 31455232 blocks long.

[[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 48G 4.9G 43G 11% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 144K 1.9G 1% /dev/shm tmpfs 1.9G 9.0M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 148M 867M 15% /boot /dev/mapper/cl-home 24G 33M 24G 1% /home /dev/mapper/VolGroup1-lvData1 118G 60M 113G 1% /oracle tmpfs 378M 12K 378M 1% /run/user/0 [[email protected] ~]#

刪除和解除安裝磁碟 1.umount /app 2.修改/etc/fstab 3.lvremove /dev/VolGroup1/lvData1 4.vgremove VolGroup1 5.pvremove /dev/sdb1 6.pvs 7.vgs 8/lvs

常用命令 1、 物理卷命令 一般維護命令: #pvscan //在系統的所有磁碟中搜索已存在的物理卷 #pvdisplay 物理卷全路徑名稱 //用於顯示指定物理卷的屬性。 #pvdata 物理卷全路徑名稱 //用於顯示物理卷的卷組描述區域資訊,用於除錯目的。 #pvchange –x|–allocation {y|n} 物理卷全路徑名 //用於改變物理卷的分配許可設定物理卷的建立與刪除命令 #pvcreate 裝置全路徑名 //用於在磁碟或磁碟分割槽上建立物理卷初始化資訊,以便對該物理捲進行邏輯卷管理。 #pvmove 源物理卷全路徑我[目的物理卷全路徑名] //用於把某物理卷中的資料轉移到同卷組中其他的特刊卷中。 2、 卷組命令 一般維護命令 #vgscan //檢測系統中所有磁碟 #vgck [卷組名] //用於檢查卷組中卷組描述區域資訊的一致性。 #vgdisplay [卷組名] //顯示卷組的屬性資訊 #vgrename 原卷組名 新卷組名 #vgchange -a y|n [卷組名] //改變卷組的相應屬性。是否可分配 #vgchange -l 最大邏輯卷數 //卷組可容納最大邏輯卷數 #vgchange -x y|n [卷組名] //卷是否有效 #vgmknodes [卷組名|卷組路徑] //用於建立(重新建立)已有卷組目錄和其中的裝置檔案 //卷組配置的備份與恢復命令 #vgcfgbackup [卷組名] //把卷組中的VGDA資訊備份到“/etc/lvmconf”目錄中的檔案 #vgcfgrestore -n 卷組名 物理卷全路命名 //從備份檔案中必得指定物理卷的資訊 卷組的建立與刪除命令 #vgcreate 卷組名 物理卷全路徑名[物理卷全路徑名] #vgmove 卷組名 卷組的擴充與縮小命令 #vgextend 卷組名 物理卷全路徑名[物理卷全路徑名] #vgreduce 卷組名 物理卷全路徑名[物理卷全路徑名] 卷組的合併與拆分 #vgmerge 目的卷組名 源卷組名 //合併兩個已經存在的卷組,要求兩個卷組的物理區域大小相等且源卷組是非活動的。 #vgsplit 現有卷組 新卷組 物理卷全路徑名[物理卷全路徑名] 卷組的輸入與輸出命令 #vgexport 卷組名 #vgimport 卷組名 卷組中的物理卷[卷組中的物理卷] 3、 邏輯卷命令 一般命令 #lvscan #lvdisplay 邏輯卷全路徑名[邏輯卷全路徑名] #lvrename 舊邏輯卷全路徑名 新邏輯卷全路徑名 #lvrename 卷組名 舊邏輯卷名 新邏輯卷名 #lvchange #e2fsadm -L +|- 邏輯卷增減量 邏輯卷全路徑名 邏輯卷的建立與刪除命令 #lvcreate #lvremove 邏輯卷的擴充與縮小命令 #lvextend -L|–size +邏輯卷大小增量 邏輯卷全路徑名 #lvreduce q -L|–size +邏輯卷減小量 邏輯卷全路徑名 4、 邏輯卷管理命令 #lvmdiskscan //檢測所有的SCSI、IDE等儲存裝置 #lvmchange -R|–reset //復位邏輯卷管理器 #lvmsadc [日誌檔案全路徑名] //收信邏輯卷管理器讀寫統計資訊,儲存到日誌文 //件中。 #lvmsar 日誌檔案全路徑名 //從lvmsadc命令生成的日誌檔案中讀取並報告邏輯卷