Archive for September, 2009

SBDavid

Resizing a Physical Volume

Resizing a Physical Volume

If you need to change the size of an underlying block device for any reason, use the pvresize command to update LVM with the new size. You can execute this command while LVM is using the physical volume.


EXAMPLES

Expand the PV on /dev/sda1 after enlarging the partition with fdisk:

pvresize /dev/sda1

Shrink the PV on /dev/sda1 prior to shrinking the partition with fdisk (ensure that the PV size is appropriate for your intended new partition size):

pvresize –setphysicalvolumesize 40G /dev/sda1

RESTRICTIONS

pvresize will refuse to shrink PhysicalVolume if it has allocated extents after where its new end would be. In the future, it should relocate these elsewhere in the volume group if there is sufficient free space, like pvmove does.

pvresize won’t currently work correctly on LVM1 volumes or PVs with extra metadata areas

Preventing Allocation on a Physical Volume

You can prevent allocation of physical extents on the free space of one or more physical volumes with the pvchange command. This may be necessary if there are disk errors, or if you will be removing the physical volume.

The following command disallows the allocation of physical extents on /dev/sdk1.

pvchange -x n /dev/sdk1

You can also use the -xy arguments of the pvchange command to allow allocation where it had previously been disallowed.

“pvchange -x n /dev/sdk1″ disallows the allocation of physical extents on this physical volume (possibly because of disk errors, or because it will be removed after freeing it.

SBDavid

Displaying Physical Volumes

Displaying Physical Volumes

There are three commands you can use to display properties of LVM physical volumes: pvs, pvdisplay, and pvscan.

The pvs command provides physical volume information in a configurable form, displaying one line per physical volume.

The pvs command provides a great deal of format control, and is useful for scripting.

For information on using the pvs command to customize your output,

The pvdisplay command provides a verbose multi-line output for each physical volume. It displays physical properties (size, extents, volume group, etc.) in a fixed format. The following example shows the output of the pvdisplay command for a single physical volume.

# pvdisplay
— Physical volume —
PV Name /dev/sdc1

The pvscan command scans all supported LVM block devices in the system for physical volumes.

The following command shows all physical devices found:

# pvscan
PV /dev/sdb2 VG vg0 lvm2 [964.00 MB / 0 free]
PV /dev/sdc1 VG vg0 lvm2 [964.00 MB / 428.00 MB free]
PV /dev/sdc2 lvm2 [964.84 MB]
Total: 3 [2.83 GB] / in use: 2 [1.88 GB] / in no VG: 1 [964.84 MB]

SBDavid

Scanning for Block Devices

Scanning for Block Devices

You can scan for block devices that may be used as physical volumes with the lvmdiskscan command, as shown in the following example.

# lvmdiskscan
/dev/ram0 [ 16.00 MB]
/dev/sda [ 17.15 GB]
/dev/root [ 13.69 GB]
/dev/ram [ 16.00 MB]
/dev/sda1 [ 17.14 GB] LVM physical volume
/dev/VolGroup00/LogVol01 [ 512.00 MB]
/dev/ram2 [ 16.00 MB]

lvmdiskscan scans all SCSI, (E)IDE disks, multiple devices and a bunch of other block devices in the system looking for LVM physical volumes. The size reported is the real device size. Define a filter in lvm.conf(5) to restrict the scan to avoid a CD ROM, for example.

If run as a user then.

$ lvmdiskscan
WARNING: Running as a non-root user. Functionality may be unavailable.
0 disks
0 partitions
0 LVM physical volume whole disks
0 LVM physical volumes
SBDavid

Using LVM CLI Commands

There are several general features of all LVM CLI commands.

When sizes are required in a command line argument, units can always be specified explicitly. If you do not specify a unit, then a default is assumed, usually KB or MB. LVM CLI commands do not accept fractions.

Where commands take volume group or logical volume names as arguments, the full path name is optional. A logical volume called lvol0 in a volume group called vg0 can be specified as vg0/lvol0. Where a list of volume groups is required but is left empty, a list of all volume groups will be substituted. Where a list of logical volumes is required but a volume group is given, a list of all the logical volumes in that volume group will be substituted. For example, the lvdisplay vg0 command will display all the logical volumes in volume group vg0.

All LVM commands accept a -v argument, which can be entered multiple times to increase the output verbosity. For example, the following examples shows the default output of the lvcreate command.

# lvcreate -L 50MB new_vg
Rounding up size to full physical extent 52.00 MB
Logical volume “lvol0″ created

The following command shows the output of the lvcreate command with the -v argument.

# lvcreate -v -L 50MB new_vg
Finding volume group “new_vg”
Rounding up size to full physical extent 52.00 MB
Archiving volume group “new_vg” metadata (seqno 4).
Creating logical volume lvol0
Creating volume group backup “/etc/lvm/backup/new_vg” (seqno 5).
Found volume group “new_vg”
Creating new_vg-lvol0
Loading new_vg-lvol0 table
Resuming new_vg-lvol0 (253:2)
Clearing start of logical volume “lvol0″
Creating volume group backup “/etc/lvm/backup/new_vg” (seqno 5).
Logical volume “lvol0″ created

All LVM objects are referenced internally by a UUID, which is assigned when you create the object.

« Prev - Next »