1

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

or

sudo parted -l

or

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

and:

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"

and:

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 '14 at 14:07
  • I did the outputs. – Boris Sorokin Nov 13 '14 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 '14 at 14:25
  • I appologize please take a look at my re-edited post. How do I ensure if everything is ok? – Boris Sorokin Nov 13 '14 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 '14 at 14:45
  • thank you for the help but I figured it out already I edited fstab with an appropriate swap UUID and it seems ok now even in Gparted it says activated. – Boris Sorokin Nov 13 '14 at 15:01
  • I suspect you only freed up some space on you disk but didn't create a new partition with it. Unfortunately parted and fdisk don't display unallocated space very obviously. Can you make a screen shot with GParted? – David Foerster Nov 13 '14 at 22:32

2 Answers2

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.

0

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.

DMCoding
  • 121