How to shrink a Windows partition and get space in Ubuntu Linux

Since 90% of my computer time i spent on Ubuntu, i needed more space and the only easy way was to shrink a Windows partition, format the new partition ext4 (Linux file system) and mount it in Ubuntu.

The setup before:

  • dual-boot Linux/windows
  • Linux partitions:
  1. root partition – /
  2. swap partition
  3. home partition – /
  • Windows partitions:
  1. system – C:
  2. data partitions – D:

So i wanted to shrink the D: drive, minus 80 GB and use that 80 GB as a Linux partition and this is what i have done:

  1. FIRST BACKUP YOUR DATA on the partition you want to shrink. (A little secret…i skipped this part but don’t do that, you won’t be that like maybe)
  2. Back in Linux, install GParted if it’s not installed. The most easy way is to go to Applications > Ubuntu Software Center > [here search for gparted and hit Install]
  3. MAKE SURE THAT THE PARTITION YOU WANT TO SHRINK IS NOT MOUNTED, IF IT IS, UNMOUNT IT (in Nautilus, right click > Unmount).
  4. After install, start GParted (it should be in Applications > Accessories)
  5. You will now see all your partitions being Linux or Windows, explore this. You should see the partitions like /dev/sda1, /dev/sda2 etc. for how many partitions yo have. EG: if you have 8, our new partition will be /dev/sda9.
  6. Right click on the partition you want to shrink and click on Resize/Move
  7. You will see a left arrow at the beginning of the partition and a right arrow at the end of the partition. Drag the right arrow to the left to the desired size. Make sure that there will still be some free space on the shrinked partition. You can setup this visually or enter the desired values. Play a little with the arrows and watch the values updating.
  8. when you are ready, hit OK, and you should see the new shrinked partition with the new size and some unallocated space (this will be the new Linux partition)
  9. while we are still here, right click on the “Unallocated Space” and Format (i did an ext4 file system and put a name (like DATA) for the partition on the Label field), hit OK
  10. at the bottom of GParted you will see 2 tasks pending, the first is the resizing and the second is the formatting of the new partition
  11. if you are ready, hit apply (the green check mark at the top of GParted)
  12. wait till the magic happens
  13. now in GParted you should see the shrinked partition and our brand Linux partition (EG: the sda9 partition above)
  14. we now have the let’s say /dev/sda9 partition with the label DATA
  15. open a Terminal and type: sudo fdisk -l, and it should list all you partitions, including the new one
  16. to permanently have the DATA partition mounted we need to make a directory and mount the new partition there
  17. in the Terminal type this: sudo mkdir /data
  18. then type: ls -l /dev/disk/by-uuid
  19. this will list your partitons UUID. I have something like this:
  20. lrwxrwxrwx 1 root root 10 2010-10-15 20:56 3dc8c97a-76e2-4176-a3ae-2aa7bca80067 -> ../../sda7
    lrwxrwxrwx 1 root root 10 2010-10-15 20:56 46183BE7183BD521 -> ../../sda5
    lrwxrwxrwx 1 root root 10 2010-10-15 20:56 51148f5b-e51f-4dde-af92-84e3fbc1ae2f -> ../../sda9
    lrwxrwxrwx 1 root root 10 2010-10-15 20:56 72A427B4A42779AD -> ../../sda1
    lrwxrwxrwx 1 root root 10 2010-10-15 20:56 759C-E00A -> ../../sdg1
    lrwxrwxrwx 1 root root 10 2010-10-15 20:56 77234bd3-2683-4fb1-b798-82271750058e -> ../../sda8
    lrwxrwxrwx 1 root root 10 2010-10-15 20:56 A163-5F05 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 2010-10-15 20:56 e108dced-77d6-4530-ad35-228b698cdc1e -> ../../sda6
  21. see the new sd9 and the bold red UUID. Copy that on the clipboard.
  22. now you have to edit the fstab (the file with the partitions and mounting settings)
  23. first backup it: sudo cp /etc/fstab /etc/fstab_backup
  24. open for edit fstab (i use gvim, you can use whatever text editor you like):
  25. sudo gvim /etc/fstab
  26. and add a line like this:
  27. UUID=56 51148f5b-e51f-4dde-af92-84e3fbc1ae2f /data ext4 defaults 0 0
  28. the red UUID should be yours and corresponding to your new partition, the one you get at step 18
  29. save and close the file
  30. tell Linux to be aware of the new changes:
  31. in Terminal type: sudo mount -a
  32. now you have to link your user to the mount point (the directory created in step 17) and the partition, and to give read/write permissions for the mount point:
  33. sudo chown -R yourusername:yourusername /data
  34. sudo chmod -R 755 /data

Now open Nautilus and go to File System (the root), where you should see the /data directory. Drag this to the left to make a shortcut to the mount point/partition for easy accessing.

That’s it ! Seems complicated but it’s not, next time you will do it in no time.

PS: no windows partitions were harmed during the process.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s