<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/openrc-migration.xml,v 1.14 2009/02/12 00:59:32 nightmorph Exp $ -->

<guide link="/doc/en/openrc-migration.xml">
<title>Baselayout and OpenRC Migration Guide</title>

<author title="Author">
  <mail link="cardoe"/>
</author>
<author title="Author">
  <mail link="nightmorph"/>
</author>
<author title="Contributor">
  <mail link="uberlord"/>
</author>

<abstract>
This guide shows you how to migrate from baselayout-1 to baselayout-2 and
OpenRC.
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
<license/>

<version>1.8</version>
<date>2009-02-11</date>

<chapter>
<title>Background</title>
<section>
<title>What's baselayout?</title>
<body>

<p>
Baselayout provides a basic set of files that are necessary for all systems to
function properly, such as <path>/etc/hosts</path>. It also provides the basic
filesystem layout used by Gentoo (i.e. <path>/etc</path>, <path>/var</path>,
<path>/usr</path>, <path>/home</path> directories).
</p>

</body>
</section>
<section>
<title>What's OpenRC?</title>
<body>

<p>
OpenRC is a dependency-based rc system that works with whatever init is provided
by the system, normally <path>/sbin/init</path>. However, it is <e>not</e> a
replacement for <path>/sbin/init</path>. The default init used by Gentoo Linux
is <c>sys-apps/sysvinit</c>, while Gentoo/FreeBSD uses the FreeBSD init provided
by <c>sys-freebsd/freebsd-sbin</c>.
</p>
</body>
</section>
<section>
<title>So why migrate?</title>
<body>

<p>
Originally Gentoo's rc system was built into baselayout 1 and written entirely
in bash. This led to several limitations. For example, certain system calls need
to be accessed during boot and this required C-based callouts to be added. These
callouts were each statically linked, causing the rc system to bloat over time.
</p>

<p>
Additionally, as Gentoo expanded to other platforms like
Gentoo/FreeBSD and Gentoo Embedded, it became impossible to require a bash-based
rc system. This led to a development of baselayout 2, which is written in
C and only requires a POSIX-compliant shell. During the development of
baselayout 2, it was determined that it was a better fit if baselayout merely
provided the base files and filesystem layout for Gentoo and the rc system
was broken off into its own package. Thus we have OpenRC.
</p>

<p>
OpenRC is primarily developed by <uri link="http://roy.marples.name/openrc">Roy
Marples</uri> and supports all current Gentoo variations (i.e. Gentoo Linux,
Gentoo/FreeBSD, Gentoo Embedded, and Gentoo Vserver) and other platforms such as
FreeBSD and NetBSD.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Migration to OpenRC</title>
<section>
<body>

<p>
Migration to OpenRC is fairly straightforward; it will be pulled in as part of
your regular upgrade process by your package manager. The most important step
actually comes after you install the new <c>>=sys-apps/baselayout-2</c> and
<c>sys-apps/openrc</c> packages. It is <e>critical</e> that you run
<c>dispatch-conf</c> and ensure your <path>/etc</path> is up to date before
rebooting. <brite>Failure to do so will result in an unbootable system</brite>
and will require the use of the Gentoo LiveCD to perform the steps below to
repair your system.
</p>

<p>
Once you've finished updating your config files, there are a few things to
verify prior to rebooting.
</p>
	
</body>
</section>

<section id="rc_conf">
<title>/etc/conf.d/rc</title>
<body>

<p>
<path>/etc/conf.d/rc</path> has been deprecated and any settings you have in
there will need to be migrated to the appropriate settings in
<path>/etc/rc.conf</path>. Please read through <path>/etc/rc.conf</path> and
<path>/etc/conf.d/rc</path> and migrate the settings. Once you are complete,
delete <path>/etc/conf.d/rc</path>.
</p>

</body>
</section>
<section id="modules">
<title>Kernel modules</title>
<body>

<p>
Normally, when you want certain kernel modules automatically loaded at boot, you
place them into <path>/etc/modules.autoload.d/kernel-2.6</path> along with any
parameters you wanted to pass to them. In baselayout-2, this file is not used
anymore. Instead, autoloaded modules and module parameters are placed in one
file, <path>/etc/conf.d/modules</path>, no matter the kernel version.
</p>

<p>
An example old style configuration would be:
</p>

