Logical Volume Manager Background

Logical Volume Manager is a disk management subsystem that allows you to manage physical disks as logical volumes. This means that a file system can span multiple physical disks. You can view Logical Volume Manager as a flexible way of defining boundaries of disk space that are independent of one another. Not only can you specify the size of a logical volume, but you can also change its size if the need arises. This possibility is a great advancement over dedicating a disk to a filesystem or having fixed-size partitions on a disk. Logical volumes can hold filesystems, raw data, or swap space. You can now specify a logical volume to be any size you wish, have logical volumes that span multiple physical disks, and then change the size of the logical volume if you need to do so!

So what do you need to know in order to set up Logical Volume Manager and realize all these great benefits? First, you need to know the terminology, and second, you need to know Logical Volume Manager commands. As with many other system administration tasks, you can use graphical management tools covered in Chapter 10. But, as usual, I recommend that you read this overview and at least understand the basics of Logical Volume Manager.

For use with the Journaled Filesystem (JFS), Hewlett-Packard has an add-on product called HP OnLineJFS. This product allows you to perform many of the LVM functions without going into single-user mode. For example, when a filesystem needs to be expanded, the logical volume on which it resides needs to be unmounted before the expansion takes place. Normally, that unmounting would mean shutting the system down into single-user mode so that no user or process could access the volume and it could then be unmounted. With OnLineJFS, the logical volumes and file systems are simply expanded with the system up and running and no interruption to users or processes.

With both JFS and OnlineJFS an intent log, or journal, is used to keep track of metadata (structural information) that would be written synchronously on a traditional HFS-based system. The journal information is used to complete an operation if a crash occurs, thereby making system recovery with fsck much faster.

With both the base JFS product and OnlineJFS product, you would specify a file system as vxfs rather than hfs. With the newfs or mount commands, for instance, you would specify -F vxfs. There are many options that you could specify with -o when working with JFS. One of the most common is -o largefiles, which allows files larger than two GBytes in size.

Logical Volume Manager Terms

The following terms are used when working with Logical Volume Manager. They are only some of the terminology associated with Logical Volume Manager, but they are enough for you to get started with Logical Volume Manager. It is a good idea to read the following brief overview of these terms.

VolumeA volume is a device used for a filesystem, swap, or raw data. Without Logical Volume Manager, a volume would be either a disk partition or an entire disk drive.
Physical Volume 
 A physical volume is a disk that has been not been initialized for use by Logical Volume Manager. An entire disk must be initialized if it is to be used by Logical Volume Manager; that is, you can't initialize only part of a disk for Logical Volume Manager use and the rest for fixed partitioning.
Volume GroupA volume group is a collection of logical volumes that are managed by Logical Volume Manager. You would typically define which disks on your system are going to be used by Logical Volume Manager and then define how you wish to group these into volume groups. Each individual disk may be a volume group, or more than one disk may form a volume group. At this point, you have created a pool of disk space called a volume group. A disk can belong to only one volume group. A volume group may span multiple physical disks.
Logical VolumeThis is space that is defined within a volume group. A volume group is divided up into logical volumes. This is like a disk partition, which is of a fixed size, but you have the flexibility to change its size. A logical volume is contained within a volume group, but the volume group may span multiple physical disks. You can have a logical volume that is bigger than a single disk.
Physical ExtentA physical extent is a set of contiguous disk blocks on a physical volume. If you define a disk to be a physical volume, then the contiguous blocks within that disk form a physical extent. Logical Volume Manager uses the physical extent as the unit for allocating disk space to logical volumes. If you use a small physical extent size, such as 1 MByte, then you have a fine granularity for defining logical volumes. If you use a large physical extent size such as 256 MBytes, then you have a coarse granularity for defining logical volumes. The default size is 4 MBytes.
Logical ExtentsA logical volume is a set of logical extents. Logical extents and physical extents are the same size within a volume group. Although logical and physical extents are the same size, this doesn't mean that two logical extents will map to two contiguous physical extents. It may be that you have two logical extents that end up being mapped to physical extents on different disks!
/etc/lvmtabThis file has in it the device file associated with each disk in a volume group. /sbin/lvmrc starts each volume group by reading the contents of this file at boot time. This file can be rebuilt with vgscan. This is not an ascii file, so strings /etc/lvmtab is used to see its contents.
PV LinksPhysical Volume Links (PV Links) provide dual SCSI or FL links to the same disk. If one of the links were to fail, the other link would automatically take over routing I/O to the disk.

