linux 之LVM

liqilin0429發表於2011-06-08
LVM
      LVM(Logicl Volume Manager),邏輯卷管理器,通過使用邏輯卷管理器對硬碟儲存裝置進行管理,可以實現硬碟空間的動態劃分和調整。

PE(Physical Extent)物理區域  物理區域是物理卷中可用於分配的最小儲存單元,物理區域的大小可根據實際情況在建立物理卷時指定。物理區域大小一旦確定將不能更改,同一卷組中 的所有物理卷的物理區域大小需要一致。
LE(Logical Extent)邏輯區域 邏輯區域是邏輯卷中可用於分配的最小儲存單元,邏輯區域的大小取決於邏輯卷所在卷組中的物理區域的大小。
pv------&gtvg------&gtlv
PV(Physical Volume)物理卷 物理卷在邏輯卷管理中處於最底層,它可以是實際物理硬碟上的分割槽,也可以是整個物理硬碟(也即使為一個硬碟如sdb,sdc,sdd,sde ;也可以為一個硬碟裡 面的一個分割槽如sdb1,sdc1,sdc2)。
1 對物理磁碟進行分割槽操作,並把標卷屬性設定成8e(假如有4塊磁碟,依次進行分割槽並設定成LVM分割槽格式)
[root@weblogic-primary ~]# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +2048M
Command (m for help): t 
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2 建立物理卷
[root@weblogic-primary ~]# pvcreate /dev/sd[bcde]1    --建立4個物理卷
  Physical volume "/dev/sdb1" successfully created
  Physical volume "/dev/sdc1" successfully created
  Physical volume "/dev/sdd1" successfully created
  Physical volume "/dev/sde1" successfully created
3 檢視物理卷
[root@weblogic-primary ~]# pvs   --檢視pv的數量
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb1       lvm2 --   1.92G 1.92G
  /dev/sdc1       lvm2 --   1.92G 1.92G
  /dev/sdd1       lvm2 --   1.92G 1.92G
  /dev/sde1       lvm2 --   1.92G 1.92G    
[root@weblogic-primary ~]# pvscan
  PV /dev/sdb1                      lvm2 [1.92 GB]
  PV /dev/sdc1                      lvm2 [1.92 GB]
  PV /dev/sdd1                      lvm2 [1.92 GB]
  PV /dev/sde1                      lvm2 [1.92 GB]
  Total: 4 [7.66 GB] / in use: 0 [0   ] / in no VG: 4 [7.66 GB]
[root@weblogic-primary ~]# pvdisplay  --檢視詳細資訊
4 修改物理卷
VG(Volumne Group)卷組 卷組建立在物理卷之上,一個卷組中至少要包括一個物理卷,在卷組建立之後可動態新增物理捲到卷組中
1 建立卷組
[root@weblogic-primary ~]# vgcreate vg_data /dev/sd[bc]1  --建立一個卷組名稱為vg_data的卷組,物理捲成員是sdb1和sdc1
2 檢視眷組
[root@weblogic-primary ~]# vgs   --檢視VG數量和使用情況
  VG      #PV #LV #SN Attr   VSize VFree
  vg_data   2   0   0 wz--n- 3.83G 3.83G
[root@weblogic-primary ~]# vgdisplay   --詳細列出PV的資訊
  --- Volume group ---
  VG Name               vg_data
  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               3.83 GB
  PE Size               4.00 MB
  Total PE              980
  Alloc PE / Size       0 / 0  
  Free  PE / Size       980 / 3.83 GB
  VG UUID               s261r1-NWLN-jB5f-CgfB-1ebx-zlWS-32uCmE
3 備份卷組
[root@weblogic-primary ~]# vgcfgbackup -f vg_data_bak vg_data  --備份一個名為vg_data的卷組成vg_data_bak到當前目錄下
  Volume group "vg_data" successfully backed up.
4 恢復備份的卷組
[root@weblogic-primary ~]# vgcfgrestore -f vg_data_bak vg_data   --恢復一個名為vg_data_bak的VG備份到當前名為vg_data
  /dev/cdrom: open failed: Read-only file system
  Restored volume group vg_data
