Fedora Linux Support Community & Resources Center
Old 14th November 2008, 07:38 PM
RVF16 Offline
Registered User
Join Date: Mar 2007
Posts: 149
Swap file and complete removal of swap partition


I know similar subjects have appeared several times but i need to know how i can completely remove the swap partition, not just extend my swap memory (swap partition) by adding space via swap files.

After searching here and there i found the following method that adds a swap file :

How to add more Linux Swap with Swap File

Assuming you want to put it in "/", Create an empty 500MB file
$ sudo dd if=/dev/zero of=/swap.img bs=1024k count=512

Format it as a swap file
$ sudo mkswap /swap.img

Add it to your running Linux system
$ sudo swapon /swap.img

Optionally you can add /swap.img to fstab for automatic swap activation.

$ sudo gedit /etc/fstab

Add this line at the end of the file
/swap.img none swap sw 0 0

Run "free -m" command to verify that you've added the newly created swap to your Linux based operating system.

I have a Dell Inspiron E1505 with a sata I 320Gb hdd.

Now since there is a limit of partitions that can be created under linux (i think 15 including extended and all inside it) and for some reason i need the most out of it, could you please tell me how i can completely remove the swap partition and use a swap file so that each linux rests in only one partition?

My layout looked like this :
sda4 extended
sda5 boot
sda6 root
sda7 swap

I then moved the boot partitions in the root partitions so swaps are the last ones.

so now my layout is :
sda4 extended
sda5 root
sda6 swap

I know i have to fix entries in /boot/grub/grub.conf and /etc/fstab and unzip, edit and rezip the kernel init files in /boot directory.
The problem is how to declare the swap files, what string to use.

If for example i create the swap file described in the procedure above would it work if i edited the kernel root line in grub.conf and added the string :

Would i have to do the same for the kernel init file as there is a line there :
resume /dev/sda6
and change it to :
resume /dev/sda5/swap.img
or could i just delete that line and use only the above kernel parameter in grub.conf?

Thank you in advance.
Reply With Quote
Old 14th November 2008, 10:47 PM
stoat Offline
Registered User
Join Date: Jun 2006
Posts: 7,548
Hello RVF16,

I believe everything you have said is correct and should work. And if you edit the initial ramdisk(s) or create a new one(s) with mkinitrd after adding the swap file(s) to the fstab file(s), I don't think you will need to use the kernel resume parameter. That is all I ever had to do anyway.

But your wording makes it sound like you have or intend to have multiple distros and have or had (or think you should have) a separate swap partition for each one. Did you know that one swap partition can be shared by all of the distros that you have or intend to have? You could then have, I guess, thirteen distros on single root partitions with one swap shared by all of them. Would that help you any?

Last edited by stoat; 14th November 2008 at 11:00 PM.
Reply With Quote
Old 14th November 2008, 11:29 PM
RVF16 Offline
Registered User
Join Date: Mar 2007
Posts: 149
Thanks stoat for the confirmation.
I'll give it a try and see.

Yes i know that multiple distros can utilize one common swap partition but there is that rather unprobable condition when, while you are in a distro, you hibernate then boot into another distro, hibernate again and finally boot the first distro. Its swap has been overwritten by the one of the second distro.

Not much of a problem but ...

Reply With Quote
Old 15th November 2008, 01:35 AM
Posts: n/a
Stoat - the initrd doesn't set up swap. That happens in /etc/rc.d/rc.sysinit
Reply With Quote
Old 15th November 2008, 11:25 AM
RVF16 Offline
Registered User
Join Date: Mar 2007
Posts: 149
Hello again.

Even though i have managed to load the system with the swap file as the only swap memory ("free -m" command shows the swap size) it still doesn't work.
It seems that the system cannot locate the swap file header so it returns back to the graphical environment without completing the hibernation procedure.
Here is the output of "/var/log/messages" :

PM: Wrote 501660 kbytes in 26.70 seconds (18.78 MB/s)
PM: S<3>PM: Swap header not found!
Restarting tasks ... done.
After googling around i found in several threads regarding software suspend that when using a swap file instead of a swap partition the offset of this file is needed :

The "resume offset" parameter is necessary if a swap file is used for
suspending. In such a case the device identified by the "resume device"
parameter is regarded as the partition that contains the swap file, and
"resume offset" must be equal to the offset from the beginning of this
partition at which the swap file's header is located, in <PAGE_SIZE> units.
The value of this parameter for given swap file can be determined by the
swap-offset program (has to be run as root) included in this package. [For
this feature to work, you will need an -mm kernel, 2.6.18-mm3 or newer.]
I am not using software suspend, i am using the pm-hibernate command but i guess it's the same problem.

In another thread :

24 1) Create the swap file and make it active, eg.
26 # dd if=/dev/zero of=<swap_file_path> bs=1024 count=<swap_file_size_in_k>
27 # mkswap <swap_file_path>
28 # swapon <swap_file_path>
30 2) Use an application that will bmap the swap file with the help of the
31 FIBMAP ioctl and determine the location of the file's swap header, as the
32 offset, in <PAGE_SIZE> units, from the beginning of the partition which
33 holds the swap file.
35 3) Add the following parameters to the kernel command line:
37 resume=<swap_file_partition> resume_offset=<swap_file_offset>
Has anybody resolved this?