Figure 3-1 graphically depicts some of the logical volume terms we just covered. In this diagram you can see clearly that logical extents are not mapped to contiguous physical extents, because some of the physical extents are not used.

Figure 3-1. Logical Volume Manager Partial Logical to Physical Mapping


Another diagram that is helpful in understanding LVM is Figure 3-2 which shows some of the important components of which an LVM boot disk is comprised.

Figure 3-2. Boot Disk Components


Some of these components exist only on a boot disk, as noted, and others exist on all LVM disks. The components in LIF are put there when the mkboot and lvlnboot commands are run.

Disk Mirroring

Logical volumes can be mirrored one or more times, creating an identical image of the logical volume. This means that a logical extent can map to more than one physical extent if mirrored.

Mirroring is done with the MirrorDisk/UX product. Mirroring is done on a logical volume basis, not a disk basis. You must specify the logical volumes you want mirrored. This is demonstrated in several examples later in this chapter. Recall Figure 3-1, which showed logical extents mapped to physical extents. With mirroring you map each logical extent to two or more physical extents, meaning that your data physically resides in two or more places.

You may have an environment where you wish to mirror some or all of the logical volumes. You can configure your mirroring manually (as shown in some examples later in this chapter) or graphical management tools covered in Chapter 10 can be used to set up disk mirroring for you. You must first, however, decide the characteristics of your mirroring. There is a mirroring policy called "strict." You define one of the following three strict policies when you create the logical volume using the following options:

nNo, this is not a strict allocation policy, meaning that mirrored copies of a logical extent can share the same physical volume. This means that your original data and mirrored data may indeed be on the same physical disk. If you encounter a disk mechanism problem of some type, you may lose both your original and mirrored data.
yYes, this is a strict allocation policy, meaning that mirrored copies of a logical extent may not share the same physical volume. This is safer than allowing mirrored copies of data to share the same physical volume. If you have a problem with a disk in this scenario, you are guaranteed that your original data is on a different physical disk from your mirrored data. Original data and mirrored data are always part of the same volume group even if you want them on different physical volumes.
gMirrored data will not be on the same Physical Volume Group (PVG) as the original data. This policy is called a PVG-strict allocation policy.

The strict allocation policy depends on your environment. Most installations that employ mirroring buy sufficient disk drives to mirror all data. In an environment such as this, I would create two volume groups, one for the original data and one for the mirrored data, and use the "strict -g" option when creating logical volumes so that the original data is on one volume group and the mirrored data on the other.

Logical Volume Manager Commands

The following are definitions of some of the more common Logical Volume Commands. I am giving a description of these commands here so that when you see them, you'll have an idea of each command's use. Although these are not all of the Logical Volume Manager commands, these are the ones I use most often and are the commands you should have knowledge of when using Logical Volume Manager. The commands are grouped by physical volume (pv) commands, volume group (vg) commands, and logical volume (lv) commands. There are usage summaries of some of the commands included with the descriptions, and details can be found in the online manual pages. Some of the commands, such as vgdisplay, pvdisplay, and lvdisplay were issued so that you could see examples of these. The following output of bdf will be helpful to you when you view the output of Logical Volume Manager commands that are issued. The output of bdf shows several logical volumes mounted (lvol1, lvol3, lvol4, lvol5, lvol6, lvol7, lvol8), all of which are in volume group vg00 (see the bdf command overview later in this chapter).

$ bdf

