You are not logged in.

#1 2009-10-23 00:03:23

duke11235
Member
Registered: 2009-10-09
Posts: 221

Swapfile

I have been unable to procure information on a swap file. I assume its stored on /root? Is there a way to encrypt the swap partition so I can have suspend and hibernate support? If not, can i resume from swapfile on encrypted partition? Help appreciated

Last edited by duke11235 (2009-10-23 00:04:02)

Offline

#2 2009-10-23 07:55:00

miau
Member
Registered: 2009-05-06
Posts: 202

Re: Swapfile

The swapfile is an extra partition. Take a look at your /etc/fstab.

Offline

#3 2009-10-23 08:07:05

grey
Member
From: Europe
Registered: 2007-08-23
Posts: 679

Re: Swapfile

I never heard of someone using a swap file on Linux. I don't think it's possible, and it certainly doesn't sound like a good idea. Do you mean swap partition by any chance?


Good ideas do not need lots of lies told about them in order to gain public acceptance.

Offline

#4 2009-10-23 08:08:58

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: Swapfile

You can dedicate a file for swap use. See man mkswap.
But you need to be very careful!


To know or not to know ...
... the questions remain forever.

Offline

#5 2009-10-23 08:58:32

byte
Member
From: Düsseldorf (DE)
Registered: 2006-05-01
Posts: 2,046

Re: Swapfile

I've been using swapfiles ever since using Linux, no problem at all.
For best performance you should create it right after creating the filesystem.
As long as the file doesn't get fragmented it shouldn't be different from using a swap partition.

Example:
dd if=/dev/zero of=/swapfile bs=1M count=512

fstab entry:
/swapfile  swap  swap  defaults  0  0

Last edited by byte (2009-10-23 09:00:40)


1000

Offline

#6 2009-10-23 09:24:24

grey
Member
From: Europe
Registered: 2007-08-23
Posts: 679

Re: Swapfile

Thanks for the info. I was under the impression that swap had to be on a primary partition. Not sure where that came from.


Good ideas do not need lots of lies told about them in order to gain public acceptance.

Offline

#7 2009-10-23 09:33:40

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: Swapfile

Swap files work just fine but I don't think they can be used for hibernation.


neutral

Offline

#8 2009-10-23 09:36:37

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Swapfile

Tuxonice and possibly uswsusp work with swap files, in-kernel hibernation doesn't.

Last edited by lucke (2009-10-23 09:37:15)

Offline

#9 2009-10-23 10:42:35

vacant
Member
From: downstairs
Registered: 2004-11-05
Posts: 816

Re: Swapfile

byte wrote:

As long as the file doesn't get fragmented it shouldn't be different from using a swap partition.

I had a swap partition when I first used linux. As I got more memory and realised it didn't get used I changed to a swap file for a bit, then didn't bother.

http://bbs.archlinux.org/viewtopic.php? … 54#p212254

Using a fragmented swapfile should be slower going in and out of hibernate. Is swap needed at all going in and out of suspend? While in use, I can't see how a fragmented swap file would be any slower than a swap partition as disk reads are being done all over the place. In fact if you have a separate swap partition but are accessing other partitions then a swap partition is forcing disk heads to move out of the /root partition (or other partitions you are using anyway) so a swap file will probably be faster.

Offline

#10 2009-10-23 11:06:23

miau
Member
Registered: 2009-05-06
Posts: 202

Re: Swapfile

lucke wrote:

Tuxonice and possibly uswsusp work with swap files, in-kernel hibernation doesn't.

Maybe with this tutorial it also works with kernel hibernation

http://ubuntuforums.org/showthread.php?t=1042946

Last edited by miau (2009-10-23 11:10:53)

Offline

#11 2009-10-23 13:37:06

duke11235
Member
Registered: 2009-10-09
Posts: 221

Re: Swapfile

This is nice but I m still wondering if encrypting a swap partition with a fixed key stored in /etc on an encrypted root partition will solve my problem just as well. Where would a swapfile be stored? On /root? The advantage for the swap file was having it inside a encrypted partition.

Offline

#12 2009-10-23 21:46:42

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: Swapfile

duke11235 wrote:

This is nice but I m still wondering if encrypting a swap partition with a fixed key stored in /etc on an encrypted root partition will solve my problem just as well. Where would a swapfile be stored? On /root? The advantage for the swap file was having it inside a encrypted partition.

