yum服務器lvm擴容,data目錄是yum存放rpm包的目錄,只有20G,須要添加磁盤擴容到80G # df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_node5-root 20G 479M 18G 3% / tmpfs 935M 0 935M 0% /dev/shm /dev/sda1 485M 39M 421M 9% /boot /dev/mapper/vg_node5-data 20G 172M 19G 1% /data /dev/mapper/vg_node5-usr 9.7G 1.6G 7.6G 18% /usr /dev/mapper/vg_node5-web 15G 165M 14G 2% /web 1.添加一塊硬盤 2.對硬盤分區,並將格式調整爲8e即linux lvm格式 #掛載系統分區 # kpartx -l /dev/sdb # kpartx -af /dev/sdb # partx -a /dev/sdb 3.建立物理卷 在將幾塊盤作LVM時,遇到一個以前都沒遇到過的問題: # pvcreate /dev/sdb5 Can't open /dev/sdb5 exclusively. Mounted filesystem? 首先第一反應就是查看這個分區是否已經在使用了,可是沒有。 查看硬盤的一些信息: # cat /proc/partitions major minor #blocks name 8 0 83886080 sda 8 1 512000 sda1 8 2 83373056 sda2 8 16 125829120 sdb 8 17 1 sdb1 8 21 125796982 sdb5 253 0 20480000 dm-0 253 1 4096000 dm-1 253 2 15360000 dm-2 253 3 20480000 dm-3 253 4 10240000 dm-4 253 5 1 dm-5 253 6 125796982 dm-6 # fdisk /dev/sdb -l Disk /dev/sdb: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 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: 0x44c662ff Device Boot Start End Blocks Id System /dev/sdb1 1 15665 125829081 5 Extended /dev/sdb5 5 15665 125796982+ 8e Linux LVM 接着看一些底層的信息: dmsetup 是一個底層的邏輯卷管理, dm 應該是 Device Mapper的簡稱。 [root@node5 /]# dmsetup status sdb1: 0 2 linear vg_node5-web: 0 30720000 linear sdb5: 0 251593965 linear vg_node5-usr: 0 20480000 linear vg_node5-swap: 0 8192000 linear vg_node5-root: 0 40960000 linear vg_node5-data: 0 40960000 linear [root@node5 /]# dmsetup ls sdb1 (253:5) vg_node5-web (253:2) sdb5 (253:6) vg_node5-usr (253:4) vg_node5-swap (253:1) vg_node5-root (253:0) vg_node5-data (253:3) 例如: root@ubuntu:~# dmsetup ls 35000c50026716847 (254, 2) vg_data-lv_home (254, 0) 35000c5002670f03e (254, 3) 35000c5002670f03e-part1 (254, 5) 35000c50026716847-part1 (254, 4) vg_data-lv_swap (254, 1) 能夠看到 35000c5002670f03e 和 35000c50026716847 組成了multipath(多路徑) # ll /dev/mapper/ total 0 crw-rw---- 1 root root 10, 58 Jul 26 19:51 control lrwxrwxrwx 1 root root 7 Jul 26 19:59 vg_node5-data -> ../dm-3 lrwxrwxrwx 1 root root 7 Jul 26 19:59 /dev/sdb1 -> ../dm-5 lrwxrwxrwx 1 root root 7 Jul 26 19:59 /dev/sdb5 -> ../dm-6 lrwxrwxrwx 1 root root 7 Jul 26 19:59 vg_node5-root -> ../dm-0 lrwxrwxrwx 1 root root 7 Jul 26 19:59 vg_node5-swap -> ../dm-1 lrwxrwxrwx 1 root root 7 Jul 26 19:59 vg_node5-usr -> ../dm-4 lrwxrwxrwx 1 root root 7 Jul 26 19:59 vg_node5-web -> ../dm-2 使用 dmsetup remove xxx 移除掉就能夠建立PV了: # dmsetup remove /dev/sdb1 # dmsetup remove /dev/sdb5 從新建立物理捲成功 root@ubuntu:~# pvcreate /dev/sdb5 Physical volume "/dev/sdb5" successfully created 也能夠使用dmsetup remove_all移除全部。 # vgdisplay --- Volume group --- VG Name vg_node5 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 5 Open LV 5 Max PV 0 Cur PV 1 Act PV 1 VG Size 79.51 GiB PE Size 4.00 MiB Total PE 20354 Alloc PE / Size 17250 / 67.38 GiB Free PE / Size 3104 / 12.12 GiB VG UUID tNuKXc-UdQO-Z8BK-ZtOQ-W93k-pqui-HAxKja 4.對物理卷vg_node5進行擴容 # vgextend vg_node5 /dev/sdb5 Volume group "vg_node5" successfully extended [root@node5 ~]# vgs VG #PV #LV #SN Attr VSize VFree vg_node5 2 5 0 wz--n- 199.47g 132.09g 將邏輯卷vg_node5-data即/data分區擴容到80G [root@node5 ~]# lvextend -L 80G /dev/mapper/vg_node5-data Extending logical volume data to 80.00 GiB Logical volume data successfully resized 從新讀取大小 [root@node5 ~]# resize2fs /dev/mapper/vg_node5-data resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_node5-data is mounted on /data; on-line resizing required old desc_blocks = 2, new_desc_blocks = 5 Performing an on-line resize of /dev/mapper/vg_node5-data to 20971520 (4k) blocks. The filesystem on /dev/mapper/vg_node5-data is now 20971520 blocks long. [root@node5 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_node5-root 20G 479M 18G 3% / tmpfs 935M 0 935M 0% /dev/shm /dev/sda1 485M 39M 421M 9% /boot /dev/mapper/vg_node5-data 79G 184M 75G 1% /data /dev/mapper/vg_node5-usr 9.7G 1.6G 7.6G 18% /usr /dev/mapper/vg_node5-web 15G 165M 14G 2% /web