LVM Management

From n0r1sk software solutions
Jump to: navigation, search

WORK IN PROGRESS!

This Document only covers LVM2. It may not work with LVM1!

Please always BACKUP if you are working with partitions, filesystems or LVM!

HP Array Configuration Utility (hpacucli)

What? So at work we are using uniformly server systems from Hewlett Packard (HP) with Smart Array Raid Controllers. HP provides all supported operating systems with an utility for managing these arrays. Under Microsoft Windows this is a GUI based application and for *nix it is a command line version.

Display the status of the Array System

You can simply run the following command to display the current status:

~# hpacucli ctrl all show config detail

And this would be the output:

Smart Array 6i in Slot 0
   Bus Interface: PCI   
   Slot: 0              
   RAID 6 (ADG) Status: Disabled
   Controller Status: OK        
   Chassis Slot:                
   Hardware Revision: Rev B     
   Firmware Version: 2.68       
   Rebuild Priority: Low        
   Expand Priority: Low         
   Surface Scan Delay: 15 sec
   Cache Board Present: True
   Cache Status: OK
   Accelerator Ratio: 100% Read / 0% Write
   Total Cache Size: 64 MB
   Battery Pack Count: 0
   SATA NCQ Supported: False

   Array: A
      Interface Type: Parallel SCSI
      Unused Space: 210564 MB
      Status: OK

      Logical Drive: 1
         Size: 33.9 GB
         Fault Tolerance: RAID 1+0
         Heads: 255
         Sectors Per Track: 32
         Cylinders: 8716
         Stripe Size: 128 KB
         Status: OK
         Array Accelerator: Enabled
         Unique Identifier: 600508B1001FFFFFA008B76D3D410002
         Disk Name: /dev/cciss/c0d0
         Mount Points: /boot 141 MB, / 4.8 GB
         Logical Drive Label: A008B76D3D40

      physicaldrive 1:0
         SCSI Bus: 1
         SCSI ID: 0
         Status: OK
         Drive Type: Data Drive
         Interface Type: Parallel SCSI
         Transfer Mode: Ultra 320 Wide
         Size: 146.8 GB
         Transfer Speed: 320 MB/Sec
         Rotational Speed: 10000
         Firmware Revision: HPB8
         Serial Number: 3HY896VF00007447L0Y7
         Model: COMPAQ  BD14685A26
      physicaldrive 1:1
         SCSI Bus: 1
         SCSI ID: 1
         Status: OK
         Drive Type: Data Drive
         Interface Type: Parallel SCSI
         Transfer Mode: Ultra 320 Wide
         Size: 146.8 GB
         Transfer Speed: 320 MB/Sec
         Rotational Speed: 10000
         Firmware Revision: HPB4
         Serial Number: 3KS1FY6600007549QMUR
         Model: COMPAQ  BD14688278

Resize / modify the Array

The following command will expand the existing logical drive to its maximum.

~# hpacucli
=> controller slot=0 logicaldrive 1 modify size=max

Check the result

After that you have modified your logical drive to its maximum but the operating system did not recognize it. You must reboot your machine!

LVM Management

Create LVM Volume

Use a whole block device or use a partition

It is your opinion if you want to use a raw device (without partition table) or if you want to use a partition table.Personally I prefer the latter one because I am often expanding devices and I would like to be able to make a new partition on in.

pvcreate

The physical block device is the lowest layer in the LVM. Physical devices are used to create Volume Groups. First thing to do is to let LVM know that a device should be used of LVM. Thats it.

~# pvcreate /dev/cciss/c0d0p5
Physical volume "/dev/cciss/c0d0p5" successfully created

vgcreate or vgextend

Based upon what you like to do, you have to create a Volume Group or you have to extend an existing one.

First the create command. Be careful! One Logical Volume could not have more then 65000 extents and the default extent size is 4 megabytes - this applies for LVM1! With LVM2 there should be no restriction.

vgcreate -s 128M MyVolumeGroup /dev/cciss/c0d0p5

To extend a Volume Group with a physical device you could run the following command.

~# vgextend debian /dev/cciss/c0d0p5
Volume group "debian" successfully extended

Now you should see free extents when you issue the vgdisplay command:

