Saturday, March 5, 2016

partitioning - How to give Ubuntu 14.04 more disk space


My original OS was / is W7 and whenever I installed Ubuntu 14.04 LTS it gave me 17GB of space but now I want to expand it for certain applications.


enter image description here


I kinda am new to the whole disk and partitioning thing so GOOD help would be appreciated.


I also installed Ubuntu alongside W7.



To give more space to Ubuntu, you'll need to do a few things:



  • Shrink /dev/sda2

  • Resize the extended partition (/dev/sda3) to include the space freed up by the previous step.

  • Decide whether the space is for system applications (those installed by apt-get, Software Centre, etc.) or user applications (those installed by you from source, precompiled binaries, etc.

  • If the former, resize root (/dev/sda5); if the latter, make a partition in the free space and mount it somewhere convenient. I'll cover the former for now, and the latter if anybody requests it.


To accomplish the first step, you have two options:



  • Shrink using GParted or

  • Shrink using the Disk Management section in Windows' Computer Management.


With GParted, you can shrink to free up as much space as available, but the operation will be slow. With Windows, shrinking will be very fast, but you may not be able to free up as much space as is shown to be unused. This is because the Windows utility only shrinks upto the last used sector, whereas GParted moves around files. I recommend that you see how much Windows is willing to free up, and if it is satisfactory, use it, or else use GParted. And if you do choose to use GParted, use a live CD/USB to do so. I'll assume a live environment for any Linux operations henceforth.



  1. To shrink in Windows, right click My Computer and select Manage. Go to the Disk Management section, select the C: partition, right click it and choose Shrink Volume:
    Random image lifted from the net

  2. To do so in GParted: Unmount the partition first if it is mounted (the key icon shows it is mounted) by right clicking /dev/sda2 and selecting Unmount. Choose Resize/Move, and drag the right end of the slider (or enter in values manually) until enough free space is shown at the end of the partition.

  3. Right click the root partition and select Information. You'll get a window that looks like this:
    GParted information window screenshot
    Copy the UUID to somewhere (open a file in gedit and paste it there, if you will).

  4. Repeat the above step with the extended partition and the root partition, but this time dragging the slider to fill up the free space at the beginning.

  5. Click on the green tick to apply.


Once the operations have finished, you'll probably have to change the UUID values of the partitions (as used in /etc/fstab, GRUB, etc.). For this, we will set up a chroot. But first, repeat step 2 to get the new UUID of the root partition. If they are the same, no worries, skip the next section. You are done. If not:


Now open a terminal and do the following steps:


sudo mount /dev/sda5 /mnt
sudo mount -o bind /dev /mnt/dev
sudo mount -t devpts none /mnt/dev/pts
sudo mount -t proc none /mnt/proc
sudo mount -t sysfs none /mnt/sysfs
sudo chroot /mnt /bin/bash -l

Now, you will be inside a chroot environment in your installed Ubuntu, as opposed to the live Ubuntu used to get there. We must replace the UUID value for root in /etc/fstab, so use your choice of editor to open it and change the value to the one you copied a few steps ago (if you aren't familiar with vi, use nano):


vi /etc/fstab

(You are root within the chroot, so you don't need sudo.)
Or use the sed command:


sed -i 's/OLD_UUID/NEW_UUID/' /etc/fstab

(Replace OLD_UUID and NEW_UUID with the appropriate values.)


Finally, update GRUB:


update-grub

If this finished without errors, you can exit the chroot (exit) and reboot. Done!


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...