<pre caption="/etc/modules.autoload.d/kernel-2.6">
ivtv
cx88_dvb video_br=2
</pre>

<p>
Converting the above example would result in the following:
</p>

<pre caption="/etc/conf.d/modules">
<comment># Modules autoloaded at boot</comment>
modules_2_6="ivtv cx88_dvb"
<comment># Module parameters</comment>
module_cx88_dvb_args_2_6="video_br=2"
</pre>

<p>
In the above examples, the modules and their parameters would only be passed
to 2.6.x series kernels. The new configuration allows for fine grained
control over the modules and parameters based on kernel version.
</p>

<p>
An in-depth example would be:
</p>

<pre caption="detailed example of /etc/conf.d/modules">
<comment># Always load ochi1394 and ieee1394, no matter the kernel version</comment>
modules="ohci1394 ieee1394"
<comment># Only load tun and usbserial for 2.6.x series kernels</comment>
modules_2_6="tun usbserial"
<comment># Only load cx88_dvb for 2.6.23 kernels</comment>
modules_2_6_23="cx88_dvb"
<comment># Only load ivtv for 2.6.23-gentoo-r5</comment>
modules_2_6_23_gentoo_r5="ivtv"

<comment># For 2.6.23-gentoo-r5, pass video_br=2 to cx88_dvb</comment>
module_cx88_dvb_args_2_6_23_gentoo_r5="video_br=2"
<comment># For 2.6.x series kernels, always pass vendor and product</comment>
module_usbserial_args_2_6="vendor=0x1410 product=0x2110"
<comment># Always pass debug to ieee1394</comment>
module_ieee1394_args="debug" 
</pre>

<note>
Please note the difference between <b>module_</b> and <b>modules_</b>.
</note>

</body>
</section>
<section id="boot">
<title>Boot runlevel</title>
<body>

<p>
The <c>boot</c> runlevel performs several important steps for every machine. For
example, making sure your root filesystem is mounted read/write, that your
filesystems are checked for errors, that your mountpoints are available, and
that the <path>/proc</path> pseudo-filesystem is started at boot.
</p>

<p>
With OpenRC, volume management services for your block storage devices are no
longer run automatically at boot. This includes lvm, raid, swap, device-mapper
(dm), dm-crypt, evms, and the like. You must ensure the appropriate initscript
for these services is in the <c>boot</c> runlevel, otherwise it's possible that
your system will not boot!
</p>

<p>
While the OpenRC ebuild will attempt to do this migration for you, you should
verify that it migrated all the volume management services properly:
</p>

<pre caption="Display all services in boot runlevel">
# <i>ls -l /etc/runlevels/boot/</i>
</pre>

<p>
If you don't see root, procfs, mtab, swap, and fsck in the above listing,
perform the following to add them to the <c>boot</c> runlevel:
</p>

<pre caption="Adding critical services to the boot runlevel">
# <i>rc-update add root boot</i>
# <i>rc-update add procfs boot</i>
# <i>rc-update add mtab boot</i>
# <i>rc-update add fsck boot</i>
# <i>rc-update add swap boot</i>
</pre>

<p>
If you know you use mdraid and lvm but do not see them above, you would run
the following to add initscripts to the <c>boot</c> runlevel:
</p>

<pre caption="Adding raid and lvm to the boot runlevel">
# <i>rc-update add raid boot</i>
# <i>rc-update add lvm boot</i>
</pre>

</body>
</section>
<section>
<title>Udev</title>
<body>

<p>
OpenRC no longer starts <c>udev</c> by default, but it does need to be present
in the <c>sysinit</c> runlevel to be started. The OpenRC ebuild should detect if
<c>udev</c> was previously enabled and add it to the <c>sysinit</c> runlevel.
However, to be safe, check if <c>udev</c> is present:
</p>

<pre caption="Verifying udev">
# <i>ls -l /etc/runlevels/sysinit</i>
lrwxrwxrwx 1 root root 14 2009-01-29 08:00 /etc/runlevels/sysinit/udev -> \
/etc/init.d/udev
</pre>

<p>
If <c>udev</c> is not listed, add it to the correct runlevel:
</p>

<pre caption="Adding udev to the sysinit runlevel">
# <i>rc-update add udev sysinit</i>
</pre>

</body>
</section>
<section>
<title>Network</title>
<body>

