Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I just installed Linux for the first time (after 5 tries). I was trying to follow directions on creating a swap file from this website:

http://www.linux.com/news/software/applications/8208-all-about-linux-swap-space

It was my first time using the console, and I don't know if I succeeded or not. Is there some way to tell if it worked? Here is what I typed:

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

paul@knight:~/Desktop$ dd if=/dev/zero of =/swapfile bs=1024 count=1048576
dd: unrecognized operand `of'
Try `dd --help' for more information.
paul@knight:~/Desktop$ dd if=/dev/zero of=/swapfile bs=1024 count=1048576
dd: opening `/swapfile': Permission denied
paul@knight:~/Desktop$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
[sudo] password for paul: 
1048576+0 records in
1048576+0 records out
1073741824 bytes (1.1 GB) copied, 49.6973 s, 21.6 MB/s
paul@knight:~/Desktop$ sudo mkswap /swapfile
mkswap: /swapfile: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=5e900a84-03ca-4a00-ad60-df4784abc7ef
paul@knight:~/Desktop$ sudo swapon /swapfile
paul@knight:~/Desktop$ etc/fstab
bash: etc/fstab: No such file or directory
paul@knight:~/Desktop$ /etc/fstab/swapfile
bash: /etc/fstab/swapfile: Not a directory
paul@knight:~/Desktop$ /etc/fstab swapfile
bash: /etc/fstab: Permission denied
paul@knight:~/Desktop$ sudo /etc/fstab swapfile
sudo: /etc/fstab: command not found
paul@knight:~/Desktop$ /swapfile
bash: /swapfile: Permission denied
paul@knight:~/Desktop$ sudo /swapfile
sudo: /swapfile: command not found
paul@knight:~/Desktop$ 

I'm totally new at this. Also, my physical memory is 256 Mb and my swap space is about twice that (I think). My partition for Linux (Xubuntu 11.04) is 50 Gb.

Do I have a 1 Gb swap file now? Or just a hole in my hard drive?

Is a swap file as good as the swap space?

Thank you in advance!

share|improve this question
    
For the posterity: you can do it with fallocate -l 1G /swapfile && mkswap /swapfile && swapon /swapfile (which avoids dd and thus is faster) –  ignis Jun 21 '13 at 14:15
add comment

1 Answer

up vote 2 down vote accepted

Is swapfile has nearly the same performance as a swap-partition. You can check it by simply issuing

free -m

it should look something like this:

             total       used       free     shared    buffers     cached
Mem:          1754       1645        109          0         42        227
-/+ buffers/cache:       1375        379
Swap:         1023        245        778

since sudo swapon didn't throw an error it should have been successful. Now you can make this permanent by editing fstab: sudo nano /etc/fstab. On the last line add: /swapfile swap swap defaults 0 0 with /swapfile [TAB]swap[TAB] etc... (so no spaces).

You can read more at the Ubuntu Wiki swap FAQ

share|improve this answer
    
Hey, wow! That made sense! I've got the swap file working. Thank you so much for your help! I'm having trouble making it permanent, though. After entering sudo leafpad /etc/fstab , it tells me sudo: leafpad: command not found . Also, when I tried to enter the command after that, my tab key wasn't tabbing. I can use tab in other applications, though. –  paul4209 Jun 14 '11 at 17:26
    
oh sorry, I tought leafpad was the default editor in Xubuntu. Try sudo gedit /etc/fstab and if that doesn't work either use sudo nano /etc/fstab I'll edit the post accordingly. –  turbo Jun 14 '11 at 17:41
    
It looks like nano did the trick. Do I only need one [TAB] between each entry, regardless of how it lines up with the info above the line I'm adding? Also, what do I do when I'm done? I pressed ctrl-X to exit, and it asked if I wanted to save in Mac or Dos format. I chose to cancel for now. –  paul4209 Jun 14 '11 at 21:38
    
I'm about 99% sure it doesn't have to be aligned, but you could as well just align everything for a more beautiful /etc/fstab... Don't forget to mark the answer solved (if it is). –  turbo Jun 14 '11 at 21:59
    
How do I save the /etc/fstab when I'm done? –  paul4209 Jun 14 '11 at 22:20
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.