lVM邏輯卷管理相關總結

來源:互聯網
上載者:User

標籤:cccccc   style   color   

建立、管理LVM:

建立分區

Disk /dev/xvdc: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xd199e24a    Device Boot      Start         End      Blocks   Id  System/dev/xvdc1               1          65      522081   8e  Linux LVM #調整分區類型為 Linux LVM/dev/xvdc2              66         104      313267+  8e  Linux LVM/dev/xvdc3             105         181      618502+  8e  Linux LVM

建立PV:

pvcreate  /path/to/device 建立物理卷

[[email protected]_168_102_centos ~]# pvcreate /dev/xvdc{1,2,3}  Writing physical volume data to disk "/dev/xvdc1"  Physical volume "/dev/xvdc1" successfully created  Writing physical volume data to disk "/dev/xvdc2"  Physical volume "/dev/xvdc2" successfully created  Writing physical volume data to disk "/dev/xvdc3"  Physical volume "/dev/xvdc3" successfully created

pvs [ /path/to/pv_device ] 查看現有物理卷

[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1      lvm2 a--  509.84m 509.84m  /dev/xvdc2      lvm2 a--  305.93m 305.93m  /dev/xvdc3      lvm2 a--  604.01m 604.01m[[email protected]_168_102_centos ~]# pvs /dev/xvdc1  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1      lvm2 a--  509.84m 509.84m

pvdisplay [ /path/to/pv_device ] 顯示物理卷屬性

[[email protected]_168_102_centos ~]# pvdisplay /dev/xvdc1  "/dev/xvdc1" is a new physical volume of "509.84 MiB"  --- NEW Physical volume ---  PV Name               /dev/xvdc1  #pv名字  VG Name                           #所屬VG組         PV Size               509.84 MiB  #PV大小  Allocatable           NO  PE Size               0 #pe大小,預設4     Total PE              0 #pe總計數量    Free PE               0 #空閑pe數量  Allocated PE          0 #被分配的PE數量   PV UUID               sCID3E-GNNl-DoeW-BaLW-kuYj-fskV-RhLx8g

建立VG卷組:

vgcreate [-s SIZE] vg_name /path/to/pv_device

-s:指定PE大小,預設4MB

[[email protected]_168_102_centos ~]# vgcreate -s 8 myvg /dev/xvdc{1,2}  Volume group "myvg" successfully created

vgs [ /path/to/vg_device ] 查看現有卷組

[[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize   VFree    myvg   2   0   0 wz--n- 808.00m 808.00m

vgdisplay [ /path/to/vg_device ] 查看卷組屬性

[[email protected]_168_102_centos ~]# vgdisplay   --- Volume group ---  VG Name               myvg  System ID               Format                lvm2  Metadata Areas        2  Metadata Sequence No  1  VG Access             read/write  VG Status             resizable  MAX LV                0  Cur LV                0  Open LV               0  Max PV                0  Cur PV                2  Act PV                2  VG Size               808.00 MiB  PE Size               8.00 MiB  Total PE              101  Alloc PE / Size       0 / 0     Free  PE / Size       101 / 808.00 MiB  VG UUID               R35yt2-S4dp-M9oY-4O1d-1CqX-4CQd-t0TpB9

vgrename vg_name new_name 修改卷組名稱

[[email protected]_168_102_centos ~]# vgrename myvg testvg  Volume group "myvg" successfully renamed to "testvg"[[email protected]_168_102_centos ~]# vgs  VG     #PV #LV #SN Attr   VSize   VFree    testvg   2   0   0 wz--n- 808.00m 808.00m

建立邏輯卷:

lvcreate –L size –n name  vg_name 建立邏輯卷

[[email protected]_168_102_centos ~]# lvcreate -L 500M -n mylv /dev/myvg  Rounding up size to full physical extent 504.00 MiB  Logical volume "mylv" created

lvs [ /path/to/lv_device ] 查看現有邏輯卷

[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-a--- 504.00m

lvdisplay [ /path/to/lv_device ] 查看邏輯卷屬性

/path/to/lv_device[[email protected]_168_102_centos ~]# lvdisplay   --- Logical volume ---  LV Path                /dev/myvg/mylv  LV Name                mylv  VG Name                myvg  LV UUID                nnelF1-sSxC-0A1l-IzLf-YqwL-djsy-lMeiTH  LV Write Access        read/write  LV Creation host, time VM_168_102_centos, 2014-08-24 16:12:08 +0800  LV Status              available  # open                 0  LV Size                504.00 MiB  Current LE             63  Segments               1  Allocation             inherit  Read ahead sectors     auto  - currently set to     256  Block device           253:7

講mylv2邏輯據進行格式化掛載:

[[email protected]_168_102_centos ~]# mke2fs -t ext4 /dev/myvg/mylvmke2fs 1.41.12 (17-May-2010)...省略This filesystem will be automatically checked every 26 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.[[email protected]_168_102_centos ~]# mount /dev/myvg/mylv /tmp/wanghan[[email protected]_168_102_centos ~]# mount /dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,mode=0620,gid=5)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)/dev/mapper/myvg-mylv on /tmp/wanghan type ext4 (rw)

將myvg剩餘的空間分配200M給mylv2:

[[email protected]_168_102_centos ~]# lvcreate -L 200M -n mylv2 /dev/myvg  Logical volume "mylv2" created[[email protected]_168_102_centos ~]# lvs  LV    VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv  myvg -wi-a--- 504.00m                                             mylv2 myvg -wi-a--- 200.00m                                           [[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize   VFree    myvg   2   2   0 wz--n- 808.00m 104.00m

移除mylv2邏輯卷:

lvremove [ /path/to/lv_device ] 移除指定邏輯卷

[[email protected]_168_102_centos ~]# lvremove /dev/myvg/mylv2Do you really want to remove active logical volume mylv2? [y/n]: y  Logical volume "mylv2" successfully removed[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-a--- 504.00m

擴充卷組:

準備好要添加的物理卷

[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1 myvg lvm2 a--  504.00m      0   /dev/xvdc2 myvg lvm2 a--  304.00m 304.00m  /dev/xvdc3      lvm2 a--  604.01m 604.01m

向卷組中添加物理卷

vgextend vg_name /path/to/pv_device

[[email protected]_168_102_centos ~]# vgextend /dev/myvg /dev/xvdc3  Volume group "myvg" successfully extended[[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize VFree    myvg   3   1   0 wz--n- 1.38g 904.00m[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1 myvg lvm2 a--  504.00m      0   /dev/xvdc2 myvg lvm2 a--  304.00m 304.00m  /dev/xvdc3 myvg lvm2 a--  600.00m 600.00m

縮減卷組

1、要移除的物理卷的總空間大小,要小於當前VG可用空間的大小

2、將要移除的PV上的資料移動至其他pv

pvmove 可以將一個PV上的資料移轉到新的PV上

[[email protected]_168_102_centos ~]# pvmove /dev/xvdc2  No data to move for myvg

3、將要指定的PV從VG中移除

vgreduce 從卷組中刪除物理卷

[[email protected]_168_102_centos ~]# vgreduce /dev/myvg /dev/xvdc2  Removed "/dev/xvdc2" from volume group "myvg"[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1 myvg lvm2 a--  504.00m      0   /dev/xvdc2      lvm2 a--  305.93m 305.93m  /dev/xvdc3 myvg lvm2 a--  600.00m 600.00m[[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize VFree    myvg   2   1   0 wz--n- 1.08g 600.00m

擴充邏輯卷:

1、確定要擴充的邏輯卷所屬的卷組有足夠的剩餘空間

2、擴充物理邊界(物理邊界:我們對一個磁碟進行分區的分區邊界)

lvextend 擴充邏輯卷空間

[[email protected]_168_102_centos ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/xvda1            7.9G  2.2G  5.3G  30% //dev/mapper/myvg-mylv                      489M   31M  433M   7% /tmp/wanghan[[email protected]_168_102_centos ~]# lvextend -L 700M /dev/myvg/mylv  Rounding size to boundary between physical extents: 704.00 MiB  Extending logical volume mylv to 704.00 MiB  Logical volume mylv successfully resized[[email protected]_168_102_centos ~]# df -lhFilesystem            Size  Used Avail Use% Mounted on/dev/xvda1            7.9G  2.2G  5.3G  30% //dev/mapper/myvg-mylv                      489M   31M  433M   7% /tmp/wanghan

3、擴充邏輯邊界(邏輯邊界:我們格式化分區,建立檔案系統後形成的分區邊界)

resize2fs:檔案系統大小調整工具

[[email protected]_168_102_centos ~]# resize2fs /dev/myvg/mylvresize2fs 1.41.12 (17-May-2010)Filesystem at /dev/myvg/mylv is mounted on /tmp/wanghan; on-line resizing requiredold desc_blocks = 2, new_desc_blocks = 3Performing an on-line resize of /dev/myvg/mylv to 720896 (1k) blocks.The filesystem on /dev/myvg/mylv is now 720896 blocks long.[[email protected]_168_102_centos ~]# df -lhFilesystem            Size  Used Avail Use% Mounted on/dev/xvda1            7.9G  2.2G  5.3G  30% //dev/mapper/myvg-mylv                      682M   31M  616M   5% /tmp/wanghan[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-ao-- 704.00m

縮減邏輯卷(有風險,不推薦):

1、卸載卷,並執行強制檢測

[[email protected]_168_102_centos ~]# umount /dev/myvg/mylv[[email protected]_168_102_centos ~]# e2fsck -f /dev/myvg/mylve2fsck 1.41.12 (17-May-2010)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/myvg/mylv: 1307/180224 files (0.2% non-contiguous), 54323/720896 blocks

2、先縮減邏輯邊界

[[email protected]_168_102_centos ~]# resize2fs /dev/myvg/mylv 400Mresize2fs 1.41.12 (17-May-2010)Resizing the filesystem on /dev/myvg/mylv to 409600 (1k) blocks.The filesystem on /dev/myvg/mylv is now 409600 blocks long.

3、再縮減物理邊界

[[email protected]_168_102_centos ~]# lvreduce -L 400M /dev/myvg/mylv  WARNING: Reducing active logical volume to 400.00 MiB  THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce mylv? [y/n]: y  Reducing logical volume mylv to 400.00 MiB  Logical volume mylv successfully resized[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-a--- 400.00m

快照卷:

1、生命週期為整個資料時間長度,在這段時間長度內,資料的增長量不能超出快照卷大小2、快照卷應該是唯讀3、跟原卷在同一卷組內
[[email protected]_168_102_centos ~]# lvcreate -s -L 50M -n snap-mylv -p r /dev/myvg/mylv  Rounding up size to full physical extent 56.00 MiB  Logical volume "snap-mylv" created[[email protected]_168_102_centos ~]# lvs  LV        VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv      myvg owi-a-s- 400.00m                                             snap-mylv myvg sri-a-s-  56.00m      mylv     0.00
 

lVM邏輯卷管理相關總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.