I have a hdd with /, /home. I just got new SSD and I need to change my partitions without any reinstalling. I would like to create a separate /var partition (which is currently under /) and leave it on hdd. Rest of the / (including /boot) I would like to move to ssd. How should I do it in ubuntu 12.04?

cat /etc/fstab
proc            /proc           proc    nodev,noexec,nosuid 0       0
UUID=4f614ad4-8b21-4e21-b6fc-13ba7f489a88 /               ext4    errors=remount-ro 0       1
UUID=dba112c1-1647-4e73-b907-0117ad3a058e /home           ext3    defaults        0       2
UUID=01CB6A18FD7DF1C0 /windows/c      ntfs    defaults,umask=007,gid=46 0       0
UUID=01CB6A18E6F42370 /windows/d      ntfs    defaults,umask=007,gid=46 0       0
UUID=48d5b437-91c9-4304-9bde-ee661779089d none            swap    sw              0       0

I have also some lvm partitions but they are irrelevant for this problem

  • Please specify your partitions' filesystems. Some are reducible, some are not. Mar 8 '14 at 19:28
  • done. hope that's enough
    – piotrek
    Mar 8 '14 at 19:48

They way I would go about this is to partition the SSD as you want it (/, /boot, /home, etc) and since you're moving everything to a new SSD you don't need to worry about shrinking partitions or anything complicated like that. You basically just need to copy everything to the SSD, repartition the HDD and edit your mount points on disk and in your fstab.

Prepare the migration

  1. Make a backup of your current HDD!
  2. Partition the SSD

    For the purposes of demonstration I am going to use these partitions:

    • /dev/sdb1 -- /boot
    • /dev/sdb2 -- /
    • /dev/sdb3 -- /home

    You can omit /boot and keep it as a normal directory inside of / as you currently do if you want.

  3. Create your filesystems on the new partitions (mkfs.ext4 or mkfs.whatever filesystem you want)
  4. Mount your new paritions under a hierarchy in your current filesystem. For example, mount your new / on the SSD as /mnt, and your new /boot on the SSD and /mnt/boot, and your new /home on the SSD as /mnt/home

    • For example:

      mkdir -p /mnt/newroot
      mkdir /mnt/newroot/boot
      mkdir /mnt/newroot/home
      mount /dev/sdb2 /mnt/newroot
      mount /dev/sdb1 /mnt/newroot/boot
      mount /dev/sdb3 /mnt/newroot/home

Migrate from HDD to SSD

  1. Copy (preserving timestamps, permissions and ownership) everything into the new partitions.

    • You can one of the following sets of commands

      cp -ax --sparse=always / /mnt/newroot
      cp -ax --sparse=always /home /mnt/newroot /home
    • or

      rsync -avSx / /mnt/newroot
      rsync -avSx /home /mnt/newroot/home
    • These will copy with the archive flag (preserves file ownership and other information), copy sparse when able and will not cross filesystem boundaries on the source filesystem. If you don't specify the -x flag to stay in filesystem you can do the copy in one command but will need to take steps to exclude /proc, /dev, and other in-memory filesystems from the copy.

  2. Edit the file /mnt/newroot/etc/fstab and change the entries to reflect the new partitions

  3. Install grub to the new disk (if it will be your boot device) and point it toward your new /boot on the SSD so that it can find its boot configuration.
  4. Unmount the new partitions.

    umount /mnt/newroot/home
    umount /mnt/newroot/boot
    umount /mnt/newroot

Verify the migration

  1. Reboot into the new partitions

    • If you setup grub properly and the new /etc/fstab is correct the boot will behave exactly like before except that it is using the new partitions rather than the old ones.
  2. Verify everything is proper.

    • If something is not expected, you have the old disk untouched and a backup. Nothing is lost. Yet.
    • I don't have advice for the windows partitions except to make clones of them on the new disk (use a clone tool or dd, if you are moving them)
    • If you are dual booting to windows, verify that still works and windows is on the SSD (if you want it SSD, if you are keeping it on the HDD, that is fine too)
    • I'm not up to speed on windows these days, so I have nothing further to offer on that front.

At this point you should have a working system on your SSD that is a clone of what was on the HDD. Any steps beyond this point will be destructive to your old data. Have a backup before proceeding

Re-purpose the HDD

  1. Re-partition the HDD

    • If you are not touching the windows partitions, just delete the linux partitions you no longer need and create a new partition for /var and whatever else you need.
    • If you did move windows to the SSD, you can entirely re-partition the HDD.
  2. Make the filesystem for the new /var
  3. Mount this new /var temporarily as /mnt/var or something

    mkdir /mnt/var
    mount /dev/sd?? /mnt/var
  4. Stop services dependent on /var or drop into single user mode

    • This is needed because if daemons are writing to /var during the copy, you will lose this new data when we switch to the new /var. Single-user mode is also runlevel 1 (init 1 on sysvinit, not sure with upstart)
  5. Copy old /var into new /var

    cp -av --sparse=always /var /mnt/var
  6. Delete old /var (leave the directory, but make it empty).

    rm -rf /var
    mkdir /var
  7. Umount new /var

    umount /mnt/var
  8. Edit /etc/fstab and add an entry for /var

  9. Mount /var (this will be the new one if you edited the fstab).

     mount /var
  10. Restart any services you stopped or go back into multi-user mode (or reboot if you want)

This general process should help you in the migration, and the most important step is the backup in case you mess something up.

  • how to copy data including symlinks, permissions, timestamps etc?
    – piotrek
    Mar 8 '14 at 19:59
  • @piotrek updated.
    – casey
    Mar 8 '14 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.