Eighth. Disk and file System Management LVM Logical Volume management

Source: Internet
Author: User

Eighth Chapter LVM Logical Volume Management

Basic concepts of LVM mechanism

Pv(physical Volume, physical volume)

An entire hard drive, or a common partition built using tools such as Fdisk

Includes many default 4MB sizes of PE (physical Extent, base unit)

VG(Volume Group, Volume group)

The overall combination of one or more physical volumes

LV(Logical Volume, logical volume)

A piece of space separated from a volume group used to create a file system

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" Image "Src=" http://s3.51cto.com/wyfs02/M02/6C/6C/wKiom1VI413z6EzbAACCXfsFoAE351.jpg "width=" 422 "height=" 124 "/ >

(Create a physical volume--Create a volume group--Create a logical volume from a volume group)

Related commands

Pvcreate Device Name

Vgcreate Volume group Name Physical volume name 1 physical volume name 2

Lvcreate-l size-N Logical Volume name volume group name

Lvextend-l + size/dev/Volume group name/Logical volume name

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" Image "Src=" http://s3.51cto.com/wyfs02/M00/6C/6C/wKiom1VI42Ph44WNAADoOgQA-vM884.jpg "width=" 423 "height=" 166 "/ >

Steps:

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" Image "Src=" http://s3.51cto.com/wyfs02/M01/6C/6C/wKiom1VI42nTcWr0AACZsBk1aVo151.jpg "width=" 474 "height=" 158 "/ >

One. Insert two new disks, and use the fdisk command to divide the two new disks into a 10G size partition and change the ID number to 8e(logical volume). :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image002 "src=" http://s3.51cto.com/wyfs02/M02/6C/6C/wKiom1VI426zD2_OAACX6nv1aJ0885.jpg "width=" 446 "height=" 166 "/>

Two Set up the logical Volume mbox, format it to the EXT3 file system, and mount it to the/mailbox directory.

Steps:

1. Use the pvcreate command to create a new two partition (which can also be a whole hard disk ) as a logical volume. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image004 "src=" http://s3.51cto.com/wyfs02/M00/6C/68/wKioL1VI5OXy1XpzAAA1VlGeREk437.jpg "width=" 444 "height=" "/>

PV Physical Volume Management

Pvscan command : Used to scan all physical volumes in the system and output relevant information. With the Rhel 5 system installed with the automatic partitioning scheme, the system disk SDA is divided into sda1 and sda2 two partitions, where the SDA2 partition is converted to a physical volume and a VolGroup00 volume group is created based on the physical volume, and a logical volume VOLGROUP00 is created in the LogVol00 volume group. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image006 "src=" http://s3.51cto.com/wyfs02/M01/6C/68/wKioL1VI5OrzVcWyAABBTGuAfws590.jpg "width=" "height=" "/>

pvcreate command: used to convert a partition or an entire hard disk into a physical volume, mainly by adding LVM attribute information and dividing the PE storage unit. This command requires a device file of the hard disk or partition as a parameter (there can be more than one).

Pvdisplay command: to display the details of a physical volume, you need to use the specified physical volume as the command parameter, which displays information for all physical volumes by default:

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image008 "src=" http://s3.51cto.com/wyfs02/M02/6C/68/wKioL1VI5PCD20RbAACY2VFVFhg378.jpg "width=" 439 "height=" 222 "/>

Pvremove command: to restore a physical volume to a normal partition or disk, no longer used in the LVM system, the removed physical volume will not be recognized by Pvscan. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image010 "src=" http://s3.51cto.com/wyfs02/M00/6C/68/wKioL1VI5PWBpUK-AAAaD8NnECA422.jpg "width=" 442 "height=" "/>

2. Use the Vgcreate command to create a new two partition as a volume group named Mail. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image012 "src=" http://s3.51cto.com/wyfs02/M01/6C/68/wKioL1VI5PvCJZ1CAAAw4-DL5SE268.jpg "width=" 434 "height=" "/>

VG Volume Group Management

Vgscan command : Used to scan an established LVM volume group and related information in the system. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image014 "src=" http://s3.51cto.com/wyfs02/M02/6C/6C/wKiom1VI44_R7rt_AAAzkXlXPrI241.jpg "width=" 442 "height=" "/>

vgcreate commands : Used to create one or more physical volumes as a volume group, the first command parameter sets the name of the new volume group, and then, in turn, specifies the physical volume that needs to be added to the volume group as a parameter.

