關於LVMRedHat官方提供了一份文檔 LOGICAL VOLUME MANAGER ADMINISTRATION,詳細介紹了LVM及其使用。此內容在RedHat7的PDF版中有193頁,因時間原因,本文不打算使用此文檔詳細介紹LVM。而是結合CodingBee撰寫的RHCSA系列中的RHCSA-Logical Volume Management(LVM)來介紹LVM的使用。

本文將關注 * LVM中相關概念 * 創建、擴展、收縮、刪除邏輯卷及注意點 * 擴展swap分區

實驗在虛擬機Virtual Box中進行,操作系統是CentOS Linux release 7.2.1511 (Core)

LVM Introduction

在Linux中,LVM是一種設備映射器(device mapper),用於爲Linux內核提供邏輯卷管理(logical volume management)。在計算機存儲中,提供了一種在大存儲設備上分配空間的機制,較常規分區方案更爲靈活。一個volume manager可拼接(concatename),刪除(stripe)或合併分區到更大的虛擬分區中。管理者可在不中斷系統使用的情況下改變其大小或刪除。

In Linux, Logical Volume Manager (LVM) is a device mapper target that provides logical volume management for the Linux kernel. – Logical Volume Manager (Linux)

In computer storage, logical volume management or LVM provides a method of allocating space on mass-storage devices that is more flexible than conventional partitioning schemes. In particular, a volume manager can concatenate, stripe together or otherwise combine partitions (or block devices in general) into larger virtual ones that administrators can re-size or move, potentially without interrupting system use. – Logical volume management

以上兩段解釋來自Wikipedia相關詞條。

LVM用於創建、管理邏輯卷(logical volume)。一個邏輯卷(logical volume或LV)可認爲是在虛擬硬盤驅動器(virtual hdd)的一個分區。邏輯卷的存儲空間可跨多個塊設備,可以靈活的管理磁盤空間。LVM使用分區(pritition)分區管理存儲空間,大部分文件系統都可以運行在邏輯卷(LVs)上,但對一些核心目錄,如/boot目錄,需要有單獨的主分區或硬盤驅動器。

注意MBR不能存儲關於LVS的信息,不能將分區/boot掛在到邏輯卷(LV)上,因爲MBR沒辦法在邏輯卷上通過啓動流程。

Advantages Of LVM

  • 管理靈活
  • 更換硬盤驅動器簡單
  • 通過LVM快照(snapshots)的方式進行備份
  • 爲存在的LVM添加新磁盤驅動器簡單
  • 可創建數目近乎無限的邏輯卷(每個硬盤驅動器最多只能有15個分區)

Creating Procedure

  1. 從塊設備(block device)創建新物理卷(physical volume)
    • LVM的partiion-id是8e
    • 塊設備尚未被格式化且未被掛載
  2. 添加物理卷(physical volume)到卷組(volume group)中,如果卷組不存在,會自動創建
  3. 從卷組(volume group)中創建邏輯卷(logical volume)
  4. 安裝文件系統(格式化),掛載使用

注意:文件系統只能安裝在邏輯卷上,而不能安裝在物理卷或卷組上,它們只是創建邏輯卷的中間步驟。

LVM Commands

以下爲LVM中相關命令

[root@lvm ~]# lvm help
  Available lvm commands:
  Use 'lvm help <command>' for more information

  config          Display and manipulate configuration information
  devtypes        Display recognised built-in block device types
  dumpconfig      Display and manipulate configuration information
  formats         List available metadata formats
  help            Display help for commands
  lvchange        Change the attributes of logical volume(s)
  lvconvert       Change logical volume layout
  lvcreate        Create a logical volume
  lvdisplay       Display information about a logical volume
  lvextend        Add space to a logical volume
  lvmchange       With the device mapper, this is obsolete and does nothing.
  lvmconfig       Display and manipulate configuration information
  lvmdiskscan     List devices that may be used as physical volumes
  lvmsadc         Collect activity data
  lvmsar          Create activity report
  lvreduce        Reduce the size of a logical volume
  lvremove        Remove logical volume(s) from the system
  lvrename        Rename a logical volume
  lvresize        Resize a logical volume
  lvs             Display information about logical volumes
  lvscan          List all logical volumes in all volume groups
  pvchange        Change attributes of physical volume(s)
  pvresize        Resize physical volume(s)
  pvck            Check the consistency of physical volume(s)
  pvcreate        Initialize physical volume(s) for use by LVM
  pvdata          Display the on-disk metadata for physical volume(s)
  pvdisplay       Display various attributes of physical volume(s)
  pvmove          Move extents from one physical volume to another
  lvpoll          Continue already initiated poll operation on a logical volume
  pvremove        Remove LVM label(s) from physical volume(s)
  pvs             Display information about physical volumes
  pvscan          List all physical volumes
  segtypes        List available segment types
  systemid        Display the system ID, if any, currently set on this host
  tags            List tags defined on this host
  vgcfgbackup     Backup volume group configuration(s)
  vgcfgrestore    Restore volume group configuration
  vgchange        Change volume group attributes
  vgck            Check the consistency of volume group(s)
  vgconvert       Change volume group metadata format
  vgcreate        Create a volume group
  vgdisplay       Display volume group information
  vgexport        Unregister volume group(s) from the system
  vgextend        Add physical volumes to a volume group
  vgimport        Register exported volume group with system
  vgmerge         Merge volume groups
  vgmknodes       Create the special files for volume group devices in /dev
  vgreduce        Remove physical volume(s) from a volume group
  vgremove        Remove volume group(s)
  vgrename        Rename a volume group
  vgs             Display information about volume groups
  vgscan          Search for all volume groups
  vgsplit         Move physical volumes into a new or existing volume group
  version         Display software and driver version information
