<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="convert-fstab-services">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>convert-fstab-services</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">administrator commands</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>convert-fstab-services</refname>
<refpurpose>convert <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry> into services</refpurpose>
<refname>write-volume-service-bundles</refname>
<refpurpose>write the service bundles for a given volume</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>system-control</command>
<arg choice="req">convert-fstab-services</arg>
<arg choice='opt'>--etc-bundle</arg>
<arg choice='opt'>--bundle-root <replaceable>root</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>system-control</command>
<arg choice="req">write-volume-service-bundles</arg>
<arg choice='opt'>--etc-bundle</arg>
<arg choice='opt'>--bundle-root <replaceable>root</replaceable></arg>
<arg choice='opt'>--want-fsck</arg>
<arg choice="req"><replaceable>fstype</replaceable></arg>
<arg choice="req"><replaceable>source</replaceable></arg>
<arg choice="req"><replaceable>directory</replaceable></arg>
<arg choice="req"><replaceable>options</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
These (sub)commands generate sets of service bundles that contain scripts, dependencies, and autoboot dependency configuration information appropriate for mounting, unmounting, and checking a volume.
See <citerefentry><refentrytitle>system-control</refentrytitle><manvolnum>8</manvolnum></citerefentry> for an explanation of service bundles.
</para>

<para>
The bundles generated by these subcommands are written in the current directory (or in the <arg choice='plain'><replaceable>root</replaceable></arg> directory).
They are not enabled by the conversion process, but can be started and enabled as they stand, with the <command>start</command> and <command>preset</command> subcommands, just like any other service bundle.
With <command>preset</command> the <arg choice='plain'>--fstab</arg> option is appropriate of course.
(It is <command>preset</command> that handles the <code>noauto</code> option in <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>.)
</para>

<para>
The assumption is that all service bundles are under one common <arg choice='plain'><replaceable>root</replaceable></arg> and all target bundles under another; so service-to-service dependencies and orderings can be relative pathnames whilst service-to-target and target-to-service dependencies and orderings have to be absolute pathnames.
The <arg choice='plain'>--etc-bundle</arg> option changes this assumption, such that target bundles are now assumed to be reachable with relative pathnames from the converted service bundle; as is the case for special early bootstrap service bundles that live in <filename>/etc/service-bundles/services/</filename>.
It also forces the bundle to be marked as an <code>EarlySupervise</code> bundle whose <filename>supervise/</filename> directory lives in a tmpfs.
</para>

<refsection><title>Converting the whole of <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry></title>

<para>
The <command>convert-fstab-services</command> subcommand takes the records from the flat file table in <filename>/etc/fstab</filename> (see <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry>) and generates from them a set of service bundles for each record.
</para>

<note>
<para>
<citerefentry><refentrytitle>console-flat-table-viewer</refentrytitle><manvolnum>1</manvolnum></citerefentry> explains what a flat file table is.
<citerefentry><refentrytitle>getent</refentrytitle><manvolnum>1</manvolnum></citerefentry> does not support reading the <citerefentry><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry> table.
To see this table as <command>convert-fstab-services</command> sees it, run:
</para>
<literallayout><userinput>
(
    printf '%s\t' source directory fstype options 'dump\040frequency' 'pass\040number'
    printf '\n'
    cat /etc/fstab
) |
console-flat-table-viewer --header-count 1
</userinput></literallayout>
</note>

<itemizedlist>

<listitem>
<para>
For each non-swap entry:
</para>
<itemizedlist>
<listitem>
<para>
It acts as if it had run <command>write-volume-service-bundles</command> with the values from the entry, discarding the "dump frequency" column of the table.
If the entry specifies a "pass number" that is greater than zero, it acts as if the <arg choice='plain'>--want-fsck</arg> option had been passed.
</para>
</listitem>
</itemizedlist>
</listitem>

<listitem>
<para>
For each swap entry the "source" column is taken to be a <filename><replaceable>device</replaceable></filename> special device filename and the "options" column may contain various flags.
</para>
<itemizedlist>
<listitem>
<para>
It always creates a <filename>swap@<replaceable>device</replaceable></filename> bundle running <citerefentry><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> at service startup and <citerefentry><refentrytitle>swapoff</refentrytitle><manvolnum>8</manvolnum></citerefentry> at service shutdown.
The bundle is created as <filename>wanted-by/</filename> either the system <code>swapauto.target</code> or the system <code>swaplate.target</code>, so that it is started during autoboot when it is enabled.
The choice depends from whether the entry is marked <code>late</code>.
</para>
<para>
If the entry is marked <code>discard</code> then it creates a bundle that passes the <arg choice='plain'>--discard</arg> flag to <citerefentry><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
If the entry is marked <code>pri=<replaceable>N</replaceable></code> then it creates a bundle that passes the <arg choice='plain'>--priority <replaceable>N</replaceable></arg> flag.
</para>
<note>
Not all <citerefentry><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> utilities support these options.
</note>
</listitem>
<listitem>
<para>
It always creates a <filename>dump@<replaceable>device</replaceable></filename> bundle running <citerefentry><refentrytitle>dumpon</refentrytitle><manvolnum>8</manvolnum></citerefentry> at service startup and <citerefentry><refentrytitle>dumpoff</refentrytitle><manvolnum>8</manvolnum></citerefentry> at service shutdown.
The bundle is created as <filename>wanted-by/</filename> the system <code>dumpauto.target</code>, so that it is started during autoboot when it is enabled.
</para>
</listitem>
</itemizedlist>
</listitem>