Vgdisplay command : Used to display detailed information for each volume group in the system, you need to use the specified volume group name as the command parameter (information for all volume groups is displayed when a volume group is not specified). :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image016 "src=" http://s3.51cto.com/wyfs02/M01/6C/6C/wKiom1VI48Dj7A4KAAB995Z8jUQ560.jpg "width=" 443 "height=" 214 "/>

Vgremove command : To delete the specified volume group, specify the volume group name as the parameter. When deleting, make sure that there are no logical volumes in use in the volume group. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image018 "src=" http://s3.51cto.com/wyfs02/M02/6C/6C/wKiom1VI48WCyZfPAAAY4E89pUw944.jpg "width=" "height=" "/>

Vgextend command : The disk space used to extend the volume group. When you create a new physical volume and need to add it to an existing volume group, you can use the Vgextend command. The first parameter of the command is the name of the volume group that needs to expand capacity, followed by each physical volume that needs to be added to the volume group. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image020 "src=" http://s3.51cto.com/wyfs02/M00/6C/68/wKioL1VI5TvA7eWdAAAm4J4cxvg943.jpg "width=" 444 "height=" "/>

3. Use the command lvcreate command to create a new logical volume named Mbox in the mail volume group. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image022 "src=" http://s3.51cto.com/wyfs02/M00/6C/6C/wKiom1VI49CyMow0AAAtms0jK38003.jpg "width=" "height=" "/>

LV Logical Volume Management

Lvscan command : Used to scan established logical volumes and related information in the system. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image024 "src=" http://s3.51cto.com/wyfs02/M01/6C/6C/wKiom1VI49Xzn8QuAAAlcvt-UUY971.jpg "width=" 433 "height=" "/>

lvcreate command : Used to split space from the specified volume group to create a new logical volume. You need to specify the size, name, and volume group name of the logical volume as the parameter. When a logical volume is created, it can be accessed through a device file in the form of "/dev/volume Group name/Logical volume name" (or "/dev/mapper/volume group name--; Logical volume name"). The basic format for this command is as follows:

lvcreate-l Capacity Size - N Logical Volume name Volume group name

Lvdisplay command : To display the details of a logical volume, you need to specify the device file for the logical volume as a parameter, or you can use the volume group name as a parameter to display information for all logical volumes in the volume group. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image026 "src=" http://s3.51cto.com/wyfs02/M02/6C/6C/wKiom1VI49ui6MyXAABPrEDBhE0036.jpg "width=" 373 "height=" 129 "/>

Lvextend command : space for dynamically expanding logical volumes, which can be extended by splitting additional space from the volume group in which the logical volume space is currently used. Just specify the amount of capacity you want to increase and the location of the logical volume file. The prerequisite is that the volume group also has unallocated disk space, otherwise you need to expand the volume set capacity first. In addition, after adjusting the capacity of the logical volume, you need to perform "resize2fs/dev/ Volume group name / Logical volume name" command for the Linux system to re-identify the size of the file system (the RESIZE2FS command is used to adjust the file system size online).

The basic format for using the Lvextend command is as follows:

Lvextend-l + size /dev/ Volume Group name / Logical Volume name

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image028 "src=" http://s3.51cto.com/wyfs02/M00/6C/6C/wKiom1VI4-CyrSJBAAAuzlQRNqM977.jpg "width=" 441 "height=" "/>

Execute the "resize2fs/dev/ Volume group name / Logical volume name" command. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image030 "src=" http://s3.51cto.com/wyfs02/M01/6C/6C/wKiom1VI4-bQVE0KAAAs8VyjC7Y568.jpg "width=" 462 "height=" "/>

Lvremove command: used to delete the specified logical volume, directly using the logical volume's device file as a parameter. It is important to note that before you delete a logical volume, you should make sure that the logical volume is no longer in use and that the necessary data is ready for backup. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image032 "src=" http://s3.51cto.com/wyfs02/M02/6C/6C/wKiom1VI4-ux_6wAAAAW-hdTeng427.jpg "width=" 479 "height=" "/>

When expanding capacity for logical volumes, the size that can be scaled is limited by the amount of space remaining in the volume group (not used by other logical volumes).

4. Use the MKFS.EXT3 command to format the newly created mbox logical volume. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image034 "src=" http://s3.51cto.com/wyfs02/M00/6C/6C/wKiom1VI4_DxuUqeAACKbsBlegg241.jpg "width=" "height=" 179 "/>