[root@lvm ~]#

Creating A Logical Volume

使用命令df -hlsblkmount可查看文件系統是否已經掛載。

Steps Of Createing LV

此處以/dev/sda爲例,創建物理卷/dev/sda3,卷組名vgtest,邏輯卷名lvmtest,分配空間8G,暫裝文件系統ext4,掛載到目錄/tmp/lvm下。

  1. 創建分區:fdsik /dev/sda
  2. 創建物理卷:pvcreate /dev/sda3
  3. 創建卷組:vgcreate vgtest /dev/sda3
  4. 創建邏輯卷並分配空間大小:lvcreate -n lvmtest -L 8G vgtest
  5. 安裝文件系統: mkfs.ext4 /dev/vgtest/lvmtest
  6. 創建掛載目錄: mkdir /tmp/lvm
  7. 掛載: mount /dev/vgtest/lvmtest /tmp/lvm
    • /etc/fstab中設置爲開機自動掛載: /dev/vgtest/lvmtest /tmp/lvm ext4 defaults 0 0
    • 掛載fstab中所有文件系統:mount -a

操作前

[root@lvm ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   58G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   32G  0 part
  ├─centos-root 253:0    0   30G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk
sr0              11:0    1 1024M  0 rom  
[root@lvm ~]#

Operations of Createing LV

場景設計 * 在硬盤驅動器/dev/sda/dev/sdb各創建2各磁盤分區 * /dev/sda上使用擴展分區,在/dev/sdb分別使用主分區和擴展分區 * /dev/sda上分區大小爲1.5G2G/dev/sdb2.5G3G * 創建卷組vglemp,包含2G2.5G的分區 * 創建2個邏輯卷,lvfirstlemp安裝ext4文件系統,大小2G;lvsecondlemp安裝xfs文件系統,大小1.5G * 掛載並使用

操作過程

Createing Disk Partition

  • /dev/sda創建磁盤分區
[root@lvm ~]# fdisk /dev/sda
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.


Command (m for help): p

Disk /dev/sda: 62.3 GB, 62277025792 bytes, 121634816 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: 0x0002e6ce

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    69224447    33562624   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e
Partition number (3,4, default 3):
First sector (69224448-121634815, default 69224448):
Using default value 69224448
Last sector, +sectors or +size{K,M,G} (69224448-121634815, default 121634815): 10G
Value out of range.
Last sector, +sectors or +size{K,M,G} (69224448-121634815, default 121634815): 10G
Value out of range.
Last sector, +sectors or +size{K,M,G} (69224448-121634815, default 121634815): ^C
[root@lvm ~]#
[root@lvm ~]# fdisk /dev/sda
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.


Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e
Partition number (3,4, default 3):
First sector (69224448-121634815, default 69224448):
Using default value 69224448
Last sector, +sectors or +size{K,M,G} (69224448-121634815, default 121634815): +10G
Partition 3 of type Extended and of size 10 GiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (69226496-90195967, default 69226496):
Using default value 69226496
Last sector, +sectors or +size{K,M,G} (69226496-90195967, default 90195967): +1500M
Partition 5 of type Linux and of size 1.5 GiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (72300544-90195967, default 72300544):
Using default value 72300544
Last sector, +sectors or +size{K,M,G} (72300544-90195967, default 90195967): +2G
Partition 6 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sda: 62.3 GB, 62277025792 bytes, 121634816 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: 0x0002e6ce

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    69224447    33562624   8e  Linux LVM
/dev/sda3        69224448    90195967    10485760    5  Extended
/dev/sda5        69226496    72298495     1536000   83  Linux
/dev/sda6        72300544    76494847     2097152   83  Linux

Command (m for help): t
Partition number (1-3,5,6, default 6): 5   
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t
Partition number (1-3,5,6, default 6): 6
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sda: 62.3 GB, 62277025792 bytes, 121634816 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: 0x0002e6ce

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    69224447    33562624   8e  Linux LVM
/dev/sda3        69224448    90195967    10485760    5  Extended
/dev/sda5        69226496    72298495     1536000   8e  Linux LVM
/dev/sda6        72300544    76494847     2097152   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@lvm ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-2
[root@lvm ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-3
partx: /dev/sda: error adding partitions 5-6
[root@lvm ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   58G  0 disk
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   32G  0 part
│ ├─centos-root 253:0    0   30G  0 lvm  /
│ └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
├─sda3            8:3    0    1K  0 part
├─sda5            8:5    0  1.5G  0 part
└─sda6            8:6    0    2G  0 part
sdb               8:16   0   10G  0 disk
sr0              11:0    1 1024M  0 rom  
[root@lvm ~]#
  • /dev/sdb創建磁盤分區 ``` [root@lvm ~]# fdisk /dev/sdb 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 0x3d1a9b1d.

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3d1a9b1d

Device Boot Start End Blocks Id System

Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2500M Partition 1 of type Linux and of size 2.5 GiB is set

Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): e Partition number (2-4, default 2): First sector (5122048-20971519, default 5122048): Using default value 5122048 Last sector, +sectors or +size{K,M,G} (5122048-20971519, default 20971519): +5G Partition 2 of type Extended and of size 5 GiB is set

Command (m for help): n Partition type: p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5) Select (default p): l Adding logical partition 5 First sector (5124096-15607807, default 5124096): Using default value 5124096 Last sector, +sectors or +size{K,M,G} (5124096-15607807, default 15607807): +3G Partition 5 of type Linux and of size 3 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3d1a9b1d

Device Boot Start End Blocks Id System /dev/sdb1 2048 5122047 2560000 83 Linux /dev/sdb2 5122048 15607807 5242880 5 Extended /dev/sdb5 5124096 11415551 3145728 83 Linux

Command (m for help): t Partition number (1,2,5, default 5): 1 Hex code (type L to list all codes): 8e Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3d1a9b1d

Device Boot Start End Blocks Id System /dev/sdb1 2048 5122047 2560000 8e Linux LVM /dev/sdb2 5122048 15607807 5242880 5 Extended /dev/sdb5 5124096 11415551 3145728 83 Linux

Command (m for help): w The partition table has been altered!

Calling ioctl() to re-read partition table. Syncing disks. [root@lvm ~]# partx -a /dev/sdb partx: /dev/sdb: error adding partitions 1-2 partx: /dev/sdb: error adding partition 5 [root@lvm ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 58G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 32G 0 part │ ├─centos-root 253:0 0 30G 0 lvm / │ └─centos-swap 253:1 0 2G 0 lvm [SWAP] ├─sda3 8:3 0 1K 0 part ├─sda5 8:5 0 1.5G 0 part └─sda6 8:6 0 2G 0 part sdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 2.5G 0 part ├─sdb2 8:18 0 1K 0 part └─sdb5 8:21 0 3G 0 part sr0 11:0 1 1024M 0 rom
[root@lvm ~]#


| partition | space |
| :--- | :--- |
| sda5 | 1.5G |
| sda6 | 2G |
| sdb1 | 2.5G |
| sdb5 | 3G |

#### Creating Physical Volumes
* 創建物理卷(physical volume)

[root@lvm ~]# pv pvchange pvcreate pvmove pvresize pvscan
pvck pvdisplay pvremove pvs
[root@lvm ~]# pvcreate /dev/sda{5,6} Physical volume “/dev/sda5” successfully created Physical volume “/dev/sda6” successfully created [root@lvm ~]# pvcreate /dev/sdb{1,5} Physical volume “/dev/sdb1” successfully created Physical volume “/dev/sdb5” successfully created [root@lvm ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a– 32.00g 4.00m /dev/sda5 lvm2 — 1.46g 1.46g /dev/sda6 lvm2 — 2.00g 2.00g /dev/sdb1 lvm2 — 2.44g 2.44g /dev/sdb5 lvm2 — 3.00g 3.00g [root@lvm ~]# pvdisplay — Physical volume — PV Name /dev/sda2 VG Name centos PV Size 32.01 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 8193 Free PE 1 Allocated PE 8192 PV UUID OfMaBa-LIEY-mle5-9PLn-nIHC-c5up-4aEy07

”/dev/sda6” is a new physical volume of “2.00 GiB” — NEW Physical volume — PV Name /dev/sda6 VG Name
PV Size 2.00 GiB Allocatable NO PE Size 0
Total PE 0 Free PE 0 Allocated PE 0 PV UUID nL14V7-iJT2-Y1yX-LE3d-2grp-DwW6-HetTqY

”/dev/sda5” is a new physical volume of “1.46 GiB” — NEW Physical volume — PV Name /dev/sda5 VG Name
PV Size 1.46 GiB Allocatable NO PE Size 0
Total PE 0 Free PE 0 Allocated PE 0 PV UUID Kds5n2-G6d8-gdJx-Syn3-ySrN-diEQ-q9Mn1G

”/dev/sdb1” is a new physical volume of “2.44 GiB” — NEW Physical volume — PV Name /dev/sdb1 VG Name
PV Size 2.44 GiB Allocatable NO PE Size 0
Total PE 0 Free PE 0 Allocated PE 0 PV UUID uW66KI-KNpT-37hu-UfEd-eWeR-K2yU-cG5NCq

”/dev/sdb5” is a new physical volume of “3.00 GiB” — NEW Physical volume — PV Name /dev/sdb5 VG Name
PV Size 3.00 GiB Allocatable NO PE Size 0
Total PE 0 Free PE 0 Allocated PE 0 PV UUID X0cLJw-HJma-SkNa-yqt2-J56i-Jzvx-JCAnMt

[root@lvm ~]#


#### Creating Volume Group
創建卷組(volume group)

[root@lvm ~]# vg vgcfgbackup vgconvert vgextend vgmknodes vgs vgcfgrestore vgcreate vgimport vgreduce vgscan vgchange vgdisplay vgimportclone vgremove vgsplit vgck vgexport vgmerge vgrename
[root@lvm ~]# vgcreate “vglemp” /dev/sda6 Volume group “vglemp” successfully created [root@lvm ~]# vgextend “vglemp” /dev/sdb1 Volume group “vglemp” successfully extended [root@lvm ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz–n- 32.00g 4.00m vglemp 2 0 0 wz–n- 4.43g 4.43g [root@lvm ~]# pvs | grep -i vglemp /dev/sda6 vglemp lvm2 a– 2.00g 2.00g /dev/sdb1 vglemp lvm2 a– 2.44g 2.44g [root@lvm ~]#


#### Creating Logical Volume
創建邏輯卷(logical volume)

[root@lvm ~]# lv lvchange lvextend lvmconfig lvmpolld lvremove lvscan lvconvert lvm lvmdiskscan lvmsadc lvrename
lvcreate lvmchange lvmdump lvmsar lvresize
lvdisplay lvmconf lvmetad lvreduce lvs
[root@lvm ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao—- 30.00g
swap centos -wi-ao—- 2.00g
[root@lvm ~]# ls -l /dev/mapper/ total 0 lrwxrwxrwx 1 root root 7 Mar 2 00:07 centos-root -> ../dm-0 lrwxrwxrwx 1 root root 7 Mar 2 00:07 centos-swap -> ../dm-1 crw——- 1 root root 10, 236 Mar 2 00:07 control [root@lvm ~]# lvcreate -n lvfirstlemp -L 2G vglemp Logical volume “lvfirstlemp” created. [root@lvm ~]# lvcreate -n lvsecondlemp -L 1.5G vglemp Logical volume “lvsecondlemp” created. [root@lvm ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao—- 30.00g
swap centos -wi-ao—- 2.00g
lvfirstlemp vglemp -wi-a—– 2.00g
lvsecondlemp vglemp -wi-a—– 1.50g
[root@lvm ~]# lvs | grep -i vglemp lvfirstlemp vglemp -wi-a—– 2.00g
lvsecondlemp vglemp -wi-a—– 1.50g
[root@lvm ~]# vgs VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz–n- 32.00g 4.00m vglemp 2 2 0 wz–n- 4.43g 956.00m [root@lvm ~]# ls -l /dev | grep -i vglemp drwxr-xr-x 2 root root 80 Mar 2 07:46 vglemp [root@lvm ~]# ls -l /dev/vglemp/ total 0 lrwxrwxrwx 1 root root 7 Mar 2 07:46 lvfirstlemp -> ../dm-2 lrwxrwxrwx 1 root root 7 Mar 2 07:46 lvsecondlemp -> ../dm-3 [root@lvm ~]#


#### Installing File System
安裝文件系統

* 當前狀態

[root@lvm ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 58G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 32G 0 part │ ├─centos-root 253:0 0 30G 0 lvm / │ └─centos-swap 253:1 0 2G 0 lvm [SWAP] ├─sda3 8:3 0 1K 0 part ├─sda5 8:5 0 1.5G 0 part └─sda6 8:6 0 2G 0 part └─vglemp-lvsecondlemp 253:3 0 1.5G 0 lvm
sdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 2.5G 0 part │ └─vglemp-lvfirstlemp 253:2 0 2G 0 lvm
├─sdb2 8:18 0 1K 0 part └─sdb5 8:21 0 3G 0 part sr0 11:0 1 1024M 0 rom
[root@lvm ~]# blkid /dev/sda1: UUID=“6329fc2a-5ea1-41ae-be55-f620d1d5675a” TYPE=“xfs” /dev/sda2: UUID=“OfMaBa-LIEY-mle5-9PLn-nIHC-c5up-4aEy07” TYPE=“LVM2_member” /dev/sda5: UUID=“Kds5n2-G6d8-gdJx-Syn3-ySrN-diEQ-q9Mn1G” TYPE=“LVM2_member” /dev/sda6: UUID=“nL14V7-iJT2-Y1yX-LE3d-2grp-DwW6-HetTqY” TYPE=“LVM2_member” /dev/sdb1: UUID=“uW66KI-KNpT-37hu-UfEd-eWeR-K2yU-cG5NCq” TYPE=“LVM2_member” /dev/sdb5: UUID=“X0cLJw-HJma-SkNa-yqt2-J56i-Jzvx-JCAnMt” TYPE=“LVM2_member” /dev/mapper/centos-root: UUID=“79fbe268-55e9-4015-8ec8-d5ebffac59bb” TYPE=“xfs” /dev/mapper/centos-swap: UUID=“5e2dcac6-c307-4941-a481-422ad76cee32” TYPE=“swap” [root@lvm ~]#


* 第一個邏輯卷

[root@lvm ~]# mkfs.xfs /dev/vglemp/lvfirstlemp meta-data=/dev/vglemp/lvfirstlemp isize=256 agcount=4, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=524288, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@lvm ~]#


* 第二個邏輯卷

[root@lvm ~]# mkfs.ext4 /dev/vglemp/lvsecondlemp mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 98304 inodes, 393216 blocks 19660 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=402653184 12 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done

[root@lvm ~]#


* 當前狀態

[root@lvm ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 58G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 32G 0 part │ ├─centos-root 253:0 0 30G 0 lvm / │ └─centos-swap 253:1 0 2G 0 lvm [SWAP] ├─sda3 8:3 0 1K 0 part ├─sda5 8:5 0 1.5G 0 part └─sda6 8:6 0 2G 0 part └─vglemp-lvsecondlemp 253:3 0 1.5G 0 lvm
sdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 2.5G 0 part │ └─vglemp-lvfirstlemp 253:2 0 2G 0 lvm
├─sdb2 8:18 0 1K 0 part └─sdb5 8:21 0 3G 0 part sr0 11:0 1 1024M 0 rom
[root@lvm ~]# blkid /dev/sda1: UUID=“6329fc2a-5ea1-41ae-be55-f620d1d5675a” TYPE=“xfs” /dev/sda2: UUID=“OfMaBa-LIEY-mle5-9PLn-nIHC-c5up-4aEy07” TYPE=“LVM2_member” /dev/sda5: UUID=“Kds5n2-G6d8-gdJx-Syn3-ySrN-diEQ-q9Mn1G” TYPE=“LVM2_member” /dev/sda6: UUID=“nL14V7-iJT2-Y1yX-LE3d-2grp-DwW6-HetTqY” TYPE=“LVM2_member” /dev/sdb1: UUID=“uW66KI-KNpT-37hu-UfEd-eWeR-K2yU-cG5NCq” TYPE=“LVM2_member” /dev/sdb5: UUID=“X0cLJw-HJma-SkNa-yqt2-J56i-Jzvx-JCAnMt” TYPE=“LVM2_member” /dev/mapper/centos-root: UUID=“79fbe268-55e9-4015-8ec8-d5ebffac59bb” TYPE=“xfs” /dev/mapper/centos-swap: UUID=“5e2dcac6-c307-4941-a481-422ad76cee32” TYPE=“swap” /dev/mapper/vglemp-lvsecondlemp: UUID=“76e61209-b372-4383-b8f7-f287eb748842” TYPE=“ext4” /dev/mapper/vglemp-lvfirstlemp: UUID=“444b90a5-2a8d-456c-8bb7-bf6f50d9d7f9” TYPE=“xfs” [root@lvm ~]#


#### Mounting Logical Volumes
掛載邏輯卷

* 掛載邏輯卷`lvsecondlemp`

[root@lvm ~]# mkdir -pv /tmp/lvm{1,2} mkdir: created directory ‘/tmp/lvm1’ mkdir: created directory ‘/tmp/lvm2’ [root@lvm ~]# mount /dev/vglemp/lvsecondlemp /tmp/lvm2 [root@lvm ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 58G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 32G 0 part │ ├─centos-root 253:0 0 30G 0 lvm / │ └─centos-swap 253:1 0 2G 0 lvm [SWAP] ├─sda3 8:3 0 1K 0 part ├─sda5 8:5 0 1.5G 0 part └─sda6 8:6 0 2G 0 part └─vglemp-lvsecondlemp 253:3 0 1.5G 0 lvm /tmp/lvm2 sdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 2.5G 0 part │ └─vglemp-lvfirstlemp 253:2 0 2G 0 lvm
├─sdb2 8:18 0 1K 0 part └─sdb5 8:21 0 3G 0 part sr0 11:0 1 1024M 0 rom
[root@lvm ~]# df -h | grep -i lvsecondlemp /dev/mapper/vglemp-lvsecondlemp 1.5G 4.5M 1.4G 1% /tmp/lvm2 [root@lvm ~]#


* 開機自動掛載邏輯卷`lvfirstlemp`

[root@lvm ~]# echo “/dev/mapper/vglemp-lvfirstlemp /tmp/lvm1 xfs defaults 0 0” >> /etc/fstab [root@lvm ~]# tail -1 /etc/fstab /dev/mapper/vglemp-lvfirstlemp /tmp/lvm1 xfs defaults 0 0 [root@lvm ~]# lsblk | grep -i vglemp └─vglemp-lvsecondlemp 253:3 0 1.5G 0 lvm /tmp/lvm2 │ └─vglemp-lvfirstlemp 253:2 0 2G 0 lvm
[root@lvm ~]# mount -a [root@lvm ~]# lsblk | grep -i vglemp └─vglemp-lvsecondlemp 253:3 0 1.5G 0 lvm /tmp/lvm2 │ └─vglemp-lvfirstlemp 253:2 0 2G 0 lvm /tmp/lvm1 [root@lvm ~]# df -h | grep -i vglemp /dev/mapper/vglemp-lvsecondlemp 1.5G 4.5M 1.4G 1% /tmp/lvm2 /dev/mapper/vglemp-lvfirstlemp 2.0G 33M 2.0G 2% /tmp/lvm1 [root@lvm ~]# blkid | grep -i vglemp /dev/mapper/vglemp-lvsecondlemp: UUID=“76e61209-b372-4383-b8f7-f287eb748842” TYPE=“ext4” /dev/mapper/vglemp-lvfirstlemp: UUID=“444b90a5-2a8d-456c-8bb7-bf6f50d9d7f9” TYPE=“xfs” [root@lvm ~]# mount | grep -i vglemp /dev/mapper/vglemp-lvsecondlemp on /tmp/lvm2 type ext4 (rw,relatime,data=ordered) /dev/mapper/vglemp-lvfirstlemp on /tmp/lvm1 type xfs (rw,relatime,attr2,inode64,noquota) [root@lvm ~]#


---
## Extending A Logical Volume

擴展邏輯卷空間

**注意**:文件系統類型是`xfs`的設備在擴展時需要使用命令`xfs_growfs`

Ext和XFS都支持在線擴展,即文件系統可在掛載狀態下進行擴展操作

* 查看邏輯卷信息: `lvs`
* 查看卷組磁盤空間:`vgs`

* 查看邏輯卷`lvfirstlemp`的文件系統類型:`mount | grep -i 'lvfirstlemp'`或`blkid | grep -i 'lvfirstlemp'`
* 爲`lvfirstlemp`擴充600M空間: `lvextend -L +600M /dev/vglemp/lvfirstlemp`
    * 將對應卷組中所有剩餘空間都擴充給`lvfirstlemp`:`lvextend -l +100%FREE /dev/vglemp/lvfirstlemp`
* Extnding
    * Extx
        * 調整邏輯卷大小,使用新分配的空間:`resize2fs /dev/vglemp/lvfirstlemp`
            * resize2fs - ext2/ext3/ext4 file system resizer
    * XFS
        * 指定參數`-D`,擴展空間到指定文件系統塊數大小:`xfs_growfs -D {filesystem blocks num} /dev/vglemp/lvfirstlemp`
        * 如果未指定參數`-D`,則所有可用空間都被分配:`xfs_growfs /dev/vglemp/lvfirstlemp`

* 擴充和調整可通過`-r`選現直接實現: `lvextend -r -L +600M /dev/vglemp/lvfirstlemp`



## Shrinking A Logical Volume
縮減邏輯卷空間,操作前需要先取消掛載

**注意**:文件系統類型是`xfs`的設備無法縮減空間,縮減時
* 卸載:`unmount /dev/vglemp/lvfirstlemp`
* 調整邏輯卷至指定大小:`resize2fs /dev/vglemp/lvfirstlemp 1.5G`
    * 會提示先執行`e2fsck -f /dev/vglemp/lvfirstlemp`命令,執行該命令後再執行`resize2fs`
* 爲`lvfirstlemp`縮減至1.5G空間: `lvreduce -L 1.5G /dev/vglemp/lvfirstlemp`


* 縮減和調整可通過`-r`選現直接實現: `lvreduce -rL 1.5G /dev/vglemp/lvfirstlemp`


## Deleting A Logical Volume
* 重新分配物理卷`/dev/sdb6`:`pvmove /dev/sdb6`
* 從卷組`vglemp`中移除物理卷`/dev/sdb6`:`vgreduce vglemp /dev/sdb6`

[root@lvm ~]# pvmove /dev/sdb6 No data to move for vglemp [root@lvm ~]# vgreduce vglemp /dev/sdb6 Removed “/dev/sdb6” from volume group “vglemp” [root@lvm ~]# pvs PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a– 32.00g 4.00m /dev/sda5 lvm2 — 1.46g 1.46g /dev/sda6 vglemp lvm2 a– 2.00g 508.00m /dev/sdb1 vglemp lvm2 a– 2.44g 2.05g /dev/sdb6 lvm2 — 2.00g 2.00g [root@lvm ~]#


## Creating SWAP Disks
* 查看ram狀態: `free -m`;
* 從設備`/dev/sdb`創建類型爲swap(partition's system id是`82`)的新分區: `fdisk /dev/sdb`;
* 在`/dev/sdb5`安裝sawp文件系統並命令:`mkswap -L {LABELNAME} /dev/sdb5`;
* 激活swap文件`/dev/sdb5`:`swapon /dev/sdb5`;
* 激活所有sawps: `swapon -s`;
* 關閉swap文件`/dev/sdb5`:`swapoff /dev/sdb5`;
* 編輯`/etc/fstab`文件,開機自動掛載:`LABEL={LABELNAME} swap swap defaults 0 0`;
* 激活所有swap文件: `swapon -a`;
* 關閉所有swap文件:`swapoff -a`


操作過程
### Create a Swap Disk From a Disk Partition

[root@lvm ~]# fdisk /dev/sdb 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.

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3d1a9b1d

Device Boot Start End Blocks Id System /dev/sdb1 2048 5122047 2560000 8e Linux LVM /dev/sdb2 5122048 15607807 5242880 5 Extended /dev/sdb5 5124096 11415551 3145728 83 Linux

Command (m for help): l

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext’d (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix

Command (m for help): t Partition number (1,2,5, default 5): 5 Hex code (type L to list all codes): 82 Changed type of partition ‘Linux’ to ‘Linux swap / Solaris’

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3d1a9b1d

Device Boot Start End Blocks Id System /dev/sdb1 2048 5122047 2560000 8e Linux LVM /dev/sdb2 5122048 15607807 5242880 5 Extended /dev/sdb5 5124096 11415551 3145728 82 Linux swap / Solaris

Command (m for help): w The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@lvm ~]# partx -a /dev/sdb partx: /dev/sdb: error adding partitions 1-2 partx: /dev/sdb: error adding partition 5 [root@lvm ~]# partx -a /dev/sdb partx: /dev/sdb: error adding partitions 1-2 partx: /dev/sdb: error adding partition 5 [root@lvm ~]#


### Installing SWAP Filesystem

[root@lvm ~]# mkswap -L ‘swaplvm’ /dev/sdb5 mkswap: /dev/sdb5: warning: wiping old LVM2_member signature. Setting up swapspace version 1, size = 3145724 KiB LABEL=swaplvm, UUID=606e319f-a5bc-4a8b-bf5b-3bf25e796433 [root@lvm ~]#


參數`-L`是設置卷標(label),屬於可選項,但強烈建議設置。

### Activing SWAP

[root@lvm ~]# free -m total used free shared buff/cache available Mem: 993 69 818 6 104 807 Swap: 2047 0 2047 [root@lvm ~]# swapon /dev/sdb5 [root@lvm ~]# free -m total used free shared buff/cache available Mem: 993 72 816 6 104 805 Swap: 5119 0 5119 [root@lvm ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 /dev/sdb5 partition 3145724 0 -2 [root@lvm ~]#


### Deactiving SWAP

[root@lvm ~]# swapoff /dev/sdb5 [root@lvm ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 [root@lvm ~]# free -m total used free shared buff/cache available Mem: 993 69 819 6 104 808 Swap: 2047 0 2047 [root@lvm ~]#

重啓系統也關閉此swap,原因是`swapon`操作不是持久的。若需持久,可將此設備設置爲開機自動加載。

### Installing SWAP Filesystem From Logical Volume

[root@lvm ~]# umount /dev/vglemp/lvfirstlemp [root@lvm ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 58G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 32G 0 part │ ├─centos-root 253:0 0 30G 0 lvm / │ └─centos-swap 253:1 0 2G 0 lvm [SWAP] ├─sda3 8:3 0 1K 0 part ├─sda5 8:5 0 1.5G 0 part └─sda6 8:6 0 2G 0 part └─vglemp-lvsecondlemp 253:3 0 1.5G 0 lvm /tmp/lvm2 sdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 2.5G 0 part │ └─vglemp-lvfirstlemp 253:2 0 2G 0 lvm
├─sdb2 8:18 0 1K 0 part └─sdb5 8:21 0 3G 0 part sr0 11:0 1 1024M 0 rom
[root@lvm ~]# free -m total used free shared buff/cache available Mem: 993 69 820 6 103 808 Swap: 2047 0 2047 [root@lvm ~]# mkswap -L ‘swaplemp’ /dev/vglemp/lvfirstlemp mkswap: /dev/vglemp/lvfirstlemp: warning: wiping old swap signature. Setting up swapspace version 1, size = 2097148 KiB LABEL=swaplemp, UUID=96e3900a-f727-416d-b762-a70b60890322 [root@lvm ~]# swapon /dev/vglemp/lvfirstlemp [root@lvm ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 /dev/dm-2 partition 2097148 0 -2 [root@lvm ~]# free -m total used free shared buff/cache available Mem: 993 70 818 6 103 807 Swap: 4095 0 4095 [root@lvm ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 58G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 32G 0 part │ ├─centos-root 253:0 0 30G 0 lvm / │ └─centos-swap 253:1 0 2G 0 lvm [SWAP] ├─sda3 8:3 0 1K 0 part ├─sda5 8:5 0 1.5G 0 part └─sda6 8:6 0 2G 0 part └─vglemp-lvsecondlemp 253:3 0 1.5G 0 lvm /tmp/lvm2 sdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 2.5G 0 part │ └─vglemp-lvfirstlemp 253:2 0 2G 0 lvm [SWAP] ├─sdb2 8:18 0 1K 0 part └─sdb5 8:21 0 3G 0 part sr0 11:0 1 1024M 0 rom
[root@lvm ~]#


### Automounting swap disks

[root@lvm ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 /dev/dm-2 partition 2097148 0 -2 [root@lvm ~]# swapoff /dev/vglemp/lvfirstlemp [root@lvm ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 [root@lvm ~]# blkid | grep -i ‘lvfirstlemp’ /dev/mapper/vglemp-lvfirstlemp: LABEL=“swaplemp” UUID=“96e3900a-f727-416d-b762-a70b60890322” TYPE=“swap” [root@lvm ~]#

在`/etc/fstab`中設置,可使用`LABEL`或`UUID`指代該設備

[root@lvm ~]# echo “LABEL=swaplemp swap swap defaults 0 0” >> /etc/fstab [root@lvm ~]# tail -1 /etc/fstab LABEL=swaplemp swap swap defaults 0 0 [root@lvm ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 [root@lvm ~]# free -m total used free shared buff/cache available Mem: 993 69 819 6 103 808 Swap: 2047 0 2047 [root@lvm ~]# mount -a [root@lvm ~]# swapon -a [root@lvm ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 /dev/dm-2 partition 2097148 0 -2 [root@lvm ~]# free -m total used free shared buff/cache available Mem: 993 70 813 6 108 804 Swap: 4095 0 4095 [root@lvm ~]#



## LVM Names and The Device Mapper
* 列出所有設備映射設備: `ls -l /dev | grep -i 'dm-'`
* 列出`dm-*`塊文件的軟鏈接信息: `ls -l /dev/mapper`
* 列出邏輯卷設備的軟鏈接設備信息: `ls -l /dev/{vg-name}/`

Linux Kernel本身並不能識別LVMs,只能識別類似`sda1`, `sda2`的設備。而`dm-`是稱爲 *Device Mapper* 的軟件層,用於聯結內核和邏輯卷。設備映射器(device mapper)允許內核與名爲`/dev/dm-{num}`的設備進行交互,這些設備就是 *Device Mapper*。 使用塊設備代表LVs。

[root@lvm ~]# ls -l /dev | grep -i ‘dm-’ brw-rw—- 1 root disk 253, 0 Mar 2 07:46 dm-0 brw-rw—- 1 root disk 253, 1 Mar 2 07:46 dm-1 brw-rw—- 1 root disk 253, 2 Mar 2 08:03 dm-2 brw-rw—- 1 root disk 253, 3 Mar 2 08:00 dm-3 [root@lvm ~]#


`Device Mapper`不僅支持LVM,還支持如`LUKS encrypted partitions`、`RAID setups`等。故而`/dev/mapper`可包含很多軟鏈接。

`dm-{num}`塊文件在系統啓動時被創建,意味着這些塊設備在機器下一次啓動時可代表不同的LVs。通過`dm-1`, `dm-2`等通用名稱,並不能分辨是哪個設備。故`Device Mapper`提供了一種對用戶更爲友好的途徑來指代這些塊設備,即通過軟鏈接(symbolic link)設置有具體含義的名稱。可在目錄`/dev/mpaaer`下找到這些軟鏈接

[root@lvm ~]# ls -l /dev/mapper/ | grep -i ‘dm-’ lrwxrwxrwx 1 root root 7 Mar 2 07:46 centos-root -> ../dm-0 lrwxrwxrwx 1 root root 7 Mar 2 07:46 centos-swap -> ../dm-1 lrwxrwxrwx 1 root root 7 Mar 2 08:03 vglemp-lvfirstlemp -> ../dm-2 lrwxrwxrwx 1 root root 7 Mar 2 08:00 vglemp-lvsecondlemp -> ../dm-3 [root@lvm ~]#

可以看到,指向這些設備的軟鏈接的命名格式爲`{vg-name}-[lv-name]`,更有含義且易於管理。故而,最好在命名`volume group`時添加前綴`vg`,命名`logical volume`時添加前綴`lv`,這樣更易於追溯。

這些軟鏈接也是在系統啓動時被創建,`device mapper`自動解析(resolve)軟鏈接到對應的`dm-{num}`設備。

如果您不想使用`Device Manager`生成的軟鏈接,LVM也創建有的屬於自己的軟鏈接,其結構爲`/dev/{vg-name}/{lv-name}`

[root@lvm ~]# ls -l /dev/vglemp/ total 0 lrwxrwxrwx 1 root root 7 Mar 2 08:03 lvfirstlemp -> ../dm-2 lrwxrwxrwx 1 root root 7 Mar 2 08:00 lvsecondlemp -> ../dm-3 [root@lvm ~]# ```

使用何種軟鏈接指向邏輯卷,看個人喜好。


Change Log

  • 2016.03.02 14:11 Wed Asia/Beijing
    • 初稿完成

  • Note Time: 2016.03.02 14:11 Wed
  • Note Location: Asia/Beijing
  • Writer: lempstacker