Partitioning – How to Safely Delete a Second Swap Partition

partitioningswap

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

Best Answer

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!

Related Question