Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What's wrong with this sequence of operation, running on a Debian Squeeze system with a Btrfs filesystem?

$ dd if=/dev/zero of=swapfile2 bs=1024 count=524288
$ sudo mkswap swapfile2
$ sudo chown root:root swapfile2
$ sudo chmod 0600 swapfile2  
$ sudo swapon -v -f swapfile2
swapon on swapfile2
swapon: /home/mathieu/swapfile2: found swap signature: version 1, page-size 4, same byte order
swapon: /home/mathieu/swapfile2: pagesize=4096, swapsize=536870912, devsize=536870912
swapon: swapfile2: swapon failed: Invalid argument

My file system is:

$ mount
/dev/mapper/voxbox-root on / type btrfs (rw)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/mapper/voxbox-boot on /boot type ext2 (rw)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
share|improve this question
    
malat, I've reopened your question & added your answer as below. Feel free to post your answer, I'll delete mine. –  Sathya Jan 22 '13 at 9:59
    
@Sathya thanks ! –  malat Jan 22 '13 at 12:18

3 Answers 3

up vote 4 down vote accepted

This bug report leads to this discussion

So "Invalid argument" should be read as "Your filesystem do not support swap file"

as posted by malat

share|improve this answer
    
Nice catch! The btrfs filesystem cannot support swap files because it moves file data around and the Linux swap code only takes the swap file's mapping once. Catastrophe would occur if this is allowed -- random file data that used blocks that the swap file once used would get corrupted. –  David Schwartz Jan 22 '13 at 9:52
1  
newer swapon man page document a new trick "One possible workaround is to map the file to a loopback device". I have not tried it yet. –  malat Jan 22 '13 at 12:20

If you want to swap on a file anyway, just use btrfs-swapon

share|improve this answer

Invalid argument says that something is wrong in arguments for swapon command.

First of all, read man swapon.

Try sudo swapon swapfile2. In my case it works.

share|improve this answer
    
Do you possibly think, I could find -v and -f flag without reading the man page ? –  malat Jan 21 '13 at 8:33

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.