old-www/HOWTO/Linux+FreeBSD-3.html

97 lines
4.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>The Linux+FreeBSD mini-HOWTO: Sharing swap space between Linux and FreeBSD</TITLE>
<LINK HREF="Linux+FreeBSD-4.html" REL=next>
<LINK HREF="Linux+FreeBSD-2.html" REL=previous>
<LINK HREF="Linux+FreeBSD.html#toc3" REL=contents>
</HEAD>
<BODY>
<A HREF="Linux+FreeBSD-4.html">Next</A>
<A HREF="Linux+FreeBSD-2.html">Previous</A>
<A HREF="Linux+FreeBSD.html#toc3">Contents</A>
<HR>
<H2><A NAME="s3">3. Sharing swap space between Linux and FreeBSD</A><!--FreeBSD dualboot!swap space, sharing--></H2>
<P>This section describes how I got Linux and FreeBSD to share a swap partition.
There may be other ways to get the same result. You can install FreeBSD before
Linux if you want to, just pay attention to the order of the partitions in the
FreeBSD slice.
<P>
<H2><A NAME="installlinux"></A> <A NAME="ss3.1">3.1 Installing and preparing Linux</A>
<!--FreeBSD dualboot!Linux, installing--></H2>
<P>The first step is to install Linux as normal. You have to leave space for the
FreeBSD slice at your hard drive. You don't have to make a Linux swap
partition, but if you want one, put it in the space you want to allocate for
FreeBSD. That way you can delete the Linux swap partition later and use the
space for FreeBSD.
<P>When you have installed Linux you have to build a new kernel. Read <B>The
Linux Kernel HOWTO</B> if this is new to you. You <EM>have</EM> to include both
<B>UFS filesystem support (read only)</B> and <B>BSD disklabel (FreeBSD
partition tables) support</B>:
<PRE>
UFS filesystem support (read only) (CONFIG_UFS_FS) [N/y/m/?] y
BSD disklabel (FreeBSD partition tables) support (CONFIG_BSD_DISKLABEL) [N/y/?]
(NEW) y
</PRE>
<P>Install the new kernel and reboot. Remove any line including the word <EM>swap</EM>
from your <CODE>/etc/fstab</CODE> file if you have made a Linux swap partition.
<EM>Make sure you have a working Linux boot floppy with the new kernel.</EM> Now
you are ready to install FreeBSD.
<P>
<H2><A NAME="ss3.2">3.2 Installing FreeBSD</A>
<!--FreeBSD dualboot!FreeBSD, installing--></H2>
<P>Install FreeBSD as described in the FreeBSD documentation. Remove the Linux
swap partition if you have made one (you can use the FreeBSD <CODE>fdisk</CODE>
program.) Pay attention to the order of the partitions in the FreeBSD
slice. If you use the default labelling the second partition will be the swap
partition. Complete the installation of FreeBSD and reboot into Linux
<EM>using the new Linux boot floppy</EM>.
<P>
<H2><A NAME="ss3.3">3.3 Setting up the FreeBSD swap partition in Linux</A>
<!--FreeBSD dualboot!FreeBSD swap partition configuration--></H2>
<P>Run <CODE>dmesg</CODE> when you have booted into Linux. In the output you should see
something like this:
<PRE>
Partition check:
hda: hda1 hda2 hda3 hda4 &lt; hda5 hda6 hda7 hda8 >
</PRE>
<P>This means that <CODE>/dev/hda4</CODE> is your FreeBSD slice, while
<CODE>/dev/hda5</CODE>, <CODE>/dev/hda6</CODE>, <CODE>/dev/hda7</CODE> and
<CODE>/dev/hda8</CODE> are the FreeBSD partitions. If your swap partition is
the second partition in the slice, it will be <CODE>/dev/hda6</CODE>.
<P>You have to put the following line into your Linux <CODE>/etc/fstab</CODE> file to
enable the swap partition:
<PRE>
/dev/hda6 none swap sw 0 0
</PRE>
<P>While FreeBSD can use any type of partition as swap space, Linux needs a
special signature in the swap partition. This signature is made by <CODE>mkswap</CODE>.
FreeBSD ruins this signature when it uses the shared swap partition, so you
will have to run <CODE>mkswap</CODE> each time you boot into Linux. To do this
automagically you have to find the script that runs <CODE>swapon</CODE> at boot time.
In Red Hat Linux it is <CODE>/etc/rc.d/rc.sysinit</CODE>. Put the following line
into that file just <EM>before</EM> <CODE>swapon -a</CODE>:
<PRE>
awk -- '/swap/ &amp;&amp; ($1 !~ /#/) { system("mkswap "$1"") }' /etc/fstab
</PRE>
<P>This will run <CODE>mkswap</CODE> on any swap partitions in <CODE>/etc/fstab</CODE> every
time you boot except if they are commented out (having ``#'' as the first
character in the line.)
<P>Run <CODE>free</CODE> to check out the size of the swap space when you have rebooted
into Linux. You should also reboot into FreeBSD to make sure everything works
as expected. If it does not, you have probably used the wrong partition
as swap partition. The only solution to that problem is to reinstall FreeBSD
and try again. Experience is a great teacher. :-)
<P>
<HR>
<A HREF="Linux+FreeBSD-4.html">Next</A>
<A HREF="Linux+FreeBSD-2.html">Previous</A>
<A HREF="Linux+FreeBSD.html#toc3">Contents</A>
</BODY>
</HTML>