Note:
PV: physical volume
VG: volume group (a VG on the physical layer is composed of one or more PVs)
LV: logical volume (a VG on the logical level is composed of one or more LV)
The logical volume creation sequence is PV-> VG-> LV
The hard disk of the IDE interface is displayed as hda.
The hard disk of the SCSI interface is displayed as sda.
1. Create a logical volume:
For example, if we select hda5 as the logic, we must first confirm that hda5 is in umount state.
# Df-h # Check the mount status of hda5 in the mount status # umount/dev/hda5 # Remove hda5
# Pvcreate/dev/hda5 # create hda5 as a physical volume # pvscan # View all the current physical volumes and confirm that hda5 exists
# Vgcreate VolGroup0/dev/hda5 # Create a volume group VolGroup0 and add hda5 to the volume group # vgscan # View all the current volume groups. Check that VolGroup0 exists.
# Lvcreate-L 5G-nVol01 VolGroup0 # Create a 5G logical volume Vol01, specify the volume group as VolGroup0 # lvremove VolGroup0/Vol01 # Delete the logical volume Vol01 # lvscan # View all the current logical volumes and confirm that there is Vol01
# Mkfs. ext3/dev/VolGroup0/Vol01 # format the new logical volume Vol01 # mkdir/test # Create a directory # mount/dev/VolGroup0/Vol01/test # mount the logical volume Vol01 to test directory
As a result, a logical volume is complete.
II. Extend the logical volume:
2.1 VG space is large enough to only expand LV
# Lvextend-L + 2G/dev/VolGroup0/Vol01 # Add 2 GB space to the logical volume Vol01 # resize2fs/dev/VolGroup0/Vol01 # reset the volume of Vol01 # lvscan # you can see the current lv size changes to 7 GB # reboot # restart the machine (do not restart) # df-hl # After restart, the size of/dev/VolGroup0/Vol01 is changed to 7 GB.
2.2 The VG space is insufficient. Expand the VG
The premise of extending the VG is that there is still unallocated space on your hard disk.
# Fdisk/dev/hdan-> e-> 6-> + 5G-> w # Create a 5G extended differentiation zone number of 6 # mkfs. ext3/dev/hda6 # format the new hda6 # fdisk-l # View all the current partitions and you will see hda6.
2.3 next we will merge the new hda6 into VG.
# Pvcreate/dev/hda6 # create hda6 as a physical volume # pvscan # View all the current physical volumes and confirm that hda6 exists
# Vgextend VolGroup0/dev/hda6 # Add hda6 to the VolGroup0 volume group # vgs # view the brief information of vgs and find that the space of VolGroup0 increases
III. Zoom outLVLogical Volume(Note:700 MRemaining size after reduction)
Today I learned how to reduce LV size in RHEL6, and the example below is to set LV "/dev/mapper/vg_redhat6-lv_pgdata_01"
To 700 M, that is, to reduce 86 M.
3.1 Current LVM information
/Dev/mapper/vg_redhat6-lv_root 13G 7.7G 4.6G 63%/tmpfs 250 M 264 K 250 M 1%/dev/shm/dev/sda1 485 M 31 M 429 M 7%/boot/ dev/mapper/vg_redhat6-lv_opt 786 M 593 M 154 M 80%/opt |
3.2 unmount)
[[Email protected] ~] # Umount/dev/mapper/vg_redhat6-lv_opt |
3.3 check the file system (e2fsck)
[[Email protected] ~] # E2fsck/dev/mapper/vg_redhat6-lv_opt e2fsck 1.41.12 (17-May-2010)/dev/mapper/vg_redhat6-lv_opt: clean, 236/49152 files, 154817/179200 blocks |
3.4 shrink the file system (resize2fs)
[[Email protected] ~] # Resize2fs-f/dev/mapper/vg_redhat6-lv_opt 700 M resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on/dev/mapper/vg_redhat6-lv_pgdata_01 to 179200 (4 k) blocks. the filesystem on/dev/mapper/vg_redhat6-lv_pgdata_01 is now 179200 blocks long. |
3.5 LV reduce)
[[Email protected] ~] # Lvreduce-L 700 M/dev/mapper/vg_redhat6-lv_opt WARNING: rolling Cing active logical volume to 700.00 MiB This may destroy your data (filesystem etc .) Do you really want to reduce lv_pgdata_01? [Y/n]: y Indexing Cing logical volume lv_pgdata_01 to 700.00 MiB Logical volume lv_pgdata_01 successfully resized |
3.6 view the current LV size
[[Email protected] ~] # Lvs lv vg Attr LSize Origin Snap % Move Log Copy % Convert lv_opt vg_redhat6-wi-ao ---- 700.00 m lv_root vg_redhat6-wi-ao ---- 13.10g lv_swap vg_redhat6-wi-ao ---- 1.91g |
3.7 re-mount the file system. View
[[Email protected] ~] # Mount-t ext4/dev/mapper/vg_redhat6-lv_opt/opt [[Email protected] ~] # Df-hl Filesystem Size Used Avail Use % Mounted on /Dev/mapper/vg_redhat6-lv_root 13G 7.7G 4.6G 63%/ Tmpfs 250 M 264 K 250 M 1%/dev/shm /Dev/sda1 485 M 31 M 429 M 7%/boot /Dev/mapper/vg_redhat6-lv_opt 688 M 593 M 61 M 91%/opt |
Note: The Directory/database/skytf/pgdata1 has been successfully reduced to about 700 MB.
Ps. At this time, vg has free space. You can use # vgdisplay to view the remaining size (in the red box), and use 2.1 to allocate the idle size to other logical volumes. For example
650) this. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4D/DB/wKioL1RbHiKiDKRSAAHChxMDF2Q928.jpg "title =" QQ20141106150513.jpg "alt =" wKioL1RbHiKiDKRSAAHChxMDF2Q928.jpg "/>
--Summary
Before reducing the LV size, you must first reduce the file system size.
This article from the "IT-smile" blog, please be sure to keep this http://pynliu.blog.51cto.com/5027391/1573438
Establish, expand, and contract LVM Logical Volumes