Transforming an Ubuntu 14.04 one partition into several partitions

Disclaimer: this manipulation should be done only if you’re familiar with linux, partitions mounting etc. If done wrongly (and sometimes even if done right), you can lose all your data, make your system unbootable and cause havoc in general on your computer. Use at your own risk, preferably if you’re familiar with all these concepts. BACKUP YOUR DATA FIRST!

If you don’t feel comfortable with this kind of manipulations, I advise you to try out these on a minimal install in VirtualBox. You can even create snapshots to rollback some changes if you make mistakes.

I have an ubuntu 14.04 system that is installed by default as /dev/sda1 (root) and /dev/sda5 (extended) with /dev/sda2 (swap). Note that I didn’t select encryption, so my whole system is non encrypted – I’m encrypting what needs to be, that’s all, so if your system is encrypted, you’ll need other steps to make it work. I’m also not using LVMs, and my disks are smaller than 2TB. Otherwise you have to go the GPT path, and I’m not covering this here.

I would like to add a /boot partition at the beginning of the drive and a /home partition, of course moving my data around and reboot with exactly the same system, but with partitions this time.

Boot through live CD.

Open GParted. Create your partitions as needed. For instance, you’ll have:

sda1 = root (unchanged – probably shrinked and moved to make some room for other partitions – gparted will complain, but we’ll fix it later)
sda5 = extended (unchanged)
sda2 = swap (unchanged)
sda3 = boot (new – at the beginning of the disk)
sda4 = home (new – after sda1 for instance)

Apply. It will take some time.

Once it is done, we need to move our data around. Make sure you’re root for the rest of the process. Note that being root is a dangerous position to be – think that you’re just having a gun pointed to the computer and it will shoot if you do something wrong. Hm. Maybe not. But you get the idea. 🙂

Create /mnt/root, /mnt/boot and /mnt/home and mount them with the correct partitions (it’s a good idea to have the partition table on a piece of paper to not screw up here 🙂 ).

Then move directories around:

mv /mnt/root/home/* /mnt/home
mv /mnt/root/boot/* /mnt/boot

Unmount all of these now and delete the directories under /mnt.

Now comes the tricky part, because we have to tell the system to mount the new partitions, and reinstall grub for it to be able to boot with the new topology.

If you’re using UUIDs, you’ll need to get the new partition’s UUIDs:

blkid /dev/sda3
blkid /dev/sda4

Now mount root into /mnt. Go to /etc/fstab and add lines for your new /home and /boot with the correct UUIDs (use defaults as the last parameters).

Mount home and boot into mnt (mount /dev/sda3 /mnt/boot …).

You also have to mount important system directories into /mnt before the next step, otherwise grub will not know where to search:

mount –bind /dev /mnt/dev
mount –bind /dev/pts /mnt/dev/pts
mount –bind /proc /mnt/proc
mount –bind /sys /mnt/sys

Now switch to your filesystem instead of the live one and update grub so that it finds the partitions on this new system:

chroot /mnt

grub-install /dev/sda
grub-install –recheck /dev/sda

If everything passes without any error, you’ll probably have a running grub!

Exit (Ctrl-D or ‘exit’) and unmount all the partitions:

umount /mnt/dev/pts
umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount /mnt/home
umount /mnt/boot
umount /mnt

Now cross your fingers and:


Once rebooted, check that everything is as expected:

df -h


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s