I installed Ubuntu and forgot to create swap during installation... So I did cut off 4GiB out of my system partition and I'm confused what to do next? I can reboot Ubuntu everything is fine but when I run:

sudo blkid


sudo parted -l


sudo fdisk -l

it doesn't appear anywhere... for example this output:

ubuntu@ubuntu:~$ sudo parted -l
Model: ATA Hitachi HDP72503 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
1      32,3kB  47,5GB  47,5GB  primary   ext4         boot
3     47,5GB  51,5GB  3999MB  primary   linux-swap(v1)
2      51,5GB  320GB   269GB   extended
5      51,5GB  320GB   269GB   logical   ntfs

Warning: Unable to open /dev/sr0 read-write (Read-only file system).
/dev/sr0 has been opened read-only.
Error: Can't have a partition outside the disk! 

I was using this topic but still cannot figure it out.

other outputs:

ubuntu@ubuntu:~$ sudo fdisk -l

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x27252724

/dev/sda1   *          63    92851625    46425781+  83  Linux
/dev/sda2       100663357   625137344   262236994    5  Расширенный
/dev/sda3        92852224   100663295     3905536   82  Linux своп / Solaris
/dev/sda5       100663359   625137344   262236993    7  HPFS/NTFS/exFAT


ubuntu@ubuntu:~$ sudo blkid
/dev/sda1: UUID="98b0cee6-3b81-4e39-bb43-4847e297b7ff" TYPE="ext4" 
/dev/sda3: UUID="807aba97-139f-4170-9bbf-5b58def95125" TYPE="swap" 
/dev/sda5: UUID="2644E68F76515A43" TYPE="ntfs"


free -l
         total       used       free     shared    buffers     cached
memory:    2063796    1238992     824804       8024      78256     535504
Low:        880428     576176     304252
High:      1183368     662816     520552
-/+ buffer/cache:     625232    1438564
Swap:            0          0          0
  • please edit the question with the output of sudo fdisk -l and sudo blkid
    – astrob0t
    Nov 13, 2014 at 14:07
  • I did the outputs. Nov 13, 2014 at 14:12
  • there's no 4GB partition visible in the outputs. what did you do to create the 4GB partition? please post the output of df -h
    – astrob0t
    Nov 13, 2014 at 14:25
  • I appologize please take a look at my re-edited post. How do I ensure if everything is ok? Nov 13, 2014 at 14:35
  • the free -l command gives the status of RAM . we don't want that. post the output of df -h which will give the filesystem disk space usage for all mounted partitions
    – astrob0t
    Nov 13, 2014 at 14:45

2 Answers 2


To begin, one last check to make sure you definitely don't have swap:

sudo swapon -s

This should list any available swap files. If nothing is listed then you will need to create one. The following command will create a 4gb swap, as an approximate rule the size of your swap should be the same size as the amount of RAM your machine has:

sudo fallocate -l 4G /swapfile

(obviously replace 4G with 8G if you have 8gb of RAM etc.!)

Verify that the swap size is correct with:

ls -lh /swapfile

Next set the permissions on the swap file so it's only accessible by root:

sudo chmod 600 /swapfile

Next set the swap file up using:

sudo mkswap /swapfile

Finally use the following command to enable the swap:

sudo swapon /swapfile

You can check that swap is now in use by typing:

sudo swapon -s

Congrats, you should now have swap. Next you might want to...

Make swap automatically load at startup:

sudo nano /etc/fstab

And then add the following line to the bottom of the file:

/swapfile   none    swap    sw    0   0

For more information, such as optimizing swap, this article has a great overview.

  • when I run sudo fallocate -l 4G /swapfile it says fallocate: /swapfile: fallocate failed: No space left on device Nov 13, 2014 at 14:16
  • you can try sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 instead of sudo fallocate -l 4G /swapfile.
    – astrob0t
    Nov 13, 2014 at 14:36
  • I re-edited my question if you can take a look now when I run sudo fallocate -l 4G /swapfile nothing appears Nov 13, 2014 at 14:38
  • thank you I figured it out with the help of your answer. It seems ok now. Nov 13, 2014 at 15:03
  • Swap files have the distinct disadvantage of being incompatible with suspension to disk. Nov 13, 2014 at 22:27

Many OS' allow the option for dynamic paging files, which grow and shrink depending on need. Most linuxes, including ubuntu, do not, I think, allow this option by default.

I use the fantastic program swapspace for managing dynamic paging files, available with more information from here: http://pqxx.org/development/swapspace/ I generally find this is the simplest way of managing swap on ubuntu.

You must log in to answer this question.

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