[Linux] CentOS 6.5 LVM Logical Volume Management Lab report

Source: Internet
Author: User
Tags bz2 hex code

Directory

1. Introduction to LVM

2. Basic LVM Terminology

3. Installation of LVM

4. Use of LVM

4.1 Management of physical volumes

Management of 4.2 volume groups:

4.3 Management of logical volumes:

5. An example

5.1 Exercises:

5.2 Start Deployment

1. Introduction to LVM

LVM Logical Volume Manager (English: Logical Volume Manager, abbreviated to LVM), also translated as logical File Manager, logical Sector Manager, Logical Disk Manager, is the logical volume management provided by the Linux core (Logical Volume Management) function. It creates a logical layer on top of the hard disk partition to facilitate system management of the hard disk partition system.

Four partitions can make up a lot of space, and then partition some logical partitions on these spaces, we can resize these logical partitions, or we can take a snapshot backup.

2. Basic LVM Terminology

Physical Volume (PV): A physical volume refers to a hard disk partition or a device that logically has the same function as a disk partition (such as RAID), which is the basic storage logic block of LVM, but compared to basic physical storage media such as partitions, disks, etc. Contains management parameters that are relevant to LVM. A typical physical volume is a hard disk partition, but it can also be an entire hard disk or a software RAID volume that has been created.

Volume Group (VG): A volume group is the highest abstraction layer in LVM and is a memory pool composed of one or more physical volumes. You can create one or more LVM partitions (logical volumes) on a volume group, and an LVM volume group consists of one or more physical volumes.

Logical Volume (LV): A logical volume is equivalent to a partition in a non-LVM system, which is established on a volume group and is a standard block device on which file systems can be established

physical Extent (PE): physical blocks, physical volumes are stored in units of equal size, and the size of the block is the same as the size of the logical volume block in the volume group. The size of the PE is configurable and defaults to 4MB.

3. Installation of LVM

See if LVM2 is already installed

1 [[email protected] ~]# rpm-qa| grep LVM

mesa-private-llvm-3.3-0.3.rc3.el6.i686

lvm2-2.02.100-8.el6.i686

lvm2-libs-2.02.100-8.el6.i686

If no content is returned, installation is required

1 Yum Install lvm2
4. Use of LVM

If you are creating a logical volume you need to go through the following three stages:

4.1 Management of physical volumes:

Pvcreate/path/to/dev: Initializes a disk or partition to be created as a physical volume;

Pvmove/path/to/dev: Move the physical blocks on the device to other devices. (can be used when removing physical volumes to prevent data loss)

Pvscan: Search for any disk or partition with physical volume in the current system;

Pvdisplay: Shows the status of the physical volume above the current system;

Pvremove/path/to/pv_dev: Remove the physical volume so that the partition does not have physical volume properties.

Management of 4.2 volume groups:

Vgcreate: Create Volume Group command –s PE size, default 4M;

Vgscan: Whether a volume group exists on the search system

Vgdisplay: Displays the status of the volume group above the current system;

Vgextend: Add additional physical volumes within the volume group;

Vgreduce: Removal of physical volumes within the volume group;

Vgchange: Configure whether the volume group is started (active);

Vgremove: Deleting a volume group

4.3 Management of logical volumes:

Lvcreate: Create a logical volume.

Lvscan: Queries the logical volume above the system.

Lvdisplay: Displays the status of the logical volume above the system

Lvextend: Add capacity inside the logical volume.

Lvreduce: Reduces the volume inside the logical volume.

Lvremove: Deletes a logical volume.

Lvresize: The size adjustment of the LV.

5. An example

5.1 Exercises:

1. Create a volume group with a size of 20G consisting of two physical volumes MYVG, which requires a PE size of 16M.

2. Create a logical volume of 7G on the volume group MYLV1, requiring its file system to be Ext4, with a block size of 2048,

3. Boot automatically mount to/users

4. New user OpenStack, whose home directory is/users/openstack, switch to OpenStack user, copy some files to home directory

5. Reduce MYLV1 to 5G size, switch to OpenStack user, ensure no data loss

6. Create the snapshot volume Snap-mylv1 for Mylv1, and through its backup data to/tmp/user.tar.bz2;

5.2 Start Deployment

    1. Two partitions prepared, SDB1 (8G), SDC1 (12G) to form a 20G MYVG volume group

Formatting the first SDB1

#使用fdisk格式化sdb

1 [[email protected] ~]# Fdisk/dev/sdb

Warning:dos-compatible mode is deprecated. It ' s strongly recommended to

