home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / doc / HOWTO / mini / Linux+FreeBSD-mini-HOWTO < prev    next >
Text File  |  1998-10-14  |  19KB  |  595 lines

  1.   The Linux+FreeBSD mini-HOWTO
  2.   Niels Kristian Bech Jensen, nkbj@image.dk
  3.   v1.6.1, 18 April 1998
  4.  
  5.   This document describes how to use Linux and FreeBSD on the same sys¡
  6.   tem. It introduces FreeBSD and discusses how the two operating systems
  7.   can cooperate, e.g. by sharing swap space. You should probably have
  8.   some experience with Linux or FreeBSD and hard drive partitioning
  9.   (fdisk) before you read this document. The tips herein are tested
  10.   using FreeBSD 2.2.2, but they should be valid for newer versions as
  11.   well. Do not hesitate to mail me if you have comments, questions or
  12.   suggestions about this document. I would also like to hear from people
  13.   who have experience using Linux together with NetBSD or OpenBSD.
  14.   ______________________________________________________________________
  15.  
  16.   Table of Contents
  17.  
  18.  
  19.   1. What is FreeBSD?
  20.  
  21.   2. The FreeBSD way of labelling hard drives
  22.  
  23.      2.1 FreeBSD ``slices'' and ``partitions''
  24.      2.2 Drive and partition labelling in Linux and FreeBSD
  25.  
  26.   3. Sharing swap space between Linux and FreeBSD
  27.  
  28.      3.1 Installing and preparing Linux
  29.      3.2 Installing FreeBSD
  30.      3.3 Setting up the FreeBSD swap partition in Linux
  31.  
  32.   4. Booting FreeBSD using LILO
  33.  
  34.   5. Mounting file systems
  35.  
  36.      5.1 Mounting UFS file systems under Linux
  37.      5.2 Mounting ext2fs file systems under FreeBSD
  38.  
  39.   6. Running foreign binaries
  40.  
  41.      6.1 Running FreeBSD binaries under Linux
  42.      6.2 Running Linux binaries under FreeBSD
  43.  
  44.   7. References and other documents of interest
  45.  
  46.   8. Acknowledgments and Copyright
  47.  
  48.      8.1 Disclaimer
  49.      8.2 Copyright
  50.  
  51.  
  52.   ______________________________________________________________________
  53.  
  54.   1.  What is FreeBSD?
  55.  
  56.   FreeBSD is a free Unix-like operating system much like Linux. The main
  57.   difference is that, while the Linux kernel has been written from
  58.   scratch, FreeBSD is based on the freely redistributable parts of
  59.   4.4BSD (Berkeley Software Distribution) known as 4.4BSD-lite. This
  60.   fact might lead some people to suggest that FreeBSD is closer to being
  61.   ``real'' UNIX(TM) than Linux. FreeBSD runs only on the Intel PC
  62.   platform (i386 and higher); ports to the DEC Alpha and Sun Sparc
  63.   platforms are being worked on at the moment.  Hardware requirements
  64.   for FreeBSD are much like those for Linux.
  65.  
  66.  
  67.   The development of FreeBSD is managed in a different way than the
  68.   Linux development. A core team of developers serve as arbitrators and
  69.   provide leadership for the project. Big changes are discussed in
  70.   advance on the mailing lists. The FreeBSD project has two development
  71.   trees (just like Linux): ``-CURRENT'' and ``-STABLE''. The
  72.   ``-CURRENT'' development tree is where the development of new features
  73.   happens. Development to the ``-STABLE'' tree are restricted to bug
  74.   fixes and some thoroughly tested new features.
  75.  
  76.   FreeBSD can be used and (re-)distributed freely just as Linux. Most
  77.   parts of the system are released under the BSD copyright; the rest is
  78.   under the GNU GPL or the GNU LGPL.
  79.  
  80.   You can find more information about FreeBSD (and download the whole
  81.   system) at The FreeBSD Project Homepage <http://www.freebsd.org/>. The
  82.   newest ``-STABLE'' releases and snapshots of the ``-CURRENT''
  83.   development code are sold on CDROMs by Walnut Creek CDROM
  84.   <http://www.cdrom.com/> (their web- and ftp-servers are running
  85.   FreeBSD.)
  86.  
  87.  
  88.   2.  The FreeBSD way of labelling hard drives
  89.  
  90.   Linux and FreeBSD label hard drives and partitions after two
  91.   differents schemes. This section explains the main differences between
  92.   the two schemes.  In fact the FreeBSD labelling scheme is an adaption
  93.   of the traditional BSD labelling style ported to live within the PC's
  94.   fdisk partitions. Thus it is very similar to other BSD-based Unix
  95.   systems such as NetBSD, OpenBSD, Ultrix, Digital Unix, SunOS, and
  96.   Solaris.
  97.  
  98.  
  99.  
  100.   2.1.  FreeBSD ``slices'' and ``partitions''
  101.  
  102.   FreeBSD needs only one of the four entries in the partition table on
  103.   your PC's hard drive. This primary partition is called a ``slice'' in
  104.   FreeBSD terminology. It then uses the disklabel program to make up to
  105.   eight partitions in this primary partition. These logical partitions
  106.   are called ``partitions'' in FreeBSD terminology. This concept is
  107.   similar to the way Linux (and DOS) handles logical partitions in an
  108.   extended partition. Note that the Linux fdisk program doesn't display
  109.   the BSD partitions in a FreeBSD slice from the main menu, but it can
  110.   display BSD disklabel information if you give the command `b'. The
  111.   output is something like this (/dev/hda4 is the FreeBSD slice):
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.   bash# fdisk /dev/hda
  134.  
  135.   Command (m for help): p
  136.  
  137.   Disk /dev/hda: 64 heads, 63 sectors, 621 cylinders
  138.   Units = cylinders of 4032 * 512 bytes
  139.  
  140.      Device Boot   Begin    Start      End   Blocks   Id  System
  141.   /dev/hda1   *        1        1       27    54400+  83  Linux native
  142.   /dev/hda2           28       28       55    56448   83  Linux native
  143.   /dev/hda3           56       56      403   701568   83  Linux native
  144.   /dev/hda4          404      404      621   439488   a5  BSD/386
  145.  
  146.   Command (m for help): b
  147.   Reading disklabel of /dev/hda4 at sector 1624897.
  148.  
  149.   BSD disklabel command (m for help): p
  150.  
  151.   8 partitions:
  152.   #        size   offset    fstype   [fsize bsize   cpg]
  153.     a:    64512  1624896    4.2BSD        0     0     0   # (Cyl.  404 - 419)
  154.     b:   104832  1689408      swap                        # (Cyl.  420 - 445)
  155.     c:   878976  1624896    unused        0     0         # (Cyl.  404 - 621)
  156.     e:    64512  1794240    4.2BSD        0     0     0   # (Cyl.  446 - 461)
  157.     f:   645120  1858752    4.2BSD        0     0     0   # (Cyl.  462 - 621)
  158.  
  159.   BSD disklabel command (m for help): q
  160.   bash#
  161.  
  162.  
  163.  
  164.   The letters `a'...`f' in the first column are the same labels as shown
  165.   below in the example for a FreeBSD slice. There are three special
  166.   partitions in BSD parlace. The letter `a' designates the root
  167.   partition, `b' designates the swap partition, while `c' designates the
  168.   whole slice. See the FreeBSD documentation for more information on the
  169.   ``standard'' way of assigning these letters to different partition
  170.   types.
  171.  
  172.  
  173.   2.2.  Drive and partition labelling in Linux and FreeBSD
  174.  
  175.   The hard drives are labelled in the following way in Linux and
  176.   FreeBSD:
  177.  
  178.                           Linux           FreeBSD
  179.   First IDE drive         /dev/hda        /dev/wd0
  180.   Second IDE drive        /dev/hdb        /dev/wd1
  181.   First SCSI drive        /dev/sda        /dev/sd0
  182.   Second SCSI drive       /dev/sdb        /dev/sd1
  183.  
  184.  
  185.  
  186.   The partitions (FreeBSD slices) on an IDE drive are labelled in the
  187.   following way (/dev/hda is used as an example):
  188.  
  189.                                   Linux           FreeBSD
  190.   First primary partition         /dev/hda1       /dev/wd0s1
  191.   Second primary partition        /dev/hda2       /dev/wd0s2
  192.   Third primary partition         /dev/hda3       /dev/wd0s3
  193.   Fourth primary partition        /dev/hda4       /dev/wd0s4
  194.  
  195.  
  196.  
  197.   The partitions in my FreeBSD slice is labelled in the following way.
  198.   It is the labelling you get by default. It is possible to change the
  199.   labelling if you do a custom installation of FreeBSD (/dev/hda4 is the
  200.   FreeBSD slice in the example):
  201.  
  202.   Linux label     FreeBSD label   FreeBSD mount point
  203.   /dev/hda5       /dev/wd0s4a     /
  204.   /dev/hda6       /dev/wd0s4b     swap
  205.   /dev/hda7       /dev/wd0s4e     /var
  206.   /dev/hda8       /dev/wd0s4f     /usr
  207.  
  208.  
  209.  
  210.   If you run dmesg in Linux you will see this as (The linux kernel must
  211.   be build with UFS filesystem support for this to work. See section
  212.   ``Installing and preparing Linux''):
  213.  
  214.   Partition check:
  215.    hda: hda1 hda2 hda3 hda4 < hda5 hda6 hda7 hda8 >
  216.  
  217.  
  218.  
  219.   If you have installed FreeBSD in the /dev/sd1s3 slice (/dev/sdb3 in
  220.   Linux parlace), and /dev/sdb2 is a Linux extended partition containing
  221.   two logical partitions (/dev/sdb5 and /dev/sdb6), the previous example
  222.   would look like this:
  223.  
  224.   Linux label     FreeBSD label   FreeBSD mount point
  225.   /dev/sdb7       /dev/sd1s3a     /
  226.   /dev/sdb8       /dev/sd1s3b     swap
  227.   /dev/sdb9       /dev/sd1s3e     /var
  228.   /dev/sdb10      /dev/sd1s3f     /usr
  229.  
  230.  
  231.  
  232.   This will be shown as
  233.  
  234.   Partition check:
  235.    sdb: sdb1 sdb2 < sdb5 sdb6 > sdb3 < sdb7 sdb8 sdb9 sdb10 >
  236.  
  237.  
  238.   in the output from dmesg.
  239.  
  240.   If you have a Linux extended partition after your FreeBSD slice you're
  241.   in for trouble, because most Linux kernels installation floppies are
  242.   build without UFS support, they will not recognise the FreeBSD
  243.   partitions inside the slice. What should have have been seen as
  244.   (/dev/hda3 is the FreeBSD slice and /dev/hda4 is the Linux extended
  245.   partition)
  246.  
  247.   Partition check:
  248.    hda: hda1 hda2 hda3 < hda5 hda6 hda7 hda8 > hda4 < hda9 hda10 >
  249.  
  250.  
  251.   is seen as:
  252.  
  253.   Partition check:
  254.    hda: hda1 hda2 hda3 hda4 < hda5 hda6 >
  255.  
  256.  
  257.  
  258.   This can give you the wrong device assignment and cause the loss of
  259.   data. My advice is to always put your FreeBSD slice after any Linux
  260.   extended partitions, and do not change any logical partitions in your
  261.   Linux extended partitions after installing FreeBSD!
  262.  
  263.  
  264.  
  265.   3.  Sharing swap space between Linux and FreeBSD
  266.  
  267.   This section describes how I got Linux and FreeBSD to share a swap
  268.   partition.  There may be other ways to get the same result. You can
  269.   install FreeBSD before Linux if you want to, just pay attention to the
  270.   order of the partitions in the FreeBSD slice.
  271.  
  272.  
  273.   3.1.  Installing and preparing Linux
  274.  
  275.   The first step is to install Linux as normal. You have to leave space
  276.   for the FreeBSD slice at your hard drive. You don't have to make a
  277.   Linux swap partition, but if you want one, put it in the space you
  278.   want to allocate for FreeBSD. That way you can delete the Linux swap
  279.   partition later and use the space for FreeBSD.
  280.  
  281.   When you have installed Linux you have to build a new kernel. Read The
  282.   Linux Kernel HOWTO if this is new to you. You have to include both UFS
  283.   filesystem support (read only) and BSD disklabel (FreeBSD partition
  284.   tables) support:
  285.  
  286.   UFS filesystem support (read only) (CONFIG_UFS_FS) [N/y/m/?] y
  287.   BSD disklabel (FreeBSD partition tables) support (CONFIG_BSD_DISKLABEL) [N/y/?]
  288.   (NEW) y
  289.  
  290.  
  291.  
  292.   Install the new kernel and reboot. Remove any line including the word
  293.   swap from your /etc/fstab file if you have made a Linux swap
  294.   partition.  Make sure you have a working Linux boot floppy with the
  295.   new kernel. Now you are ready to install FreeBSD.
  296.  
  297.  
  298.   3.2.  Installing FreeBSD
  299.  
  300.   Install FreeBSD as described in the FreeBSD documentation. Remove the
  301.   Linux swap partition if you have made one (you can use the FreeBSD
  302.   fdisk program.) Pay attention to the order of the partitions in the
  303.   FreeBSD slice. If you use the default labelling the second partition
  304.   will be the swap partition. Complete the installation of FreeBSD and
  305.   reboot into Linux using the new Linux boot floppy.
  306.  
  307.  
  308.   3.3.  Setting up the FreeBSD swap partition in Linux
  309.  
  310.   Run dmesg when you have booted into Linux. In the output you should
  311.   see something like this:
  312.  
  313.   Partition check:
  314.    hda: hda1 hda2 hda3 hda4 < hda5 hda6 hda7 hda8 >
  315.  
  316.  
  317.  
  318.   This means that /dev/hda4 is your FreeBSD slice, while /dev/hda5,
  319.   /dev/hda6, /dev/hda7 and /dev/hda8 are the FreeBSD partitions. If your
  320.   swap partition is the second partition in the slice, it will be
  321.   /dev/hda6.
  322.  
  323.   You have to put the following line into your Linux /etc/fstab file to
  324.   enable the swap partition:
  325.  
  326.   /dev/hda6       none            swap            sw              0       0
  327.  
  328.  
  329.  
  330.  
  331.   While FreeBSD can use any type of partition as swap space, Linux needs
  332.   a special signature in the swap partition. This signature is made by
  333.   mkswap.  FreeBSD ruins this signature when it uses the shared swap
  334.   partition, so you will have to run mkswap each time you boot into
  335.   Linux. To do this automagically you have to find the script that runs
  336.   swapon at boot time.  In Red Hat Linux it is /etc/rc.d/rc.sysinit. Put
  337.   the following line into that file just before swapon -a:
  338.  
  339.   awk -- '/swap/ && ($1 !~ /#/) { system("mkswap "$1"") }' /etc/fstab
  340.  
  341.  
  342.  
  343.   This will run mkswap on any swap partitions in /etc/fstab every time
  344.   you boot except if they are commented out (having ``#'' as the first
  345.   character in the line.)
  346.  
  347.   Run free to check out the size of the swap space when you have
  348.   rebooted into Linux. You should also reboot into FreeBSD to make sure
  349.   everything works as expected. If it does not, you have probably used
  350.   the wrong partition as swap partition. The only solution to that
  351.   problem is to reinstall FreeBSD and try again. Experience is a great
  352.   teacher. :-)
  353.  
  354.  
  355.   4.  Booting FreeBSD using LILO
  356.  
  357.   You can easily boot FreeBSD with LILO. Do not install the FreeBSD boot
  358.   selector (Booteasy) if you want to use LILO. Append the following
  359.   lines to your /etc/lilo.conf file and run lilo (assuming the FreeBSD
  360.   slice is /dev/hda4):
  361.  
  362.   other=/dev/hda4
  363.           table=/dev/hda
  364.           label=FreeBSD
  365.  
  366.  
  367.  
  368.   If you have installed FreeBSD on the second SCSI drive, use something
  369.   like this (the FreeBSD slice being /dev/sdb2):
  370.  
  371.   other=/dev/sdb2
  372.           table=/dev/sdb
  373.           loader=/boot/chain.b
  374.           label=FreeBSD
  375.  
  376.  
  377.  
  378.  
  379.   5.  Mounting file systems
  380.  
  381.   5.1.  Mounting UFS file systems under Linux
  382.  
  383.   Unfortunately the UFS driver in the Linux 2.0.xx kernels do not
  384.   include support for FreeBSD. When you try to mount a FreeBSD file
  385.   system, you just get some error messages (the file system actually
  386.   gets mounted, but you cannot read anything from it.) This problem has
  387.   been solved in Linux 2.1.87 and higher.
  388.  
  389.   There is another version of the UFS driver for Linux 2.0.xx kernels
  390.   (xx <= 30) on SunSite <ftp://sunsite.unc.edu/pub/Linux/ALPHA/ufs/>. It
  391.   is called U2FS and the current version is u2fs-0.4.3.tar.gz. A version
  392.   of U2FS (ufs-0.4.4.tar.gz) for Linux 2.0.31 and higher (2.0.xx; not
  393.   2.1.xx) can be found at this site <http://www.mathi.uni-
  394.   heidelberg.de/~flight/projects/u2fs/> along with further information
  395.   about U2FS (and UFS.)
  396.  
  397.   Now you have to build a new kernel with support for the U2FS file
  398.   system and BSD disklabels. See section ``Installing and preparing
  399.   Linux'' for more information on this. You can leave out UFS filesystem
  400.   support from the kernel when you use U2FS.
  401.  
  402.   When you have installed the new kernel, you can mount your UFS file
  403.   systems (all the partitions in the FreeBSD slice except the swap
  404.   partition) with a command like this:
  405.  
  406.   mount -t u2fs /dev/hda8 /mnt
  407.  
  408.  
  409.  
  410.   You should use a command like
  411.  
  412.   mount -t ufs /dev/hda8 /mnt
  413.  
  414.  
  415.   if you use a Linux kernel version 2.1.87 or higher.
  416.  
  417.   The UFS (and U2FS) driver is read-only. That is; you can read from the
  418.   UFS file systems but you cannot write to them. Work on a read/write
  419.   driver has just begun.
  420.  
  421.  
  422.   5.2.  Mounting ext2fs file systems under FreeBSD
  423.  
  424.   To mount ext2fs file systems under FreeBSD, you first have to build a
  425.   new kernel with ext2fs support. Read the FreeBSD handbook
  426.   <http://www.freebsd.org/handbook/> to learn how to do that. Put the
  427.   line
  428.  
  429.   options         "EXT2FS"
  430.  
  431.  
  432.   in your kernel configuration file for the new kernel.
  433.  
  434.   When you have booted with the new kernel, you can mount an ext2fs file
  435.   system by giving a command like:
  436.  
  437.   mount -t ext2fs /dev/wd0s3 /mnt
  438.  
  439.  
  440.  
  441.   Note that you cannot mount ext2fs file systems in extended partitions
  442.   from FreeBSD.
  443.  
  444.   Due to a bug in FreeBSD 2.2.5 and earlier you will have to unmount all
  445.   ext2fs file systems before you shut down FreeBSD if you are using
  446.   these versions.  If you shut down FreeBSD with an ext2fs file system
  447.   mounted, FreeBSD cannot sync the UFS file systems. This results in
  448.   fsck being run the next time FreeBSD is booted.
  449.  
  450.  
  451.   6.  Running foreign binaries
  452.  
  453.   6.1.  Running FreeBSD binaries under Linux
  454.  
  455.   The iBCS package has support for running FreeBSD binaries under Linux;
  456.   but it's old and unmaintained. I can't get it to work. Please let me
  457.   know if you have had better luck with this.
  458.  
  459.  
  460.  
  461.  
  462.  
  463.   6.2.  Running Linux binaries under FreeBSD
  464.  
  465.   FreeBSD has the ability to run Linux binaries, both in a.out and ELF
  466.   formats.  To do this you have to take the following three steps:
  467.  
  468.  
  469.   1. You have to enable Linux compatibility. To do this (in FreeBSD
  470.      2.2.2 --- details may vary in other versions) you have to edit your
  471.      /etc/rc.conf file and change
  472.  
  473.      linux_enable="NO"
  474.  
  475.  
  476.   to
  477.  
  478.   linux_enable="YES"
  479.  
  480.  
  481.   and reboot. Another way to load the Linux binary support is to execute
  482.   the command /usr/bin/linux. This way you don't have to reboot, and you
  483.   don't always have the Linux binary support loaded (i.e. you save mem¡
  484.   ory.)
  485.  
  486.   2. You have to install the Linux shared libraries if your Linux
  487.      binaries are dynamically linked. The libraries are included in
  488.      FreeBSD 2.2.{2,5,6} as the package linux_lib-2.4.tgz. Run the
  489.      following command to install the package:
  490.  
  491.      pkg_add <path_to_package>/linux_lib-2.4.tgz
  492.  
  493.  
  494.   <path_to_package> is the directory where the package is stored. You
  495.   may also load it off the net by:
  496.  
  497.   pkg_add ftp://ftp.freebsd.org/pub/FreeBSD/packages-stable/All/linux_lib-2.4.tgz
  498.  
  499.  
  500.   or by re-running /stand/sysinstall. Enter ``Configure'', ``Packages''
  501.   and use the menus.
  502.  
  503.   3. Install the Linux program(s) you want to run. The program(s) can be
  504.      installed on either UFS or ext2fs file systems. See section
  505.      ``Mounting ext2fs file systems under FreeBSD'' for more information
  506.      about using ext2fs file systems under FreeBSD.
  507.  
  508.   I have successfully run the Linux versions of Applixware 4.3 and
  509.   Netscape 3.01 (both ELF format) under FreeBSD 2.2.2 using this method
  510.   (yes, I know there is a native FreeBSD version of Netscape 4.) The
  511.   Linux versions of acroread and StarOffice also work well under
  512.   FreeBSD. Read the FreeBSD documentation for more information on this
  513.   topic.
  514.  
  515.  
  516.   7.  References and other documents of interest
  517.  
  518.   The latest version of this mini-HOWTO can be downloaded from my
  519.   homepage <http://www.image.dk/~nkbj/> in several formats (including
  520.   SGML and PostScript.) The document has been translated into Japanese
  521.   by Mr. Teruyoshi Fujiwara as part of the JF project
  522.   <ftp://jf.linux.or.jp/pub/JF/other-formats/>.
  523.  
  524.   Gregor Hoffleit maintains a homepage <http://www.mathi.uni-
  525.   heidelberg.de/~flight/projects/u2fs/> with information about the
  526.   developement of U2FS and UFS.
  527.  
  528.  
  529.   The FreeBSD Project Homepage <http://www.freebsd.org/> has a lot of
  530.   information about FreeBSD (besides the whole system ready for
  531.   download.)
  532.  
  533.   The Linux Kernel HOWTO is released as part of The Linux Documentation
  534.   Project <http://sunsite.unc.edu/LDP/>.
  535.  
  536.  
  537.   8.  Acknowledgments and Copyright
  538.  
  539.   Thanks to the members of the *BSD user group in Denmark
  540.   <http://hotel.prosa.dk/bsd-dk/> for answering the questions of a
  541.   FreeBSD newbie, to Mr. Takeshi Okazaki for bringing the existence of
  542.   U2FS to my attention, and to Mr. David O'Brien for valuable
  543.   suggestions.
  544.  
  545.  
  546.   8.1.  Disclaimer
  547.  
  548.   Although the information given in this document is believed to be
  549.   correct, the authors will accept no liability for the content of this
  550.   document. Use the tips and examples given herein at your own risk.
  551.  
  552.  
  553.   8.2.  Copyright
  554.  
  555.   Copyright (c) 1997, 1998 by Niels Kristian Bech Jensen. This document
  556.   may be distributed only subject to the terms and conditions set forth
  557.   in the LDP license <http://sunsite.unc.edu/LDP/LDP-COPYRIGHT.html>.
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.