Ubuntu – Move the whole installed files to another partition


I have installed ubuntu on a 8GB 5GB partition. As I have installed many packages, I am running out of space.

Qn 1 : Is there a way that I can specify another portion for installing the packages ?

Qn 2 : Can I move the whole installed files from my current partition to another place ( partition ) and make the changes in grub or so?

I don't want to reinstall the whole, so after that I just can make an upgrade 🙂

The / , and home directory is in same place.

Thank you .

Best Answer

A1: no, it's not possible. The paths are fixed.

A2: if you want to move files to another partition, you'll need to use a Live CD. Please consider resizing partitions first which is much easier and less error-prone. This is only possible if you've enough space on one disk. Consider moving your /home folder as described here too, 8GB should be enough for / in most cases. If you want to use a second disk as root partition or wish to create a new partition on the current disk, please continue.

  1. Make a backup (preferably with disk-cloning software like Clonezilla).
  2. Boot into the Live CD, do not mount anything
  3. Create a new partition using the Disk Utility or GParted. This partition must support Linux file permissions. Such a filesystem is ext4. Label it "UbuntuRoot" so you can find the partition easier, otherwise you'll have to remember the partition name (e.g. /dev/sdb1)
  4. Open a terminal and run sudo blkid to get the UUID for your newly created partition. Example output, you'll need the last line:

    /dev/sda1: LABEL="HDD" UUID="AD078BC9C024FCDD" TYPE="ntfs"
    /dev/sda2: LABEL="DATA" UUID="FDE43758913E70EE" TYPE="ntfs"
    /dev/sda3: UUID="a88638ae-3cd3-45c0-ad06-2d56d89b19a0" TYPE="swap"
    /dev/sda4: UUID="e3f848cb-5a05-4d2d-92e0-3eaf7b27338c" TYPE="ext4"
    /dev/sdb1: LABEL="UbuntuRoot" UUID="1cdfadcf-0969-48ba-96a5-42557c23f8e9" TYPE="ext4"
  5. Mount your old root partition (/dev/sdb1 is your newly created partition, /dev/sda4 was your old partition):

    sudo mkdir /media/old
    sudo mount /dev/sda4 /media/old
    sudo mount /dev/sdb1 /mnt
  6. Copy over the files (this may take a while):

    sudo cp -prvT /media/old /mnt
  7. Update /mnt/etc/fstab with the new UUID. Pick an editor at your choice:

    sudo nano /mnt/etc/fstab
    gksu gedit /mnt/etc/fstab

    Find the line that looks like and replace the UUID of /dev/sda4 with the /dev/sdb1's UUID:

    # / was on /dev/sda4 during installation
    UUID=e3f848cb-5a05-4d2d-92e0-3eaf7b27338c /               ext4    errors=remount-ro 0       1
  8. Save /mnt/etc/fstab and exit the editor. Next, GRUB needs to be updated to boot from the new disk and partition.

    sudo grub-install --root-directory=/mnt /dev/sdb
  9. Unmount the partitions to finish it:

    sudo umount /mnt /media/old
  10. Reboot to check the result.