5 啟用當前恢復的卷組
[root@weblogic-primary ~]# vgchange -ay   --啟用所有的卷組
  0 logical volume(s) in volume group "vg_data" now active
6 新增lv到卷組vg_data中
  a 對物理磁碟進行分割槽操作,並
[root@weblogic-primary ~]# fdisk /dev/sdb
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (251-522, default 251):
Using default value 251
Last cylinder or +size or +sizeM or +sizeK (251-522, default 522): +2048M
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
  
  b 把標卷屬性設定成8e
[root@weblogic-primary ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): w  
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
  c 建立物理卷
[root@weblogic-primary ~]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created
  d 新增物理捲到卷組
[root@weblogic-primary ~]# vgextend vg_data /dev/sdb2
  /dev/cdrom: open failed: Read-only file system
  /dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  Volume group "vg_data" successfully extended
 
  e 檢視卷組情況
  [root@weblogic-primary ~]# pvs
  PV         VG      Fmt  Attr PSize PFree
  /dev/sdb1  vg_data lvm2 a-   1.91G 1.91G
  /dev/sdb2  vg_data lvm2 a-   1.91G 1.91G
  /dev/sdc1  vg_data lvm2 a-   1.91G 1.91G
  /dev/sdd1          lvm2 --   1.92G 1.92G
  /dev/sde1          lvm2 --   1.92G 1.92G

LV(Logical Volume)邏輯卷 邏輯卷建立在卷組之上,卷組中的未分配空間可以用於建立新的邏輯卷,邏輯卷建立後可以動態地擴充套件和縮小空間。
系統中的多個邏輯卷可以屬於同一個卷組,也可以屬於不同的多個卷組。
一個邏輯卷管理系統工程中可以只有一個卷組,也可以擁有多個卷組。
1 建立邏輯卷
[root@weblogic-primary ~]# lvcreate -L 1024M -n lv_archive_3 vg_arc  --建立邏輯卷lv_archive_3到卷組vg_arc中(-L表示建立邏輯卷lv_archive_3的大小,-n表示建立邏輯卷的名稱 ,vg_arc卷組名稱)
2 擴張邏輯卷的容量
a 檢視當前的邏輯卷的容量
[root@weblogic-primary ~]# lvscan
  ACTIVE            '/dev/vg_data/lv_data_1' [1.00 GB] inherit
b 增加容量
[root@weblogic-primary ~]# lvextend -L +512M /dev/vg_data/lv_data_1    
  /dev/cdrom: open failed: Read-only file system
  Extending logical volume lv_data_1 to 1.50 GB
  Logical volume lv_data_1 successfully resized

3 檢視邏輯卷
[root@weblogic-primary ~]# lvdisplay                   --檢視所有的邏輯卷
[root@weblogic-primary ~]# lvdisplay vg_arc            --檢視卷組vg_arc有哪些邏輯卷
[root@weblogic-primary ~]# lvscan                      --檢視被啟用的所有邏輯卷
4 刪除邏輯卷
5 分割槽格式化
[root@weblogic-primary ~]# mkfs.ext3 /dev/vg_arc/lv_archive_1
[root@weblogic-primary ~]# mkfs -j /dev/vg_arc/lv_archive_2
6 掛載新分割槽
[root@weblogic-primary home]# mkdir archive_1
[root@weblogic-primary home]# mkdir archive_2
[root@weblogic-primary home]# mount /dev/vg_arc/lv_archive_1 /home/archive_1
[root@weblogic-primary home]# mount /dev/vg_arc/lv_archive_2 /home/archive_2
7 永久寫入啟動項
vi /etc/fstab
8 檢視掛載情況
[root@weblogic-primary ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              37G   13G   22G  38% /
/dev/sda1             190M   12M  169M   7% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/mapper/vg_arc-lv_archive_1
                     1008M   34M  924M   4% /home/archive_1
/dev/mapper/vg_arc-lv_archive_2
                      516M   17M  474M   4% /home/archive_2
 
 
 
 
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20976446/viewspace-697416/,如需轉載,請註明出處,否則將追究法律責任。

相關文章