5. Create the/mailbox directory to mount the newly created mbox logical volume to the/mailbox directory. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image036 "src=" http://s3.51cto.com/wyfs02/M01/6C/68/wKioL1VI5WbA7VIFAABF9EgawV4556.jpg "width=" 410 "height=" "/>

Set up and enable disk quotas

A Enable quota support for file systems mounted to the/mailbox directory

Steps:

1. mount the file system in a way that supports the quota function

In addition to kernel and quota software support, the implementation of the disk quotas feature has a precondition that the specified partition must already be mounted and the disk quota feature is supported.

During configuration debugging, you can use the Mount command with the "O Usrquota,grpquota" option to re-mount the specified partition to increase support for user, group quota functionality. For file systems that support the quota feature, "Usrquota,grpquota" is displayed in the Mount information. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image038 "src=" http://s3.51cto.com/wyfs02/M02/6C/68/wKioL1VI5WygwZWUAABxlNcZuDU106.jpg "width=" 394 "height=" 111 "/>

Convenient for subsequent testing, allowing any user to write data. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image040 "src=" http://s3.51cto.com/wyfs02/M00/6C/68/wKioL1VI5XGzcZirAAAcGja80Zw438.jpg "width=" 425 "height=" "/>

If you need to mount the partition automatically after each boot with a support quota feature, you can write the "Usrquota,grpquota" mount parameter to the "/etc/fstab" file. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image042 "src=" http://s3.51cto.com/wyfs02/M00/6C/6C/wKiom1VI5AbTCbJ5AAAhA8KAnhE071.jpg "width=" 410 "height=" Wuyi "/>

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image044 "src=" http://s3.51cto.com/wyfs02/M01/6C/6C/wKiom1VI5AzA0TJeAABeiAIvfvw170.jpg "width=" 399 "height=" 162 "/>

2. detect disk quotas and generate quota files

You can use the quotacheck command to perform disk quota detection on a specified file system, or to establish a quota file to hold the user, group quota settings in that partition. To automatically scan the available file systems, you can not specify a detection object. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image046 "src=" http://s3.51cto.com/wyfs02/M02/6C/6D/wKiom1VI5BXy5DKdAACATg-SQuc242.jpg "width=" 406 "height=" 107 "/>

In the above operation, the option "-a" means scanning all partitions, "-U" and "-G" respectively indicate the detection of user and group quota information, "-C" means the creation of a new quota file, "-V" indicates the display of the command during the execution of detailed information. When you do not use the "-a" option, you must specify a partition (device file or mount point directory) as the command parameter.

Because an earlier version of the quota file is not used in the/mailbox file system, a prompt such as "old file not found" is normal. The newly created quota file includes "Aquota.user", "Aquota.group", respectively, to save the user, group quota settings. The quota file is saved at the root of the file system, and the default permission is 600. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image048 "src=" http://s3.51cto.com/wyfs02/M00/6C/6D/wKiom1VI5Bvw-x88AAA-5BGtJXM766.jpg "width=" 444 "height=" "/>

Three Limit user jerry can use up to 100MB of disk space, limit user totals for ACCP groups to use up to 500MB of disk space

Steps:

1. Create the user Zhangsan and Lisi, group ACCP, and then add the user Lisi to the ACCP group. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image050 "src=" http://s3.51cto.com/wyfs02/M01/6C/68/wKioL1VI5ZHzjEkbAAA5JEmNPzU531.jpg "width=" 399 "height=" "/>

2. Edit quota settings for user and group accounts

Quota settings are the most important part of implementing disk quotas, and using the edquota command with the "-U", "-g" option allows you to edit the quota settings for a user or group. After the Edquota command is executed correctly, it will go to the text editing interface (the default call VI as the editor), you can set the disk settings, the file size of the soft and hard limit values.

Edit the quota for the user Zhangsan. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image052 "src=" http://s3.51cto.com/wyfs02/M01/6C/6D/wKiom1VI5CaCXDqnAAAbX3hMw8g165.jpg "width=" 497 "height=" "/>650" this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; border= "0" alt= "clip_image054" src= "http://s3.51cto.com/wyfs02/M02/6C/6D/wKiom1VI5Cvx0OyzAAAqXg0TG5U958.jpg" width= "321" Height= "/>"

Edit the quota for the group ACCP. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image056 "src=" http://s3.51cto.com/wyfs02/M02/6C/68/wKioL1VI5aHB5gCbAAAZ8clwxAk809.jpg "width=" 384 "height=" "/>650" this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border= "0" alt= "clip_image058" src= "http://s3.51cto.com/wyfs02/M01/6C/68/wKioL1VI5aeRkVLxAAA67tsBbR8382.jpg" width= "468" height= "178"/>

