9

I need to add a swap partition to a running installation of Ubuntu. So I freed up 4 GB, but I can't create a new partition to assign as Swap because I get the following error: "It is not possible to create more than 4 primary partitions"

I have dual boot with windows, my four partitions are: - The 100 MB partition Windows always makes - The Windows Partitions - The Ubuntu partition - The second Ubuntu partition for files

When I installed Ubuntu I decided to not have a Swap partition but now I would like to add it. This is the distribution of the HDD:

My Partitions

How can I solve this without formatting my current partitions, and add a swap partition?

2
  • no need to use all primary partitions. Both Linux and Windows (since Vista) were able to boot from a logical partition for decades
    – phuclv
    Commented Dec 12, 2016 at 10:43
  • If it's a desktop, you could put another physical drive in and have /dev/sdb1 as your swap
    – Chris H
    Commented Dec 12, 2016 at 11:54

3 Answers 3

19

You do not need a swap partition: you can just as well use a swap file. There is no performance difference between a swap partition and a swap file. To add a swap file:

  1. Create the file (in this example, a 4 GiB file named /swapfile):

    sudo fallocate -l 4G /swapfile
    
  2. Format it as swap:

    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    
  3. Enable swapping on the new swap file:

    sudo swapon /swapfile
    
  4. Add the newly created file to /etc/fstab by appending /swapfile none swap sw 0 0 to /etc/fstab.

See the Digital Ocean tutorial How To Add Swap on Ubuntu 14.04.

5

If you want a swap partition, and not just a swap file, you will need to reformat one partition into an extended partition, and then you will have to create logical partitions within that.

Then once you get to installing, use LVM for even more partitioning fun and flexibility!

1
  • Since he doesn't NEED to do that - see above answer with the swapfile solution - this should be slightly edited to describe it as one possible solution. Commented Dec 12, 2016 at 11:07
-1

you need to go into your windows side and use disk management to create a simple partition taking free space from the 29+GB free space and leave as unallocated space. You are going to want a partition that is equal to at least 1.5 times available RAM on your system. Once this is done, boot into your ubuntu and use ubuntu disk tool to set up this unallocated space as SWAP. gparted is a tool that will do this, but there are other tools resident from a command line whose name I do not currently remember. Hope this helps Craig

2
  • 6
    Do not use Windows to create partitions, especially if you already have 4 primary. It converts to dynamic proprietary from from basic. It is a one way conversion, although some third party tools may undo it. You may be able to use fixparts to convert a primary to logical and then shrink to to make another logical. rodsbooks.com/fixparts But probably easier to just use the swap file in other answer.
    – oldfred
    Commented Dec 11, 2016 at 23:07
  • @oldfred Windows diskmgmt.msc is inferior to other disk partitioning tools, so don't use it for this. But many 3rd party partitioning tools on Windows (like Easeus Partition Master, Partition Wizard, Acronis Disk Director...) provide much better features than gparted, like automatic handling of logical partitions, smart data movement... Those tools are just lightning fast and safe to use with many partition recovery options. In gparted just the scan for partition info took forever, and then the copying is even longer. I've never found a comparable solution on Linux.
    – phuclv
    Commented Dec 14, 2016 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .