LVM:邏輯卷管理,可以動态的管理分區,任意擴容
準備磁盤分區
1、[root@test76 ~]# fdisk /dev/sdb
2、指令n 建立3個分區為1G
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 396 1060290 83 Linux
3、指令t 更改分區類型為8e
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x3cdb107b
/dev/sdb1 1 132 1060258+ 8e Linux LVM
/dev/sdb2 133 264 1060290 8e Linux LVM
/dev/sdb3 265 396 1060290 8e Linux LVM
4、準備實體卷
[root@test76 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@test76 ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@test76 ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created
5、列出目前的實體卷
[root@test76 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup lvm2 a-- 9.51g 0
/dev/sdb1 lvm2 --- 1.01g 1.01g
/dev/sdb2 lvm2 --- 1.01g 1.01g
/dev/sdb3 lvm2 --- 1.01g 1.01g
删除實體卷
[root@test76 ~]# pvremove /dev/sdb3
6、準備卷組
[root@test76 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
Volume group "vg1" successfully created
7、列出卷組
[root@test76 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 9.51g 0
vg1 3 0 0 wz--n- 3.02g 3.02g
8、删除
[root@test76 ~]# vgremove vg1
9、建立邏輯卷
[root@test76 ~]# lvcreate -L 200M -n lv1 vg1
Logical volume "lv1" created.
10、列出邏輯卷
[root@test76 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID RVgYEp-6wM3-YFq5-C69S-Crp7-53ec-YoQh8S
LV Write Access read/write
LV Creation host, time test76, 2017-10-19 08:20:09 +0800
LV Status available
# open 0
LV Size 200.00 MiB
Current LE 50
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID NOtLqX-KqlD-cGnO-mqhm-eAj1-dMUe-31JACU
LV Creation host, time localhost.localdomain, 2017-09-03 07:24:07 +0800
# open 1
LV Size 8.54 GiB
Current LE 2186
Block device 253:0
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
LV UUID 0LUNef-xqk6-NKRJ-6Kfm-AOoX-wEhw-exYwo2
LV Creation host, time localhost.localdomain, 2017-09-03 07:24:09 +0800
LV Size 992.00 MiB
Current LE 248
Block device 253:1
11、格式化,再挂載
meta-data=/dev/vg1/lv1 isize=256 agcount=4, agsize=12800 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=51200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=1200, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂載:
[root@test76 ~]# mount /dev/vg1/lv1 /newbackup/
[root@test76 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 246M 0 246M 0% /dev/shm
/dev/sda1 477M 33M 419M 8% /boot
/dev/mapper/vg1-lv1 196M 11M 186M 6% /newbackup
[root@test76 ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/vg1-lv1 on /newbackup type xfs (rw)
12、删除邏輯卷
[root@test76 ~]# lvremove /dev/vg1/lv1
擴充邏輯卷
1、重新設定卷大小
[root@test76 ~]# lvresize -L 300M /dev/vg1/lv1
2、這個是xfs檔案系統下執行
更新操作
[root@test76 ~]# xfs_growfs /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1 isize=256 agcount=4, agsize=12800 blks
log =internal bsize=4096 blocks=1200, version=2
data blocks changed from 51200 to 76800
/dev/mapper/VolGroup-lv_root
8.3G 4.2G 3.8G 53% /
/dev/mapper/vg1-lv1 296M 11M 286M 4% /newbackup #變為300M
ext4下執行:
resize2fs /dev/vg1/lv1 更新邏輯卷資訊(ext4執行)
縮減邏輯卷(xfs不支援)
1、umount
2、
e2fsck -f /dev/vg1/lv1 檢查磁盤錯誤(ext)
resize2fs /dev/vg1/lv1 100M 更新邏輯卷資訊(ext)
lvresize -L 100M /dev/vg1/lv1 重新設定卷大小
磁盤故障小案例
故障
Give root password for maintenance(or type Control-D to continue)
解決:輸入root密碼
1、fsck 檢測磁盤
2、reboot
本文轉自 jiekegz 51CTO部落格,原文連結:http://blog.51cto.com/jacksoner/1977511