Difference between revisions of "How to Remove a Drive from LVM"

From Amahi Wiki
Jump to: navigation, search
(Created page with '13.5. Removing an Old Disk Say you have an old IDE drive on /dev/hdb. You want to remove that old disk but a lot of files are on it. Caution Backup Your System You should a…')
 
Line 11: Line 11:
 
If you have enough free extents on the other disks in the volume group, you have it easy. Simply run
 
If you have enough free extents on the other disks in the volume group, you have it easy. Simply run
  
# pvmove /dev/hdb
+
 
 +
<div style="border: 1px solid #A3B1BF; padding: .5em 1em; color: #000; background-color: #E6F2FF; margin: 3px 3px 1em 3px;">pvmove /dev/hdb
 
pvmove -- moving physical extents in active volume group "dev"
 
pvmove -- moving physical extents in active volume group "dev"
 
pvmove -- WARNING: moving of active logical volumes may cause data loss!
 
pvmove -- WARNING: moving of active logical volumes may cause data loss!
 
pvmove -- do you want to continue? [y/n] y
 
pvmove -- do you want to continue? [y/n] y
 
pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved
 
pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved
         
+
</div>   
  
 
This will move the allocated physical extents from /dev/hdb onto the rest of the disks in the volume group.
 
This will move the allocated physical extents from /dev/hdb onto the rest of the disks in the volume group.
Line 28: Line 29:
 
We can now remove the old IDE disk from the volume group.
 
We can now remove the old IDE disk from the volume group.
  
# vgreduce dev /dev/hdb
+
 
 +
<div style="border: 1px solid #A3B1BF; padding: .5em 1em; color: #000; background-color: #E6F2FF; margin: 3px 3px 1em 3px;"> vgreduce dev /dev/hdb
 
vgreduce -- doing automatic backup of volume group "dev"
 
vgreduce -- doing automatic backup of volume group "dev"
 
vgreduce -- volume group "dev" successfully reduced by physical volume:
 
vgreduce -- volume group "dev" successfully reduced by physical volume:
 
vgreduce -- /dev/hdb
 
vgreduce -- /dev/hdb
           
+
</div>         
  
 
The drive can now be either physically removed when the machine is next powered down or reallocated to other users.
 
The drive can now be either physically removed when the machine is next powered down or reallocated to other users.
Line 42: Line 44:
 
First, you need to pvcreate the new disk to make it available to LVM. In this recipe we show that you don't need to partition a disk to be able to use it.
 
First, you need to pvcreate the new disk to make it available to LVM. In this recipe we show that you don't need to partition a disk to be able to use it.
  
# pvcreate /dev/sdf
+
 
 +
<div style="border: 1px solid #A3B1BF; padding: .5em 1em; color: #000; background-color: #E6F2FF; margin: 3px 3px 1em 3px;"> pvcreate /dev/sdf
 
pvcreate -- physical volume "/dev/sdf" successfully created
 
pvcreate -- physical volume "/dev/sdf" successfully created
           
+
</div>           
  
 
13.5.2.2. Add it to the volume group
 
13.5.2.2. Add it to the volume group
Line 50: Line 53:
 
As developers use a lot of disk space this is a good volume group to add it into.
 
As developers use a lot of disk space this is a good volume group to add it into.
  
# vgextend dev /dev/sdf
+
 
 +
<div style="border: 1px solid #A3B1BF; padding: .5em 1em; color: #000; background-color: #E6F2FF; margin: 3px 3px 1em 3px;"> vgextend dev /dev/sdf
 
vgextend -- INFO: maximum logical volume size is 255.99 Gigabyte
 
vgextend -- INFO: maximum logical volume size is 255.99 Gigabyte
 
vgextend -- doing automatic backup of volume group "dev"
 
vgextend -- doing automatic backup of volume group "dev"
 
vgextend -- volume group "dev" successfully extended
 
vgextend -- volume group "dev" successfully extended
           
+
</div>
  
 
13.5.2.3. Move the data
 
13.5.2.3. Move the data
Line 60: Line 64:
 
Next we move the data from the old disk onto the new one. Note that it is not necessary to unmount the file system before doing this. Although it is *highly* recommended that you do a full backup before attempting this operation in case of a power outage or some other problem that may interrupt it. The pvmove command can take a considerable amount of time to complete and it also exacts a performance hit on the two volumes so, although it isn't necessary, it is advisable to do this when the volumes are not too busy.
 
Next we move the data from the old disk onto the new one. Note that it is not necessary to unmount the file system before doing this. Although it is *highly* recommended that you do a full backup before attempting this operation in case of a power outage or some other problem that may interrupt it. The pvmove command can take a considerable amount of time to complete and it also exacts a performance hit on the two volumes so, although it isn't necessary, it is advisable to do this when the volumes are not too busy.
  
