I. Introduction Logical Volume Manager
Logical Volume Manager (English: Logical Volume Manager, abbreviated as LVM), also translated as logical volume manager, a logical sector manager, Logical Disk Manager is the Linux kernel provided by the Logical Volume Manager (Logical volume management) function . It is in the hard disk of the hard disk partition basis, but also to create a logical layer management system to facilitate segmentation system hard disk.
Originally developed by IBM, in AIX to realize the system, OS / 2 operating system with HP-UX also supports this feature. In 1998, Heinz Mauelshagen based on HP-UX Logical Volume Manager on writing the first version of the Linux Logical Volume Manager.
LVM basic terms:
- PV: physical volumes, the lowest level of the PV system in LVM, which may be an entire disk or disk partition and a device having the same function (e.g., the RAID), but a physical storage medium and substantially compared more management parameters associated with LVM
- VG: volume group is created on the PV, PV composed by one or more, may create one or more "LVM partitions" (logical volume), the system functions like a non-LVM physical disk on VG
- LV: logical volume, divided from the VG a space size after creating retractable, the system can create a file (e.g., / var, / home) on LV
- PE: physical areas, each being divided into a base unit PV (also referred to as PE), PE has a unique number that can be stored in LVM minimum addressable units, the default is 4MB
LVM for the following purposes:
- Creating multiple physical volume of the entire hard drive or a single logical volume (somewhat similar to the RAID 0 , but more similar to JBOD ), so that the volume size can be dynamically adjusted.
- By combining hot-swappable , allows you to add and replace a disk without downtime or service interruption, to manage a large hard field.
- On small systems (such as desktop), LVM partition does not have to estimate how much may be required during installation, but you can easily adjust the size of the file system needs based.
- To perform a consistent backup by the logical volume snapshot.
- Using a plurality of password encryption physical partitions.
LVM can be seen as a thin software layer on top of the hard disk and partition, it creates continuity and ease of use of the abstract for the replacement, repartitioning management and backup hard drive.
Second, the Logical Volume Manager Operation
1, LVM preparation # Add a new hard disk / dev / sdb [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk sr0 11: 0:01 1024M 0 accommodations # On the new hard disk / dev / sdb partition [root@localhost ~]# 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 0xd1c551dc. 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): 1 First sector (2048-41943039, default 2048): 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +3G Partition 1 of type Linux and of size 3 GiB is set Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (6293504-41943039, default 6293504): Using default value 6293504 Last sector, +sectors or +size{K,M,G} (6293504-41943039, default 41943039): +4G Partition 2 of type Linux and of size 4 GiB is set Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): First sector (14682112-41943039, default 14682112): Using default value 14682112 Last sector, +sectors or +size{K,M,G} (14682112-41943039, default 41943039): +2G Partition 3 of type Linux and of size 2 GiB is set # Of three new primary hard disk partitions change attributes to "Linux LVM" (Code: 8e) Command (m for help): t Partition number (1-3, default 3): 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, default 3): 1 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, default 3): 2 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. # See the new hard disk partition, and due to the hard disk properties [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 3G 0 part ├─sdb2 8:18 0 4G 0 part └─sdb3 8:19 0 2G 0 part sr0 11: 0:01 1024M 0 accommodations [root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xd1c551dc Device Boot Start End Blocks Id System /dev/sdb1 2048 6293503 3145728 8e Linux LVM /dev/sdb2 6293504 14682111 4194304 8e Linux LVM /dev/sdb3 14682112 18876415 2097152 8e Linux LVM 2, create LVM # Of three primary partition PV (physical volume) to create [root@localhost ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@localhost ~]# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created. [root@localhost ~]# pvcreate /dev/sdb3 Physical volume "/dev/sdb3" successfully created. # Check whether there are three primary partitions PV [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <19.00g 0 /dev/sdb1 lvm2 --- 3.00g 3.00g /dev/sdb2 lvm2 --- 4.00g 4.00g /dev/sdb3 lvm2 --- 2.00g 2.00g # Add three to LVMtest the PV VG (volume group) and set PE (physical area) size of 12M [root@localhost ~]# vgcreate -s 12M LVMtest /dev/sdb{1..3} Volume group "LVMtest" successfully created # View LVMtest the VG exists. [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree LVMtest 3 0 0 wz--n- <8.98g <8.98g centos 1 2 0 wz--n- <19.00g 0 # Size LVMtest 4G create the logical partition [root@localhost ~]# lvcreate -L 4G -n LVMtest LVMtest Rounding up size to full physical extent <4.01 GiB Logical volume "LVMtest" created. # View LVMtest the presence or absence of a logical partition [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert LVMtest LVMtest -wi-a----- <4.01g root centos -wi-ao---- <17.00g swap hundreds -Wi-to 2.00g ---- # Format partition / dev / LVMtest / LVMtest, set partition type ext4, and its mount to / data / directory [root@localhost ~]# mkfs.ext4 /dev/LVMtest/LVMtest 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 262944 inodes, 1050624 blocks 52531 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1075838976 33 block groups 32768 blocks per group, 32768 fragments per group 7968 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [Root @ localhost ~] # partprobe // the system without restarting the machine to re-read the partition Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 3G 0 part │ └─LVMtest-LVMtest 253:2 0 4G 0 lvm ├─sdb2 8:18 0 4G 0 part │ └─LVMtest-LVMtest 253:2 0 4G 0 lvm └─sdb3 8:19 0 2G 0 part sr0 11:0 1 4.2G 0 rom /mnt [root@localhost ~]# mkdir /data [root@localhost ~]# mount /dev/LVMtest/LVMtest /data # Copy certain data for later tests [root@localhost ~]# cp -R /etc/pam.d/ /data/ [root@localhost ~]# ll -d /data/ drwxr-xr-x. 4 root root 4096 Dec 24 02:16 /data/ [root@localhost ~]# ll -dl /data/ drwxr-xr-x. 4 root root 4096 Dec 24 02:16 /data/ [root@localhost ~]# ll /data/ total 20 drwx------. 2 root root 16384 Dec 24 02:15 lost+found drwxr-xr-x. 2 root root 4096 Dec 24 02:16 pam.d 3, to increase the capacity of the experiments performed LVM # 2G capacity LVMtest new partition, and verify data integrity 1) Extended physical boundaries 2) extended logical boundary [Root @ localhost ~] # lvextend -L + 2G / dev / LVMtest / LVMtest // extended physical boundaries Rounding size to boundary between physical extents: 2.00 GiB. Size of logical volume LVMtest/LVMtest changed from <4.01 GiB (342 extents) to 6.01 GiB (513 extents). Logical volume LVMtest/LVMtest successfully resized. [Root @ localhost ~] # resize2fs / dev / LVMtest / LVMtest // extended logical boundaries resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/LVMtest/LVMtest is mounted on /data; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/LVMtest/LVMtest is now 1575936 blocks long. [root@localhost ~]# ls -l /data/ total 20 drwx------. 2 root root 16384 Dec 24 02:15 lost+found drwxr-xr-x. 2 root root 4096 Dec 24 02:16 pam.d 4, reduced capacity to perform LVM # LVMtest will be reduced to the size of 2G and verify data integrity (in a production environment is not recommended to do this !!!!!) # Here the use of the ext4 file system type, 1) uninstall the physical file system 2) the file system mandatory testing and repair 3) reduce the logical boundary 4) reduce the physical boundaries 5) Remount LVM partition [root@localhost ~]# umount /dev/LVMtest/LVMtest/ [Root @ localhost ~] # e2fsck -f / dev / LVMtest / LVMtest // the file system mandatory testing and repair e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/LVMtest/LVMtest: 43/390432 files (0.0% non-contiguous), 61412/1575936 blocks [Root @ localhost ~] # resize2fs / dev / LVMtest / LVMtest 2G // 2G boundary logic reduced size resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/LVMtest/LVMtest to 524288 (4k) blocks. The filesystem on /dev/LVMtest/LVMtest is now 524288 blocks long. [Root @ localhost ~] # lvreduce -L 2G / dev / LVMtest / LVMtest // reduced physical size boundary 2G Rounding size to boundary between physical extents: 2.00 GiB. WARNING: Reducing active logical volume to 2.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce LVMtest/LVMtest? [y/n]: y Size of logical volume LVMtest/LVMtest changed from 6.01 GiB (513 extents) to 2.00 GiB (171 extents). Logical volume LVMtest/LVMtest successfully resized. [Root @ localhost ~] # mount / dev / LVMtest / LVMtest / data // LVM partition remounting # Check the LVM partition size [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 3G 0 part ├─sdb2 8:18 0 4G 0 part │ └─LVMtest-LVMtest 253:2 0 2G 0 lvm /data └─sdb3 8:19 0 2G 0 part sr0 11:0 1 4.2G 0 rom /mnt # Check data integrity [root@localhost ~]# ll /data/ total 20 drwx------. 2 root root 16384 Dec 24 02:15 lost+found drwxr-xr-x. 2 root root 4096 Dec 24 02:16 pam.d 5, delete LVM Case # Unload LVM partition [root@localhost ~]# umount /data/ # Delete the LVM partition on LVMtest [root@localhost ~]# lvremove /dev/LVMtest/LVMtest Do you really want to remove active logical volume LVMtest/LVMtest? [y/n]: y Logical volume "LVMtest" successfully removed # Deleted on LVMtest of VG (Volume Group) [root@localhost ~]# vgremove LVMtest Volume group "LVMtest" successfully removed # Delete the hard disk partition PV [root@localhost ~]# pvremove /dev/sdb1 Labels on physical volume "/dev/sdb1" successfully wiped. [root@localhost ~]# pvremove /dev/sdb2 Labels on physical volume "/dev/sdb2" successfully wiped. [root@localhost ~]# pvremove /dev/sdb3 Labels on physical volume "/dev/sdb3" successfully wiped. [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <19.00g 0 [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <19.00g 0 [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <17.00g swap hundreds -Wi-to 2.00g ----