LVM creates, expands, reduces logical disk size, and the corresponding file system size

Source: Internet
Author: User
Tags ldap uuid
PVs LVs VGs
PVS: View the physical volume LVS: View logical Volumes VGS: View Volume Group One, create LVM fdisk-l view hard disk information The prerequisite is a graphical interface with a disk: 1. Initialize a physical disk device to a physical volume [Root@mail ~]# Pvcreate/dev/sdb/dev /SDC if displayed: [Root@test ~]# pvcreate/dev/xvda1 Can ' t open/dev/xvda1 exclusively. Mounted filesystem? Need to uninstall First: UMOUNT/DEV/XVDA1 2. Create a volume group and add PV to the volume Group [root@mail ~]# vgcreate LINUXRHEL/DEV/SDB/DEV/SDC 3. To create a logical volume based on a volume group [root@mail ~]# LV Create-n mylv-l 2G Linuxrhel 4. To create a file system for a good logical volume [Root@mail ~]# ls-l/dev/linuxrhel/mylv lrwxrwxrwx 1 root 7 May 6 00 : 07/dev/linuxrhel/mylv->. /dm-0 [Root@mail ~]# mkfs.ext4/dev/linuxrhel/mylv 5. Mount a formatted logical volume using [root@mail ~]# mkdir/test [Root@mail ~]# mount/dev/li nuxrhel/mylv/test [Root@mail ~]# DF
Second, extended volume group VGS: If the volume group space is not enough 1. The hard disk to be added to the VG is formatted as PV [Root@mail ~]# pvcreate/dev/sdd Physical Volume "/DEV/SDD" successfully created 2 Add the new PV to the specified volume group [root@mail ~]# vgextend linuxrhel/dev/sdd Volume Group "Linuxrhel" successfully extended 3. Look at the enlarged VG size [root@ Mail ~]# vgs VG #PV #LV #SN Attr vsize vfree Linuxrhel 3 1 0 wz--n-14.99g 10.99g Third, extended logical volume LVS: Pull operations on logical volumes can be performed online without unloading logical volumes 1. Guarantee There is enough free space in the VG [Root@mail ~]# vgdisplay 2. Expand logical volumes [Root@mail ~]# lvextend-l +2g/dev/linuxrhel/mylv 3. Look at the expanded LV size [Root@mail ~]# Lvdisplay 4. update file system [Root@mail ~]# df-h [Root@mail ~]# resize2fs/dev/linuxrhel/mylv 5] Check the updated file system [Root@mail ~]# df-h Four: Delete Except LVM if LV is in use, first uninstall: [Root@mail ~]# umount/dev/linuxrhel/mylv 1. Delete LV [root@mail ~]# lvremove/dev/linuxrhel/mylv 2. Remove VG [Root@mail ~]# vgremove Linuxrhel 3. Delete physical volumes [Root@mail ~]# PVREMOVE/DEV/SDB/DEV/SDC
V. Reduce logical volumes
The abbreviated operation of the logical volume must be performed offline to uninstall the logical volume
1. Uninstall the logical volumes that have been mounted
Umount/dev/linuxrhel/mylv
2. Reduce the file system
You will be prompted to run E2fsck–f (encounter error direct fix not prompt) Check file system
Resize2fs/dev/linuxrhel/mylv 2G (shrink 2 g)
[Root@mail ~]# e2fsck-f/dev/linuxrhel/mylv e2fsck 1.41.12 (17-may-2010) pass 1:checking inodes, blocks, and sizes 2:checking directory structure pass 3:checking directory connectivity Pass 4:checking reference counts pass 5:checking Group summary information/dev/linuxrhel/mylv:11/262144 files (0.0% non-contiguous), 33870/1048576 blocks
[Root@mail ~]# resize2fs/dev/linuxrhel/mylv 2G resize2fs 1.41.12 (17-may-2010) resizing the filesystem on/dev/linuxrhel/ Mylv to 524288 (4k) blocks. The filesystem on/dev/linuxrhel/mylv is now 524288 blocks long.

