cd / && dd if=/dev/zero of=file bs=1M count=10000 將磁盤變大的測試命令. 生產環境不要用. 這只是用於測試擴容後的效果
pvdisplay 查看檢查pv pvremove /dev/sdb #清除一個pv vgremove [vg名] #清除一個vg lvremove [lv名] #清除一個lv fdisk -l 檢查磁盤 df -h 檢查所有磁盤大小 df -Th 檢查磁盤大小和分區格式類型 pvdisplay 檢查pv vgdisplay 檢查vg lvdisplay 檢查lv
echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -" > /sys/class/scsi_host/host1/scan echo "- - -" > /sys/class/scsi_host/host2/scan
[root@localhost /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 40G 9.6G 31G 24% / devtmpfs 982M 0 982M 0% /dev tmpfs 993M 0 993M 0% /dev/shm tmpfs 993M 8.7M 984M 1% /run tmpfs 993M 0 993M 0% /sys/fs/cgroup /dev/sda1 197M 103M 95M 53% /boot tmpfs 199M 0 199M 0% /run/user/0
注意: /dev/mapper/centos-root 是邏輯卷的路徑.node
[root@localhost /]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 19.80 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 5069 Free PE 0 Allocated PE 5069 PV UUID 4YLVja-jT6q-FphK-3E60-5Qde-Z3gw-zLpcYT --- Physical volume --- PV Name /dev/sdb1 VG Name centos PV Size <20.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 5119 Free PE 0 Allocated PE 5119 PV UUID SBfuCJ-tli0-Mi2U-wO3w-eQub-0v36-0XkQBw
[root@localhost ~]# vgdisplay --- Volume group --- VG Name centos 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 19.80 GiB PE Size 4.00 MiB Total PE 5069 Alloc PE / Size 5069 / 19.80 GiB Free PE / Size 0 / 0 VG UUID lkJhAi-7Df5-0K69-LYV4-exS2-ZqE1-FYMyIG
[root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID tUUfhM-dDfU-Aw6K-tiAj-wyqf-cvbl-FcLOxj LV Write Access read/write LV Creation host, time localhost.localdomain, 2019-11-22 04:12:42 +0800 LV Status available # open 1 LV Size 19.80 GiB Current LE 5069 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
1. 加入磁盤 2. 檢查磁盤id 修改爲須要擴容的磁盤ID一致,經過fdisk -l 能夠查看ID [root@localhost ~]# fdisk -l /dev/sda ..... Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 41943039 20765696 8e Linux LVM 能夠看到ID是 8e LVM,因此新加入的磁盤也須要改成 8e 3. 建立物理卷 pv 4. pv加入vg卷組 5. 擴容磁盤 6. 格式化磁盤 7. 結束
xxx 本身意淫把linux
掃描: echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -" > /sys/class/scsi_host/host1/scan echo "- - -" > /sys/class/scsi_host/host2/scan
## 建立分區並修改磁盤格式爲 [8e]: fdisk /dev/sdc [操做新磁盤] [root@localhost /]# 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 0xc7dec5f2. Command (m for help): n #####-----建立分區 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p #####-----建立默認主分區[主分區總共就只能分出4個超過4個須要建立擴展分區] Partition number (1-4, default 1): First sector (2048-62914559, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559): Using default value 62914559 Partition 1 of type Linux and of size 30 GiB is set Command (m for help): t #####-----更改磁盤格式 Selected partition 1 Hex code (type L to list all codes): 8e #####-----更改成8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p ### 查看一下是否是 8e Disk /dev/sdc: 32.2 GB, 32212254720 bytes, 62914560 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: 0xc7dec5f2 Device Boot Start End Blocks Id System /dev/sdc1 2048 62914559 31456256 8e Linux LVM #確實已是8e了 Command (m for help): w #####-----保存 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ##分區和磁盤格式更改完畢
# 建立物理卷 pvcreate /dev/sdc1 [root@localhost /]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created. # 物理卷加入刀 centos 這個 vg 中 [root@localhost /]# vgextend centos /dev/sdc1 Volume group "centos" successfully extended
vgdisplay [root@localhost /]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 69.79 GiB PE Size 4.00 MiB Total PE 17867 Alloc PE / Size 10188 / <39.80 GiB Free PE / Size 7679 / <30.00 GiB ###這是剩餘PE數量, 7679,也是新增的30G磁盤,7679個PE VG UUID lkJhAi-7Df5-0K69-LYV4-exS2-ZqE1-FYMyIG
#先看目前磁盤狀況: [root@localhost /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 40G 9.6G 31G 24% / ## 31G. devtmpfs 982M 0 982M 0% /dev tmpfs 993M 0 993M 0% /dev/shm tmpfs 993M 8.7M 984M 1% /run tmpfs 993M 0 993M 0% /sys/fs/cgroup /dev/sda1 197M 103M 95M 53% /boot tmpfs 199M 0 199M 0% /run/user/0 # 擴容並格式化磁盤: lvresize -r -l +7679 /dev/centos/root #結果: [root@localhost /]# lvresize -r -l +7679 /dev/centos/root Size of logical volume centos/root changed from <39.80 GiB (10188 extents) to 69.79 GiB (17867 extents). Logical volume centos/root successfully resized. meta-data=/dev/mapper/centos-root isize=512 agcount=9, agsize=1297664 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=10432512, 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 10432512 to 18295808 #這是將全部PE都劃分給了 /dev/centos/root , 其中 -r 是劃分的同時格式化這塊新磁盤,並加入到 該分區中. #也就是本身先格式化後擴容給/dev/centos/root 磁盤 . #這種方法是按照PE個數來劃分磁盤的, 磁盤總大小就是 磁盤總大小 = PE個數 * PE size
# 查看現有磁盤大小: [root@localhost /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 70G 9.6G 61G 14% / ##-----擴容成功,磁盤從 32%降低到了14 ,大小也變成了 61G devtmpfs 982M 0 982M 0% /dev tmpfs 993M 0 993M 0% /dev/shm tmpfs 993M 8.7M 984M 1% /run tmpfs 993M 0 993M 0% /sys/fs/cgroup /dev/sda1 197M 103M 95M 53% /boot tmpfs 199M 0 199M 0% /run/user/0 ## 31G+擴容給的 30G一共是 61G 所有劃分正確.
[root@localhost ~]# blkid /dev/sda1: UUID="cb322c86-f37a-49e8-86a0-924d9b0c719e" TYPE="xfs" /dev/sda2: UUID="4YLVja-jT6q-FphK-3E60-5Qde-Z3gw-zLpcYT" TYPE="LVM2_member" /dev/sdb1: UUID="SBfuCJ-tli0-Mi2U-wO3w-eQub-0v36-0XkQBw" TYPE="LVM2_member" /dev/sdc1: UUID="Z7K8RO-denr-cyn8-sCjb-9HMa-Pu3I-ciK3kt" TYPE="LVM2_member" /dev/sr0: UUID="2017-09-06-10-51-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" /dev/mapper/centos-root: UUID="e3508edd-30c0-4e7d-9d8f-622c8dbd174e" TYPE="xfs"
擴容完成.centos
lvm01.pdfapp