# pvmove /dev/hdb /dev/sdf
+
 
 +
<div style="border: 1px solid #A3B1BF; padding: .5em 1em; color: #000; background-color: #E6F2FF; margin: 3px 3px 1em 3px;"> pvmove /dev/hdb /dev/sdf
 
pvmove -- moving physical extents in active volume group "dev"
 
pvmove -- moving physical extents in active volume group "dev"
 
pvmove -- WARNING: moving of active logical volumes may cause data loss!
 
pvmove -- WARNING: moving of active logical volumes may cause data loss!
 
pvmove -- do you want to continue? [y/n] y
 
pvmove -- do you want to continue? [y/n] y
 
pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved
 
pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved
           
+
</div>
  
 
13.5.2.4. Remove the unused disk
 
13.5.2.4. Remove the unused disk
Line 71: Line 76:
 
We can now remove the old IDE disk from the volume group.
 
We can now remove the old IDE disk from the volume group.
  
# vgreduce dev /dev/hdb
+
 
 +
<div style="border: 1px solid #A3B1BF; padding: .5em 1em; color: #000; background-color: #E6F2FF; margin: 3px 3px 1em 3px;"> vgreduce dev /dev/hdb
 
vgreduce -- doing automatic backup of volume group "dev"
 
vgreduce -- doing automatic backup of volume group "dev"
 
vgreduce -- volume group "dev" successfully reduced by physical volume:
 
vgreduce -- volume group "dev" successfully reduced by physical volume:
 
vgreduce -- /dev/hdb
 
vgreduce -- /dev/hdb
           
+
</div>
  
 
The drive can now be either physically removed when the machine is next powered down or reallocated to some other users.
 
The drive can now be either physically removed when the machine is next powered down or reallocated to some other users.

Revision as of 14:32, 3 May 2010

13.5. Removing an Old Disk

Say you have an old IDE drive on /dev/hdb. You want to remove that old disk but a lot of files are on it.

Caution Backup Your System


You should always backup your system before attempting a pvmove operation. 13.5.1. Distributing Old Extents to Existing Disks in Volume Group

If you have enough free extents on the other disks in the volume group, you have it easy. Simply run


pvmove /dev/hdb

pvmove -- moving physical extents in active volume group "dev" pvmove -- WARNING: moving of active logical volumes may cause data loss! pvmove -- do you want to continue? [y/n] y pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved

This will move the allocated physical extents from /dev/hdb onto the rest of the disks in the volume group.

Note pvmove is Slow


Be aware that pvmove is quite slow as it has to copy the contents of a disk block by block to one or more disks. If you want more steady status reports from pvmove, use the -v flag. 13.5.1.1. Remove the unused disk

We can now remove the old IDE disk from the volume group.


vgreduce dev /dev/hdb

vgreduce -- doing automatic backup of volume group "dev" vgreduce -- volume group "dev" successfully reduced by physical volume: vgreduce -- /dev/hdb

The drive can now be either physically removed when the machine is next powered down or reallocated to other users. 13.5.2. Distributing Old Extents to a New Replacement Disk

If you do not have enough free physical extents to distribute the old physical extents to, you will have to add a disk to the volume group and move the extents to it. 13.5.2.1. Prepare the disk

First, you need to pvcreate the new disk to make it available to LVM. In this recipe we show that you don't need to partition a disk to be able to use it.


pvcreate /dev/sdf

pvcreate -- physical volume "/dev/sdf" successfully created

13.5.2.2. Add it to the volume group

As developers use a lot of disk space this is a good volume group to add it into.


vgextend dev /dev/sdf

vgextend -- INFO: maximum logical volume size is 255.99 Gigabyte vgextend -- doing automatic backup of volume group "dev" vgextend -- volume group "dev" successfully extended

13.5.2.3. Move the data

Next we move the data from the old disk onto the new one. Note that it is not necessary to unmount the file system before doing this. Although it is *highly* recommended that you do a full backup before attempting this operation in case of a power outage or some other problem that may interrupt it. The pvmove command can take a considerable amount of time to complete and it also exacts a performance hit on the two volumes so, although it isn't necessary, it is advisable to do this when the volumes are not too busy.


pvmove /dev/hdb /dev/sdf

pvmove -- moving physical extents in active volume group "dev" pvmove -- WARNING: moving of active logical volumes may cause data loss! pvmove -- do you want to continue? [y/n] y pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved

13.5.2.4. Remove the unused disk

We can now remove the old IDE disk from the volume group.


vgreduce dev /dev/hdb

vgreduce -- doing automatic backup of volume group "dev" vgreduce -- volume group "dev" successfully reduced by physical volume: vgreduce -- /dev/hdb

The drive can now be either physically removed when the machine is next powered down or reallocated to some other users.