[linux-lvm] Replace small drive with bigger, using LVM?

James Hawtin oolon at ankh.org
Wed Sep 10 09:36:54 UTC 2014


Ok this is such an easy bread and butter task, but its really easy to 
get wrong so be careful! You have 7 tasks here, you will notice not all 
your OS is on lvm a small part /boot is on its own partition and you 
need to copy that as well to get you os to boot.

I am assuming here your second disk is called sdb.

Task 1) fdisk

fdisk /dev/sdb

c
p
1
2048
499711
a
1

c
p
2
<return>
<return>
t
8e

Task 2) Copying /boot

mkfs.ext3 /dev/sdb1
mkdir /boot2
mount /dev/sdb1 /boot2
cd /boot
tar -cPpSslf - . | ( cd /boot2 ; tar -xvPpSslf -)
umount /boot2
change /etc/fstab to us /dev/sda1 for how to reference /boot

Task 3) moving lvm... easy!
pvcreate /dev/sdb2
vgextend ubuntu-vg /dev/sdb2
swapoff -a
pvmove /dev/sda5 /dev/sdb2
vgreduce ubuntu-vg /dev/sda5


And now the tricky bit!

task4) Install grub on your new drive

Hopefully this is right... if not your need task 6.

grub-setup /dev/sdb

task5) Turn off your computer.

swap sda and sdb

and boot from your new drive.

check /boot is comming from the right device (/dev/sda1), if not unmount 
and mount it, then install a new kernel. This is the easiest way to get 
it to build a new initrd.
Shut down your computer remove /dev/sdb (old disk)
and you should be able to boot from just your new drive... SIMPLEZ!

Task 6) If you computer does no boot.

boot the ubuntu install disk and use rescue to install the grub boot 
block and verify /boot is mounted and populated with data. If not ... fix.

Task 7) I have no new space. Yes you do use pvs its just unallocated,

use either lvextend or lvcreate to extend or create a new logical 
volume, if you extend you will then need to use resize2fs for make he 
filesystem bigger, personally I would create a new mount point and not 
use / for everything.

James




More information about the linux-lvm mailing list