Migrate from partition to LVM

Robert Heller heller at deepsoft.com
Sun Jul 13 13:36:50 UTC 2014


At Sun, 13 Jul 2014 15:07:39 +0200 "Ubuntu user technical support,  not for general discussions" <ubuntu-users at lists.ubuntu.com> wrote:

> 
> On 13 July 2014 11:24, Alfredo De Luca <alfredo.deluca at gmail.com> wrote:
> >
> > I have ubuntu 13.10 running  on a partition on one disk and I'd like
> > to migrate  to a new disk with LVM2.
> > What 's the best way to do it?
> > Any procedure/info/doc?
> 
> 13.10 is obsolete. I think you would be much better employed starting afresh.
> 
> Saying that, it *can* be done, but AFAIK most ordinary imaging tools
> (e.g. Gparted, Clonezilla etc.) don't understand LVM.
> 
> So you'd have to do it manually:
> 
> http://www.tldp.org/HOWTO/archived/Linux+XFS-HOWTO/x154.html
> 
> http://www.thinkwiki.org/wiki/How_to_copy_a_Linux_installation

Yes, it is trivial.  I needed to do something similar involving installing on 
a VM under Xen without hardware virtualization (no you don't *really* want to 
know).  In my case, I did a 'normal' bare-metal install on a real spare disk, 
and then create a LVM volume on the virtual host.  Then it was just a matter 
of mkfs and dump/restore:

# create LVM volume
lvcreate -n vmfs -L10G hostvg
# partition it with fdisk
fdisk /dev/hostvg/vmfs 
# create a loop device that is offset to the internal partition offset
losetup -o <offset> /dev/loop1 /dev/hostvg/vmfs
# make the file system
mkfs.ext3 /dev/loop1
# make a mount point
mkdir /mnt/vmfs
# mount it
mount -v -t ext3 /dev/loop1 /mnt/vmfs
# make a mount point for the bare metal partition
mkdir /mnt/barefs
# mount it
mount -v -t ext3 -r /dev/sdd1 /mnt/barefs
# disk-to-disk backup
dump -0f - /mnt/barefs| (cd /mnt/vmfs;restore -rf -)
# unmount file systems
umount /mnt/vmfs
umount /mnt/barefs
# delete loop device
losetup -d /dev/loop1

(In my case this was followed up with some fun with installing a suitable 
version of grub on the VM's 'MBR', which involved interesting fun with 
losetup, etc. and then fun with virtsh...  Oh, and some monkeying with the 
VM's grub conf file and fstab, since the UUID of the new LVM file system 
changed...)

Note: if you are NOT setting up a VM (eg need to make a virtual MBR), you can
skip the fun and games with fdisk and losetup and just make the new fs on the
whole LVM volume. 

Note: if this will be a multi-boot system, the original /boot directory *has*
to be on a real partition, presumably on a *shared* /boot filesystem (shared
by all of the various Linuxes), since grub does not understand LVM. OTOH, if
this is just a backup / reference copy, that would not matter.


> 
> 

-- 
Robert Heller             -- 978-544-6933
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller at deepsoft.com       -- Webhosting Services
                                                      




More information about the ubuntu-users mailing list