You can put the swap file anywhere you like.


neutral

Offline

#13 2009-10-24 00:19:00

duke11235
Member
Registered: 2009-10-09
Posts: 221

Re: Swapfile

On the Arch wiki here
http://wiki.archlinux.org/index.php/Sys … r_dm-crypt
It says I can create a swap partition with a fixed key in /etc

dd if=/dev/urandom bs=1 count=512 of=/etc/keys/swap.key

But then it says it stored it in the unencrypted boot image.

Then create the hook setup in /lib/initcpio/install containing (THIS APPEARS TO BE DANGEROUS AND INSECURE SINCE IT INCLUDES THE KEY IN THE UNENCRYPTED BOOT IMAGE, DON'T DO IT, GET THE KEY FROM SOMEWHERE ELSE!):
# vim: set ft=sh:

install ()
{
    MODULES=""
    BINARIES=""
    add_file "/etc/keys/swap.key"
    FILES=""
    SCRIPT="openswap"
}

help ()
{
cat<<HELPEOF
  This opens the swap encrypted partition /dev/<device> in /dev/mapper/swapDevice
HELPEOF
}

Is this true, or is it only secured it /etc?

Last edited by duke11235 (2009-10-24 01:50:48)

Offline

#14 2009-10-24 11:09:44

Pank
Member
From: IT
Registered: 2009-06-13
Posts: 371

Re: Swapfile

Hello,
I am trying to make hybernate work with a swap-file as in the Ubuntu-guide.
However, I need the first sector. It appears that filefrag does not output this anymore?!
Here is a sample output:

╰─[13:05:47]> sudo filefrag -v /swap 
Password: 
Filesystem type is: 3153464a
File size of /swap is 541065216 (132096 blocks, blocksize 4096)
Discontinuity: Block 25 is at 8231 (was 8230)
...
/swap: 241 extents found

Also, can I somehow make a continuous swap-file, i.e. a non-fragged swap file?

Thanks,
Rasmus


Arch x64 on Thinkpad X200s/W530

Offline

#15 2009-10-24 14:10:25

duke11235
Member
Registered: 2009-10-09
Posts: 221

Re: Swapfile

I know how to create a contiguos logical volume in a lvm group......
lvcreate -C y -L 4G archvol -n lvolswap

Offline

#16 2009-10-24 16:13:49

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Swapfile

I know this is redundant, but still. The sheer confidence in some of those replies is flabbergasting - all the more because they're either blatantly wrong or testimony of horrible desinformation.

miau wrote:

The swapfile is an extra partition. Take a look at your /etc/fstab.

No, you see - a swap partition is a partition. A swap file is, well, a file!

Isn't Linux full of surprises?

grey wrote:

I never heard of someone using a swap file on Linux. I don't think it's possible, and it certainly doesn't sound like a good idea. Do you mean swap partition by any chance?

Do you know how long the belief that earth was flat held firm? Check the mkswap manual, and turn yourself into a believer wink.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#17 2009-10-24 18:14:05

duke11235
Member
Registered: 2009-10-09
Posts: 221

Re: Swapfile

Can someone tell me if this stores it in the unencrypted boot image, i thought it was in /etc. It's the last barrier to continuing arch install

hen create the hook setup in /lib/initcpio/install containing (THIS APPEARS TO BE DANGEROUS AND INSECURE SINCE IT INCLUDES THE KEY IN THE UNENCRYPTED BOOT IMAGE, DON'T DO IT, GET THE KEY FROM SOMEWHERE ELSE!):
# vim: set ft=sh:

install ()
{
    MODULES=""
    BINARIES=""
    add_file "/etc/keys/swap.key"
    FILES=""
    SCRIPT="openswap"
}

help ()
{
cat<<HELPEOF
  This opens the swap encrypted partition /dev/<device> in /dev/mapper/swapDevice
HELPEOF
}

Offline

#18 2009-10-24 18:59:59

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,549

Re: Swapfile

The benefit of a swap file is more dynamic resizing...  the benefit of a swap partition is less fragmentation, which is important when talking about swap.  Both less fragmentation for your swap and for the partition your swapfile would be stored on.

Offline

Board footer

Powered by FluxBB