unit5~~ use Logical Volume Manager to manage flexible storage

Source: Internet
Author: User
Tags hex code
1.LVM Logical Volume creation

Why use logical volumes
• Logical volume and logical volume management help to manage more easily
Disk space. If the file system needs more space,
You can assign the free space of its volume group to a logical volume, and
You can adjust the file system size. If the disk starts
An error occurred, you can register the replacement disk with the volume group as
Physical volumes, and the range of logical volumes can be migrated to new disks

Implementing LVM storage using command line tools
• Prepare physical volumes
–disk is used to create a new partition that is used in conjunction with LVM. On the partition to be used in conjunction with LVM, always
"Type" set to "0x8e Linux LVM"
–pvcreate/dev/vdan is used to initialize partitions (or other physical devices) as physical volumes and LVM knots
Combined use. To create a header for storing LVM configuration data directly in a physical volume
• Create volume groups
–vgcreate Vgname/dev/vdan will create a volume named Vgname that is composed of a physical volume/dev/vdan
Group. You can specify other physical volumes (separated by spaces) when you create them, or you can then use Vgextend to add
New Physical Volume
• Create and use new logical volumes
–lvcreate-n lvname-l 2G Vgname can create a physical block from the Vgname that is named Lvname,
A new logical volume with a capacity of 2GB
–mkfs-t Ext4/dev/vgname/lvname will create the Ext4 file system on the new logical volume
–mkdir/data create the desired directory as the mount point
– Add an entry to the/etc/fstab file:
/dev/mapper/vgname-lvname/data EXT4 Defaults 1 2
– Run mount-a to mount all file systems in/etc/fstab, including the entry you just added

Command (M for help): T                          # #选择分区类型 Partition number (1,2, default 2): 1 Hex code (type L to list all codes): 8e          # #选择LVM类型的 Partition Changed type of partition ' Linux ' to ' Linux LVM ' Command (M for help): P             &NB Sp             # #显示创建好的分区 disk/dev/vdb:10.7 GB, 10737418240 bytes, 20971520 sectors Units =  Sectors of 1 * bytes = sector size (logical/physical): bytes/512 bytes I/o size (minimum/optimal): bytes /bytes Disk label Type:dos disk identifier:0x92763b95 Device Boot Start end Blocks Id Sys   TEM/DEV/VDB1 2048 2099199 1048576 8e Linux lvm/dev/vdb2 2099200 4196351 1048576

8e Linux LVM Command (M for help): Wq the partition table has been altered!
Calling IOCTL () to re-read partition table.
Syncing disks. [RooT@localhost ~]# partprobe [root@localhost ~]# pvcreate/dev/vdb1 Physical-volume/dev/vdb1 not found Can ' t open/dev/  VDB1 exclusively.
Mounted filesystem? [Root@localhost ~]# mount/dev/vdb1/mnt mount:unknown filesystem type ' Linux_raid_member ' [root@localhost ~]#/  DEV/VDB1 physical volume/dev/vdb1 not found Can ' t open/dev/vdb1 exclusively.
Mounted filesystem?
  [Root@localhost ~]# vgcreate vg0/dev/vdb1 physical volume/dev/vdb1 not found physical volume/dev/vdb1 not found  Can ' t open/dev/vdb1 exclusively.
  Mounted filesystem?
Unable to add physical volume '/dev/vdb1 ' to Volume group ' vg0 '. [Root@localhost ~]# DF filesystem 1k-blocks Used Available use% mounted on/dev/vda1 10473900 3298000 71759 32%/DEVTMPFS 927072 0 927072 0%/dev tmpfs 942660 140 942520 1%/DEV/SHM TM PFS 942660 664 941996 1%/run tmpfs 942660 0 942660 0%/sys/fs/cgroup [Root@lo CaLhost ~]# mdadm-d/dev/md0 mdadm:md device/dev/md0 does to is active. [Root@localhost ~]# mdadm-s/dev/md0 mdadm:stopped/dev/md0 [root@localhost ~]# pvcreate/dev/vdb1 Physical] Volume/de V/VDB1 not found Warning:linux_raid_member signature detected on/dev/vdb1 at offset 4096. Wipe it?
[y/n] y wiping linux_raid_member signature on/dev/vdb1. WARNING:XFS Signature detected on/dev/vdb1 at offset 0. Wipe it?
  [y/n] y wiping XFS signature on/dev/vdb1. Physical volume "/DEV/VDB1" successfully created [root@localhost ~]# vgcreate vg0/dev/vdb1 Volume Group "vg0" success Fully created [root@localhost ~]# lvcreate-l 300m-n lv0 vg0 Logical Volume "lv0" created [root@localhost ~]# MKFS.XFS /dev/vg0/lv0 meta-data=/dev/vg0/lv0 isize=256 agcount=4, agsize=19200 blks = s ectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 Blo cks=76800, imaxpct=25 =                       Sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 Log =internal log bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, L Azy-count=1 Realtime =none extsz=4096 blocks=0, rtextents=0 [root@localhost ~]#-Mount/dev/vg0/lv0/mn t [root@localhost ~]#


2. View LVM status information

Pvdisplay/dev/vdan will display information about specific physical
Information about the volume
Vgdisplay Vgname will display information about a specific volume group
Information
Lvdisplay/dev/vgname/lvname will show a
Information about a specific logical volume 3. Expansion of logical volumes

[Root@localhost ~]# lvextend-l 900m/dev/vg0/lv0   # #lv的扩展大小后为900M extending Logical Volume Lv0 to 900.00 MiB Lo Gical volume lv0 successfully resized [root@localhost ~]# xfs_growfs/dev/vg0/lv0      # #文件系统的扩展 meta-data= /dev/mapper/vg0-lv0 isize=256 agcount=4, agsize=19200 blks = sectsz=512 attr=2, pro
         Jid32bit=1 = crc=0 data = bsize=4096 blocks=76800, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype= 0 Log =internal bsize=4096 blocks=853, version=2 = sectsz=512 sunit=  0 blks, Lazy-count=1 Realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 76800 to 230400 [root@localhost ~]# lvextend-l 1500m/dev/vg0/lv0   # #lv扩展为1500M, hint size is not enough extending logical volume to 1. GiB Insufficient FREE space:150 extents needed, but only available [root@localhost ~]# pvcreate/dev/vdb2         &NB Sp      # #生成新的pv physical volume/dev/vdb2 not found Warning:linux_raid_member signature detected on/dev/vdb2 at Offset 4096. Wipe it?
  [y/n] y wiping linux_raid_member signature on/dev/vdb2. Physical volume "/DEV/VDB2" successfully created [root@localhost ~]# vgextend vg0/dev/vdb2         # #将新的pv扩展到vg0中 Volume Group "VG0" successfully extended [root@localhost ~]# lvextend-l 1500m/dev/vg0/lv0     # #重新进行lv扩展, and successfully extending logical volume Lv0 to 1.46 GiB Logical Volume lv0 successfully [resized root@localhost XF S_growfs/dev/vg0/lv0           # #扩展文件系统 Meta-data=/dev/mapper/vg0-lv0 isize=256 agcount=12 , agsize=19200 blks = sectsz=512 attr=2, projid32bit=1 = C rc=0 data = bsize=4096 blocks=230400, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096                       ascii-ci=0 ftype=0 Log =internal bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 Blks, lazy-count=1 realtime =none extsz=4096, blocks=0 data rtextents=0 C  Hanged from 230400 to 384000 [root@localhost ~]#

4. Reduction of logical volumes

Change File system type
[Root@localhost ~]# umount/mnt/# #先进行卸载
[Root@localhost ~]# Mkfs.ext4/dev/vg0/lv0 # #更改文件系统类型

Preparatory work before downsizing

[Root@localhost ~]# e2fsck-f/dev/vg0/lv0
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/vg0/lv0:11/96000 files (9.1% non-contiguous), 15356/384000 blocks

[Root@localhost ~]# mount/dev/vg0/lv0/mnt First reduce the file system to 300M in the uninstall, and then reduce the LV, in turn to reduce

5. Create and use snapshots for backup

• Create a/dev/vgname/lvname named Snaplvname, size
New Snapshot volume for 20M
–lvcreate-s-N snaplv-l 20m/dev/vgname/lvname
• If you are backing up your software requirements, mount the snapshot and point the Backup program to the new
Mount point
–mkdir/snapmount
–mount-o Ro/dev/vgname/snaplv/snapmount
• Verifying the state of the snapshot logical volume
–lvs/dev/vgname/snaplv
• When you are no longer using the snapshot, remove the mount and delete it
–umount/snapmount
–lvremove/dev/vgname/snaplv





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.