Switch off the mode (command ' C ') and change display units to

Sectors (Command ' u ').

#创建一个新的分区

Command (M for help): N

Command Action

E Extended

P primary partition (1-4)

P

Partition number (1-4): 1

First cylinder (1-1305, default 1): 1

Last cylinder, +cylinders or +size{k,m,g} (1-1305, default 1305): +8g

#调整分区格式为LVM

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)

#如果忘了代码, you can enter L to find the code in LVM format

#查看分区状况

Command (M for help): P

disk/dev/sdb:10.7 GB, 10737418240 bytes

255 heads, Sectors/track, 1305 cylinders

Units = Cylinders of 16065 * 8225280 bytes

Sector size (logical/physical): bytes/512 bytes

I/O size (minimum/optimal): bytes/512 bytes

Disk identifier:0x8633d49d

Device Boot Start End Blocks Id System

/DEV/SDB1 1 1045 8393931 8e Linux LVM

#保存退出

Command (M for help): W

The partition table has been altered!

Calling IOCTL () to re-read partition table.

Syncing disks.

#格式化并保存退出

Prepare for the second physical partition SDC1 (12G) step above:

1 [[email protected] ~]# FDISK/DEV/SDC

#确认分区状况:

1 [[email protected] ~]# lsblk

2. Create a physical volume

1 [[email protected] ~]# PVCREATE/DEV/SDB1/DEV/SDC1

1 [[email protected] ~]# PVs

#查看物理卷情况

1 [[email protected] ~]# Pvscan

3. Create a volume group MYVG size 20G, which requires a PE size of 16M.

1 [[email protected] ~]# vgcreate-s 16M MYVG/DEV/SDB1/DEV/SDC1

1 [[email protected] ~]# VGS

#查看卷组情况

4. Create a logical volume of 7G on the volume group MYLV1, requiring its file system to be Ext4, with a block size of 2048

1 [[email protected] ~]# lvcreate myvg-n mylv1-l 7G

#在卷组myvg上创建大小为7G的逻辑卷mylv1

1 [[email protected] ~]# FDISK/DEV/MYVG/MYLV1

#在逻辑卷上创建分区

1 2048 /DEV/MYVG/MYLV1

#格式化逻辑卷mylv1为ext4文件系统块大小2048K

5. Boot automatically mount to/users

1 mkdir /users23 [[email protected]/]# vim +/etc/fstab

#设置开机自动挂载逻辑卷到/users.

#添加/dev/myvg/mylv1/users ext4 Defaults 0 2 to/dev/fstab last row

1 Mount –a

#自动挂载

6. New user OpenStack, whose home directory is/users/openstack, switch to OpenStack user, copy some files to home directory

1 [[email protected] users]# useradd openstack-d/users/openstack

#新建用户openstack, whose home directory is/users/openstack

1 su - openstack2cp -r/etc/*  ~/

#切换至openstack用户, copy some/etc/files in the home directory

7. Reduce MYLV1 to 5G size, switch to OpenStack user, ensure no data loss

Reduce logical volume size ideas:

7.1. Unmount the volume and perform force detection

# e2fsck-f/path/to/lv_device

7.2. Reduce logical boundaries:

# Resize2fs/path/to/lv_device Size

7.3. Reduce physical boundaries:

# lvreduce-l [-]size/path/to/vg_name/lvname

7.4. Verify that it is normal

7.5. Commencement of implementation:

1 umount /dev/myvg/mylv1 #卸载卷 2 [[email protected] ~]# e2fsck-f/dev/myvg/mylv1 #强行检测 3 [[email protected] ~]# resize2fs/dev/myvg/mylv1 5G #缩减逻辑边界到5G4 [[email protected] ~]# lvred Uce-l 5g/dev/myvg/mylv1 #缩减物理边界到 5G5 [[email protected] ~]# lsblk #验证数据

1 Mount –a #重新挂载逻辑卷 2 [[email protected] ~]# cd/users/openstack/ #验证数据 3 [[email protected] openstack]# LL

8. Create the snapshot volume Snap-mylv1 for Mylv1, and through its backup data to/tmp/user.tar.bz2;

1 [[email protected] openstack]# lvcreate-s-l 50m-n snap_mylv1-p r/dev/myvg/mylv1 #建立快照 2
   
    mount /dev/myvg/snap_mylv1/media/snap/
     #挂载快照 
    3
    tar -jcf/tmp/user. 
    tar. Bz2/media/snap/openstack/
    * 
     #建立归档
   

[Linux] CentOS 6.5 LVM Logical Volume Management Lab report

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.