</itemizedlist>

</refsection>

<refsection><title>Generating services for a single volume</title>

<para>
The <command>write-volume-service-bundles</command> subcommand writes service bundles for a single volume described with its command-line arguments.
</para>

<itemizedlist>
<listitem>
<para>
It always creates a <filename>mount@<replaceable>directory</replaceable></filename> bundle that at service startup mounts <replaceable>source</replaceable> there with <citerefentry><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry> and the options <replaceable>options</replaceable> (if any), and at service shutdown unmounts it with <citerefentry><refentrytitle>umount</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
(The <filename>auto</filename>, <filename>noauto</filename>, <filename>nofail</filename>, and <filename>_netdev</filename> options have no meaning to the actual mount process and are not passed through to the mount options used in the service bundle.)
</para>
<para>
The bundle is created as <filename>wanted-by/</filename> the system <code>local-fs.target</code> or the system <code>remote-fs.target</code>, depending from the filesystem type <replaceable>fstype</replaceable> and whether the <replaceable>options</replaceable> contains <code>_netdev</code>.
This so that it is started during autoboot when it is enabled.
The list of types that are considered to be "remote" is a superset of the old Debian list from <filename>mountall.sh</filename>, with a few additions from the BSDs.
The <code>_netdev</code> option overrides this list and forces a bundle to be unconditionally considered "remote".
</para>
<para>
If it detects a FUSE mount, it makes the bundle <filename>wants/</filename> and <filename>after/</filename> a bundle to load the FUSE kernel module.
Similarly, if the <replaceable>fstype</replaceable> is <filename>efivarfs</filename>, it makes the bundle <filename>wants/</filename> and <filename>after/</filename> a bundle to load that kernel module.
</para>
<para>
"API" filesystems (see <citerefentry><refentrytitle>system-control</refentrytitle><manvolnum>1</manvolnum></citerefentry>) and the root filesystem are specially handled:
</para>
<itemizedlist>
<listitem><para>
They are assumed already mounted by the time that service management starts, and are thus mounted with the "remount"/"update" flag.
</para></listitem>
<listitem><para>
The root is required to remain mounted beyond service management termination, and thus it is merely remounted/updated to read-write at start and to read-only at stop.
</para></listitem>
</itemizedlist>
</listitem>
<listitem>
<para>
If the <arg choice='plain'>--want-fsck</arg> option is used, it creates a <filename>fsck@<replaceable>directory</replaceable></filename> bundle, running <citerefentry><refentrytitle>monitored-fsck</refentrytitle><manvolnum>1</manvolnum></citerefentry> at service startup.
Any <filename>fsck@<replaceable>directory</replaceable></filename> bundle that is created is ordered <filename>before/</filename> the respective <filename>mount@<replaceable>directory</replaceable></filename> bundle, and is <filename>wanted-by/</filename> it.
So when the bundle is enabled <citerefentry><refentrytitle>fsck</refentrytitle><manvolnum>8</manvolnum></citerefentry> is run (monitored, on <replaceable>source</replaceable>) before the volume is actually mounted.
</para>
</listitem>
<listitem>
<para>
If <replaceable>source</replaceable> ends in <filename>.bde</filename>, it creates a <filename>gbde@<replaceable>source</replaceable></filename> bundle, running <citerefentry><refentrytitle>gbde</refentrytitle><manvolnum>8</manvolnum></citerefentry> at service startup and shutdown (to attach <filename><replaceable>source</replaceable></filename> to <filename><replaceable>source</replaceable>.bde</filename> and detach it), removing that suffix from <replaceable>source</replaceable> to generate the main bundles.
Any <filename>gbde@<replaceable>source</replaceable></filename> bundle that is created is ordered <filename>before/</filename> the respective <filename>fsck@<replaceable>directory</replaceable></filename> and <filename>mount@<replaceable>directory</replaceable></filename> bundle, and is <filename>wanted-by/</filename> them.
So when the main bundles are started <citerefentry><refentrytitle>gbde</refentrytitle><manvolnum>8</manvolnum></citerefentry> is run before the volume is actually checked and mounted.
</para>
</listitem>
<listitem>
<para>
If <replaceable>source</replaceable> ends in <filename>.eli</filename>, it creates a <filename>geli@<replaceable>source</replaceable></filename> bundle, running <citerefentry><refentrytitle>geli</refentrytitle><manvolnum>8</manvolnum></citerefentry> at service startup and shutdown (to attach <filename><replaceable>source</replaceable></filename> to <filename><replaceable>source</replaceable>.eli</filename> and detach it), removing that suffix from <replaceable>source</replaceable> to generate the main bundles.
Any <filename>geli@<replaceable>source</replaceable></filename> bundle that is created is ordered <filename>before/</filename> the respective <filename>fsck@<replaceable>directory</replaceable></filename> and <filename>mount@<replaceable>directory</replaceable></filename> bundle, and is <filename>wanted-by/</filename> them.
So when the main bundles are started <citerefentry><refentrytitle>geli</refentrytitle><manvolnum>8</manvolnum></citerefentry> is run before the volume is actually checked and mounted.
</para>
</listitem>
</itemizedlist>

</refsection>

</refsection>

<refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
