Using Logical volume (LVM) in Linux to achieve the overall and sustainable expansion of multiple hard disks (II)

Source: Internet
Author: User

From: http://space.baidu.com/hl_jacky/blog/item/8c75e0617189666b0d33fa53.html

2. resizing of LVM Devices

One of the biggest advantages of LVM devices is that space can be expanded as long as the hardware conditions permit. The method is as follows:

To expand a device, you must first know how many other devices can be used. When creating a VG device, you can add up the size of the two partitions. You can use it to reduce the number of used partitions, here we will discuss the expansion in two cases.

(1) using the original available space for expansion, both of my hard disks are 34.6 GB, and 60 GB, that is, 34.6 + 34.6-60, there is at least 5 GB space available, the hard disk capacity is different from the capacity identified by the operating system, so I have less space here.

[Root @ vpnserv ~] # Vgdisplay
Data
#### You can also run the vgdisplay command to view the current VG usage.
--- Volume group ---
VG Name Data
System ID
Format lvm2
Metadata areas 2
Metadata Sequence No 4
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 68.36
GB
#### Here we can see that our VG data is 68 Gb in total
PE size 4.00
MB
#### By default, each extended block is 4 MB. The size of the extended block can be adjusted using the-S parameter when creating the VG. The largest block can even be used as a parameter using t.
Total PE
17500
#### A total of 17500 extension Blocks
Alloc PE/size 15500/60 .55
GB
#### We have used 60 GB
Free PE/size 2000/7 .81 GB
Vg uuid hOixVC-ljbJ-Z5QG-de9b-KFEy-PDZb-o2EDME

[Root @ vpnserv ~] #
Mount
#### View the current Mount status
/Dev/sda2 on/type ext3 (RW)
None on/proc type proc (RW)
None on/sys type sysfs (RW)
None on/dev/PTS type devpts (RW, gid = 5, mode = 620)
Usbfs on/proc/bus/USB Type usbfs (RW)
/Dev/sda1 on/boot type ext3 (RW)
/Dev/sda5 on/Data Type ext3 (RW)
None on/dev/SHM type tmpfs (RW)
None on/proc/sys/fs/binfmt_misc type binfmt_misc (RW)
SunRPC on/var/lib/nfs/rpc_pipefs type rpc_pipefs (RW)
/Dev/mapper/data-lvdata on/usr/local/WWW type ext3 (RW)
[Root @ vpnserv ~] # DF
-H
#### View disk space usage using the DF command
TEM size used avail use % mounted on
/Dev/sda2 15 GB 7.8g 6.0g 57%/
/Dev/sda1 99 m 12 m 83 m 12%/boot
/Dev/sda5 16g 2.7g 12g 19%/Data
None 506 M 0 506 m 0%/dev/SHM
/Dev/mapper/data-lvdata
58G 12g 44g 21%
/Usr/local/WWW
#### Here we can see that the original 60g recognition has become 58G and 12G has been used
[Root @ vpnserv ~] # Ls/usr/local/www/#### View data on this device
STABLE-200706-i386-bootonly.iso [rhce ????,???? Rhel.4.dvd).cd5.rar
6.2-STABLE-200706-i386-disc1.iso [rhce ????,???? Rhel.4.dvd).cd6.rar
6.2-STABLE-200706-i386-docs.iso [rhce ????,???? Rhel.4.dvd).cd7.rar
[Rhce ????,???? Rhel.4.dvd).cd1.rar [rhce ????,???? Rhel.4.dvd]. RHEL4-U5-i386-AS-dvd.iso
[Rhce ????,???? Rhel.4.dvd).cd2.rar [????????. Linux.5]. TLF-SOFT-RedHat.Enterprise.Linux.5.Update.1-XiSO.iso
[Rhce ????,???? Rhel.4.dvd).cd3.rar [????????. Linux.5]. TLF-SOFT-RedHat.Enterprise.Linux.5.Update.1.x64-XiSO.iso
[Rhce ????,???? Rhel.4.dvd).cd4.rar lost + found