<p>
Due to baselayout and OpenRC being broken into two different packages, your
net.eth0 initscript may disappear during the upgrade process. To replace this
initscript please perform the following:
</p>

<pre caption="Adding back missing net.eth0 script">
# <i>cd /etc/init.d</i>
# <i>ln -s net.lo net.eth0</i>
</pre>

<p>
If you are missing any other network initscripts, follow the instructions above
to re-add them. Simply replace <c>eth0</c> with the name of your network
device.
</p>

<p>
Also, <path>/etc/conf.d/net</path> no longer uses bash-style arrays for
configuration. Please review <path>/usr/share/doc/openrc/net.example</path> for
configuration instructions. Conversion should be relatively straight-forward,
for example a static IP assignment would change as follows:
</p>

<pre caption="Old /etc/conf.d/net style">
config_eth0=( "192.168.1.37 netmask 255.255.255.0 brd 192.168.1.255" )
routes_eth0=( "default via 192.168.1.100" )
</pre> 

<pre caption="New /etc/conf.d/net style">
config_eth0="192.168.1.37 netmask 255.255.255.0 brd 192.168.1.255"
routes_eth0="default via 192.168.1.100"
</pre>

</body>
</section>
<section>
<title>Clock</title>
<body>

<p>
Clock settings have been renamed from <path>/etc/conf.d/clock</path> to your
system's native tool for adjusting the clock. This means on Linux it will be
<path>/etc/conf.d/hwclock</path> and on FreeBSD it will be
<path>/etc/conf.d/adjkerntz</path>. The initscript in <path>/etc/init.d/</path>
has also been renamed accordingly, so make sure it's in the appropriate
runlevel.
</p>

<p>
Additionally, the <c>TIMEZONE</c> variable is no longer in this file. Its
contents are instead found in the <path>/etc/timezone</path> file. If it
doesn't exist, you will of course have to create it with your timezone. Please
review both of these files to ensure their correctness.
</p>

<p>
The proper value for this file is the path relative to your timezone from
<path>/usr/share/zoneinfo</path>. For example, for someone living on the east
coast of the United States, the following would be a correct setting:
</p>

<pre caption="/etc/timezone">
America/New_York
</pre>

</body>
</section>
<section>
<title>XSESSION</title>
<body>

<p>
The XSESSION variable is no longer found in <path>/etc/rc.conf</path>. The
<c>x11-apps/xinit</c> package now provides <path>/etc/env.d/90xsession</path>,
which can be used to set the XSESSION variable.
</p>

<p>
This variable will <b>NOT</b> be migrated for you by default, so you will need
to edit <path>/etc/env.d/90xsession</path>.
</p>

<impo>
You must run <c>env-update</c> after creating a file in <path>/etc/env.d</path>,
and then logout and login for it to take effect.
</impo>

</body>
</section>
<section>
<title>EDITOR / PAGER</title>
<body>

<p>
The EDITOR variable is no longer found in <path>/etc/rc.conf</path>.  Both
EDITOR and PAGER are set by default in <path>/etc/profile</path>.  You should
change this as needed in your <path>~/.bashrc</path> (or equivalent) file or
create <path>/etc/env.d/99editor</path> and set the system default there.
</p>

<impo>
You must run <c>env-update</c> after creating a file in <path>/etc/env.d</path>,
and then logout and login for it to take effect. If you set the variable in
<path>~/.bashrc</path>, you can re-source the file with <c>source
~/.bashrc</c>.
</impo>

</body>
</section>
<section>
<title>Boot log</title>
<body>

<p>
Previously, you could log the boot process by using
<c>app-admin/showconsole</c>. However, OpenRC now handles all logging
internally, so there's no need for the hacks that <c>showconsole</c> employed.
You can safely unmerge <c>showconsole</c>. To continue logging boot messages,
just set the appropriate variable in <path>/etc/rc.conf</path>. Logs will appear
in <path>/var/log/rc.log</path>.
</p>

<pre caption="Enabling boot logging in /etc/rc.conf">
rc_logger="YES"
</pre>

</body>
</section>
<section>
<title>Finishing up</title>
<body>

<p>
Once you've finished updating your config files and initscripts, the last thing
to do is <b>reboot</b>. This is necessary because system state information is
not preserved during the upgrade, so you'll need to provide it with a fresh
boot.
</p>

</body>
</section>
</chapter>
</guide>