~# vgdisplay
  --- Volume group ---
  VG Name               debian
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               131.82 GB
  PE Size               4.00 MB
  Total PE              33745
  Alloc PE / Size       7424 / 29.00 GB
  Free  PE / Size       26321 / 102.82 GB
  VG UUID               8o10iw-NfIQ-OdSj-4chC-sRxx-aUTA-o8Y021

lvcreate

Only thing to notice here is, that you could use e.g. 100M or number of extents to specify the Logical Volume size. Oh, and the Logical Volume will be the thing, which you are formatting! I prefer -l|--extents LogicalExtentsNumber

~# lvcreate -l 5000 -n MyLogicalVolume MyVolumeGroup

Resize ext3 filesystem with LVM

The actual version of resize2fs<ref>http://oreilly.com/linux/command-directory/cmd.csp?path=r/resize2fs</ref> is able to online expand a ext3 volume and you must not disable the journal as in previous versions. But be aware, that this is only working a Linux kernel > 2.6 and only expanding! You cannot shrink online!

Grow ext3 filesystem

If it is your root file system, you have to boot with an actual Linux rescue or live cd. We recommended grml<ref>http://grml.org/</ref> Linux because the needed software is build in and it is mostly up-to-date. See also -> #Booting single user mode #Booting with rescue cd (grml)

Extend LVM volume

Before you could grow your filesystem you must extend your Logical Volume. Run the following command. Please notice that you have to apply the whole size! You have to summarize the existing extent count and the count you want to grow.

~# lvextend -l 16947 /dev/debian/var
Extending logical volume var to 66.20 GB
Logical volume var successfully resized

Grow ext3 filesystem

After you have extended you Logical Volume you could resize your ext3 partition. This is done online! Thats is.

~# resize2fs /dev/debian/var
resize2fs 1.41.3 (12-Oct-2008)
Filesystem at /dev/debian//var is mounted on /var; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 5
Performing an on-line resize of /dev/debian//var to 17353728 (4k) blocks.
The filesystem on /dev/debian//var is now 17353728 blocks long.

Shrink ext3 filesystem

Before you can use the LVM comman lvreduce you have to shrink your ext3 filesystem. If the filesystem is NOT mounted as root filesystem it will be possible to boot your Linux machine to init level 1 (single user).

If it is your root file system, you have to boot with an actual Linux rescue or live cd. We recommended grml<ref>http://grml.org/</ref> Linux because the needed software is build in and it is mostly up-to-date.

Booting single user mode

Booting with rescue cd (grml)

Activate LVM volumes

Activate the LVM volumes and logical volumes

~ # vgscan
~ # vgchange -ay
~ # lvscan

After that, you could list your logical volumes with this command.

~ # lvdisplay

Control mount state

Controlling the mount state is an essential factor. You can control this through:

~ # mount

Shrinking

After you controlled everything needed, you could run the following command to shrink the partition. Please this is an example!!!

~ # resize2fs /dev/ovz1/root 5700M

This command will end up with a output similar to the following:

~ # resize2fs /dev/ovz1/root 5700M
resize2fs 1.40.4 (05-Dec-2007)
Please run 'e2fsck -f /dev/ovz1/root' first.

You should to this. This could take some time!

~ # e2fsck -f /dev/ovz1/root

Afterwards you can rerun the resize command.

~ # resize2fs /dev/ovz1/root 5700M

The output should be something like that:

The filesystem on ... is now ... blocks long.

Now we could resize the logical volume via LVM. Please DO NOT make the LVM2 logical volume smaller than the partition! Maybe you have to calculate the right count of extents you would like to reduce the volume!

The extend size is important

Run the following command to show how many extents the logical volume captures.

~ # lvdisplay -a /dev/ovz1/root 

look for this output:

Current LE 1888 

Now reduce the LE count by 460:

~ # lvreduce -l 1428 /dev/ovz1/root 

Double, tripple check what you are calculating and doing!!!!

Check the result

If the command

~ # vgdisplay

showed

Free PE / Size     0 / 0 GB

before. It should now display something like that:

Free PE / Size     460 / 1.80 GB

Reboot.

References

<references/>