Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently have all my backups in /home. I added a new 2 TB disk in the machine and would like to extend my current /home partition by 2 TB (possibly with LVM). However, I don't want to lose my data on the /home for obvious reasons.

What would be the best way to do this? Creating a new LVM group on the 2 TB disk and then add the old /home partition to it? Or any other way?


My current partition table:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              39G   11G   27G  28% /
/dev/sda2              99M   31M   64M  33% /boot
/dev/sda5             2.0G   68M  1.9G   4% /tmp
/dev/sda6             876G  474G  357G  58% /home
share|improve this question
You have stated you added a TB disk but not what size disk you had in the machine beforehand, could you post that so a few things can be clarified. – user88311 Oct 1 '12 at 14:04
@user88311 Edited :) – Devator Oct 1 '12 at 14:13
up vote 1 down vote accepted

Let say your 2 TB drive is /dev/sdb.

  1. create a physical volume out of it: pvcreate /dev/sdb.
  2. create a Volume group: vgcreate <name of the VG> /dev/sdb.
  3. create a LV from the VG: lvcreate --extents %FREE --name <name of the LV> <name of the VG>.
  4. let say your preferred filesystem type is ext4: mkfs.ext4 -m 0 /dev/mapper/<name of the VG>-<name of the LV>.
  5. mount the newly created LV somewhere (for instance /mnt): mount /dev/mapper/<name of the VG>-<name of the LV> /mnt and copy the contents from /home there. I would use rsync for this purpose: rsync -av /home/ /mnt/. This would take you a while and you want /home to stay mounted in order for your daily backups to run smoothly. After the rsync is done, rerun it to catch the changes. To be absolutely sure you got all data from /home to /mnt you could remount /dev/sda6 as read-only and run the rsync again.
  6. after rsync completes: umount /dev/sda6, umount /dev/mapper/<name of the VG>-<name of the LV>, mount /dev/mapper/<name of the VG>-<name of the LV> /home and fix /etc/fstab accordingly (run mount -a to test it).
  7. at this moment you would have /home on the new drive and /dev/sda6 is free to join the LVM configuration. You would need to add it to LVM. Change the System type for the partition: fdisk /dev/sda, then t-6-L-8e-w-q (I believe this is the sequence but am not sure how needed it is these days).
  8. add /dev/sda6 to the VG: pvcreate /dev/sda6, vgextend, lvextend, resize2fs -p /dev/mapper/<name of the VG>-<name of the LV>.
  9. Done!
share|improve this answer
Great, thank you! Was currently creating the LVM already and started to move files around, but your answer is very clear and comprehensive. Cheers for that :) – Devator Oct 1 '12 at 15:00

Instead of extending the home folder you could source the home directory out to an extra partition. This will also make it a lot easier to migrate to a new system without having to move the home directory.

Create a new partition and format it with a filesystem of your choice (i.e. ext4). Copy everything from your home folder to the new partition and then tell your system to mount the new partition in your home directory during startup by adding a corresponding line to /etc/fstab:

UUID=<some UID of your new partition>  /home/username  ext4  nodev,nosuid  0  1

Depending on the filesystem and mount options you might need to alter this line.

Edit - Ahh got ya. You really want both drives. In that case LVM could do it, but you would have to store your data somewhere while you make the partition...

sudo vgcreate vol_grp1 /dev/sda7
sudo lvcreate -n logical_vol1 vol_grp1
sudo  mkfs.ext3 /dev/vol_grp1/logical_vol1

Then mount it somewhere and copy your data to it. Unmount your current home disk and mount the new VG disk in its place. After this you'll be able to extend it to the original drive with lvextend.

vgextend logical_vol1 /dev/sda?
lvextend  /dev/logical_vol1/logical_vol1
share|improve this answer
But this way, I can't use my first hard drive, so I'm not able to use 1 TB basically. – Devator Oct 1 '12 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .