Viimased kanded

Share swap space between Linux (Ubuntu) and Windows (XP)

I have a laptop, which has dualboot, ubuntu 9.04 and windows xp. Xp is only for Adobe lightroom. Laptop has 1,2Gb of memory and 80 Gb HDD. I had it set up so, that linux had it's swap partition (~750Mb) and windows used a swap file in C:

Recently I ran into problems with space on C: drive (Lightroom keeps it's cache of pictures there) and began to look for a solution. After some bigger ideas (repartition, reinstall) and smaller (reconfigure lightroom) i noticed, that I have 2 places that different OSs use for swapping - but they never do it at the same time. So one of the places is always unused - leaving around 750 Mb of space just wasted.

When looking for a solution, I couldn't find a howto, how to make win/linux share the same swapspace, so I had to dig a little and come out with my own solution (which works more or less ok now - some issues with current kernel so i have to use previous one).

Here's my solution (I'm writing this in linux, so windows click-paths may be a little off).

Usual disclaimer applies, I'm not responsible, if you f*** something up, delete your whole porn collection or if your kid learns to swear while you are implementing this etc...

In windows, my computer > right click > Manage, find Storage, delete your linux swap partition and create/format new FAT32 partition there (anyone - what is the best cluster size for FAT32 swapspace?) and assign a drive letter for it.

now go to my computer > right click > properties > advanced and find Virtual memory. Put your virtual memory file onto newly created partition (windows requires for you to leave 5+ Mb free on the partition ie. on a 750Mb partition 745Mb is max swapfile size), and remove it from the previous location.

Boot to linux

If You have plenty of RAM, your system will boot up normally to your desktop environment. Open a terminal and become root. As I'm writing this with ubuntu in mind, it is:

> sudo bash

check your kernel version:

> uname -a

if it's 2.6.28-XXX, check the note at the end of this post, otherwise continue.

check the partition name for your new fat32 partition with:

> fdisk -l

which for me gives:


Disk /dev/sda: 80.0 GB, 80026361856 bytes
240 heads, 63 sectors/track, 10337 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Disk identifier: 0xfddefdde

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1355 10243768+ 7 HPFS/NTFS
/dev/sda2 1356 2647 9759487+ 83 Linux
/dev/sda3 2647 2750 779152+ 5 Extended
/dev/sda4 2750 10338 57360082+ b W95 FAT32
/dev/sda5 2647 2750 779121 b W95 FAT32


/dev/sda5 being my shared swap partition.

make a mountpoint for the partition

>mkdir /mnt/swap

edit /etc/fstab with your favourite text editor

> vi /etc/fstab

comment out (add # in the beginning of line) to your current (not working) swap line and add a line for mounting new swap, like follows:

/dev/sda5 /mnt/swap vfat utf8 0 0

Of course, change partition name (and mount point) if neccesary.

edit /etc/rc.local

>vi /etc/rc.local

and add following line (editing where neccesary) before the "exit 0" line

mkswap /mnt/swap/pagefile.sys && swapon /mnt/swap/pagefile.sys


Reboot your machine back to Linux and check with

> free

if your swap is activated - it should show you something like this:

total used free shared buffers cached
Mem: 1293272 1263016 30256 0 141640 761424
-/+ buffers/cache: 359952 933320
Swap: 762872 0 762872


If Swap line contains zeros, something is missing somewhere and you should dig around.

NOTE for 2.6.28 kernels: .28 kernel contains some known bug, which prevents swapon command from working, it just hangs. Solution: use previous kernel until the bug gets fixed (edit /boot/grub/menu.lst and change default to 2 - to boot third choice).

Let me know, if/how this works out for you.

2009-07-30 00:50:43 - loetud 3114 korda


Micha kirjutab:

Hi,
This is a great little HOWTO, and perfect for dual-booting laptops.
Thanks!
- Micha.

Lisatud: 2010-02-10 12:29:02


Erik kirjutab:

Micha, I'm glad it worked out for You. Let me know if it works with newer kernels - I haven't had time to test it myself lately.

Lisatud: 2010-02-17 09:35:10


Palun kommentaarid eesti keeles / Please comment in english
Kõik väljad kohustuslikud, html on keelatud





validation picture
Sisesta kood pildilt / Enter the code from the picture

site

last 20 comments

rss 2.0