First of all I've tried to install Ubuntu , but something went wrong and the installation was interrupted. Then I tried to install again , and it was installed successfully.

And there was another partition about 600 Mb , but I removed it using Disk Utility .And I had to restore grub from a live CD.

but Why is /dev/sda4 now extended and contains 2 linux swap ?And how can I remove the other linux swap? and how to make it one Linux partition with one swap ?

enter image description here

enter image description here

When I try to remove /dev/sda5

Please unmount any logical partitions having a number higher than 5 . enter image description here


I'm not sure why your system ended up with 2 swap partitions, but it's easy to fix.

  • I recommend using gparted instead of fdisk or Disk Utility. You can delete the "extra" swap partition and resize the others to claim the freed disk space. It will also tell you if either swap partitions are being actually used or not. Very helpful. gparted is not installed by default, but it is available for install in the repositories. It is also pre-installed in Live sessions from the Ubuntu install CD/USB.

  • About the extended partition: using a traditional partition table, you can only have 4 primary ("non-extended") partitions. Since you already have 3 NTFS/Windows, and you need 2 more for Ubuntu (OS and Swap), this only can be done using an extended partition. So your 4 primary partitions are the 3 NTFS ones + Extended (the extended partition itself takes up 1 "slot"), and the other partitions are within the extended.

  • Using gparted, check the status of your swap partitions. If they are locked, it's being currently used by the system. Take note of their status, and decide which one you want to keep and which to delete. Also, right-click them both, go to information, and take note of their UUID (sudo blkid also works).

The possible scenarios are:

1 - The one you want to delete is NOT being used by the system: nice, just delete the partition.

2 - Both swaps are being used by the system: right-click it the one you want to delete, select Swapoff. To make that permanent, remove its entries from /etc/fstab and /etc/initramfs-tools/conf.d/resume (deleting the lines that match its UUID). Now you can safely delete the partition.

3 - Just the one you want to delete is being used, the one you want to keep is not: right-click the one you want to delete, select Swapoff. Right-click the other, select Swapon. Edit /etc/fstab and /etc/initramfs-tools/conf.d/resume, and replace the UUID from one to the other. Delete the unwanted partition.

If any changes are made to /etc/initramfs-tools/conf.d/resume, use the following command to apply the changes:

sudo update-initramfs -u

If you have any question about the answer, feel free to ask!

  • Having once done something similar, I'd hazard a guess that the reason you have two partitions is in the way Ubuntu automatically sets up a drive when installing (without selecting more advance settings.) - It creates a main partition and a swap. If it failed the first time and you selected the main partition it installed the first time, it'll split that again into a main partition and a swap. – thomasmichaelwallace May 26 '11 at 11:13
  • This is very helpful, but the one that isn't being used by the system I can't delete it, see the picture above. – Binarylife May 26 '11 at 11:21
  • @thomas: yes, i also suspect that is the reason why he has 2 swaps. Too bad that Ubuntu install isnt smart enough to detect that there is already a swap partotion avaliable, and set it up instead of creating a brand new one – MestreLion May 26 '11 at 11:51
  • @binarylife: that may be related to the partition table not be in order. Close gparted, do sudo fdisk /dev/sda and use x (extra functionality), then f (fix partition order), then w (write table to disk and exit). Then retry in gparted. – MestreLion May 26 '11 at 11:55
  • 2
    Its safer to do that re-ordering in a Live CD Session, so all your hard drive partitions are not mounted. – MestreLion May 26 '11 at 12:04

Identify your partition using

sudo blkid

and look at /etc/fstab to see which swap partition is use

grep swap /etc/fstab

Then delete the old swap partition, graphically with gparted or from the command line with fdisk.

If you wish to resize partitions, I suggest you do so with gparted from a live CD.

  • thanks to every one who viewed and answered the question it really helped – coder Dec 17 '11 at 16:08

What you get from the screenshots is that there are indeed two partitions that have been designated as swap partitions. Whether they are both used can be determined by running free.

For example, the output of free has the lines

Swap:      4200000          0    4200000

This means that there is one or more swap partitions totaling to about 4.2GB of swap space.

You can use free to establish whether both partitions are used as swap, or just one of them.

Then, you can select which one to deactivate, by running (for the second swap)

sudo swapoff /dev/sda7

Once deactivated, you can use the Disk Utility to erase the partition.

When your computer boots up, it runs the command sudo swapon -a which activates all available swap partitions. Therefore, simply the removal of one of the swap partitions is enough to complete the work. No further action/configuration is required.

  • Just disabling the swap is not enough for safe delete of the partition: One must also edit /etc/fstab to remove its entry (or swapon -a at boot will complain), and also /etc/initramfs-tools/conf.d/resume, for the resume/hibernate feature (that uses swap space) – MestreLion May 26 '11 at 11:03
  • I run the code sudo swapoff /dev/sda7 and then using gparted I made /dev/sda5 swapon , so this is worked well – Binarylife May 26 '11 at 11:39
  • 1
    it works well... until you reboot. You need to edit fstab and resume, otherwise you will see errors when booting up, and when trying to use hibernation. – MestreLion May 26 '11 at 11:49

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.