Last edited by RVF16; 15th November 2008 at 02:56 PM.
Reply With Quote
Old 15th November 2008, 03:38 PM
RVF16 Offline
Registered User
Join Date: Mar 2007
Posts: 149
Well the suspend-0.8 source tarball that can be download from here :
which has a dependency called libx86 and can be downloaded from here :

contains a tool called "swap-offset" so i downloaded it and compiled it but didn't install it.
I just retrieved from the main source directory the swap-offset executable and used it :

swap-offset /swap.img

I then used the output number in /boot/grub/grub.conf as a kernel parameter like this :

kernel /boot/vmlinuz- ro root=/dev/sda5 acpi_sleep=s3_bios resume=/dev/sda5 resume_offset=114688 dazuko=1 selinux=0 vga=0x345

I don't know where else this offset is needed.
This time the system powered down after pressing the hibernation button.
Still it didn't resume after reboot, it more or less booted as if there was no hibernation signature.
Also during etc/fstab swap mounting of /swap.img an error was output :
invalid parameter
after boot i had to run mkswap /swap.img again for some reason otherwise "swapon -a" wouldn't mount the swap file.

dmesg output the following relevant line :
Unable to find swap-space signature
Anyone any ideas?

Last edited by RVF16; 15th November 2008 at 03:40 PM.
Reply With Quote
Old 15th November 2008, 05:53 PM
Posts: n/a
Originally Posted by stoat View Post
Hello again stevea,

Thanks. Whenever I have "tinkered" with a swap partition such as creating a new one or changing its label, it's always knocked the slats out of booting and stopped it dead in its tracks when the old resume device couldn't be found. That's the only thing I was thinking about regarding the initial ramdisk and either editing it or creating a new one with mkinitrd.
Interesting - and I'm not saying you're experience is wrong, but I don't see how.

How abt this ... the root fs has a few hidden files /.autofsck, /.automount etc.
Perhaps one of these indicates the hibernate to swap condition at boot and tries to reference non-extant swap.

Anyway no - the initrd doesn't touch the swap - I just verified this.
Reply With Quote
Old 16th November 2008, 09:43 PM
RVF16 Offline
Registered User
Join Date: Mar 2007
Posts: 149
People, i hate to break this but this thread is for swap files and you are talking about swap partitions.
Please stick to the subject.

The questions are :
How and where do we declare the swap file?
Are fstab, grub and kernel initrd files enough?
How do we describe the swap file?
As /swap.img?
As /dev/sda5/swap.img?
Why doesn't the system read the swap file during boot after hibernation.

Cannot believe no one has ever done this?

Thank you.
Reply With Quote
Old 19th November 2008, 04:00 PM
Posts: n/a
Just make the swap file as indicated (dd, mkswap) and add it to /etc/fstab, commenting out the partition version if present (well you can have more than one swap fwiw, priorities too).

I hate to break it to you - but the subtopic was - "does initrd need to know about swap".
I was wrong (mark the date) intird does know about swap (apos to stoat) !!

The initrd start script "a nash script, init) includes a line like
resume /dev/sda2
where /dev/sda2 is my swap partition.

The mkinitrd script looks for swsuspdev with:
swsuspdev=$(awk '/^[ \t]*[^#]/ { if ($3 == "swap") { print $1; exit }}' $fstab)
So mkinitrd is necessary. The script will include a line like
resume /swap/swap.img
if you use a swap file. Whether the resume works in a different matter. I suspect that you cannot resume from a swap file without redesigning mkinitrd script. It currently resumes the swap (device or file) BEFORE it mounts the root file system, so I think the resume/unhibernate is destined to fail from a swap file. If you did mount the root first then you'd likely have a problem (fsck - unclean unmount) w/ the remounting that fs later (maybe not - it's read access only). Maybe the resume could work from a file, but that's unclear.

Describe it any way you like - that's a style question.
a. /swap.img is fine.
b. I'd probably opt for /swap/swap.img or similar.
c. /dev/sda5/swap.img is bad karma - 1/ it looks like a special device (misleading).
2/ /dev is not a real file system on all flavors of the kernel.

Last edited by stevea; 19th November 2008 at 04:32 PM.
Reply With Quote
Old 20th November 2008, 11:32 PM
RVF16 Offline
Registered User
Join Date: Mar 2007
Posts: 149
Hello stevea.
Thanks for the info.

It currently resumes the swap (device or file) BEFORE it mounts the root file system, so I think the resume/unhibernate is destined to fail from a swap file
Didn't know that. I'll try to find a workaround if possible.

Reply With Quote

complete, file, partition, removal, swap

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SWAP partition and File System? superartur0 Installation, Upgrades and Live Media 4 27th October 2006 06:52 PM
Swap partition massimomm Using Fedora 3 10th March 2006 05:06 PM
crashing swap space or swap command ? mnisay Servers & Networking 2 18th January 2006 05:01 PM
Is my swap partition being used? zabolots Installation, Upgrades and Live Media 3 7th December 2005 03:55 AM

Current GMT-time: 14:52 (Saturday, 19-08-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat