Lvm tossing notes

Source: Internet
Author: User
Lvm tossing note LVM (reference Baidu Encyclopedia): LVM is short for logical disk volume management (LogicalVolumeManager). It is a mechanism for managing disk partitions in Linux, LVM is a logical layer built on the hard disk and partition to improve disk LVML... lvm tossing note LVM (reference to Baidu Encyclopedia): LVM is short for Logical Volume Manager. it is a mechanism for managing disk partitions in Linux, LVM is a logical layer built on hard disks and partitions to improve the flexibility of LVM zone management for disks. As mentioned above, LVM is a logical layer added between the disk partition and the file system to shield the file system from the underlying disk partition layout and provide an abstract disk volume, create a file system on the disk. A physical volume (physical volume) refers to a hardware partition or a device (such as RAID) with the same functions as a disk partition logically. it is the basic storage logical block of LVM, however, compared with basic physical storage media (such as partitions and disks), it contains management parameters related to LVM. The most common hard-to-decide problem that Linux users encounter when installing the Linux operating system is how to correctly evaluate the size of each partition to allocate suitable hard disk space. When a partition space is exhausted, the solution is usually to use a symbolic link or a tool to adjust the partition size (such as PatitionMagic), but this is only a temporary solution, the problem is not fundamentally solved. With the appearance of the logical disk volume management function in Linux, these problems have been solved, and users can easily adjust the size of each partition without downtime. Demo environment: CENTOS6.4. three hard disks, two of which are created. Overview of one extended basic: PE | PV | VG | LVPE (physical extend): physical extended PV (physical volume ): physical volume --- what is at the bottom layer of LVM can be a hard disk such as sda, sdb, and sdc, or a partition such as sda1 and sdb1VG (volume group) in a hard disk ): volume Group-a volume group consists of multiple LV, which is an abstract directory rather than a device, such as/dev/testVgLV (logic volume ): the logical volume --- LV exists in the PE, as shown in the following figure: pv:/dev/sdb/dev/sdc -- pv -- vg: -- pv -- lv: -- lv -- l V -- lv -- LVM command parameter description: pvs, vgs, lvs: are simple display of relevant information. pvdisplay, vgdisplay, and lvdisplay: Detailed information about LVM creation process: PV> VG> LV> formatting> Use of LVM for mounting --- create and view PV [plain] [root @ localhost ~] # Pvcreate/dev/sd [B, c] // you can use a partition or hard disk .. pvcreate/dev/sd [B, c] 1 is the first partition of the two hard disks to create PV Physical volume "/dev/sdb" successfully created Physical volume "/dev/sdc" successfully created [root @ localhost ~] # Pvs pv vg Fmt Attr PSize PFree/dev/sdb lvm2 a -- 20.00g 20.00g/dev/sdc lvm2 a -- 20.00g 20.00g [root @ localhost ~] # Pvsdisplay-bash: pvsdisplay: command not found [root @ localhost ~] # Clear [root @ localhost ~] # Pvs pv vg Fmt Attr PSize PFree/dev/sdb lvm2 a -- 20.00g 20.00g/dev/sdc lvm2 a -- 20.00g 20.00g [root @ localhost ~] # Pvdisplay "/dev/sdb" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name/dev/sdb VG Name PV Size 20.00 GiB Allocatable no pe Size 0 total PE 0 Free PE 0 Allocated PE 0 pv uuid U71gX3-EtNA-tVPL-8WYL-99Do-PY3c-LUsfeE "/dev/sdc" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name/dev/sdc VG name PVS Size 20.00 GiB Allocatable no pe Size 0 Total PE 0 F Ree PE 0 Allocated PE 0 pv uuid use of TqI9uD-vvG1-2eD2-kyTM-cEtj-ZpXc-ctLi91 LVM --- create and view VG [plain] [root @ localhost ~] # Vgcreate testVG/dev/sd [B, c] Volume group "testVG" successfully created // disk or partition where the vgcreate Volume group name falls into the Volume group [root @ localhost ~] # Vgs VG # PV # LV # SN Attr VSize VFree testVG 2 0 0 wz -- n-39.99g 39.99g [root @ localhost ~] # Vgdisplay --- Volume group --- VG Name testVG System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable max lv 0 Cur LV 0 Open LV 0 Max PV 0 cur PV 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE/Size 0/0 Free PE/Size 10238/39 .99 GiB vg uuid fSkmZR-8WiE-COe8-n4QO-rmAz-2PgJ-BRuity LVM use --- LV creation and view [plain] [root @ localhost ~] # Lvcreate-n testLV1-L 10G testVG //-n is the name of the LV volume, -L: Set the LV size [G or M] Logical volume "testLV1" created [root @ localhost ~] # Lvs lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert testLV1 testVG-wi-a ---- 10.00g [root @ localhost ~] # Lvdisplay --- Logical volume --- LV Path/dev/testVG/testLV1 LV Name testLV1 VG Name testVG lv uuid bPyUwj-twOD-flGj-x266-mXCl-rcfa-FBUykW LV Write Access read/write LV Creation host, time localhost. localdomain, 17:32:23-0700 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto-currently set to 256 Block device 253: 0 LV Use M --- LV format and Mount [plain] [root @ localhost ~] # Mkfs. ext4/dev/testVG/testLV1 // here, my format is ext4 mke2fs 1.41.12 (17-May-2010) Filesystem label = OS type: Linux Block size = 4096 (log = 2) fragment size = 4096 (log = 2) Stride = 0 blocks, Stripe width = 0 blocks 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user First data block = 0 Maximum filesystem blocks = 2684354560 80 block groups 32768 blocks per group, 32768 fragments per group 8 192 inodes per group Superblock backups stored on blocks: 32768,983 04, 163840,229 376, 294912,819 200, 884736,160 5632 Writing inode tables: done Creating journal (32768 blocks ): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 37 mounts or 180 days, whichever comes first. use tune2fs-c or-I to override. [root @ localhost ~] # Mount/dev/testVG/testLV1/mnt [root @ localhost ~] # Mount/dev/sda2 on/type ext4 (rw) proc on/proc type proc (rw) sysfs on/sys type sysfs (rw) devpts on/dev/pts type devpts (rw, gid = 5, mode = 620) tmpfs on/dev/shm type tmpfs (rw, rootcontext = "system_u: object_r: tmpfs_t: s0 ")/dev/sda1 on/boot type ext4 (rw) none on/proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/mapper/testVG-testLV1 on/mnt type ext4 (rw) LVM advanced use: Stretch and zoom expansion LV [plain] [root @ loca Lhost ~] # Lvextend-L + 5G/dev/testVG/testLV1 // increase the size of 5 GB to testLV1 Extending logical volume testLV1 to 15.00 GiB Logical volume testLV1 successfully resized [root @ localhost ~] # Resize2fs/dev/testVG/testLV1 // update the file system and redefine the disk size. resize2fs 1.41.12 (17-May-2010) filesystem at/dev/testVG/testLV1 is mounted on/mnt; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 mongoming an on-line resize of/dev/testVG/testLV1 to 3932160 (4 k) blocks. the filesystem on/dev/testVG/testLV1 is now 3932160 blocks long. [root @ localhost ~] # Df-h Filesystem Size Used Avail Use % Mounted on/dev/sda2 28G 3.4G 23G 13%/tmpfs 935 M 84 K 935 M 1%/dev/shm/dev/sda1 291 M 58 M 218 M 22%/boot/dev/mapper/testVG-testLV1 15G 153 M 14G 2%/mnt extended VG here demonstrate adding a new hard disk to an existing volume Group ,, to increase the number of PVS available [plain] [root @ localhost ~] # Pvcreate/dev/sdd Physical volume "/dev/sdd" successfully created [root @ localhost ~] # Vgextend testVG/dev/sdd Volume group "testVG" successfully extended [root @ localhost ~] # Vgs VG # PV # LV # SN Attr VSize VFree testVG 3 1 0 wz -- n-59.99g 44.99g // why not remaining 60G, it is because we created a LV1 10G and expanded 5G to it. therefore, before you perform this operation on a 45 GB disk, you must re-define the volume size of the lv mounted by umount .. shrink the volume again --- if you do not follow this step. data is very likely to be lost (irrecoverable, remember) [plain] [root @ localhost ~] # Umount/mnt // unmount the mounted LV volume. for details, refer to your mount point [root @ localhost ~]. # E2fsck-f/dev/testVG/testLV1 // check the file system [root @ localhost ~] # Resize2fs/dev/testVG/testLV1 5G // adjust The size of your file system online resize2fs 1.41.12 (17-May-2010) The filesystem is already 3932160 blocks long. nothing to do! [Root @ localhost ~] # Lvreduce-L-10G/dev/testVG/testLV1 // use lvreduce to reduce your disk size WARNING: switching active logical volume to 5.00 GiB this may destroy your data (filesystem etc .) do you really want to reduce testLV1? [Y/n]: y Cing logical volume testLV1 to 5.00 GiB Logical volume testLV1 successfully resized [root @ localhost ~] # Lvdisplay // view detailed information about LV --- Logical volume --- LV Path/dev/testVG/testLV1 LV Name testLV1 VG Name testVG lv uuid bPyUwj-twOD-flGj-x266-mXCl-rcfa-FBUykW LV Write Access read/write LV Creation host, time localhost. localdomain, 17:32:23-0700 LV Status available # open 0 LV Size 5.00 GiB // after 10 GB is removed, the remaining 5G Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto-currently set 256 Block device 253: 0 zoom out VG [plain] [root @ localhost ~] # Vgs // it is worth noting that the hard disk or partition removed from the volume group must be smaller than the remaining space. otherwise, the VG # PV # LV # SN Attr VSize VFree testVG 3 1 0 wz -- n-59.99g 54.99g [root @ localhost ~] will fail to be saved. # Vgreduce testVG/dev/sdd Removed "/dev/sdd" from volume group "testVG" [root @ localhost ~] # Vgs VG # PV # LV # SN Attr VSize VFree testVG 2 1 0 wz -- n-39.99g 34.99g delete LVM: delete order bottom-up: lv> vg> pv [plain] [root @ localhost ~] # Lvremove/dev/testVG/testLV1 Do you really want to remove active logical volume testLV1? [Y/n]: y Logical volume "testLV1" successfully removed [root @ localhost ~] # Vgremove testVG Volume group "testVG" successfully removed [root @ localhost ~] # Pvremove/dev/sd [B, c] Labels on physical volume "/dev/sdb" successfully wiped Labels on physical volume "/dev/sdc" successfully wiped [root @ localhost ~] # Pvs pv vg Fmt Attr PSize PFree/dev/sdd lvm2 a -- 20.00g 20.00g [root @ localhost ~] # Pvremove/dev/sdd Labels on physical volume "/dev/sdd" successfully wiped [root @ localhost ~] # Pvs [root @ localhost ~] # Recommended commands for vgs No volume groups found: e2fsadm uses e2fsadm-L + 10G/dev/testVG/testLv1 equivalent to # lvextend-L + 10G/dev/testVG/testLv1 # resize2fs/dev/testVG/testLv1 using e2fsadm-L -10G/dev/testVG/testLv1 (equivalent to umount first) # resize2fs/dev/testVG/testLv1 5G # lvreduce-L-10G/dev/testVG/testLv1
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.