Replace a LVM2 drive with a larger one
My MythTV box has only 2 IDE ports so I can only have 4 devices. The MB
doesn't have any SATA connectors so I'm a bit limited to what I can do
disk-wise.
In any case, the box, running RHEL 4, is setup as follows:
Disk
|
Size
|
Purpose |
hda
|
30GB
|
OS and user files (/, /usr,
/home, etc) |
hdb
|
160GB
|
MythTV disk /video, LVM2
|
hdc
|
n/a
|
DVD writer
|
hdd
|
120GB
|
MythTV disk /video, LVM2
|
I have a PVR 250 and just record with the default settings so the
recorded quality isn't that great but then again, I'm not that picky.
With my recording and watching schedule this was leaving me with about
40GB of free space at any given time. With a new season starting I
don't think this will be enough space.
In doing some de-cluttering I found a 250GB disk lying around (don't
ask). So I decided to replace the 120 with the 250. Not a large boost
in size but it should let me record in peace for the upcoming season.
It was difficult finding a single source of information on how to do
this so I cobbled the following together from various sources. It
worked for me, YMMV.
In all of these steps /video (my VG) is mounted but mythbackend is
stopped. The system was otherwise quiet.
Back up
If possible you realy should back things up before starting this, I
did. The trouble is that LVM encourages you to create volumes larger
than a single disk so back ups become difficult.
Prepare the disk
In order to use the new disk I replaced the DVD writer with it, so I
had 4 disks. I used fdisk to create a single partition for the whole
disk and set the type to 8e (LVM2).
In these examples, /dev/hdc1 is the new 250GB disk and /dev/hdd is the
old 120GB disk.
Now to make the new disk available to LVM:
# pvcreate /dev/hdc1
pvcreate -- physical volume "/dev/hdc1" successfully created
Add it to the volume group
My volume group is named vg.
# vgextend vg /dev/hdc1
vgextend -- INFO: maximum logical volume size is 259.97 Gigabyte
vgextend -- doing automatic backup of volume group "vg"
vgextend -- volume group "vg" successfully extended
Move the data:
# pvmove /dev/hdd /dev/hdc1
/dev/hdd: Moved: 0.2%
/dev/hdd: Moved: 0.4%
/dev/hdd: Moved: 0.6%
...
/dev/hdd: Moved: 100.0%
This took a LONG time. I saw it go over an hour myself, then I
went to bed. It was done in the morning. As a benchmark, it took 3
hours to move a nearly full 250GB disk to a 500GB disk.
If you get the error message:
mirror: Required device-mapper target(s) not detected in your kernel
Then load the kernel module dm-mirror and do the pvmove command again.
Remove the unused disk
# vgreduce vg /dev/hdd
vgreduce -- doing automatic backup of volume group "vg"
vgreduce -- volume group "vg" successfully reduced by physical volume:
vgreduce -- /dev/hdd
Now I powered the system down and physically removed the 120GB
disk and replaced it with the 250. I also re-connected the DVD writer.
I was a bit worried that LVM wouldn't "know" that I had moved hdc1 to
hdd but it didn't seem to care about the order of the disks.
If you do a pvscan before removing the disk it will still show up but
won't be part of a volume group.
Reboot.
Extend the volume group
I need to tell the volume group that I have more space available.
First, let's see how much space I can add:
# pvscan
PV /dev/hdb VG vg lvm2 [149.05 GB/ 0 free]
PV /dev/hdd1 VG vg lvm2 [110.92 GB/121.96 GB free]
Total: 2 [259.97 GB] / in use: 2 [259.97 GB] / in no VG: 0 [0 ]
Ok, so this tells me I have 121 GB and change free on the drive. Let us
be conservative and add the 121.
# lvextend -L+121G /dev/vg/video
lvextend -- extending logical volume "/dev/vg/video" to 380 GB
lvextend -- doing automatic backup of volume group "vg"
lvextend -- logical volume "/dev/vg/video" successfully extended
Ok, now pvscan again to see if anything is left:
# pvscan
PV /dev/hdb VG vg lvm2 [149.05 GB/ 0 free]
PV /dev/hdd1 VG vg lvm2 [231.92 GB / 96MB free]
Total: 2 [380.97 GB] / in use: 2 [380.97 GB] / in no VG: 0[0 ]
Ok, let's go ahead and use the entire drive:
# lvextend -L+96M /dev/vg/video
lvextend -- extending logical volume "/dev/vg/video" to 381 GB
lvextend -- doing automatic backup of volume group "vg"
lvextend -- logical volume "/dev/vg/video" successfully extended
# pvscan
PV /dev/hdb VG vg lvm2 [149.05 GB / 0 free]
PV /dev/hdd1 VG vg lvm2 [232.88 GB / 0 free]
Total: 2 [381.93 GB] / in use: 2 [381.93 GB] / in no VG: 0 [0 ]
Extend the file system
Now the space is available but the file system doesn't know
about it. I need to extend it. I'm using ext3 so if you are using
something else,
you'll need another guide for this section.
The drive must be mounted for this to work:
# ext2online /dev/vg/video
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
Yes, there is no other output. This took just about 5 minutes for me.
Let's see if it worked.
# df /video
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg-video 394197468 212914556 161266764 57% /video
Bingo!
Check the file system
Caution tells us to check the disk:
# umount /video
# fsck -f /video
fsck 1.35 (28-Feb-2004)
e2fsck 1.35 (28-Feb-2004)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg/video: 141/50069504 files (29.8% non-contiguous), 54799848/100120576 blocks
# mount /video
Things look good, we're done. I fired up mythbackend and verified that
my files were indeed there and playable, woo hoo.
Resources
Resize an LVM
logical volume on ext2 or ext3
LVM HOWTO
Extending
MythTV recording space with LVM
Notes
I've done this twice more. I replaced the 160GB and 250GB disks with
twin 500GB disks. I did the replacements one at a time, running through
all of these steps each time.