3. Reduce LV lvreduce-l -2g/dev/linuxrhel/mylv (reduced to 2G)
[Root@mail ~]# lvreduce-l 2g/dev/linuxrhel/mylv warning:reducing Active Logical Volume to 2.00 GiB this may DESTROY R DATA (filesystem etc.) Do your really want to reduce mylv? [y/n]: Y reducing Logical volume MYLV to 2.00 GiB-Logical Volume MYLV successfully resized

4. View the reduced LV
Lvdisplay
[Root@mail ~]# lvdisplay---Logical volume---LV path/dev/linuxrhel/mylv lv Name mylv VG Name linuxrhel LV UUID yst2ss- Tudw-kdac-o6r5-ixnd-bhxy-ezrtzf LV Write Access read/write LV creation host, time mail.linuxrhel.net, 2016-05-06 00:16:07 +0800 LV Status Available # Open 0 LV Size 2.00 GiB Current LE Segments 1 allocation inherit Read ahead sectors auto -currently set to 256 block device 253:0

5. Mount [Root@mail ~]# mount/dev/linuxrhel_mylv/test [root@mail ~]# df-h filesystem Size Used Avail use% Mounted-on/dev/s Da2 18G 3.0G 14G 18%/tmpfs 504M 224K 503M 1%/dev/shm/dev/sr0 3.1G 3.1G 0 100%/media/rhel_6.5 i386 Disc 1/dev/mapper/ Linuxrhel-mylv 2.0G 67M 1.9G 4%/test

Shrink Volume Group
1. Remove a PV from the specified volume group
[Root@mail ~]# vgreduce linuxrhel/dev/sdd removed '/DEV/SDD ' from volume group ' Linuxrhel '

2. Check the size of the shrinking volume group
[Root@mail ~]# vgdisplay---Volume group---VG Name linuxrhel System ID Format lvm2 Metadata Areas 2 Metadata Sequence N o 6 vg Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 MAX PV 0 Cur PV 2 Act PV 2 VG Size 9.99 GiB PE Si Ze 4.00 MiB Total PE 2558 Alloc pe/size 512/2.00 GiB free pe/size 2046/7.99 GiB VG UUID s1ap6j-01rs-qgao-zw7f-rg09 -uvok-abnp5k
3. Delete Physical Volume: Pvremove/dev/sde
[Root@mail ~]# PVREMOVE/DEV/SDD Labels on physical volume "/DEV/SDD" successfully wiped
Extended Logical Volume: Lvextend-l +30g/dev/rootvg/lvroot Extended Logical Volume Resize2fs/dev/rootvg/lvroot initialization file system
Requirements: Please assign resources in MISO Department host project name: Internet Security Platform _ industry V1.0.0_miso (Y9901) Product Name: Internet Security Platform V1.0.0 host: 172.21.10.40,172.21.10.140 Root password: sp@sitech.20!$10 username/password: Misoisp/misoisp directory:/misoisp size: 10G LVS |grep misoisp See if you have this file VGs Let's see what the volume group is. Next write Create file system script to use LL Cat/etc/group see which group to use if no need to build through Groupadd: cat/etc/passwd See where the UID is written that can be used echnweb:x : 2021:2000::/echnweb:/bin/bash ldap:x:55:55:ldap User:/var/lib/ldap:/sbin/nologin zabbix:x:2022:2022::/home/ Zabbix:/bin/bash Bnms:x:2023:2023::/home/bnms:/bin/bash So the next UID is 2024.
Cd/root/shell
VI createfilesys20161122.sh
Lvcreate-l 10g-n lv_misoisp datavg mkfs.ext4/dev/datavg/lv_misoisp echo "/dev/datavg/lv_misoisp/misoisp ext4 0 0 ">>/etc/fstab mkdir/misoisp mount/misoisp useradd-d/misoisp-m-u 2024-g MISO misoisp cp '/ETC/SKEL/.BASH_PR Ofile '/ETC/SKEL/.BASHRC '/etc/skel/.bash_logout '/misoisp chown-r misoisp:miso/misoisp echo misoisp|passwd--stdin m Isoisp
ll chmod u+x createfilesys20161122.sh LL./createfilesys20161109.sh
Df-h
Su-misoisp

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.