Preserving /home directory on LVM while switching distros

I have been using Slackware since I remember. Well, it wasn’t that long ago but  it was one of the first distros I tried to use. It works (like a charm, I can’t deny) on my laptop, PC, VMs and in few other places. Times changed and now I decided to switch to other distro I know and like which is Debian. The question is, how to do this and not to loose any data in /home directory?

On virtual machine with Slackware I have four partitions:

/dev/sda1 – / ext4 (root directory)
/dev/sda2 – swap
/dev/sda3 – LVM PV
/dev/sda4 – LVM PV

As numbers say (and I say), all of them are primary.

Two PVs, sda3 and sda4 are merged into one VG named “user_data” and on this there is one LV named “home” containing /home directory with ext4 filesystem. I know this design is a bit weird but on this machine I used to play with LVM (adding, removing, resizing and more) and this is what has left. What I want to do is to throw away everything except /home directory. The final, satisfactory result will be fresh Debian installation with the same /home content. There is not much to do with partition design in my case, so I won’t be doing strange joining nor splitting.

So this is what to do if you want to save existing LVM partitions while installing Debian.

Start normal installation. Go through first steps, then in “Partition disks” window select manual partitioning method. Installer should properly recognize existence of LVM volumes. There should be two lists of devices on the screen, one starting with “LVM” referring to VG and one entitled “SCSI1” which is hard disk (virtual in my case). In both there are sublists of devices.

Under “SCSI1” there are all physical partitions. Since we do not want to change PVs we are interested only in sda1 (#1) for root and sda2 (#2) for swap. In “Partition settings” displayed after selecting #1 choose filesystem type you  want in “Use as”, set mount point to “/” and agree on formatting partition. Be sure that bootable flag is set and that’s it. Swap (#2) configuration is straightforward as installer should detect it automatically.

Under “LVM” there are listed all existing LVs.  In our example there is only one and we want it to be /home. What we need to do is to select it and setup as a normal partition. Extremely important is to not format it. Make sure the chosen option says “no, keep existing data”.

After that just select “Finish partitioning and write changes to disk” then confirm formatting of partitions #1 and #2. Continue normal installation and  after reboot we have what we wanted: /dev/mapper/user_data-home device mounted to /home directory with all data already there.

21. October 2011 by resset
Categories: Software | Tags: , , | Leave a comment

Leave a Reply

Required fields are marked *