----------- 'Create a Logical Volume '[LV-Logical Volume]
--- // N Note: As of this writing, the Linux 2.6 kernel supports on-line resize
// Filesystems mounted using ext3 only.
N'currently [online amplification] resize is only applicable to ext3, and umount is required for other file systems'
--- // Differences between RHEL5 and RHEL6
[RHEL5]:/dev/vg0/lv0 [link] -->/dev/mapper/vg0-lv0 ['device']
(Lv0 is specified by lvcreate-n) ing (blkid view)
[RHEL6]:/dev/vg0/lv0 [link] &/dev/mapper/vg0-lv0 [link] -->/dev/dm-0 ['device']
--- // N: PV. VG. LV Reference Method
1. PV:/dev/sda6
2. VG: vg0
3. LV:/dev/vg0/lv0/dev/mapper/vg0-lv0/dev/dm-0 (RHEL6)
--- // N create LV
1. fdisk/dev/sda // n: Create/dev/sda {6, 7, 8}: 100 MB for each
2. pvcreate/dev/sda {6, 7, 8} // create PV: Initialize a disk or partition for use by LVM.
3. vgcreate '[-s 8 M]' vg0/dev/sda {6, 7} // create VG.-s: Specify the PE size. PE: physicalExtend, composed of multiple blocks
4. lvcreate-L 160 M-n lv0 vg0 //-L: specifies the LV size (default PE = 4 M, so it must be an integer multiple of PE = 4 M),-n: LV name
Lvcreate-L 20 M-n lv1 vg0
Lvcreate-l 100-n lv2 vg0 //-l: Number of PES, 100*8 M = 800 M
5. mkfs. ext3/dev/vg0/lv0 // format:/dev/vg0/lv0 or/dev/mapper/vg0-lv1
Mkfs. ext3/dev/mapper/vg0-lv1
6. mout-a // modify fstab and mount the FS on the LV.
--- // N [snapshot]
1. lvcreate-L 160 M-n lv0_snapshot-s/dev/vg0/lv0 //-s: snapshot; Create snapshot for lv0;
[A. snapshot is created on VG, so it occupies vg0 space]
[B. snapshot 'no formatting required. You can use it after mounting]
[C. snapshot 'no' can be written in fstab]
[D. snapshot 'Copy on write cow', '[sparse file]'] // ensure that all data is consistent when snapshot is created, and "2 + 4 = 9" does not appear"
--- // N view PV. VG. LV Information
1. pvs/pvscan/pvdisplay
2. vgs/vgscan/vgdisplay
3. lvs/lvscan/lvdisplay
--- // N view the FS information on the LV
1. tune2fs-l/dev/vg0/lv0
Tune2fs-l/dev/mapper/vg0-lv0
Tune2fs-l/dev/dm-0 // RHEL6 can be
--- // N: lvextend-L 240 M/dev/vg0/lv0
Block count: 163840 // total size = 1 K * count = 160 M
Block size: 1024 // block size = 1 K
--- // N: resize2fs/dev/vg0/lv0
Block count: 245760 // total size = 240 M
--- // N [Online] 'Extended "logical Volume LV ': [VG->] LV-> FS
1. vgextend vg0/dev/sda8 // expand VG
2. lvextend/dev/vg0/lv0-L 240 M // expand LV-> 240 M
3. resize2fs/dev/vg0/lv0 [240 M] // extended FS, Which is enlarged to the partition size (that is, the filesystem blocksize of the filesystem) by default)
[******* If you do not enlarge FS-> {New} physical space not covered by FS in lv0 [unavailable] n *******]
--- // N [offline] 'Download': FS-> LV [-> VG]
1. umount/mnt/lv0
2. resize2fs/dev/vg0/lv0 150 M
3. e2fsck-f/dev/vg0/lv0 // check a Linux ext2/3/4 filesystem
3. lvreduce/dev/vg0/lv0-L 150 M // lvreduce
4. mount/mnt/lv0
--- // N Delete the partition as PV
--- // N Delete LV
1. lvremove [-f] vg0/lv0 // Delete lv0 on vg0 [-f: delete directly without confirmation]
2. lvremove [-f] vg0 // Delete All LV
--- // N Delete VG
1. vgremove [-F] vg0 // [-F]: If LV exists on vg0, the system will prompt whether to remove it;-F forces vgremove (remove all LV together)
--- // N Delete PV
1. pvremove/dev/SDA {6, 7, 8}
--- // N Delete Partition
1. fdisk/dev/SDA //-D: delete/dev/sda6, 7,8
2. partprobe // rhel6 requires reboot
--------- <'Lvm snapshot'> -----------
@ When a snapshot is created, only metadata (meta-data) of the data in the original volume is copied ).
# There is no physical copy of data during creation, so snapshot creation is almost real-time,
# When a write operation is executed on the original volume, snapshot tracks the change of the original volume block,
# At this time, the data to be changed on the original volume is copied to the space reserved by snapshot before the change,
# Therefore, the implementation of this principle is called copy-on-write ).
@ Before writing data to a block, cow indicates that the raw data is moved to the snapshot space. This ensures that all data is consistent when snapshot is created.
# For snapshot read operations, if the read data block has not been modified, the read operations will be directly redirected to the original volume,
# If you want to read a modified block, read the block copied to snapshot.
# In this way, the general file I/0 process is changed, that is, a cow layer is added between the file system and the device driver, which is like the following:
$ File I/0 ---> filesystem --> CoW --> block I/O
$ When CoW is adopted, the snapshot size does not need to be as large as the original volume. The size only needs to be considered in two aspects:
1. estimate the volume of block changes from shapshot creation to release;
2. Data update frequency.
$ Once the space record of the snapshot is full of the information of the original volume block transformation, the snapshot will be immediately released and cannot be used. As a result, the snapshot will be invalid.
$ So, it is very important to do what you need to do in the snapshot lifecycle.
$ Of course, if your snapshot size is as big as or even as big as the original volume, then its life would be "Same as life.
# Suppose we create a m snapshot, which means that you can only change the data size of m in the snapshot lifecycle.