Web Dev Blog

Looking for help with WordPress, Apache, Vim, Web Security and more. Here are a few tips.

Tag: LVM

Replacing Hard Drive under LVM in Ubuntu

Recently had a hard drive start acting strangely on my development server. It is a 2TB Seagate drive and it started causing errors in the logs, nothing major and it still worked. I put off ordering a new drive, a mistake, I know, but thought maybe it was just some kind of software issue.

Then the machine started getting slow. Really slow. So I ordered a new 3TB Toshiba drive. Finally received it and thought I would use Clonezilla to copy the drive. Created a live USB Linux flash drive with the Clonezilla image. Worked like a champ, but the cloning was going very slowly due to the problem with the drive, so I bailed. After some additional tinkering, and fixing grub because Clonezilla had modified it, I was able to boot back up and I realized that I was using LVM and this creates another problem.

I’m not sure if cloning and replacing the drive would have worked or not, but found some guides on replacing a drive in LVM.

Here is the one I used
http://www.microhowto.info/howto/replace_one_of_the_physical_volumes_in_an_lvm_volume_group.html

Basically you add the new drive to the LVM and then use pmove to migrate the content off the old drive. Honestly, I’m not sure yet how this is going to work, it’s been almost a day and a half and I’m at 45.8%. If it fails I have a backup, but it would be nice if this process works and everything moves.

Which physical partition are my Ubuntu files on?

LVM, the Linux logical volume manager included in the Linux kernel uses the device-mapper functionality to allow easy administration and creation of logical volumes in your file system. This is great technology, but what happens when you are having hard drive problems and want o troubleshoot. How do you determine which physical drive your volume is mapped to? How to find out if the drive you are replacing is storing critical parts of your system?

Here is the technique I’ve used and it works pretty well.

The df command will tell you what volume a specific directory is on. the output of this command might look like this

# df /foo
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/kubuntu--vg-Video 739G 645G 56G 93% /foo

Once you know the volume you are looking for you can use the lvs command to report information about logical volumes. Note, lvs seems to need root access so you may need to use sudo.


# sudo lvs -o +devices /dev/mapper/kubuntu--vg-Video
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices
Video kubuntu-vg -wi-ao---- 750.00g /dev/sda5(128000)

So now we can see that the logical volum in question is on /dev/sda5

lshw can now show us what drive is on sda


# sudo lshw -class disk
*-disk
description: ATA Disk
product: ST2000DM001-1CH1
vendor: Seagate
physical id: 0.0.0
bus info: scsi@0:0.0.0
logical name: /dev/sda
version: CC27
serial: Z340BEHG
size: 1863GiB (2TB)
capabilities: partitioned partitioned:dos
configuration: ansiversion=5 logicalsectorsize=512 sectorsize=4096 signature=000c3f21

Now we know which drive is storing the content from the LVM in question and can migrate this over to a new hard drive.