Filesystemkbytesusedavail%usedMounted on
/dev/vg00/lvol347829184282461843%/
/dev/vg00/lvol167733247363622341/stand
/dev/vg00/lvol83454186732241328%/var
/dev/vg00/lvol729915714944911979256%/usr
/dev/vg00/lvol42301348206630%/tmp
/dev/vg00/lvol699669325145718836%/opt
/dev/vg00/lvol5198619178650%/home
/dev/dsk/c0t6d080221255212016987076%/mnt/9.x

Physical Volume Commands

pvchangeThis command is used to change a physical volume in some way. For example, you may wish to allow additional physical extents to be added to a physical volume if they are not permitted, or prohibit additional physical extents from being added to a physical volume if, indeed, they are allowed.
/usr/sbin/pvchange [-A autobackup] -s pv_path

/usr/sbin/pvchange [-A autobackup] -S autoswitch
 pv_path

/usr/sbin/pvchange [-A autobackup] -x

											extensibility pv_path

/usr/sbin/pvchange [-A autobackup] -t IO_timeout
 pv_path

/usr/sbin/pvchange [-A autobackup] -z sparepv pv_path
										

pvcreateThis command is used to create a physical volume that will be part of a volume group. Remember that a volume group may consist of several physical volumes. The physical volumes are the disks on your system. The example below shows creating a physical volume.
/usr/sbin/pvcreate [-b] [-B] [-d soft_defects] [-s

											disk_size]
                   [-f] [-t disk_type] pv_path
										

pvdisplayThis command shows information about the physical volumes you specify. You can get a lot of information about the logical to physical mapping with this command if you use the verbose (-v) option. With -v pvdisplay will show you the mapping of logical to physical extents for the physical volumes specified.
/usr/sbin/pvdisplay [-v] [-b BlockList] pv_path ...

 You get a lot of other useful data from this command, such as the name of the physical volume; the name of the volume group to which the physical volume belongs; the status of the physical volume; the size of physical extents on the physical volume; the total number of physical extents; and the number of free physical extents.
pvmoveYou can move physical extents from one physical volume to other physical volumes with this command. By specifying the source physical volume and one or more destination physical volumes, you can spread data around to the various physical volumes you wish with this command. In the example below, if the lvol had been left off the entire disk would have been moved.
/usr/sbin/pvmove [-A autobackup] [-n lv_path]

											source_pv_path
                 [dest_pv_path ... | dest_pvg_name
											 ...]


# pvmove -n /dev/vg01/lvol1 /dev/dsk/c0t2d0 /dev/dsk/c0t4d0
						

mknodAlthough this is not an LVM command exclusively, it is used often when creating volume groups, as shown in the example below:

# cd /dev
# mkdir vg01
# cd vg01
# mknod group c 64 0x010000
						

Volume Group Commands

vgcfgbackupThis command is used to save the configuration information for a volume group. Remember that a volume group is made up of one or more physical volumes.
/usr/sbin/vgcfgbackup [-f vg_conf_path] [-u] vg_name
										

vgcfgrestoreThis command is used to restore the configuration information for a volume group.
/usr/sbin/vgcfgrestore -n vg_name -l

/usr/sbin/vgcfgrestore [-R] [-F] -n vg_name [-o

											old_pv_path]
                        pv_path

/usr/sbin/vgcfgrestore -f vg_conf_path -l

/usr/sbin/vgcfgrestore [-R] [-F] -f vg_conf_path
                       [-o old_pv_path] pv_path
										

vgchangeThis command makes a volume group active or inactive. With the -a option, you can deactivate (-a n) a volume group or activate (-a y) a volume group.
/usr/sbin/vgchange -a availability [-l] [-p] [-q

											quorum] [-s]
                   [-P resync_daemon_count]
 [vg_name...]

vgcreateYou can create a volume group and specify all of its parameters with this command. You specify a volume group name and all of the associated parameters for the volume group when creating it. You can specify many physical volume block devices on the same command line if you wish. ex2 below shows creating a PV link. The second path in the vgcreate command is the alternate link.
/usr/sbin/vgcreate [-f] [-A autobackup] [-x

											extensibility]
                   [-e max_pe] [-l max_lv] [-p max_pv]
                   [-s pe_size] [-g pvg_name] vg_name
											pv_path ...