The biggest advantage of LVM is that it can expand the space without damaging the original data. The process is as follows:
[Root @ vpnserv ~] # Umount/usr/local/www/#### first uninstall the volume to be operated from the Operating System
[Root @ vpnserv ~] # Ls
/Usr/local/www/
#### Check whether the files are invisible
[Root @ vpnserv ~] # Lvextend-L + 1000 m
/Dev/data/lvdata
#### Use the lvextend command to expand 1 GB space for the/dev/data/lvdata Device
Extending logical volume lvdata to 59.57 GB
Logical volume lvdata successfully resized
[Root @ vpnserv ~] # E2fsck-F
/Dev/data/lvdata
#### Check the relationship between inode and block corresponding to the LVM device. Be careful about the-year-old ship.
E2fscks 1.35 (28-feb-2004)
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/data/lvdata: 24/7684096 files (4.2% non-contiguous), 3185237/15360000 Blocks
[Root @ vpnserv ~] # Resize2fs
/Dev/data/lvdata
#### Use the resize2fs command to format the newly added part
Resize2fs 1.35 (28-feb-2004)
Resizing the filesystem on/dev/data/lvdata to 15616000 (4 K) blocks.
The filesystem on/dev/data/lvdata is now 15616000 blocks long.

[Root @ vpnserv ~] # Mount/dev/data/lvdata/usr/local/www/#### remount
[Root @ vpnserv ~] # Ls
/Usr/local/www/
#### Check whether the original items are still there ????
6.2-STABLE-200706-i386-bootonly.iso [rhce ????,???? Rhel.4.dvd).cd5.rar
6.2-STABLE-200706-i386-disc1.iso [rhce ????,???? Rhel.4.dvd).cd6.rar
6.2-STABLE-200706-i386-docs.iso [rhce ????,???? Rhel.4.dvd).cd7.rar
[Rhce ????,???? Rhel.4.dvd).cd1.rar [rhce ????,???? Rhel.4.dvd]. RHEL4-U5-i386-AS-dvd.iso
[Rhce ????,???? Rhel.4.dvd).cd2.rar [????????. Linux.5]. TLF-SOFT-RedHat.Enterprise.Linux.5.Update.1-XiSO.iso
[Rhce ????,???? Rhel.4.dvd).cd3.rar [????????. Linux.5]. TLF-SOFT-RedHat.Enterprise.Linux.5.Update.1.x64-XiSO.iso
[Rhce ????,???? Rhel.4.dvd316.cd4.rar lost + found #### no harm
[Root @ vpnserv ~] # DF
-H
#### Check whether the space status has changed from 58g to 59g ?? Success!
Filesystem size used avail use % mounted on
/Dev/sda2 15 GB 7.8g 6.0g 57%/
/Dev/sda1 99 m 12 m 83 m 12%/boot
/Dev/sda5 16g 2.7g 12g 19%/Data
None 506 M 0 506 m 0%/dev/SHM
/Dev/mapper/data-lvdata
59g, 12g, 45g, 21%/usr/local/WWW

(2) If a new hard disk is added, it will be a little troublesome. If your system is a running application system, it is not allowed to put the system down, how to expand the space? In this section, the following two commands are used to expand the space online in a timely manner.

Use pvcreate/dev/hdd1 to add/dev/hdd1 to PV.

Use vgextend data/dev/hdd1 to add the partition to Data.

Use lvextend-L + 1000 m/dev/data/lvdata to increase the lvdata space by 1 GB

Use ext2online/usr/local/WWW to activate the new space.

For detailed procedures, see the following example!

[Root @ vpnserv ~] # Lvextend-L + 1000 m/dev/data/lvdata
Extending logical volume lvdata to 60.55 GB
Logical volume lvdata successfully resized
[Root @ vpnserv ~] # Ext2online/usr/local/www/
Ext2online v1.1.18-2001/03/18 for ext2fs 0.5b
[Root @ vpnserv ~] # DF-H
Filesystem size used avail use % mounted on
/Dev/sda2 15 GB 7.8g 6.0g 57%/
/Dev/sda1 99 m 12 m 83 m 12%/boot
/Dev/sda5 16g 2.7g 12g 19%/Data
None 506 M 0 506 m 0%/dev/SHM
/Dev/mapper/data-lvdata
60g, 12g, 46g, 20%/usr/local/WWW

Construction and damage. How to split LVM?

The procedure is very simple. During the construction, we built PV from the bottom up -------> VG -----------> LVM

Remove from top to bottom When disassembling

Of course, the premise is that you must uninstall it first.

Lvremove/dev/data/lvdata #### remove an LVM Device

Vgchange-An/dev/Data #### convert the VG status to offline

Vgremove data #### delete a VG group

Pvremove/dev/sdb1/dev/sdc1/dev/sdd1 #### Delete PV

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.