1

I created the SWAP partition in GParted after resizing my Ubuntu partition. All the operations went off smoothly. When I right-clicked the SWAP drive, it showed "SWAPON", so I clicked it & it activated the SWAP. Then I restarted the machine & it showed the SWAP as SWAPON again, so I hit it & it failed to activate it giving this error message:

Then I shut down the machine & restarted. The HDD looks like this now:

Then I tried to format sda15 to linux-swap & it could not do it giving the error message:

Just to give a bit of context, I asked a question before on how to repartition my Ubuntu hard disk: How can I see where Ubuntu has been installed on my HDD? I repartitioned (and actually reinstalled) Ubuntu, but now I want to create a SWAP partition.

2

Why not just create a swap file in unused space? Quick and easy:

For Adding a 512MiB swap

Creating a file for 512MiB  adjust size as desired to the size you want: 

We will create a /mnt/512MiB.swap swap file and set the permissions so that users cannot read it directly.

sudo fallocate -l 512m /mnt/512MiB.swap sudo chmod 600 /mnt/512MiB.swap

fallocate length suffixes are: k, m, g, t, p, e (See man fallocate).

By default your swap file may be created world readable. We set the 600 mode permissions in order to prevent users from being able to read potentially sensitive information from the swap file.

If fallocate fails with "fallocate failed: Operation not supported" as it currently does on my Maverick machine, you can do this the old way, again 512 mebibytes:

sudo dd if=/dev/zero of=/mnt/512MiB.swap bs=1024 count=524288 sudo chmod 600 /mnt/512MiB.swap

Formatting that file to create a swapping device: 

sudo mkswap /mnt/512MiB.swap

Adding the swap to the running system: 

sudo swapon /mnt/512MiB.swap

The additional swap is now available and can be seen by cat /proc/meminfo or free

Making the change permanent: 

Edit the /etc/fstab:

gksudo gedit /etc/fstab

Add this line at the end of the file:

/mnt/512MiB.swap none swap sw 0 0

Save. After the next reboot the swap will be used automatically.

Example of making a swap file

This is an example of making and using a swap file on a computer with no swap partition. Enter the command below and your password when prompted: sudo fallocate -l 512m /mnt/512MiB.swap

Then this command:

sudo mkswap /mnt/512MiB.swap

Output will be similar to the below.

Setting up swapspace version 1, size = 536866 kB

no label, UUID=dd6a01c8-93f0-41e0-9b7a-306956d8821b

Then issue the command:

sudo swapon /mnt/512MiB.swap

The following command shows you the results:

cat /proc/meminfo

MemTotal: 499496 kB

MemFree: 9156 kB

Buffers: 4748 kB

Cached: 233140 kB

SwapCached: 724 kB

Active: 254432 kB

Inactive: 157920 kB

HighTotal: 0 kB

HighFree: 0 kB

LowTotal: 499496 kB

LowFree: 9156 kB

SwapTotal: 524280 kB

SwapFree: 523556 kB

Dirty: 128 kB

Writeback: 0 kB

Mapped: 243420 kB

Slab: 20672 kB

CommitLimit: 774028 kB

Committed_AS: 648680 kB

PageTables: 2224 kB

VmallocTotal: 524280 kB

VmallocUsed: 5708 kB

VmallocChunk: 518176 kB

Make the change permanent by editing your fstab

gksudo gedit /etc/fstab

Add the line:

/mnt/512MiB.swap none swap sw 0 0

A simple command to see usage is:

free

              total       used       free     shared    buffers     cached
 Mem:        499496     479488      20008          0       8256     215892
 -/+ buffers/cache:     255340     244156
 Swap:       524280       3856     520424

Then, after running a few more programs...

free

              total       used       free     shared    buffers     cached
 Mem:        499496     492768       6728          0       1240     142336
 -/+ buffers/cache:     349192     150304
 Swap:       524280      53384     470896

Next, reboot to make sure it will work consistently.

free

              total       used       free     shared    buffers     cached
 Mem:        499496     493136       6360          0       7528     174700
 -/+ buffers/cache:     310908     188588
 Swap:       524280      17148     507132

Source: https://help.ubuntu.com/community/SwapFaq

2
  • Thanks Elder Geek, i reinstalled Ubuntu alongside Windows by keeping space UNALLOCATED and Ubuntu installed correctly also making a SWAP drive. – Rajeev Jul 18 '14 at 10:27
  • @Rajeev I'm glad you succeeded. Please upvote any answers that were useful to you. (upvoting/accepting answers is how we say thanks here). – Elder Geek Jul 18 '14 at 16:44
1

As your snapshots are showing you have so many partitions on your system. So first check if you're not exceedingly the limit of number of primary partitions which is 3 or 4 I don't remember exactly. If you're not exceeding that limit than try to make swap area first and than go for ext4 partition.

6
  • 1
    If he exceeded the limit, I'm sure he would have exceeded it a long time ago. The limit for primary partitions is 4. But as apparent from the screenshot, he only has two primary partitions: sda1 and the sda2 (the extended partition). Also, GParted spits out an error if he exceeds the limit by mentioning something like "Cannot create anymore partitions". – Alaa Ali Jul 22 '13 at 14:21
  • First of all, Alaa, thank you for formating my question. As Ashish says, i don't think we can create the SWAP partition first, as Ubuntu requires unallocated space to install the OS. And yesterday, i tried to format the SWAP partition to ext4, so that afterwards i can try to format it to LINUX-SWAP, but it did not succeed. – Rajeev Jul 23 '13 at 7:52
  • Maybe u need your hdd partitioned in the way u have done...but I think if you backup your data and make a clean Format of whole he'd and then make some partitions which are less in number I think it will workout – ashish Jul 23 '13 at 15:13
  • Sorry Ashish i can't do that. I need all the partitions. – Rajeev Jul 24 '13 at 6:57
  • I think the error is because you're trying to make Linux partition under the same extended part. I mean just make a new partition just exclusively for linux and then try to format it accordingly. – ashish Jul 25 '13 at 6:21

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.