In general, it is more common to limit the amount of disk capacity, while limiting the number of files is less likely. The limit value you set should not be less than the number that the user has already used, or it may prevent the user from logging on to the system properly. It is also recommended that you do not set disk quotas on the root user to avoid unpredictable risks to the operation and stability of programs and systems.

In the process of using the file system, the default grace period for users exceeding the soft limit is 7 days, allowing the user to continue using the grace period (as long as the hard limit is not exceeded). If you need to modify the grace period, you can perform the "edquota-t" command to adjust. The time unit for the grace period can be days, hours, minutes, or seconds. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image060 "src=" http://s3.51cto.com/wyfs02/M02/6C/68/wKioL1VI5ayADcuYAAAU4_cplgc676.jpg "width=" 303 "height=" "/>650" this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border= "0" alt= "clip_image062" src= "http://s3.51cto.com/wyfs02/M02/6C/6D/wKiom1VI5EHxiyaFAABANjPF8To815.jpg" width= "367" height= "205"/>

3. Start the disk quotas feature of the file system

The disk functions for starting and shutting down the file system are performed using the Quotaon,quotaoff command , which requires specifying the device file name or the mount point directory of the file system as the command parameter. The Quotaon command uses the same options as the Quotacheck option.

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image064 "src=" http://s3.51cto.com/wyfs02/M00/6C/68/wKioL1VI5bbjPwR-AAA9yKcORDg092.jpg "width=" 484 "height=" "/>

In fact, the RHEL 5 system automatically checks for a file system that supports disk quotas each time it is powered on, and if found, enables the disk quotas feature of the file system (through the system initialization script "/etc/rc.d/rc.sysinit" to complete the operation). Therefore, you do not need to execute the Quotaon command again after the next boot.

4. Verify the disk quotas feature

Log on to the Linux system with a user account with a quota limit, and switch to a file system where quotas are applied, and write operations such as copying files to test whether the disk quota entries are valid.

You can use the dd conversion tool to quickly see the results during the test. The DD command is a device conversion and copy command that specifies the input device (or file) using the "if=" option, the "of=" option specifies the output device (or file), the "bs=" option specifies the size of the read data block, and "count=" specifies the number of data blocks to read.

Switch User Zhangsan Log in to the system, enter the/mailbox directory, and then use the DD command to test. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image066 "src=" http://s3.51cto.com/wyfs02/M01/6C/68/wKioL1VI5byBt_GJAACjVWN-mmM918.jpg "width=" 540 "height=" 138 "/>

Switch user Lisi log in to the system, enter the/mailbox directory, and then use the DD command to test. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image068 "src=" http://s3.51cto.com/wyfs02/M02/6C/68/wKioL1VI5cHwF8B_AACaQLMaIoM458.jpg "width=" 545 "height=" 131 "/>

See how many files are written by two users in the/mailbox directory. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image070 "src=" http://s3.51cto.com/wyfs02/M00/6C/6D/wKiom1VI5FaxhUCkAABY82bpkwE263.jpg "width=" 547 "height=" "/>

5. View quota usage for users or partitions

To understand quota usage for users or groups in the file system, you can use the quota command,therepquota command . The quota command can be used with the "-U", "-g" option to view the quota usage of the specified users and groups, and the Repquota command will be used to report the quota usage for all available partitions, primarily for the specified file system output quotas. :

650) this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border=" 0 "alt=" clip_image072 "src=" http://s3.51cto.com/wyfs02/M00/6C/68/wKioL1VI5q6gn9-sAABm3bJoZO0951.jpg "width=" 401 "height=" "/>650" this.width=650; "style=" border-top-width:0px;border-bottom-width:0px;border-left-width:0px; "border = "0" alt= "clip_image074" src= "http://s3.51cto.com/wyfs02/M01/6C/68/wKioL1VI5rSQt4SoAABvcyieLXc898.jpg" width= "443 "Height="/>

Note: When you set quotas for a group, you have to make the Group a basic group of users (only for basic groups) when you want the user to take effect.

Set the quota first, then set the permissions.

In a Linux system, the quotas set on a group are the shared space used by users within the group.

In Windows systems, the quotas that are set on a group are the spaces that users within the group use each other.

Eighth. Disk and file System Management LVM Logical Volume management

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.