HP Certified: HP-UX System Administration
|
18.3 Listing and Creating Logical Volumes
Information about LVM can be listed using a number of commands. You can display information about physical volumes, volume groups, and logical volumes. All physical and logical volumes are divided into smaller data units known as LVM extents. A physical volume consists of physical extents.
A physical extent (PE) is the smallest amount of disk space that can be allocated to a logical volume. By default, a physical extent occupies 4 MByte of disk space. It means that a logical volume can have disk space that is a multiple of 4 Mbyte.
A logical extent is similar to a physical extent. It is a pointer in kernel memory to a physical extent on a physical volume. A logical volume may have some logical extents that point to one disk and some to another disk. Thus, a logical volume can span multiple physical disk drives .
Physical extent size is fixed at the time of the creation of a volume group and it is constant throughout the group. All physical disks in a volume group have physical extents of the same size.
Listing Physical Volumes
The pvdisplay command is used to list physical volumes. The command expects a block-type device file for the disk drive as its argument. Let's see the output of the command shown here.
$ pvdisplay /dev/dsk/c2t5d0 --- Physical volumes --- PV Name /dev/dsk/c2t5d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 2 PE Size (Mbytes) 4 Total PE 1023 Free PE 868 Allocated PE 155 Stale PE 0 IO Timeout (Seconds) default $
From this output, you get the following information about a physical volume.
-
The volume group name to which this disk is related is vg00 .
-
Currently it has space allocated to two logical volumes.
-
The physical extent size is 4 Mbytes.
-
The total number of PEs on this disk is 1023.
-
Out of 1023 PEs, 155 are allocated to volume groups, and 868 are free. The free PEs can be allocated to a logical volume when its size is extended or to create a new logical volume.
Let's take a more-detailed listing of the physical volume by using the -v option with the pvdisplay command as follows .
$ pvdisplay -v /dev/dsk/c2t5d0 --- Physical volumes --- PV Name /dev/dsk/c2t5d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 2 PE Size (Mbytes) 4 Total PE 1023 Free PE 868 Allocated PE 155 Stale PE 0 IO Timeout (Seconds) default --- Distribution of physical volume --- LV Name LE of LV PE for LV /dev/vg00/lvol4 75 75 /dev/vg00/lvol8 80 80 --- Physical extents --- PE Status LV LE 0000 current /dev/vg00/lvol8 0170 0001 current /dev/vg00/lvol8 0171 0002 current /dev/vg00/lvol8 0172 0003 current /dev/vg00/lvol8 0173 0004 current /dev/vg00/lvol8 0174 0005 current /dev/vg00/lvol8 0175 0006 current /dev/vg00/lvol8 0176 0007 current /dev/vg00/lvol8 0177 <some output deleted from here> 0078 current /dev/vg00/lvol8 0248 0079 current /dev/vg00/lvol8 0249 0080 current /dev/vg00/lvol4 0025 0081 current /dev/vg00/lvol4 0026 0082 current /dev/vg00/lvol4 0027 0083 current /dev/vg00/lvol4 0028 <some output deleted from here> 0150 current /dev/vg00/lvol4 0095 0151 current /dev/vg00/lvol4 0096 0152 current /dev/vg00/lvol4 0097 0153 current /dev/vg00/lvol4 0098 0154 current /dev/vg00/lvol4 0099 0155 free 0000 0156 free 0000 0157 free 0000 0158 free 0000 0159 free 0000 0160 free 0000 0161 free 0000 <some output deleted from here> 1023 free 0000 $
This listing shows more useful information. First of all, it shows that the space on this disk is allocated to the logical volumes lvol4 and lvol8 . Out of a total of 155 allocated PEs, 75 PEs are allocated to lvol4 and 80 PEs are allocated to lvol8 . It also lists all PEs and the logical volumes to which these are attached. From the detailed list it can be verified that PEs 079 are allocated to lvol8 and PEs 80154 are allocated to lvol4 . The remaining PEs are free.
Listing Volume Groups
The vgdisplay command shows information about a volume group. I have used the following command to get information about volume group vg00 .
$ vgdisplay /dev/vg00 --- Volume groups --- VG Name /dev/vg00 VG Write Access read/write VG Status available Max LV 255 Cur LV 8 Open LV 8 Max PV 16 Cur PV 2 Act PV 2 Max PE per PV 2500 VGDA 4 PE Size (Mbytes) 4 Total PE 2046 Alloc PE 1178 Free PE 868 Total PVG 0 Total Spare PVs 0 Total Spare PVs in use 0 $
You can find the following information from the output of this command.
-
The maximum number of logical volumes that can be created in this volume group. This value is 255 for vg00 .
-
There are currently eight logical volumes in the group.
-
There can be 16 maximum physical volumes (disks) in the volume group.
-
Currently there are two physical volumes in the volume group, which means you can add 14 more physical disks to this volume group.
-
Every physical volume can have 2500 physical extents of 4 MBytes each. It means that you can add disks of up to 10 GBytes to this volume group.
-
Currently there are 2046 physical extents. Of these, 1178 are allocated and 868 are free. This is important information that enables you to extend the size of any logical volume or create a new logical volume, as there are plenty of unallocated PEs in the volume group.
A detailed list can be obtained using the -v option with the vgdisplay command as follows. This list shows all logical and physical volumes in the volume group and their size in terms of logical or physical extents.
$ vgdisplay -v vg00 --- Volume groups --- VG Name /dev/vg00 VG Write Access read/write VG Status available Max LV 255 Cur LV 8 Open LV 8 Max PV 16 Cur PV 2 Act PV 2 Max PE per PV 2500 VGDA 4 PE Size (Mbytes) 4 Total PE 2046 Alloc PE 1178 Free PE 868 Total PVG 0 Total Spare PVs 0 Total Spare PVs in use 0 --- Logical volumes --- LV Name /dev/vg00/lvol1 LV Status available/syncd LV Size (Mbytes) 100 Current LE 25 Allocated PE 25 Used PV 1 LV Name /dev/vg00/lvol2 LV Status available/syncd LV Size (Mbytes) 512 Current LE 128 Allocated PE 128 Used PV 1 LV Name /dev/vg00/lvol3 LV Status available/syncd LV Size (Mbytes) 200 Current LE 50 Allocated PE 50 Used PV 1 LV Name /dev/vg00/lvol4 LV Status available/syncd LV Size (Mbytes) 400 Current LE 100 Allocated PE 100 Used PV 2 LV Name /dev/vg00/lvol5 LV Status available/syncd LV Size (Mbytes) 1000 Current LE 250 Allocated PE 250 Used PV 1 LV Name /dev/vg00/lvol6 LV Status available/syncd LV Size (Mbytes) 500 Current LE 125 Allocated PE 125 Used PV 1 LV Name /dev/vg00/lvol7 LV Status available/syncd LV Size (Mbytes) 1000 Current LE 250 Allocated PE 250 Used PV 1 LV Name /dev/vg00/lvol8 LV Status available/syncd LV Size (Mbytes) 1000 Current LE 250 Allocated PE 250 Used PV 2 --- Physical volumes --- PV Name /dev/dsk/c2t6d0 PV Status available Total PE 1023 Free PE 0 PV Name /dev/dsk/c2t5d0 PV Status available Total PE 1023 Free PE 868
Listing Logical Volumes
As with the physical volumes and volume groups, information about individual logical volumes can also be displayed. You use the lvdisplay command for this purpose, providing the logical volume block device file as the argument.
$ lvdisplay /dev/vg00/lvol4 --- Logical volumes --- LV Name /dev/vg00/lvol4 VG Name /dev/vg00 LV Permission read/write LV Status available/syncd Mirror copies 0 Consistency Recovery MWC Schedule parallel LV Size (Mbytes) 400 Current LE 100 Allocated PE 100 Stripes 0 Stripe Size (Kbytes) 0 Bad block on Allocation strict IO Timeout (Seconds) default $
A more-detailed list can be generated with the help of the -v option with this command. It shows each logical extent and the disk to which it points. The output of the following lvdisplay command is truncated at the end.
$ lvdisplay -v /dev/vg00/lvol4 --- Logical volumes --- LV Name /dev/vg00/lvol4 VG Name /dev/vg00 LV Permission read/write LV Status available/syncd Mirror copies 0 Consistency Recovery MWC Schedule parallel LV Size (Mbytes) 400 Current LE 100 Allocated PE 100 Stripes 0 Stripe Size (Kbytes) 0 Bad block on Allocation strict IO Timeout (Seconds) default --- Distribution of logical volume --- PV Name LE on PV PE on PV /dev/dsk/c2t6d0 25 25 /dev/dsk/c2t5d0 75 75 --- Logical extents --- LE PV1 PE1 Status 1 0000 /dev/dsk/c2t6d0 0203 current 0001 /dev/dsk/c2t6d0 0204 current 0002 /dev/dsk/c2t6d0 0205 current 0003 /dev/dsk/c2t6d0 0206 current 0004 /dev/dsk/c2t6d0 0207 current 0005 /dev/dsk/c2t6d0 0208 current 0006 /dev/dsk/c2t6d0 0209 current <Some output deleted from here>
At this point, you know what type of information is associated with physical and logical volumes and volume groups. Let's see how we can create a logical volume by first creating physical volumes and volume groups.
Creating Physical Volumes
The creation of physical volumes is the first step for using a disk with LVM. To find out the device file name associated with a disk, you can use the ioscan command. You may wish to format and analyze the integrity of a disk with the help of the mediainit command before creating a physical volume on it as follows.
mediainit /dev/rdsk/c2t5d0
Since disk formatting and analysis is a low-level task, you need to use a raw device file with the mediainit command.
Note
The mediainit command performs read and write operations on all parts of the disk. It may take an excessively long time depending on the type and capacity of the disk. Most of the disk drives are already initialized , and you don't need to run this command before using them with LVM. Use this command only if you have some doubt about the integrity of a disk.
To create a physical volume, use the pvcreate command as shown below.
pvcreate /dev/rdsk/c2t5d0
If the disk on which a physical volume is being created was part of a volume group earlier, the physical volume will not be created. If you are sure that you are creating a physical volume on the right disk, use the -f option with the pvcreate command to force the creation of a physical volume. However, one should be very careful when using this option. Using pvcreate on the wrong disk may have catastrophic results.
Creating Volume Groups
After creating physical volumes on all disks you want to add to a volume group, you can move to the process of volume group creation. Creation of a volume group involves a number of steps as follows.
-
Create a directory in /dev with the group name. For example, if the volume group name is vg03 , the directory will be /dev/vg03 .
-
Create the group special file in this directory. The name of this control file is always group , and it has a major number of 64. The minor number shows the group number. For example, if the group number is 03 ( vg03 ), the minor number is 0x030000. The last four digits of the minor number are always 0000. To create a group special file for group vg03 , use the command:
mknod /dev/vg03/group c 64 0x030000
-
Create a volume group using the vgcreate command. Provide physical volume names as command-line arguments to the vgcreate command. To create volume group vg03 containing a single physical volume c2t5d0 , the command is:
vgcreate /dev/vg03 /dev/dsk/c2t5d0
The vgcreate command accepts the command-line options listed in Table 18-1.
Table 18-1. Options Used with the vgcreate Command
Option | Description |
---|---|
-l | Maximum number of logical volumes in the volume group |
-p | Maximum number of physical volumes in the volume group |
-e | Maximum number of physical extents in the volume group |
-s | Size of physical extents in the volume group |
After creating a volume group, you can use the vgdisplay command to verify its characteristics.
Creating Logical Volumes
Logical volumes are created using the lvcreate command. When you create a new logical volume, its raw and block device files are created in the volume group directory. To create a logical volume of 800 MBytes with the name myvolume in volume group vg03 , you can use following command.
lvcreate -L 800 -n myvolume vg03
Command-line options that can be used with the lvcreate command are shown in Table 18-2.
Table 18-2. Options Used with the lvcreate Command
Option | Description |
---|---|
-L | Size of logical volume in megabytes |
-l | Size of logical volumes in number of logical extents |
-n | Name of logical volume; if not specified, default names are used ( lvol1 , lvol2 , etc.) |
-C | Use contiguous space to create the logical volume |
-i | Set the number of disks to be included in the logical volume; may be set to the total number of physical volumes in the volume group |
-I | Set the size of stripe across each physical volume when more than one disk are used in a logical volume; options -i and -I must be used together |
LVM Data Structure
LVM data structures are created on every disk included in a volume group. These data structures include the following.
-
Physical volume reserved area (PVRA): created by the pvcreate command and contains information about the physical volume.
-
Volume group reserved area (VGRA): created by the vgcreate command and contains the volume group status area (VGSA) and volume group descriptor area (VGDA), which contains device driver information used for the volume group.
-
Bad block relocation area (BBRA): an area at the bottom of the disk used by LVM whenever a physical defect is seen on the physical volume. This area is created by the pvcreate command.
The LVM boot disk also contains additional information used for system bootup .
Study Break
Logical Volume Manager You have gone through an introduction to LVM and how to display and create LVM components . To have some practice with LVM, log into your system and use the vgdisplay -v vg00 command to list the root volume group. How many physical volumes are in this volume group? Note how many physical extents are present in the volume group and how many of these are free. If you find some free physical extents, use the lvcreate command to create a new logical volume with the name myvol . Use the vgdisplay command again to list the presence of the new logical volume. |
|
|
Top |