automatically use swap-file on start-up

Asked by Francesco M

Following http://lifehacker.com/5403100/dual+boot-windows-7-and-ubuntu-in-perfect-harmony
and https://help.ubuntu.com/community/SwapFaq#How%20do%20I%20add%20more%20swap?

I created a swap file and put it on my ntfs partition where I keep all the data shared with Windows7. Ok I know that probably is not the best solution, but since windows 7 creates automatically 2 primary partitions (one for the loader and one for the system), another primary partition is needed to install Ubuntu10.04 (with ext4) and i want to have this shared partition where i keep the files shared both with Linux and Windows (such as documents, music and so on) I couldn't create a swap partition (maximum 4 primary partitions are allowed on a disk).

The question is: how can I modify fstab so that the swap file is used automatically without me to use every time the swapon command?

I added: /media/Storage/2560MB.swap none swap sw 0 0 in fstab but id doesn't work because the partition is not mounted automatically in /media/Storage, so the file cannot be retrieved.
At this point I added (before that line): /media/Storage/2560MB.swap none swap sw 0 0

but still it doesn't work. why? Any Ideas?

Config: Dual boot with Windows7 32-bit(one partition) Ubuntu 10.04 64bit(another partition) + Storage partition

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu util-linux Edit question
Assignee:
No assignee Edit question
Solved by:
Francesco M
Solved:
Last query:
Last reply:
Revision history for this message
bcbc (bcbc) said :
#1

You need to mount your windows partition first.. the order in fstab is important.

e.g.
/dev/sda2 /media/Storage ntfs defaults 0 0 (just an example)
then afterwards add
/media/Storage/2560MB.swap none swap sw 0 0

A better solution, would be to remove one of your primary partitions and create an extended partition. Yes you have to backup the data on the primary first, but afterwards you're free to create up to 128 logical partitions in that extended, and yes ubuntu can run just fine off a logical partition.

Revision history for this message
Francesco M (francesco-hotmail) said :
#2

Yep, I did that, I tried to mount the NTFS partition first, but still it doesn't work. Btw if i use the command sudo mount -a I should see if the fstab configuration works without actual rebooting, isnt'it?

Oh... so I don't need to create a primary partition for Ubuntu?!? I could, for instance, eliminate the primary partition containing ubuntu, create an extended one and then create, inside that, a logical partition for Ubuntu and another one as swap... hum didn't know that. I could try that if I don't manage to solve with the swap file.

Revision history for this message
bcbc (bcbc) said :
#3

what doesn't work when you run "sudo mount -a"? Any errors you are getting, please pass along.
did you try "sudo swapon -a"?
and "free"

Revision history for this message
Francesco M (francesco-hotmail) said :
#4

Nope, no errors; but when I look at the meminfo file "cat /proc/meminfo" I see that for swap no memory is allocated, while if i use the "sudo swapon /media/Storage/2560MB.swap" and then i look at the meminfo file I can see memory (2.5 GB) allocated to swap.

Revision history for this message
bcbc (bcbc) said :
#5

OK try changing the line in /etc/fstab to this.
/media/Storage/2560MB.swap none swap loop,sw 0 0

Revision history for this message
Francesco M (francesco-hotmail) said :
#6

Nope.. still not working. I always have to use "swapon" to actually activate it.

Revision history for this message
Francesco M (francesco-hotmail) said :
#7

Ok... no problem. I re-installed everything doing two logical partitions: one for ubuntu and one for swap as you suggested in the first message.

Thank you very much anyway.