doc/en_US.ISO8859-1/articles/linux-users/article.xml
2014-04-29 21:14:52 +00:00

501 lines
19 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE article PUBLIC "-//FreeBSD//DTD DocBook XML V5.0-Based Extension//EN"
"http://www.FreeBSD.org/XML/share/xml/freebsd50.dtd">
<article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>FreeBSD Quickstart Guide for &linux; Users</title>
<authorgroup>
<author><personname><firstname>John</firstname><surname>Ferrell</surname></personname></author>
</authorgroup>
<copyright>
<year>2008</year>
<holder>The FreeBSD Documentation Project</holder>
</copyright>
<pubdate>$FreeBSD$</pubdate>
<releaseinfo>$FreeBSD$</releaseinfo>
<legalnotice xml:id="trademarks" role="trademarks">
&tm-attrib.freebsd;
&tm-attrib.linux;
&tm-attrib.intel;
&tm-attrib.redhat;
&tm-attrib.unix;
&tm-attrib.general;
</legalnotice>
<abstract>
<para>This document is intended to quickly familiarize
intermediate to advanced &linux; users with the basics of
&os;.</para>
</abstract>
</info>
<sect1 xml:id="intro">
<title>Introduction</title>
<para>This document highlights some of the technical differences
between &os; and &linux; so that intermediate to advanced
&linux; users can quickly familiarize themselves with the basics
of &os;.</para>
<para>This document assumes that &os; is already installed. Refer
to the <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/bsdinstall.html">
Installing &os;</link> chapter of the &os;&nbsp;Handbook for
help with the installation process.</para>
</sect1>
<sect1 xml:id="shells">
<title>Default Shell</title>
<para>&linux; users are often surprised to find that
<application>Bash</application> is not the default shell in
&os;. In fact, <application>Bash</application> is not even in
the default installation. Instead, &os; uses &man.tcsh.1; as
the default shell. However, <application>Bash</application> and
other shells are available for installation using the &os; <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports.html">Packages
and Ports Collection</link>.</para>
<para>After installing another shell, use &man.chsh.1; to change
a user's default shell. It is recommended that the
<systemitem class="username">root</systemitem> user's default
shell remain unchanged since shells which are not included in
the base distribution are installed to
<filename>/usr/local/bin</filename>. In the event of a problem,
the file system where <filename>/usr/local/bin</filename> is
located may not be mounted. In this case, <systemitem
class="username">root</systemitem> would not have access to
its default shell, preventing <systemitem
class="username">root</systemitem> from logging in and fixing
the problem.</para>
</sect1>
<sect1 xml:id="software">
<title>Packages and Ports: Adding Software in &os;</title>
<para>&os; provides two methods for installing applications:
binary packages and compiled ports. Each method has its own
benefits:</para>
<itemizedlist>
<title>Binary Packages</title>
<listitem>
<simpara>Faster installation as compared to
compiling large applications.</simpara>
</listitem>
<listitem>
<simpara>Does not require an understanding of how to
compile software.</simpara>
</listitem>
<listitem>
<simpara>No need to install a compiler.</simpara>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Ports</title>
<listitem>
<simpara>Ability to customize installation options.</simpara>
</listitem>
<listitem>
<simpara>Custom patches can be applied.</simpara>
</listitem>
</itemizedlist>
<para>If an application installation does not require any
customization, installing the package is sufficient. Compile
the port instead whenever an application requires customization
of the default options. If needed, a custom package can be
compiled from ports using <command>make</command>
<buildtarget>package</buildtarget>.</para>
<para>A complete list of all available ports and packages can
be found <link
xlink:href="http://www.freebsd.org/ports/master-index.html">here</link>.</para>
<sect2 xml:id="packages">
<title>Packages</title>
<para>Packages are pre-compiled applications, the &os;
equivalents of <filename>.deb</filename> files on
Debian/Ubuntu based systems and <filename>.rpm</filename>
files on Red&nbsp;Hat/Fedora based systems. Packages are
installed using <application>pkg</application>. For example,
the following command installs
<application>Apache 2.4</application>:</para>
<screen>&prompt.root; <userinput>pkg install <replaceable>apache24</replaceable></userinput></screen>
<para>For more information on packages refer to section 5.4 of
the &os; Handbook: <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/pkgng-intro.html">Using
pkgng for Binary Package Management</link>.</para>
</sect2>
<sect2 xml:id="ports">
<title>Ports</title>
<para>The &os; Ports Collection is a framework of
<filename>Makefiles</filename> and patches specifically
customized for installing applications from source on &os;.
When installing a port, the system will fetch the source code,
apply any required patches, compile the code, and install the
application and any required dependencies.</para>
<para>The Ports Collection, sometimes referred to as the ports
tree, can be installed to <filename>/usr/ports</filename>
using &man.portsnap.8;. Detailed instructions for installing
the Ports Collection can be found in <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports-using.html">section
5.5</link> of the &os; Handbook.</para>
<para>To compile a port, change to the port's directory and
start the build process. The following example installs
<application>Apache 2.4</application> from the Ports
Collection:</para>
<screen>&prompt.root; <userinput>cd /usr/ports/www/apache24</userinput>
&prompt.root; <userinput>make install clean</userinput></screen>
<para>A benefit of using ports to install software is the
ability to customize the installation options. This example
specifies that the <application>mod_ldap</application> module
should also be installed:</para>
<screen>&prompt.root; <userinput>cd /usr/ports/www/apache24</userinput>
&prompt.root; <userinput>make WITH_LDAP="YES" install clean</userinput></screen>
<para>Refer to <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports-using.html">Using
the Ports Collection</link> for more information.</para>
</sect2>
</sect1>
<sect1 xml:id="startup">
<title>System Startup</title>
<para>Many &linux; distributions use the SysV init system, whereas
&os; uses the traditional BSD-style &man.init.8;. Under the
BSD-style &man.init.8;, there are no run-levels and
<filename>/etc/inittab</filename> does not exist. Instead,
startup is controlled by &man.rc.8; scripts. At system boot,
<filename>/etc/rc</filename> reads
<filename>/etc/rc.conf</filename> and
<filename>/etc/defaults/rc.conf</filename>
to determine which services are to be started. The specified
services are then started by running the corresponding service
initialization scripts located in
<filename>/etc/rc.d/</filename> and
<filename>/usr/local/etc/rc.d/</filename>. These scripts are
similar to the scripts located in
<filename>/etc/init.d/</filename> on &linux; systems.</para>
<para>The scripts found in <filename>/etc/rc.d/</filename> are for
applications that are part of the <quote>base</quote> system,
such as &man.cron.8;, &man.sshd.8;, and &man.syslog.3;. The
scripts in <filename>/usr/local/etc/rc.d/</filename> are for
user-installed applications such as
<application>Apache</application> and
<application>Squid</application>.</para>
<para>Since &os; is developed as a complete operating system,
user-installed applications are not considered to be part of
the <quote>base</quote> system. User-installed applications
are generally installed using <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports-using.html">Packages
or Ports</link>. In order to keep them separate from the base
system, user-installed applications are installed under
<filename>/usr/local/</filename>. Therefore, user-installed
binaries reside in <filename>/usr/local/bin/</filename>,
configuration files are in <filename>/usr/local/etc/</filename>,
and so on.</para>
<para>Services are enabled by adding an entry for the service in
<filename>/etc/rc.conf</filename> . The system defaults are
found in <filename>/etc/defaults/rc.conf</filename> and these
default settings are overridden by settings in
<filename>/etc/rc.conf</filename>. Refer to &man.rc.conf.5; for
more information about the available entries. When installing
additional applications, review the application's install
message to determine how to enable any associated
services.</para>
<para>The following entries in <filename>/etc/rc.conf</filename>
enable &man.sshd.8;, enable <application>Apache
2.4</application>, and specify that
<application>Apache</application> should be started with
<acronym>SSL</acronym>.</para>
<programlisting># enable SSHD
sshd_enable="YES"
# enable Apache with SSL
apache24_enable="YES"
apache24_flags="-DSSL"</programlisting>
<para>Once a service has been enabled in
<filename>/etc/rc.conf</filename>, it can be started without
rebooting the system:</para>
<screen>&prompt.root; <userinput>service <replaceable>sshd</replaceable> start</userinput>
&prompt.root; <userinput>service apache24 start</userinput></screen>
<para>If a service has not been enabled, it can be started from
the command line using <option>onestart</option>:</para>
<screen>&prompt.root; <userinput>service <replaceable>sshd</replaceable> onestart</userinput></screen>
</sect1>
<sect1 xml:id="network">
<title>Network Configuration</title>
<para>Instead of a generic <emphasis>ethX</emphasis> identifier
that &linux; uses to identify a network interface, &os; uses the
driver name followed by a number. The following output from
&man.ifconfig.8; shows two &intel;&nbsp;Pro&nbsp;1000 network
interfaces (<filename>em0</filename> and
<filename>em1</filename>):</para>
<screen>&prompt.user; <userinput>ifconfig</userinput>
em0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
options=b&lt;RXCSUM,TXCSUM,VLAN_MTU&gt;
inet 10.10.10.100 netmask 0xffffff00 broadcast 10.10.10.255
ether 00:50:56:a7:70:b2
media: Ethernet autoselect (1000baseTX &lt;full-duplex&gt;)
status: active
em1: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
options=b&lt;RXCSUM,TXCSUM,VLAN_MTU&gt;
inet 192.168.10.222 netmask 0xffffff00 broadcast 192.168.10.255
ether 00:50:56:a7:03:2b
media: Ethernet autoselect (1000baseTX &lt;full-duplex&gt;)
status: active</screen>
<para>An <acronym>IP</acronym> address can be assigned to an
interface using &man.ifconfig.8;. To remain persistent across
reboots, the <acronym>IP</acronym> configuration must be
included in <filename>/etc/rc.conf</filename>. The following
<filename>/etc/rc.conf</filename> entries specify the hostname,
<acronym>IP</acronym> address, and default gateway:</para>
<programlisting>hostname="server1.example.com"
ifconfig_em0="inet 10.10.10.100 netmask 255.255.255.0"
defaultrouter="10.10.10.1"</programlisting>
<para>Use the following entries to instead configure an interface
for <acronym>DHCP</acronym>:</para>
<programlisting>hostname="server1.example.com"
ifconfig_em0="DHCP"</programlisting>
</sect1>
<sect1 xml:id="firewall">
<title>Firewall</title>
<para>&os; does not use &linux;
<application>IPTABLES</application> for its firewall. Instead,
&os; offers a choice of three kernel level firewalls:</para>
<itemizedlist>
<listitem>
<simpara><link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/firewalls-pf.html">PF</link></simpara>
</listitem>
<listitem>
<simpara><link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/firewalls-ipf.html">IPFILTER</link></simpara>
</listitem>
<listitem>
<simpara><link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/firewalls-ipfw.html">IPFW</link></simpara>
</listitem>
</itemizedlist>
<para><application>PF</application> is developed by the OpenBSD
project and ported to &os;. <application>PF</application> was
created as a replacement for <application>IPFILTER</application>
and its syntax is similar to that of
<application>IPFILTER</application>.
<application>PF</application> can be paired with &man.altq.4; to
provide <acronym>QoS</acronym> features.</para>
<para>This sample <application>PF</application> entry allows
inbound <application>SSH</application>:</para>
<programlisting>pass in on $ext_if inet proto tcp from any to ($ext_if) port 22</programlisting>
<para><application>IPFILTER</application> is the firewall
application developed by Darren Reed. It is not specific to
&os; and has been ported to several operating systems including
NetBSD, OpenBSD, SunOS, HP/UX, and Solaris.</para>
<para>The <application>IPFILTER</application> syntax to allow
inbound <application>SSH</application> is:</para>
<programlisting>pass in on $ext_if proto tcp from any to any port = 22</programlisting>
<para><application>IPFW</application> is the firewall developed
and maintained by &os;. It can be paired with &man.dummynet.4;
to provide traffic shaping capabilities and simulate different
types of network connections.</para>
<para>The <application>IPFW</application> syntax to allow inbound
<application>SSH</application> would be:</para>
<programlisting>ipfw add allow tcp from any to me 22 in via $ext_if</programlisting>
</sect1>
<sect1 xml:id="updates">
<title>Updating &os;</title>
<para>There are two methods for updating a &os; system: from
source or binary updates.</para>
<para>Updating from source is the most involved update method, but
offers the greatest amount of flexibility. The process involves
synchronizing a local copy of the &os; source code with the &os;
<application>Subversion</application> servers. Once the local
source code is up-to-date, a new version of the kernel and
userland can be compiled.</para>
<para>Binary updates are similar to using <command>yum</command>
or <command>apt-get</command> to update a &linux; system. In
&os;, &man.freebsd-update.8; can be used fetch new binary
updates and install them. These updates can be scheduled using
&man.cron.8;.</para>
<note>
<para>When using &man.cron.8; to schedule updates, use
<command>freebsd-update cron</command> in the &man.crontab.1;
to reduce the possibility of a large number of machines all
pulling updates at the same time:</para>
<programlisting>0 3 * * * root /usr/sbin/freebsd-update cron</programlisting>
</note>
<para>For more information on source and binary updates, refer to
<link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/updating-upgrading.html">the
chapter on updating</link> in the &os; Handbook.</para>
</sect1>
<sect1 xml:id="procfs">
<title>procfs: Gone But Not Forgotten</title>
<para>In some &linux; distributions, one could look at
<filename>/proc/sys/net/ipv4/ip_forward</filename> to determine
if <acronym>IP</acronym> forwarding is enabled. In &os;,
&man.sysctl.8; is instead used to view this and other system
settings.</para>
<para>For example, use the following to determine if
<acronym>IP</acronym> forwarding is enabled on a &os;
system:</para>
<screen>&prompt.user; <userinput>sysctl net.inet.ip.forwarding</userinput>
net.inet.ip.forwarding: 0</screen>
<para>Use <option>-a</option> to list all the system
settings:</para>
<screen>&prompt.user; <userinput>sysctl -a | more</userinput></screen>
<para>If an application requires procfs, add the following entry
to <filename>/etc/fstab</filename>:</para>
<screen>proc /proc procfs rw,noauto 0 0</screen>
<para>Including <option>noauto</option> will prevent
<filename>/proc</filename> from being automatically mounted at
boot.</para>
<para>To mount the file system without rebooting:</para>
<screen>&prompt.root; <userinput>mount /proc</userinput></screen>
</sect1>
<sect1 xml:id="commands">
<title>Common Commands</title>
<para>Some common command equivalents are as follows:</para>
<para>
<informaltable frame="none" pgwide="1">
<tgroup cols="3">
<thead>
<row>
<entry>&linux; command (Red&nbsp;Hat/Debian)</entry>
<entry>&os; equivalent</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><command>yum install <replaceable>package</replaceable></command> /
<command>apt-get install <replaceable>package</replaceable></command></entry>
<entry><command>pkg install <replaceable>package</replaceable></command></entry>
<entry>Install package from remote repository</entry>
</row>
<row>
<entry><command>rpm -ivh <replaceable>package</replaceable></command>
/ <command>dpkg -i <replaceable>package</replaceable></command></entry>
<entry><command>pkg add <replaceable>package</replaceable></command></entry>
<entry>Install local package</entry>
</row>
<row>
<entry><command>rpm -qa</command>
/ <command>dpkg -l</command></entry>
<entry><command>pkg info</command></entry>
<entry>List installed packages</entry>
</row>
<row>
<entry><command>lspci</command></entry>
<entry><command>pciconf</command></entry>
<entry>List <acronym>PCI</acronym> devices</entry>
</row>
<row>
<entry><command>lsmod</command></entry>
<entry><command>kldstat</command></entry>
<entry>List loaded kernel modules</entry>
</row>
<row>
<entry><command>modprobe</command></entry>
<entry><command>kldload</command>
/ <command>kldunload</command></entry>
<entry>Load/Unload kernel modules</entry>
</row>
<row>
<entry><command>strace</command></entry>
<entry><command>truss</command></entry>
<entry>Trace system calls</entry>
</row>
</tbody>
</tgroup>
</informaltable></para>
</sect1>
<sect1 xml:id="conclusion">
<title>Conclusion</title>
<para>This document has provided an overview of &os;. Refer to
the <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/index.html">&os;&nbsp;Handbook</link>
for more in-depth coverage of these topics as well as the many
topics not covered by this document.</para>
</sect1>
</article>