ex1: vgcreate /dev/vg01 /dev/dsk/c0t2d0

ex2: pvcreate /dev/rdsk/c0t1d0
							vgcreate /dev/vg01 /dev/dsk/c0t1d0 /dev/dsk/c2t1d0
						

vgdisplayThis displays all information related to the volume group if you use the verbose (-v) option, including the volume group name; the status of the volume group; the maximum, current, and open logical volumes in the volume group; the maximum, current, and active physical volumes in the volume group; and physical extent-related information.
/usr/sbin/vgdisplay [-v] [vg_name ...]

vgexportThis command removes a logical volume group from the system, but does not modify the logical volume information on the physical volumes. These physical volumes can then be imported to another system using vgimport. Use -s for sharable option in ServiceGuard environments.
/usr/sbin/vgexport [-m mapfile] [-p] [-v] [-f

											outfile] vg_name

 /usr/sbin/vgexport -m mapfile -s -p -v vg_name
										


# vgchange -a n /dev/vg01
# vgexport -v -m /etc/lvmconf/vg01.map /dev/vg01
						

vgextendPhysical volumes can be added to a volume group with this command by specifying the physical volume to be added to the volume group. After the summary of the command is an example:
/usr/sbin/vgextend [-f] [-A autobackup] [-g pvg_name]
     [-x extensibility] [-z sparepv] vg_name
 pv_path ...


# vgextend /dev/rdsk/c0t2d0
# vgextend /dev/vg01 /dev/dsk/c0t2d0
						

vgimportThis command can be used to import a physical volume to another system. Note in the example below that several disks could have been specified on the vgimport line.
/usr/sbin/vgimport [-m mapfile] [-p] [-v] [-f infile]
                   vg_name pv_path ...

/usr/sbin/vgimport -m mapfile -s -v vg_name
										


# mkdir /dev/vg01
# mknod /dev/vg01/group c 64 0x010000
# vgimport -v -m /dev/lvmconf/vg01.map /dev/vg01 /dev/dsk/c0t2d0
# vgchange -a y /dev/vg01
# vgcfgbackup vg01
						

vgreduceThe size of a volume group can be reduced with this command, by specifying which physical volume(s) to remove from a volume group. Make sure that the physical volume to be removed has no data on it before doing this.
/usr/sbin/vgreduce [-A autobackup] vg_name pv_path ...

/usr/sbin/vgreduce [-A autobackup] [-l] vg_name
 pv_path

/usr/sbin/vgreduce [-A autobackup] [-f] vg_name
										

vgremoveA volume group definition can be completely removed from the system with this command. The entry for the volume group in /dev is not removed. An example of removing a volume group is shown below also:
/usr/sbin/vgremove vg_name ...


# vgchange -a n /dev/vg01
# lvremove /dev/vg01/lvol1          ;run for all lvols in vg
# vgremove /dev/vg01
						

vgscanIn the event of a catastrophe of some type, you can use this command to scan your system in an effort to rebuild the /etc/lvmtab file. The -p option performs a preview of vgscan.
/usr/sbin/vgscan [-a] [-p] [-v]

vgsyncThere are times when mirrored data in a volume group becomes "stale" or out-of-date. vgsync is used to synchronize the physical extents in each mirrored logical volume in a volume group.
/usr/sbin/vgsync vg_name ...


Logical Volume Commands

lvcreateThis command is used to create a new logical volume. A logical volume is created within a volume group. A logical volume may span multiple disks, but must exist within a volume group. Many options exist for this command, and two that you would often use are -L to define the size of the logical volume and -n to define the name of the logical volume.
/usr/sbin/lvcreate [-A autobackup] [-c

											mirror_consistency]
     [-C contiguous] [-d schedule] [-D distributed]
     [-i stripes -I stripe_size] [-l le_number |
 -L lv_size]
     [-m mirror_copies] [-M mirror_write_cache]
 [-n lv_name]
     [-p permission] [-r relocate] [-s strict] vg_name
										

 An interesting nuance to lvcreate is that you can't specify a physical volume on which to create the logical volume. If you want a logical volume and its mirror on specific disks you first run lvcreate specifying no size, then two lvextend commands for the original and mirror copies as shown below:

# lvcreate /dev/vg03/lvol3
# lvextend -L 400 /dev/vg03/lvol3 /dev/dsk/c0t2d0
# lvextend -m 1 /dev/vg03/lvol3 /dev/dsk/c2t2d0
						

lvchangeThis command is used to change the logical volume in some way. For example, you may wish to change the permission on a logical volume to read-write (w) or read (r) with the -p option. The -C is used to specify contiguous. Or, you may want to change the strict policy (described under Disk Mirroring) to strict (y), not strict (n), or PVG strict (g).
/usr/sbin/lvchange [-a availability] [-A autobackup]
     [-c mirror_consistency] [-C contiguous]
     [-d schedule] [-D distributed] [-M

											mirror_write_cache]
     [-p permission] [-r relocate] [-s strict]
     [-t IO_timeout] lv_path
										

lvdisplayThis command shows the status and characteristics of every logical volume that you specify. If you use the verbose (-v) option of this command, you get a lot of useful data in many categories, including:
 
  1. Information about the way in which the logical volumes are set up, such as the physical volume on which the logical extents appear; the number of local extents on a physical volume; and the number of physical extents on the physical volume.

  2. Detailed information for logical extents, including the logical extent number and some information about the physical volume and physical extent for the logical extent.

/usr/sbin/lvdisplay [-k] [-v] lv_path  ...

lvextendThis command is used to increase the number of physical extents allocated to a logical volume. We sometimes underestimate the size required for a logical volume, and with this command you can easily correct this problem. You may want to extend a logical volume to increase the number of mirrored copies (using the -m option), to increase the size of the logical volume (using the -L option), or to increase the number of logical extents (using the -l option). You can specify the disk on which you want the logical volume extended and the size is the new size, not an amount by which you want the logical volume extended:
/usr/sbin/lvextend [-A autobackup] {-l le_number |
 -L lv_size
     | -m mirror_copies} lv_path [pv_path ... |

											pvg_name ...]


# lvextend -L 300 /dev/vg01/lvol1
						

extendfsUse this command after lvextend. Whereas the lvextend command expands the logical volume, extendfs expands the filesystem within the logical volume. You would use fsadm if you have OnlineJFS installed rather than the procedure that appears below:
/usr/sbin/extendfs [-F FStype] [-q] [-v] [-s size]

											special
										


# umount /dev/vg01/lvol1              ;use fsadm if online
# extendfs -f vxfs /dev/vg01/rlvol1   ;JFS installed
# mount /dev/vg01/lvol1 /backup
						

mkbootPlaces boot utilities in boot area.
/usr/sbin/mkboot  [-b boot_file_path]   [-c [-u] |
 -f | -h | -u]
   [-i included_lif_file]  [-p preserved_lif_file]
   [-l | -H | -W] [-v] device

/usr/sbin/mkboot [-a auto_file_string] [-v] device

/usr/sbin/rmboot device
										

