Welcome to TQ CMS knowledge base. Here you will find useful information for all sorts of things.

Replace one of the physical volumes in an LVM volume

Objective

To replace one of the physical volumes within an existing LVM volume group

Scenario

Suppose that /dev/vg0 is a volume group composed of a single physical volume located on a hard drive with a capacity of 100GB. You wish to replace this with a new hard drive having a capacity of 200GB. You have been able to temporarily connect both drives to the system, such that the old drive is presented as /dev/sdb and the new drive as /dev/sdc.

Method

Overview

The method described here has five steps:

  1. Optionally, initialise the new storage device as a physical volume.
  2. Add the new physical volume to the volume group.
  3. Migrate all data located on the old physical volume to the new physical volume.
  4. Remove the old physical volume from the volume group.
  5. Optionally, wipe the label from the old storage device to prevent it from being detected as a physical volume.

The corresponding sequence of commands is as follows:

pvcreate /dev/sdc
vgextend vg0 /dev/sdc
pvmove /dev/sdb /dev/sdc
vgreduce vg0 /dev/sdb
pvremove /dev/sdb

Be aware that any operation of this nature carries some risk of data loss. This is unlikely if the hardware is in good working order, but it would be prudent to make a backup of the relevant volume group before starting.

Optionally, initialise the new storage device as a physical volume

With older versions of LVM it was necessary for physical volumes to be explicitly initialised using pvcreate before being added to a volume group:

pvcreate /dev/sdc

As of version 2.02.54 this is no longer necessary because initialisation will occur automatically if required. Prior initialisation may still be desirable in order to deviate from the default settings used by pvcreate, obtain better diagnostics by proceeding one step at a time, or retain compatibility with older versions of LVM.

Add the new physical volume to the volume group

A physical volume can be added to a volume group using the vgextend command:

vgextend vg0 /dev/sdc

The first argument is the name of the volume group to be extended. This can be written as a pathname if you prefer (/dev/vg0). Subsequent arguments are the physical volumes to be added.

If successful you should see a response of the form:

  Volume group "vg0" successfully extended

If the physical volumes have not previously been initialised using pvcreate then there will be some additional diagnostic messages, for example:

  No physical volume label read from /dev/sdc
  Physical volume "/dev/sdc" successfully created
  Volume group "vg0" successfully extended

You can check that the physical volume has been added using the pvs command:

pvs

If successful then you should see a response of the form:

  PV         VG   Fmt  Attr PSize   PFree
  /dev/sdb   vg0  lvm2 a-   100.00g      0
  /dev/sdc   vg0  lvm2 a-   200.00g 200.00g

The VG column indicates which volume group each physical volume is a member of (if any). In this instance it shows (as expected) that both /dev/sdb and /dev/sdc are members of vg0.

Migrate all data located on the old physical volume to the new physical volume.

Data can be transferred from one physical volume to another using the pvmove command:

pvmove /dev/sdb /dev/sdc

The first argument is the physical volume to be emptied. The second argument is the physical volume to which the content should be moved. For large storage devices the transfer can take a considerable amount of time, however the machine should remain usable during this period so pvmove can be left to run in the background. It is safe to continue using filing systems that are wholly or partly located within the physical volume that is being moved.

pvmove periodically reports the progress it has made as a percentage, returning control when the transfer is complete. If it is interrupted for any reason then the transfer can be resumed by executing pvmove again with no arguments.

You can check that the migration was successful using the pvs command again. The response should show that the source physical volume contains no data (and therefore that PFree is equal to PSize):

  PV         VG   Fmt  Attr PSize   PFree
  /dev/sdb   vg0  lvm2 a-   100.00g 100.00g
  /dev/sdc   vg0  lvm2 a-   200.00g 100.00g

Remove the old physical volume from the volume group.

A Physical volume can be removed from a volume group using the vgreduce command:

vgreduce vg0 /dev/sdb

The first argument is the name of the volume group. Subsequent arguments are the names of physical volumes to be removed. If successful you should see a response of the form:

  Removed "/dev/sdb" from volume group "vg0"

You can check that the physical volume has been removed using the pvs command again. The response should show that the source physical volume is no longer a member of any volume group:

  PV         VG   Fmt  Attr PSize   PFree
  /dev/sdb        lvm2 a-   100.00g 100.00g
  /dev/sdc   vg0  lvm2 a-   200.00g 100.00g

Optionally, wipe the label from the old storage device to prevent it from being detected as a physical volume

LVM will continue to recognise the old storage device as a physical volume (albeit an empty one) unless you take explicit action to wipe the label that was written by pvcreate. This can be done using the pvremove command:

pvremove /dev/sdb

If successful you should see a response of the form:

  Labels on physical volume "/dev/sdb" successfully wiped

Leaving the label in place is not necessarily harmful, but it can cause confusion in some circumstances. For example, repartitioning a hard drive can result in LVM discovering physical volumes that are the wrong size for the drive layout. Use of pvremove is therefore recommended unless there is a reason not to.

There is 56 guides in the database.

More news

Bootstrap
25 February, 2014

Bootstrap

I have implemented bootstrap into the project and changed all code in the administration to use this new framework and I really love the result that I see after a couple of hours of coding. To make things look so good has never been so easy as with
Guides
20 February, 2014

Guides

I have added some of my guides for different things when it comes to the different areas in the computer, I will continue to add guides and especially when it comes to things that I am using every now and then in my own work.
First phase completed
17 February, 2014

First phase completed

Then I had time to finish the dirty work with the page and now it only remains little touches here and there and I need to upload information about what I'm doing and my progress on the project as well.
Time for a change
16 February, 2014

Time for a change

Today I've decided to update my own personal website with the latest version of my project called TQ CMS and with a completely new design that is responsive. My goal with this project is to make it as easy as possible for the end user while

Spotlight

The next step

The next step

I have now resumed my programming after a couple of months of vacation which was very much needed. I got a call one day from a friend that needed a system which can handle peoples reports on various problems like kitchen problems, water problems etc and I decided to make a system for it. Little did I know that it would totally revolutionise my own project and that it would teach me much needed jquery skills to further enhance the CMS. I also