(Created page with "== LVM Basics == === General Description === LVM allows a server filesystem to be created, extended and even moved while running, without the need for a reboot and without nee...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
 
== LVM Basics ==
 
== LVM Basics ==
 
=== General Description ===
 
=== General Description ===
Line 62: Line 63:
  
 
== Rescanning scsi bus ==
 
== Rescanning scsi bus ==
−
When you hotplug a hard drive in a virtual machine, the drive will not show in fdisk -l output until you reboot your VM
+
When you hotplug a hard drive in a virtual machine, the drive will not show in fdisk -l output until you reboot your VM the SCSI bus.
−
 
 
−
the SCSI bus .
 
  
 
The rescan will be triggered through sysfs pseudo filesystem.
 
The rescan will be triggered through sysfs pseudo filesystem.
−
 
−
 
−
 
−
 
−
 
−
 
−
 
−
 
−
 
  
 
<pre>
 
<pre>
−
# echo "- - -" > /sys/class/scsi_host//scan
+
# echo "- - -" > /sys/class/scsi_host//scan
 
</pre>
 
</pre>
  

Latest revision as of 21:29, 11 January 2018

LVM Basics

General Description

LVM allows a server filesystem to be created, extended and even moved while running, without the need for a reboot and without needing to unmount the filesystem.

Order of things

Firstly there are physical volumes, these are entire physical disks basically (not sure whether you can use partitions as physical volumes). Physical volumes are part of volume groups.

Volume groups group together physical volumes and you make logical volumes out of them, volume groups basically become 'extent' pools which are large (~4MB normally) blocks.

Logical volumes are the actual file-systems which are formatted as ext2/3/whatever. When you create or extend one you pick which volume group to use and how many 'extents' to use. The number of extents times the size of the extent becomes your file-system size.

So you can see from the drawing below the layers and how they relate to one another.


If we were to want to extend the LVM though it would look like this (green parts are the new ones and yellow parts are extended bits)

ext3
LV
VG

Rescanning scsi bus

When you hotplug a hard drive in a virtual machine, the drive will not show in fdisk -l output until you reboot your VM or rescan the SCSI bus.

The rescan will be triggered through sysfs pseudo filesystem.

Now, you should be able to see the drive when running:

Extending a logical volume

Commands

All the commands are along the same lines and use an abbreviated prefix and a full suffix. the prefixes are as follows:

  • pv [Physical Volume]
  • vg [Volume Group]
  • lv [Logical Volume]

And the suffixes (not exhaustive):

  • create
  • display
  • extend
  • reduce
  • remove

The commands that you'll need for an extend operation are (in this order): fdisk, pvdisplay, pvcreate, vgdisplay, vgextend, lvdisplay, lvextend, resize2fs. Lets get started.

Example

Here is an example of a extension that i needed to do on the backup-mirror server. I needed to add 60GB to the logical volume that was created when the system was installed. Unfortunately due to the licensing on the ESX server i couldn't hot-plug a new physical drive into the virtual machine so needed to reboot to do that part, but all the rest should be able to be done while it's running which is the general idea anyway.

Displaying what we have

Firstly we should should get an inventory of what we have in the system as far as physical disks are concerned.

So we can see from that output that there is two phyiscal disks, one ~30GB and one ~60GB. This is what i expected to see. We should check what physical volumes we have allocated now:

So we can see that there is one physical volume and it isn't /dev/sdb so we should go ahead and create that now:

Creating the physical volume

Now double check with pvdisplay again:

You can see from the output the 'Total PE', 'Free PE' and 'Allocated PE' sections show how many physical extents are where.

Now we should see what logical volumes we have:

Checking volume groups

We can now extend our volume group with the following command:

Extending Volume Groups

Don't worry about the error message about /dev/hdc. Its just complaining about the cdrom drive not being available. We should now check that the volume group has been extended properly:

Looks good, now lets check the logical volumes:

Checking logical volumes

When we're extending the logical volume we need to make sure that we extend the right one, check the 'LV Size' of each to make sure and also check the 'mount' output or cat /etc/fstab.

We can see from this output that the filesystem mounted on '/' (which is the one we want) is /dev/VolGroup00/LogVol00 which is the logical volume that we want to extend.

Extending logical volumes

You'll need to decide by how many 'PE's you want to extend the logical volume by, normally you'd just use all the free 'PE's in the volume group:

The command above extends the logical volume /dev/VolGroup00/LogVol00 by 1919 physical extents.

Extending the filesystem

The last thing we need to do is extend the actual filesystem on the logical volume with the following command (this will take some time):