lvlnbootUse this to set up a logical volume to be a root, boot, primary swap, or dump volume (this can be undone with lvrmboot). Issuing the lvlnboot command with the -v option gives the current settings.
/usr/sbin/lvlnboot [[-A autobackup { -b boot_lv |
  -d dump_lv | -r root_lv | -R | -s swap_lv }]
 [-v] [vg_name]

lvsplit and lvmerge
 These commands are used to split and merge mirrored logical volumes, respectively. If you have a mirrored logical volume, lvsplit will split this into two logical volumes. lvmerge merges two logical volumes of the same size, increasing the number of mirrored copies. In the example below, two logical volumes are split and the name backup is appended to each. fsck is run on the split volumes and they are mounted under separate names. lvsplit performs an atomic split meaning that the split takes place at the same time for all logical volumes that appear on the command line. In the lvmerge example the primary, or master copy, is specified first and the logical volume to be synchronized with the primary is specified second:
/usr/sbin/lvsplit [-A autobackup] [-s suffix]
                  [-g PhysicalVolumeGroup] lv_path ...


# lvsplit -s backup /dev/vg01/lvol1 /dev/vg01/lvol4
# fsck -f vxfs -p /dev/vg01/rlvol1backup
# fsck -f vxfs -p /dev/vg01/rlvol4backup
# mount /dev/vg01/lvol1 backuplvol1
# mount /dev/vg01/rlvol4 backuplvol4
						

/usr/sbin/lvmerge [-A autobackup] dest_lv_path
 src_lv_path
										


# lvmerge /dev/vg00/lvol1backup /dev/vg00/lvol1
						

lvmmigrateThis command prepares a root file system in a disk partition for migration to a logical volume. You would use this if you had a partition to convert into a logical volume.
lvreduceUse this to decrease the number of physical extents allocated to a logical volume. When creating logical volumes, we sometimes overestimate the size of the logical volume. This command can be used to set the number of mirrored copies (with the -m option), decrease the number of logical extents (with the -l option), or decrease the size of the logical volume (with the -L option). Be careful when decreasing the size of a logical volume. You may make it smaller than the data in it. If you choose to do this, make sure that you have a good backup of your data.
/usr/sbin/lvreduce [-A autobackup] [-f] -l

											le_number lv_path

/usr/sbin/lvreduce [-A autobackup] [-f] -L lv_size
 lv_path

/usr/sbin/lvreduce [-A autobackup] -m

											mirror_copies lv_path
[pv_path ...]

/usr/sbin/lvreduce [-A autobackup] -k -m

											mirror_copies lv_path
                   pv_key ...

lvremoveAfter emptying a logical volume, you can use this command to remove logical volumes from a volume group.
/usr/sbin/lvremove [-A autobackup] [-f] lv_path ...

lvrmbootUse this if you don't want a logical volume to be root, boot, primary swap, or a dump device (this is the converse of the lvlnboot command). However, unless you have a disk partition to boot from, don't leave the system without a root or boot device designated with the lvlnboot command, or the system won't know where to boot from.
/usr/sbin/lvrmboot [-A autobackup] [-d dump_lv]
 [-r] [-s]
                   [-v] vg_name
										

lvsyncThere are times when mirrored data in a logical volume becomes "stale" or out-of-date. lvsync is used to synchronize the physical extents in a logical volume.
/usr/sbin/lvsync lv_path ...

newfsAlthough this is not exclusively an LVM command, it is often used to place a file system on a newly created logical volume. The following example shows placing a file system on new logical volume and mounting it:
/usr/sbin/newfs [-F FStype] [-o specific_options]
 [-V] special
										


# newfs -F vxfs -o largefiles /dev/vg01/lvol1
# mount /dev/vg01/lvol1 /backup
						

JFS and OnlineJFS Commands

fsckBecause of the intent log you can run fsck much faster with JFS than without it. If you specify -F vxfs below your fsck will run faster and there are many additional options with -o that you can specify.
/usr/sbin/fsck [-F FSType] [-m] [-V] [special ...]

/usr/sbin/fsck [-F FSType] [-o FSspecific-options]
 [-V]
               [special ...]

fsadmfsadm performs a variety of operations when using OnlineJFS, such as defragmentation, resizing, online backup, and so on.
/usr/sbin/fsadm [-F FStype] [-V] [-o

											specific_options] special
										


for defragmentation:
fsadm -F vxfs [-d][-D][-d][-E] /mount_point

to increase OnlineJFS file system:
fsadm -F vxfs -b new_size /mount_point

# lvextend -L 400 /dev/vg01/lvol3
# fsadm -F vxfs 400 /backup
to reduce OnlineJFS file system:
fsadm -f vxfs -b new_size /mount_point

# fsadm -F vxfs -d -D -e -E /backup
# fsadm -f vxvs -b 300 /backup
						

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.84.29