<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>3 | FreeBSD Foundation</title>
	<atom:link href="https://staging.freebsdfoundation.org/difficulty-level/3/feed/" rel="self" type="application/rss+xml" />
	<link>https://staging.freebsdfoundation.org</link>
	<description>A non-profit organization dedicated to supporting and building the FreeBSD Project</description>
	<lastBuildDate>Tue, 21 May 2024 21:23:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://staging.freebsdfoundation.org/wp-content/uploads/2015/12/favicon.png</url>
	<title>3 | FreeBSD Foundation</title>
	<link>https://staging.freebsdfoundation.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to use VS Code on FreeBSD</title>
		<link>https://staging.freebsdfoundation.org/resource/how-to-use-vs-code-on-freebsd/</link>
		
		<dc:creator><![CDATA[Anne Dickison]]></dc:creator>
		<pubDate>Fri, 10 May 2024 16:00:38 +0000</pubDate>
				<guid isPermaLink="false">https://freebsdfoundation.org/?post_type=resource&#038;p=14846</guid>

					<description><![CDATA[<p>Visual Studio Code (VS Code) is a source-code editor developed by Microsoft for Windows, Linux, and macOS. Through the extensive work of the FreeBSD community, it has also been ported to FreeBSD and can be installed through binary packages. Setting up VS Code is simple and quick, and can be done from a fresh FreeBSD [&#8230;]</p>
<p>The post <a href="https://staging.freebsdfoundation.org/resource/how-to-use-vs-code-on-freebsd/">How to use VS Code on FreeBSD</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></description>
										<content:encoded><![CDATA[<section class="block block-classic-editor"><p></section><section class="block block-core-paragraph"></p>
<p>Visual Studio Code (VS Code) is a source-code editor developed by Microsoft for Windows, Linux, and macOS. Through the extensive work of the FreeBSD community, it has also been ported to FreeBSD and can be installed through binary packages. Setting up VS Code is simple and quick, and can be done from a fresh FreeBSD install.</p>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="alignright size-full is-resized"><img decoding="async" class="wp-image-14841 alignright" src="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/vscode-logo.png" alt="" width="197" height="197" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/vscode-logo.png 360w, https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/vscode-logo-300x300.png 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/vscode-logo-150x150.png 150w" sizes="(max-width: 197px) 100vw, 197px" /></figure>
<p></section></div>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading"><strong>Requirements:</strong></h4>
<h4></section>
<section class="block block-core-list"></h4>
<ul class="wp-block-list"><section class="block block-core-list-item">
	<li>
<p>FreeBSD running on amd64 architecture</p>
</li>
</section>
<section class="block block-core-list-item">
	<li>
<p>A desktop environment (<a href="https://staging.freebsdfoundation.org/resource/installing-a-desktop-environment-on-freebsd/">Refer to this guide to set up XFCE on your system</a>)</p>
</li>
</section></ul>
<p></section>
<section class="block block-core-heading"></p>
<p>&nbsp;</p>
<h2 class="wp-block-heading"><strong>Installation and Configuration:</strong></h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Install the VS Code binary package:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p class="has-black-color has-text-color has-link-color wp-elements-df0f7fbb3c617d84ded29c1db5127939"><code>$ su</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># pkg install vscode</code></p>
<p></section>
<section class="block block-uagb-inline-notice"></p>
<div class="wp-block-uagb-inline-notice uagb-inline_notice__align-left uagb-block-37ee6d57"><button class="uagb-notice-close-button" type="button" aria-label="Close"></button>
<p class="uagb-notice-title">Note: As of this guide being written, Electron is blacklisted from the package builder. As this is a dependency of the vscode package, this may mean you will have to build VS Code from the ports collection:</p>
<div class="uagb-notice-text"><code># pkg install git<br />
# git clone https://git.FreeBSD.org/ports.git /usr/ports<br />
# git -C /usr/ports pull<br />
# cd /usr/ports/editors/vscode<br />
# make install clean</code></div>
</div>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Exit the su root shell:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># exit</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>VS Code can be run directly from the terminal:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code>$ vscode</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Additional language extensions can be installed directly through the VS Code application. Browse the available options through the “Extensions” button on the left of the client.</p>
<p></section>
<section class="block block-uagb-inline-notice"></p>
<div class="wp-block-uagb-inline-notice uagb-inline_notice__align-left uagb-block-fa45ad1b"><button class="uagb-notice-close-button" type="button" aria-label="Close"></button>
<p class="uagb-notice-title">Note: Check the file locations where VS Code is configured to find them. rust-analyzer, for instance, will give an error because the VS Code extension searches a different file than where it is stored on FreeBSD. To quickly fix this issue:</p>
<div class="uagb-notice-text"><code>$ whereis rust-analyzer <br />
rust-analyzer: /usr/local/bin/rust-analyzer</code><br />
<br />
Navigate to the VSCode settings gear in the bottom left and open the .json settings file.<br />
<img decoding="async" src="https://lh7-us.googleusercontent.com/CfAZ7jPnzTgZJR-_Kk0uRuycWRxmcrGqw4xm7yH0cDNQIbH2D3s_rqNP5zA8Dlonf_MH-6zEz-54W9zZHBBl4Ya6pp1n8aq4uabjPzwyhUNG2SaDsK_U6haI0X9X_1YUaEsWqUTIHAXAVjJb_46_4A" alt="" /><br />
<br />
Add the correct path to the rust binary:<br />
&#8220;rust-analyzer.server.path&#8221;: &#8220;/usr/local/bin/rust-analyzer&#8221;<br />
<img decoding="async" src="https://lh7-us.googleusercontent.com/N5I-l5c5FPw_pNT9eufWe6zqAm-xox-95e14pYawGlVkuYoOK1-ZrMf6Jl7YOrMlC5xjevyfyYKkNSENY_tb1YnfUAgnvrz1QE7uF3Kc52YpmCRmqFq6GP0oCC7Ju8eLuMfogMxZdbRNkg9kPqkasA" alt="" /></div>
</div>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Using VS Code:</strong></h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Let’s use VS Code to create a simple “hello world” script using Python:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Start by creating and opening a folder, either using the dropdown menu under ‘File’ or on the welcome page. Click “Create Folder” at the top right of the client. We’ll store the text files we create here. Once opened, VS Code will show the empty folder in the “Explorer” section.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Create a new file in this folder, VS Code will ask for either a file type or file name. In this example, I named it PythonTest.py. </p>
<p></section>
<section class="block block-core-image"></p>
<p><img fetchpriority="high" decoding="async" class="alignnone  wp-image-14850" src="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-095622.png" alt="" width="995" height="144" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-095622.png 594w, https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-095622-300x43.png 300w" sizes="(max-width: 995px) 100vw, 995px" /></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>VS Code will correctly identify the file as Python, but further support will be needed to provide IntelliSense (code auto-completion and quick info), formatting, and debugging.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Navigate to the ‘Extensions’ tab on the left of the client, and install the ‘Python’ language support extension.</p>
<p></section>
<section class="block block-core-image"></p>
<p><img decoding="async" class="alignnone  wp-image-14849" src="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-100003.png" alt="" width="1004" height="363" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-100003.png 838w, https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-100003-300x108.png 300w" sizes="(max-width: 1004px) 100vw, 1004px" /></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Now when we try to type a simple print command in the Python file we created, VS Code will autocomplete and show error messages</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Type a simple hello world command:</p>
<p></section>
<section class="block block-core-image"></p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-14851" src="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-101709.png" alt="" width="1004" height="199" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-101709.png 560w, https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-101709-300x59.png 300w" sizes="(max-width: 1004px) 100vw, 1004px" /></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Save your changes under ‘File’.</p>
<p></section>
<section class="block block-uagb-inline-notice"></p>
<div class="wp-block-uagb-inline-notice uagb-inline_notice__align-left uagb-block-d1dd1418"><button class="uagb-notice-close-button" type="button" aria-label="Close"></button>
<p class="uagb-notice-title">Tip: Enable ‘Auto Save’ so you don’t have to manually save each time changes are made.</p>
</div>
<p></section>
<section class="block block-core-paragraph"></p>
<p>&nbsp;</p>
<p>Then, run and debug the file. Either by pressing ‘F5’ or selecting ‘Run Python File’ at the top right of the client.</p>
<p></section>
<section class="block block-core-image"></p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-14852" src="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-101348.png" alt="" width="1011" height="320" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-101348.png 708w, https://staging.freebsdfoundation.org/wp-content/uploads/2024/05/Screenshot-2024-04-22-101348-300x95.png 300w" sizes="(max-width: 1011px) 100vw, 1011px" /></p>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Troubleshooting VS Code:</strong></h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>While this guide aims to be as broad as possible, users may still run into issues when installing the vscode package. There&#8217;s a wide range of possible errors, from unsupported packages to known bugs to unsupported hardware.</p>
<p></section>
<section class="block block-uagb-inline-notice"></p>
<div class="wp-block-uagb-inline-notice uagb-inline_notice__align-left uagb-block-5ed2f9eb"><button class="uagb-notice-close-button" type="button" aria-label="Close"></button>
<p class="uagb-notice-title">Note: The vscode port is currently only supported for the amd64 architecture; if you run into an error mentioning unsupported architecture, confirm that the system is amd64:</p>
<div class="uagb-notice-text"><code>$ uname -a</code></div>
</div>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-paragraph"></p>
<p>1. Search the <a href="https://bugs.freebsd.org/bugzilla/query.cgi?format=advanced">Problem Report (PR) database</a> for known fixes pending implementation. This is also useful to find existing bugs that other users have encountered.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>2. If none of the above works, contact the port maintainer directly. Port maintainers are listed at the top of the <a href="https://www.freshports.org/editors/vscode/">FreshPorts page</a>. An easy way to get visibility on an issue is to post to the <a href="https://lists.freebsd.org/subscription/freebsd-ports">freebsd-ports mailing list</a> and CC the maintainer. Ask if they know of any issues and include the output before the error. </p>
<p></section><section class="block block-classic-editor"></p></section><p>The post <a href="https://staging.freebsdfoundation.org/resource/how-to-use-vs-code-on-freebsd/">How to use VS Code on FreeBSD</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>An Introduction to Packet Filter (PF)</title>
		<link>https://staging.freebsdfoundation.org/resource/an-introduction-to-packet-filter-pf/</link>
		
		<dc:creator><![CDATA[Anne Dickison]]></dc:creator>
		<pubDate>Tue, 12 Sep 2023 19:35:40 +0000</pubDate>
				<guid isPermaLink="false">https://freebsdfoundation.org/?post_type=resource&#038;p=12822</guid>

					<description><![CDATA[<p>Packet Filter, also known as PF or pf, is a BSD-licensed stateful packet filter used to filter TCP/IP traffic and perform Network Address Translation (NAT.) Originally created by OpenBSD, PF has been ported to FreeBSD since 5.3-RELEASE. PF can identify where a packet should be directed or if it should even be allowed through; this [&#8230;]</p>
<p>The post <a href="https://staging.freebsdfoundation.org/resource/an-introduction-to-packet-filter-pf/">An Introduction to Packet Filter (PF)</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></description>
										<content:encoded><![CDATA[<section class="block block-classic-editor">
<p>Packet Filter, also known as PF or pf, is a BSD-licensed stateful packet filter used to filter TCP/IP traffic and perform Network Address Translation (NAT.) Originally created by OpenBSD, PF has been ported to FreeBSD since 5.3-RELEASE.</p>
<p>PF can identify where a packet should be directed or if it should even be allowed through; this can be decided based on the source and destination of that individual packet. PF can detect and block traffic you want to keep out of or in the local network. The firewall is highly flexible and even offers bandwidth management and packet priority.</p>
<p><img loading="lazy" decoding="async" class="wp-image-12964  aligncenter" src="https://staging.freebsdfoundation.org/wp-content/uploads/2023/09/Untitled-design-43-1024x1024.png" alt="" width="448" height="448" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2023/09/Untitled-design-43-1024x1024.png 1024w, https://staging.freebsdfoundation.org/wp-content/uploads/2023/09/Untitled-design-43-300x300.png 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2023/09/Untitled-design-43-150x150.png 150w, https://staging.freebsdfoundation.org/wp-content/uploads/2023/09/Untitled-design-43-1536x1536.png 1536w, https://staging.freebsdfoundation.org/wp-content/uploads/2023/09/Untitled-design-43-2048x2048.png 2048w" sizes="(max-width: 448px) 100vw, 448px" /></p>
<h2>1 . Enabling PF</h2>
<p>PF relies on its kernel module, this must be enabled through <code>/etc/rc.conf</code> to start PF:</p>
<p><code># sysrc pf_enable=yes<br />
</code><br />
Additional options can be enabled when PF is started, this can be done by adding the following line to <code>/etc/rc.conf.</code> Required flags can later be specified between the two quotes(&#8220;&#8221;):</p>
<p><code>pf_flags="" # additional flags for pfctl startup</code></p>
<p>To start, PF will need to find its ruleset configuration file. FreeBSD does not ship with a ruleset or /etc/pf.conf. Custom rulesets can be used by specifying the path in <code>/etc/rc.conf</code></p>
<p><code>pf_rules="/path/to/pf.conf"</code><br />
<em><br />
</em>Logging support for PF is provided by <code>pflog(4)</code>. To enable logging support, add <code>pflog_enable=yes</code> to <code>/etc/rc.conf</code>:</p>
<p><code># sysrc pflog_enable=yes</code></p>
<p>The following lines can also be added to change the default location of the log file or to specify any additional flags to pass to pflog(4) when it is started:</p>
<p><code>pflog_logfile="/var/log/pflog" # where pflogd should store the logfile</code><br />
<code>pflog_flags="" # additional flags for pflogd startup</code></p>
<p>The following option will enable NAT if there is a LAN behind the firewall:</p>
<p><code>gateway_enable="YES"</code></p>
<p>PF can now be started with logging support:</p>
<p><code># service pf start</code><br />
<code># service pflog start</code></p>
<p>&nbsp;</p>
<h2>2. Using pfctl</h2>
<p>PF can be controlled using pfctl, refer to pfctl(8) for a description of all available options. Here are some of the more common pfctl options:</p>
<table style="border-collapse: collapse; width: 100%;" border="1">
<tbody>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px;"><code>pfctl -e</code></td>
<td style="width: 50%; height: 24px;">Enable PF.</td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px;"><code>pfctl -d</code></td>
<td style="width: 50%; height: 24px;">Disable PF.</td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px;"><code>pfctl -F all -f /etc/pf.conf</code></td>
<td style="width: 50%; height: 24px;">Flush all NAT, filter, state, and table rules and reload <code>/etc/pf.conf.</code></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px;"><code>pfctl -s [ rules | nat | states ]</code></td>
<td style="width: 50%; height: 24px;">Report on the filter rules, NAT rules, or state table.</td>
</tr>
<tr style="height: 23px;">
<td style="width: 50%; height: 23px;"><code>pfctl -vnf /etc/pf.conf</code></td>
<td style="width: 50%; height: 23px;">Checks <code>/etc/pf.conf</code> for errors, but does not load ruleset.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h2>3. Creating a Base PF Ruleset</h2>
<p>PF depends on a ruleset, which can be customized to best serve any system. Creating a base ruleset is the first step in customizing your firewall that can be further augmented and specified. Create the ruleset in</p>
<p>Start by creating a simple ruleset that applies to only a single machine, relies on one network, and does not run services:</p>
<div class="literalblock programlisting">
<div class="content">
<p><code>block in all</code></p>
<p><code>pass out all keep state</code></p>
</div>
</div>
<div class="paragraph">
<p>This rule will deny all incoming traffic, while the second rule allows connections created by this system to pass out while retaining state information on those connections. Load this new ruleset with the following:</p>
</div>
<div class="listingblock">
<div class="content">
<p class="rouge highlight"><code data-lang="shell"><span class="c"># pfctl -e ; pfctl -f /etc/pf.conf</span></code></p>
</div>
</div>
<div class="paragraph">
<p>In addition to keeping state, PF provides lists and macros that can be defined when creating rules. Macros can include lists and need to be defined before use. As an example, insert these lines at the very top of the ruleset:</p>
</div>
<div class="literalblock programlisting">
<div class="content">
<p><code>tcp_services = "{ ssh, smtp, domain, www, pop3, auth, pop3s }"</code></p>
<p><code>udp_services = "{ domain }"</code></p>
</div>
</div>
<div class="paragraph">
<p>PF can use port names and numbers if the names are listed in <code><span class="filename">/etc/services</span></code>. In this example, all traffic is blocked except for the connections initiated by this system for the seven specified TCP services and the one specified UDP service:</p>
</div>
<div class="literalblock programlisting">
<pre><code>tcp_services = "{ ssh, smtp, domain, www, pop3, auth, pop3s }"
udp_services = "{ domain }"
block all</code> <code>pass out proto tcp to any port $tcp_services keep state
pass proto udp to any port $udp_services keep state</code></pre>
<p>Next, at the top of your ruleset, create a set skip rule for the loopback device because it does not need to filter traffic and would likely bring your server to a crawl. </p>
<p class="content"><code>set skip on lo0</code></p>
<p class="content">Finally, add a <code>pass out inet</code> rule for the ICMP protocol, which allows you to use the ping(8) utility for troubleshooting</p>
<p class="content"><code>pass out inet proto icmp icmp-type { echoreq }</code></p>
<p class="content">The ruleset should now resemble the following: </p>
<pre><code>set skip on lo0
tcp_services = "{ ssh, smtp, domain, www, pop3, auth, pop3s }"
udp_services = "{ domain }"
block all</code><code>
pass out proto tcp to any port $tcp_services keep state
pass proto udp to any port $udp_services keep state
pass out inet proto icmp icmp-type { echoreq }</code></pre>
</div>
<div class="paragraph">
<p>After each edit, the ruleset needs to be loaded again:</p>
</div>
<div class="listingblock">
<div class="content">
<p class="rouge highlight"><code data-lang="shell"><span class="c"># pfctl -f /etc/pf.conf</span></code></p>
</div>
</div>
<div class="paragraph">
<p><code>pfctl</code> will not output any messages unless there are syntax errors that will need to be fixed. During the rule load, instead of loading the ruleset, a test can be run with:</p>
</div>
<div class="listingblock">
<div class="content">
<p class="rouge highlight"><code data-lang="shell"><span class="c"># pfctl -nf /etc/pf.conf</span></code></p>
<div class="copy-to-clipboard-wrapper">Including <code>-n</code> causes the rules to be interpreted only but not loaded. This provides an opportunity to correct any errors. The last valid ruleset loaded will be enforced until either PF is disabled or a new ruleset is loaded.</div>
</div>
</div>
<p>&nbsp;</p>
<h2>4. Testing Your Base Ruleset</h2>
<p>Testing your ruleset between major edits is crucial to ensure that PF functions properly. </p>
<p>First test for internet connectivity and DNS service:</p>
<p><code># ping -c 3 google.com</code></p>
<p>Check that the <code>pkgs</code> repository can be reached: </p>
<p><code># pkg upgrade</code></p>
<p>And finally, reboot:</p>
<p><code># reboot</code></p>
<p>Give your server a few minutes to reboot. Next, you will expand the ruleset with more advanced features to see some possible applications of the PF ruleset.</p>
<h2>5. Example Rulesets and Their Application</h2>
<p>Now that you have created a base ruleset, the base ruleset can be built upon for more advanced PF functions. While this guide won&#8217;t cover every possible function or customization, these basic rulesets may be helpful for your system, or offer insight into how PF may be used. After each example, make sure to test the base ruleset.</p>
<h3 style="padding-left: 40px;">5.1 Blocking Spoofed Packets</h3>
<p style="padding-left: 40px;">Address spoofing is a method where an outside user forges the source IP of sent packets to conceal the actual address, essentially impersonating another internet node. This opens the door for a network attack that does not disclose where it&#8217;s originating.</p>
<p style="padding-left: 40px;">The antispoof PF keyword can help protect against spoof packets:</p>
<p style="padding-left: 40px;"><code>antispoof [log] [quick] for interface [af]</code></p>
<p style="padding-left: 40px;"><code><strong>log</strong></code>: Specifies that packets matching the criteria should be reported by pflogd (8).<br />
<code><strong>quick</strong></code>: This ensured that if a packet meets this rules, examination of the ruleset will cease.<br />
<code><strong>interface</strong></code>: Specify the specific network where spoofing protection will be activated.<br />
<code><strong>af</strong></code>: Address family (i.e., inet or inet6 for IPv4 and IPv6)</p>
<p style="padding-left: 40px;">The most basic way to weed out spoofed traffic coming in from external sources, as well as any spoofed packets that originate in the local network:</p>
<p style="padding-left: 40px;"><code>antispoof for $ext_if</code><br />
<code>antispoof for $int_if</code></p>
<p style="padding-left: 40px;"> </p>
<h3 style="padding-left: 40px;">5.2 Protecting SSH Ports</h3>
<p style="padding-left: 40px;">A typical exploit is to target SSH ports, which are open to the public. This is often done with brute force attacks and can succeed if the server has weak passwords. PF has built-in features that help deal with brute-force attacks. PF can limit the simultaneous connection attempts a single host allows. Once a host exceeds this number, the connection will be dropped, and they will be banned from the server. PF&#8217;s overload mechanism has a table of banned IP addresses.</p>
<p style="padding-left: 40px;">Modify your previous base ruleset to limit simultaneous connections from a single host:</p>
<p style="padding-left: 40px;"><code>pass in on $vtnet0 proto tcp to port { 22 } \</code></p>
<p style="padding-left: 80px;"><code>keep state (max-src-conn 15, max-src-conn-rate 3/1, \</code></p>
<p style="padding-left: 120px;"><code>overload &lt;bruteforce&gt; flush global)</code></p>
<p style="padding-left: 40px;"><code><strong>keep state</strong></code>: Allows you to define the state criteria for the overload table. <br />
<code><strong>max-src-conn</strong>:</code> Specifies the number of simultaneous connections allowed from a single host per second.<br />
<code><strong>max-src-conn-rate</strong>:</code> Specifies the number of new connections allowed from a single host per second.</p>
<p style="padding-left: 40px;">If any host exceeds the specified limits, the PF overload mechanism will add the source IP to the <code>&lt;bruteforce&gt;</code> table. If a host exceeds these limits, the overload mechanism adds the source IP to the <code>&lt;bruteforce&gt;</code> table, which bans them from the server. The connection will immediately be dropped due to the flush global parameter. </p>
<p style="padding-left: 40px;">Before this ruleset can be loaded, the table you defined needs to be declared in the ruleset: </p>
<p style="padding-left: 40px;">Specify the <code>&lt;bruteforce&gt;</code> table underneath the previous <code>icmp_types</code> macro</p>
<p style="padding-left: 40px;"><code>icmp_types = "{ echoreq }"</code></p>
<p style="padding-left: 80px;"><code>table &lt;bruteforce&gt; persist</code></p>
<p style="padding-left: 40px;">The persist keyword allows an empty table to exist in the ruleset. Without it, PF will complain that there are no IP addresses in the table.</p>
<h3 style="padding-left: 40px;">5.3 Handling Non-Routable Addresses</h3>
<p style="padding-left: 40px;">As much as you can properly configure your system to be precise, some configuration may be needed to compensate for other people&#8217;s misconfigurations. One common mistake is to let traffic with non-routable addresses out to the Internet. Since non-routable addresses can be used in DoS attacks, consider blocking this traffic from entering the network.</p>
<p style="padding-left: 40px;">Define a macro containing non-routable addresses, then use it in blocking rules. Traffic to and from these addresses is dropped on the gateway’s external interface.</p>
<p style="padding-left: 40px;">
<code>external = "{ 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, \</code><br />
<code>      10.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24, \</code><br />
<code>      0.0.0.0/8, 240.0.0.0/4 }"</code></p>
<p style="padding-left: 40px;"><code>block drop in quick on $ext_if from $external to any</code><br />
<code>block drop out quick on $ext_if from any to $external</code></p>
<p>
</p>
<h2>6. Viewing PF Logs</h2>
<p>To view PF logs:</p>
<p><code>tcpdump -n -e -ttt -r /var/log/pflog</code></p>
<p>To view logs in real-time from the pflog0 interface, run the following command:</p>
<p><code>tcpdump -n -e -ttt -i pflog0</code></p>
<p>The pftop utility is a tool for quickly viewing firewall activity in real-time; it can be installed and started with:</p>
<p><code>pkg install pftop</code></p>
<p><code>pftop</code></p>
</section><p>The post <a href="https://staging.freebsdfoundation.org/resource/an-introduction-to-packet-filter-pf/">An Introduction to Packet Filter (PF)</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>An Introduction to ZFS</title>
		<link>https://staging.freebsdfoundation.org/resource/an-introduction-to-the-z-file-system/</link>
		
		<dc:creator><![CDATA[Anne Dickison]]></dc:creator>
		<pubDate>Sun, 22 Jan 2023 15:20:05 +0000</pubDate>
				<guid isPermaLink="false">https://freebsdfoundation.org/?post_type=resource&#038;p=11875</guid>

					<description><![CDATA[<p>ZFS combines the roles of volume manager and independent file system into one, giving multiple advantages over a stand-alone file system. It is renowned for speed, flexibility, and, most importantly, taking great care to prevent data loss.</p>
<p>The post <a href="https://staging.freebsdfoundation.org/resource/an-introduction-to-the-z-file-system/">An Introduction to ZFS</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></description>
										<content:encoded><![CDATA[<section class="block block-classic-editor"><p></section><section class="block block-core-paragraph"></p>
<p>ZFS combines the roles of volume manager and independent file system into one, giving multiple advantages over a stand-alone file system. It is renowned for speed, flexibility, and, most importantly, taking great care to prevent data loss. While many traditional file systems had to exist on a single disk at a time, ZFS is aware of the underlying structure of the disks and creates a pool of available storage, even on multiple disks. The existing file system will grow automatically when extra disks are added to the pool, immediately becoming available to the file system.</p>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" class="wp-image-11796 aligncenter" src="https://staging.freebsdfoundation.org/wp-content/uploads/2022/10/OpenZFS_logo.svg-1024x933.png" alt="" width="215" height="196" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2022/10/OpenZFS_logo.svg-1024x933.png 1024w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/10/OpenZFS_logo.svg-300x273.png 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/10/OpenZFS_logo.svg.png 1200w" sizes="(max-width: 215px) 100vw, 215px" /></figure>
<p></section></div>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading" id="zfs-quickstart">Getting Started</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>FreeBSD can mount ZFS pools and datasets during system initialization. To enable it, add this line to /etc/rc.conf:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">zfs_enable="YES"</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Then start the service:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># service zfs start</code></pre>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="has-text-align-left wp-block-heading">Identify Hardware</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Before setting up ZFS, identify the device names of the disk associated with the system. A quick way of doing this is with:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><code># egrep 'da[0-9]|cd[0-9]' /var/run/dmesg.boot</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The output should identify the device names, examples throughout the rest of this guide will use the default SCSI names: da0, da1, and da2. If the hardware differs, make sure to use the correct device names instead.</p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading" id="zfs-quickstart-single-disk-pool">Creating a Single Disk Pool</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To create a simple, non-redundant pool using a single disk device:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool create example /dev/da0</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To create files for users to browse within the pool:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># cd /example
# ls
# touch testfile</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The new file can be viewed using <code>ls</code>:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><code># ls -al</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>We can already start using more advanced ZFS features and properties. To create a dataset within the pool with compression enabled:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs create example/compressed
# zfs set compression=on example/compressed</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The <code>example/compressed</code> dataset is now a ZFS compressed file system.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Disable compression with:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs set compression=off example/compressed</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To unmount a file system, use <code>zfs umount</code> and then verify with <code>df</code>:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs umount example/compressed
# df</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Verify that <code>example/compressed</code> is not included as a mounted file under the output.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The file system can be re-mounted with zfs:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs mount example/compressed
# df</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>With the file system mounted, the output should include a line similar to the one below:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><code>example/compressed 17547008 0 17547008 0% /example/compressed</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>ZFS datasets are created just like any other file system, the following example creates a new file system called <code>data</code>:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs create example/data</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Use <code>df</code> to see the data and space usage (some of the output has been removed for clarity)</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># df
                                 . . . 
example/compressed  17547008       0 17547008     0%    /example/compressed
example/data        17547008       0 17547008     0%    /example/data</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Because these file systems are built on ZFS, they draw from the same pool for storage. This eliminates the need for volumes and partitions that other file systems rely on.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To destroy the file systems and then the pool that is no longer needed:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs destroy example/compressed
# zfs destroy example/data
# zpool destroy example</code></pre>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading" id="zfs-quickstart-raid-z">RAID-Z</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>RAID-Z pools require three or more disks but offer protection from data loss if a disk were to fail. Because the ZFS pools can use multiple disks, support for RAID is inherent in the design of the file system</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To create a RAID-Z pool, specifying the disks to add to the pool:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool create storage raidz da0 da1 da2</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>With the zpool created, a new file system can be made in that pool:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs create storage/home</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Enable compression and store an extra copy of directories and files:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs set copies=2 storage/home
# zfs set compression=gzip storage/home</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>A RAID-Z pool is a great place to store crucial system files, such as the home directory for users. To make the file system the home new home directory :</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># cp -rp /home/* /storage/home
# rm -rf /home /usr/home
# ln -s /storage/home /home
# ln -s /storage/home /usr/home</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>File system snapshots can be created to roll back to later, the snapshot name is marked in red and can be whatever you want:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs snapshot storage/home@<mark class="has-inline-color has-vivid-red-color">11-01-22</mark></code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>ZFS creates snapshots of a dataset, allowing users to back up a file system for roll backs or data recovery in the future.</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs rollback storage/home@<mark class="has-inline-color has-vivid-red-color">11-01-22</mark></code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To list all available snapshots, <code>zfs list</code> can be used:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zfs list -t snapshot storage/home</code></pre>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading" id="zfs-quickstart-recovering-raid-z">Recovering RAID-Z</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Every software RAID has a method of monitoring its <code>state</code>. View the status of RAID-Z devices using:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool status -x</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>If all pools are Online and everything is normal, the message shows:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code>all pools are healthy</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>If there is a problem, perhaps a disk being in the Offline state, the pool state will look like this:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code>  pool: storage
 state: DEGRADED
status: One or more devices has been taken offline by the administrator.
	Sufficient replicas exist for the pool to continue functioning in a
	degraded state.
action: Online the device using 'zpool online' or replace the device with
	'zpool replace'.
 scrub: none requested
config:

	NAME        STATE     READ WRITE CKSUM
	storage     DEGRADED     0     0     0
	  raidz1    DEGRADED     0     0     0
	    da0     ONLINE       0     0     0
	    da1     OFFLINE      0     0     0
	    da2     ONLINE       0     0     0

errors: No known data errors</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>&#8220;OFFLINE&#8221; shows the administrator took da1 offline using:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool offline storage da1</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Power down the computer now and replace da1. Power up the computer and return da1 to the pool:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool replace storage da1</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Next, check the status again, this time without <code>-x</code> to display all pools:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool status storage
 pool: storage
 state: ONLINE
 scrub: resilver completed with 0 errors on Fri Nov 4 11:12:03 2022
config:

	NAME        STATE     READ WRITE CKSUM
	storage     ONLINE       0     0     0
	  raidz1    ONLINE       0     0     0
	    da0     ONLINE       0     0     0
	    da1     ONLINE       0     0     0
	    da2     ONLINE       0     0     0

errors: No known data errors</code></pre>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading" id="zfs-quickstart-data-verification">Data Verification</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>ZFS uses checksums to verify the integrity of stored data, these data checksums can be verified (which is called <em>scrubbing</em>) to ensure integrity of the storage pool:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool scrub storage</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Only one scrub can be run at a time due to the heavy input/output requirements. The length of the scrub depends on how much data is store in the pool.After scrubbing completes, view the status with <code>zpool status</code>:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># zpool status storage
 pool: storage
 state: ONLINE
 scrub: scrub completed with 0 errors on Fri Nov 4 11:19:52 2022
config:

	NAME        STATE     READ WRITE CKSUM
	storage     ONLINE       0     0     0
	  raidz1    ONLINE       0     0     0
	    da0     ONLINE       0     0     0
	    da1     ONLINE       0     0     0
	    da2     ONLINE       0     0     0

errors: No known data errors</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Displaying the completion date of the last scrubbing helps decide when to start another. Routine scrubs help protect data from silent corruption and ensure the integrity of the pool.</p>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">ZFS Administration</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>ZFS has two main utilities for administration: The <code>zpool</code> utility controls the operation of the pool and allows adding, removing, replacing, and managing disks. The <a href="https://docs.freebsd.org/en/books/handbook/zfs/#zfs-zfs"><code>zfs</code></a> utility allows creating, destroying, and managing datasets, both file systems and volumes.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>While this introductory guide won&#8217;t cover ZFS administration, you can refer to <a href="https://www.freebsd.org/cgi/man.cgi?query=zfs&amp;sektion=8&amp;format=html">zfs(8)</a> and <a href="https://www.freebsd.org/cgi/man.cgi?query=zpool&amp;sektion=8&amp;format=html">zpool(8)</a> for other ZFS options.</p>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Further Resources</h2>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li><a href="https://openzfs.org/">OpenZFS</a></li>
	<li><a href="https://wiki.freebsd.org/ZFSTuningGuide">FreeBSD Wiki &#8211; ZFS Tuning</a></li>
	<li><a href="https://calomel.org/zfs_raid_speed_capacity.html">Calomel Blog &#8211; ZFS Raidz Performance, Capacity and Integrity</a></li>
</ul>
<p></section><section class="block block-classic-editor"></p></section><p>The post <a href="https://staging.freebsdfoundation.org/resource/an-introduction-to-the-z-file-system/">An Introduction to ZFS</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Video Playback on FreeBSD &#8211; Quick Guide</title>
		<link>https://staging.freebsdfoundation.org/resource/video-playback-on-freebsd-quick-guide/</link>
		
		<dc:creator><![CDATA[Anne Dickison]]></dc:creator>
		<pubDate>Thu, 01 Sep 2022 20:26:36 +0000</pubDate>
				<guid isPermaLink="false">https://freebsdfoundation.org/?post_type=resource&#038;p=11665</guid>

					<description><![CDATA[<p>In this guide, we&#8217;ll use the xine video player to set up basic video playback on a fresh FreeBSD install. The xine multimedia player relies on the XWindow system and the XVideo extension to provide a graphical video playback interface. System Requirements: Xorg supports a wide variety of video cards, but not all are supported [&#8230;]</p>
<p>The post <a href="https://staging.freebsdfoundation.org/resource/video-playback-on-freebsd-quick-guide/">Video Playback on FreeBSD – Quick Guide</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></description>
										<content:encoded><![CDATA[<section class="block block-classic-editor"><p></section><section class="block block-core-paragraph"></p>
<p>In this guide, we&#8217;ll use the xine video player to set up basic video playback on a fresh FreeBSD install. The xine multimedia player relies on the XWindow system and the XVideo extension to provide a graphical video playback interface.</p>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" class="wp-image-11627" src="https://staging.freebsdfoundation.org/wp-content/uploads/2022/08/Untitled-design-23-1024x576.png" alt="" width="840" height="472" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2022/08/Untitled-design-23-1024x576.png 1024w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/08/Untitled-design-23-300x169.png 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/08/Untitled-design-23-1536x864.png 1536w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/08/Untitled-design-23.png 1920w" sizes="(max-width: 840px) 100vw, 840px" /></figure>
<p></section></div>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">System Requirements:</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Xorg supports a wide variety of video cards, but not all are supported or offer good video playback performance.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>It is a good idea to have a short MPEG test file for evaluating various players and options. Since some <code>DVD</code> applications look for <code>DVD</code> media in /dev/dvd by default, or have this device name hardcoded in them, it might be useful to make a symbolic link to the proper device:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># ln -sf /dev/cd0 /dev/dvd</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Due to the nature of <a href="https://www.freebsd.org/cgi/man.cgi?query=devfs&amp;sektion=5&amp;format=html">devfs(5)</a>, manually created links will not persist after a system reboot. In order to recreate the symbolic link automatically when the system boots, add the following line to /etc/devfs.conf:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">link cd0 dvd</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>&nbsp;</p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading" id="video-interface">Installing Xorg</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>There are several possible ways to display video under Xorg and what works is largely hardware dependent. This guide will focus on the Xvideo extension which allows video to be directly displayed, even on low-end machines.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Start by installing the X Window System:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"># <code>pkg install -y xorg</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Once the package has been fully installed, the X Window System can be started with:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"># <code>startx</code></pre>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading" id="video-interface-xvideo">XVideo Support</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To check whether the Xvideo extension is running, use <code>xvinfo</code>:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><code>xvinfo</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>If XVideo is supported, the result will look similar to the example below and may include screen and video card information.</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code>X-Video Extension version 2.2
  screen #0
  Adaptor #0: "Example Engine"
    number of ports: 1
    port base: 43
     
       .   .    .</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>&nbsp;</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>XVideo is likely unsupported by the video card if the result instead look like:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code>X-Video Extension version 2.2
screen #0
no adaptors present</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The display may be unable to meet the demands of rendering video playback if XVideo is unsupported (though this is not always the case).</p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">The xine Video Player</h2>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="618" height="235" class="wp-image-11650" src="https://staging.freebsdfoundation.org/wp-content/uploads/2022/09/Screenshot-2022-09-01-154324.png" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2022/09/Screenshot-2022-09-01-154324.png 618w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/09/Screenshot-2022-09-01-154324-300x114.png 300w" sizes="(max-width: 618px) 100vw, 618px" /></figure>
<p></section></div>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-paragraph"></p>
<p>xine is a free multimedia player. It plays back CDs, DVDs, BluRays and VCDs. It also decodes multimedia files like AVI, MOV, WMV, and MP3 from local disk drives, and displays multimedia streamed over the Internet. Get started by installing the package:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><code># pkg install -y xine</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>In practice, xine requires either a fast CPU or support for the XVideo extension. The xine video player performs best on XVideo interfaces. If in the previous step, the Xvideo extension was unsupported, issues may occur.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The xine player starts a graphical user interface (GUI) and the menus can be used to navigate to multimedia files.</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><code># xine</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Alternatively, xine may be directly invoked from the command line by specifying the name of the file to play:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code># xine -g -p mymovie.avi</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>You now have a simple way to play a variety of multimedia files on your FreeBSD system! To find out more about the xine player, refer to the <a href="https://sourceforge.net/projects/xine/" target="_blank" rel="noreferrer noopener">SourceForge page</a>.</p>
<p></section><section class="block block-classic-editor"></p></section><p>The post <a href="https://staging.freebsdfoundation.org/resource/video-playback-on-freebsd-quick-guide/">Video Playback on FreeBSD – Quick Guide</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>An Introduction to FreeBSD Jails</title>
		<link>https://staging.freebsdfoundation.org/resource/an-introduction-to-freebsd-jails/</link>
		
		<dc:creator><![CDATA[Anne Dickison]]></dc:creator>
		<pubDate>Mon, 15 Aug 2022 18:29:21 +0000</pubDate>
				<guid isPermaLink="false">https://freebsdfoundation.org/?post_type=resource&#038;p=11563</guid>

					<description><![CDATA[<p>While the process creating a jail is quite simple, actual application and configuration requires a decent understanding of the FreeBSD operating system. This guide is aimed at people who are already familiar with the basics of the FreeBSD operating system.</p>
<p>The post <a href="https://staging.freebsdfoundation.org/resource/an-introduction-to-freebsd-jails/">An Introduction to FreeBSD Jails</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></description>
										<content:encoded><![CDATA[<section class="block block-classic-editor"><p></section><section class="block block-core-image"></p>
<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="512" class="wp-image-11016" src="https://staging.freebsdfoundation.org/wp-content/uploads/2022/03/Untitled-design-3-1024x512.png" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2022/03/Untitled-design-3-1024x512.png 1024w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/03/Untitled-design-3-300x150.png 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/03/Untitled-design-3-1536x768.png 1536w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/03/Untitled-design-3-2048x1024.png 2048w, https://staging.freebsdfoundation.org/wp-content/uploads/2022/03/Untitled-design-3.png 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">What are Jails?</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>Jails </em>were developed as a tool for system administrators to enhance the security of a FreeBSD system. Originally introduced in FreeBSD 4.0, jails continue to be an integral part of the development and progression of the FreeBSD operating system.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Jails were created to expand upon the <a href="https://www.freebsd.org/cgi/man.cgi?query=chroot&amp;sektion=2&amp;format=html">chroot(2)</a> concept, which is used to change the root directory of a set of processes. Jails create a safe environment independent from the rest of the system. Processes created in this environment cannot access files or resources outside of it. For this reason, compromising a service running in a jail will not compromise the entire system. Jails improved upon the <a href="https://www.freebsd.org/cgi/man.cgi?query=chroot&amp;sektion=2&amp;format=html">chroot(2)</a> concept by virtualizing access to the file system, users, and the networking subsystem.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>A jail is characterized by four elements:</p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>A <strong>directory subtree:</strong> the starting point from which a jail is entered. Once inside the jail, a process is not permitted to escape outside of this subtree.</li>
	<li>A <strong>hostname:</strong> which will be used by the jail.</li>
	<li>An <strong>IP address</strong>: which is assigned to the jail. The IP address of a jail is often an alias address for an existing network interface.</li>
	<li>A <strong>command</strong>: the path name of an executable to run inside the jail.</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p>While the theory is very simple and straightforward, it is important to note that creating a jail can quickly become extremely complex while leveraging systems and tools within the environment.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><strong>Note</strong>: Jails have their own set of users and their own <code>root</code> account which are limited to the jail environment. The <code>root</code> account of a jail is not allowed to perform operations to the system outside of the associated jail environment.</p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Examples of Jails</h2>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Jails are often used as test environments. Running a service or software in a jail allows developers to isolate and test updates or changes without jeopardizing the integrity of the rest of the system. This mitigates the risk of misconfiguration or mistakes. Developers also have the ability to run multiple instances or configurations at the same time without influencing each separate jailed process.</li>
</ul>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>In larger, more complex systems, jails can be used to split the system into separate jailed processes. Each jail could contain it&#8217;s own utilities and configurations, allowing for a much more streamlined system for specific tasks. Extremely complex processes can also be isolated to a jail, separate from the main system.</li>
</ul>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>A Jail can be used as a container for an old system, preserving critical infrastructure either as a backup, or as a way of referring to old code, all contained within a new system. This way, the old system can rely on the modern security and tools while being kept separate. This may be useful for developers who need to preserve a possibly insecure system without large changes needing to be made.</li>
</ul>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Jails are often used in place of a virtual machine, for either FreeBSD, or virtualization of another operating system such as Linux. Some developers looking to port tools and drivers to FreeBSD may find this useful.</li>
</ul>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Creating a Jail</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p><strong>Note:</strong> while the process creating a jail is quite simple, actual application and configuration requires a decent understanding of the FreeBSD operating system. This guide is aimed at people who are already familiar with the basics of the FreeBSD operating system.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Identify and create a directory for the jail. This is where the jail will physically reside within the file system of the jail’s host. A good choice can be <code>/usr/jail/jailname</code>, where <em><code>jailname</code></em> is the hostname identifying the jail. Usually, <code>/usr/ </code>has enough space for the jail file system, which for &#8220;complete&#8221; jails is, essentially, a replication of every file present in a default installation of the FreeBSD base system. In these following examples the directory will be <code>/usr/jail/myjail</code>.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The <a href="https://www.freebsd.org/cgi/man.cgi?query=bsdinstall&amp;sektion=8&amp;format=html" target="_blank" rel="noreferrer noopener">bsdinstall(8)</a> tool can be used to fetch and install the binaries needed for a jail. Distributions will be installed into the destination directory along with some basic configuration of the jail:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># cd /usr</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># mkdir myjail</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># bsdinstall jail /usr/jail/myjail</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code>bsdinstall </code>will then start the FreeBSD installation process using the installer.<br />
<br />
Once a jail is installed, it can be started by using the <a href="https://www.freebsd.org/cgi/man.cgi?query=jail&amp;sektion=8&amp;format=html">jail(8)</a> utility. The 4 elements listed earlier in the guide (directory subtree, hostname, IP address, and command) will serve as mandatory arguments for the utility, but other arguments may be specified too. The <code><em>command</em></code> argument depends on the type of the jail employed. For example, if a system requires the startup sequence, such as in the case of a virtual machine, specifying<code> /etc/rc.conf</code> under the command parameter will be ideal.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The FreeBSD <code>rc</code> mechanism provides an easy way to start jails on boot.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Configure specific jail parameters in <code>jail.conf</code>:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code>myjail { 
    host.hostname = myjail;                        # Set the hostname
    ip4.addr = 192.168.0.10;                       # Set an IP address of the jail 
    path = "/usr/jail/myjail";                     # Path to the jail 
    devfs_ruleset = "5";                           # devfs ruleset 
    mount.devfs;                                   # Mount devfs inside the jail 
    exec.start = "/bin/sh /etc/rc";                # Start command 
    exec.stop = "/bin/sh /etc/rc.shutdown";        # Stop command 
} </code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>A common configuration can also be used. This configuration will be shared by all jails that are not specifically set up like in the previous example:</p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code>host.hostname = "$name";                           # Set the hostname using the $name variable
ip4 = inherit;                                     # Inherit IP address from the host
path = "~/jail.$name";                             # Path to the jail
devfs_ruleset = $name_ruleset";                    # devfs ruleset
mount.devfs;                                       # Mount devfs inside the jail
exec.start = "/bin/sh /etc/rc";                    # Start command 
exec.stop = "/bin/sh /etc/rc.shutdown";            # Stop command 
</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><a href="https://www.freebsd.org/cgi/man.cgi?query=service&amp;sektion=8&amp;format=html">service(8)</a> can be used to start or stop a jail by hand if an entry for it exists in jail.conf:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># service jail start myjail <br />
# service jail stop myjail </code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>More information about this can be found in the <a href="https://www.freebsd.org/cgi/man.cgi?query=jail&amp;sektion=8&amp;format=html" target="_blank" rel="noreferrer noopener">jail(8)</a> manual page, including other arguments that can be set for the jail.</p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Further Configuration</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Fine tuning of a jail’s configuration is mostly done by setting <a href="https://www.freebsd.org/cgi/man.cgi?query=sysctl&amp;sektion=8&amp;format=html" target="_blank" rel="noreferrer noopener">sysctl(8)</a> variables. Here is a list of the main jail-related <code>sysctls</code>, complete with their default value. Please refer to the <a href="https://www.freebsd.org/cgi/man.cgi?query=jail&amp;sektion=8&amp;format=html" target="_blank" rel="noreferrer noopener">jail(8)</a> and <a href="https://www.freebsd.org/cgi/man.cgi?query=sysctl&amp;sektion=8&amp;format=html" target="_blank" rel="noreferrer noopener">sysctl(8)</a> manual pages for more information on each variable.</p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li><code>security.jail.set_hostname_allowed: 1</code></li>
	<li><code>security.jail.socket_unixiproute_only: 1</code></li>
	<li><code>security.jail.sysvipc_allowed: 0</code></li>
	<li><code>security.jail.enforce_statfs: 2</code></li>
	<li><code>security.jail.allow_raw_sockets: 0</code></li>
	<li><code>security.jail.chflags_allowed: 0</code></li>
	<li><code>security.jail.jailed: 0</code></li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p>These variables will need to be run by the host system system administrator and amend some limitations by default in the jail.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>FreeBSD also contains tools for viewing information on active jails and executing commands within the jail itself. The <a href="https://www.freebsd.org/cgi/man.cgi?query=jls&amp;sektion=8&amp;format=html" target="_blank" rel="noreferrer noopener">jls(8)</a> command can be used to list all active jails along with their identifier, hostname, path, and IP address. The <a href="https://www.freebsd.org/cgi/man.cgi?query=jexec&amp;sektion=8&amp;format=html" target="_blank" rel="noreferrer noopener">jexec(8</a>) command can attach to an active jail from the host system in order to run a command or perform administrative tasks. For example <a href="https://www.freebsd.org/cgi/man.cgi?query=jexec&amp;sektion=8&amp;format=html">jexec(8)</a> can be used to start a shell in an active jail with:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># jexec 1 sh</code></p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Updating/Removing a Jail</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Jails should be kept as up to date from the host operating system as possible. To update the jail to the latest patch release, execute the following commands on the host:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># freebsd-update -b  /usr/jail/myjail fetch <br />
# freebsd-update -b /usr/jail/myjail install</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To upgrade the jail to a new major or minor version, first upgrade the host system as described in <a href="https://docs.freebsd.org/en/books/handbook/cutting-edge/index.html#freebsdupdate-upgrade">“Performing Major and Minor Version Upgrades”</a>. Once the host has been upgraded and rebooted, the jail can then be upgraded. For example to upgrade from 12.3-RELEASE to 13.0-RELEASE, on the host run:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># freebsd-update -b  /usr/jail/myjail --currently-running 12.3-RELEASE -r 13.0-RELEASE upgrade <br />
# freebsd-update -b /usr/jail/myjail install <br />
# service jail restart myjail <br />
# freebsd-update -b /usr/jail/myjail install</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Then, if it was a major version upgrade, reinstall all installed packages and restart the jail again. This is required because the ABI version changes when upgrading between major versions of FreeBSD. From the host:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># pkg -j myjail upgrade -f <br />
# service jail restart myjail</code></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>In order to remove a jail, simply remove the directory after making sure that the service has stopped:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code># service jail stop myjail</code><br />
<code># rm -rf myjail  </code></p>
<p></section><section class="block block-classic-editor"></p></section><p>The post <a href="https://staging.freebsdfoundation.org/resource/an-introduction-to-freebsd-jails/">An Introduction to FreeBSD Jails</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bulk Port Management With Poudriere</title>
		<link>https://staging.freebsdfoundation.org/resource/bulk-port-management-with-poudriere/</link>
		
		<dc:creator><![CDATA[Anne Dickison]]></dc:creator>
		<pubDate>Mon, 15 Aug 2022 18:14:49 +0000</pubDate>
				<guid isPermaLink="false">https://freebsdfoundation.org/?post_type=resource&#038;p=11553</guid>

					<description><![CDATA[<p>Poudriere offers a unique way to bundle install and manage large collections of ports with minimal input, this how to guide will introduce the application and how to manage your own system.</p>
<p>The post <a href="https://staging.freebsdfoundation.org/resource/bulk-port-management-with-poudriere/">Bulk Port Management With Poudriere</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></description>
										<content:encoded><![CDATA[<section class="block block-classic-editor"><p></section><section class="block block-core-paragraph"></p>
<p><strong>Updated: September 10, 2021</strong></p>
<p></section>
<section class="block block-core-separator"></p>
<hr class="wp-block-separator has-css-opacity" />
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Step 1: Using the Ports Collection to Install Poudriere:</strong></h2>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" class="wp-image-9501" src="https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/freebsd_ports-e1585249630722.png" alt="" width="401" height="107" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/freebsd_ports-e1585249630722.png 480w, https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/freebsd_ports-e1585249630722-300x80.png 300w" sizes="(max-width: 401px) 100vw, 401px" /></figure>
<p></section></div>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>All commands in this section should be run as root, using the <code><a href="https://www.freebsd.org/cgi/man.cgi?su(1)">su(1)</a></code> command will work. You&#8217;ll need to start by installing <code>git</code>:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code><em># pkg install git</em></code></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Then, use <code>git </code>to clone the ports collection into <code>/usr/ports</code>:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># git clone https://git.freebsd.org/ports.git /usr/ports</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Next, build and install Poudriere from the ports collection using:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># cd /usr/ports/ports-mgmt/poudriere</code></em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># make install clean</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Prompts will appear throughout the installation process, stick with the default settings and install the port.</li>
</ul>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Step 2: Configuring Poudriere</strong></h2>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" class="wp-image-9504" src="https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/b849d57a.png" alt="" width="255" height="255" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/b849d57a.png 512w, https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/b849d57a-300x300.png 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/b849d57a-150x150.png 150w" sizes="(max-width: 255px) 100vw, 255px" /></figure>
<p></section></div>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Poudriere is an extremely powerful tool designed for package production, but can also be used to bulk manage ports. In order to do so, a few small tweaks will need to be made to the configuration before moving forward.</li>
	<li>First, copy and move the configuration file to the correct location with:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># cd /usr/local/etc</code></em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># cp poudriere.conf.sample poudriere.conf</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Then use the <a href="https://www.freebsd.org/cgi/man.cgi?query=ee&amp;sektion=1"><code>ee(1)</code></a> text editor to edit the copied configuration file:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># ee poudriere.conf</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Arrow keys can be used to navigate down to the line:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>FREEBSD_HOST=_PROTO_://_CHANGE_THIS_</em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Edit the above line, so it instead looks like this: (backspace to delete text)</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code>FREEBSD_HOST=ftp://ftp.freebsd.org</code></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Type <code>ESCAPE</code> and then <code>ENTER</code> twice to exit and save changes to the configuration file.</li>
</ul>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Step 3: Set Up a Poudriere Jail</strong></h2>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" class="wp-image-9497" src="https://staging.freebsdfoundation.org/wp-content/uploads/2021/06/download-10.png" alt="" width="175" height="185" /></figure>
<p></section></div>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Before continuing, Poudriere will need to fetch and extract its own version of the FreeBSD ports collection. In order to do this, run:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># rehash</code></em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># poudriere ports -c</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>A FreeBSD jail will need to be set up for Poudriere to perform bulk functions. This can be done with the commands:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># mkdir /usr/local/poudriere</code></em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># poudriere jail -c -j 91x64 -v 12.1-RELEASE -a amd64</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>In the above command, <code>91x64</code> identifies the jail, while <code>12.1-RELEASE</code> identifies the FreeBSD version to use. These can be tweaked if a different name or FreeBSD version is required. Just remember to also replace them in the rest of this guide.</li>
</ul>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Step 4: Creating a Bulk List of Ports</strong></h2>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" class="wp-image-9840" src="https://staging.freebsdfoundation.org/wp-content/uploads/2021/08/Screenshot-2021-08-06-125131.png" alt="" width="389" height="87" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2021/08/Screenshot-2021-08-06-125131.png 922w, https://staging.freebsdfoundation.org/wp-content/uploads/2021/08/Screenshot-2021-08-06-125131-300x67.png 300w" sizes="(max-width: 389px) 100vw, 389px" /></figure>
<p></section></div>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Before continuing, run the following:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># cd poudriere.d </code></em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># echo WITH_PKGNG=YES &gt;&gt; 91x64-make.conf</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>The next step will be to create a list of ports for poudriere to compile and maintain, a wide range of ports are available in the FreeBSD ports collection, and poudriere can be used to manage them all. Start with:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># cd /usr/local/etc </code></em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># ee poudriere-list</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>As before, use the <a href="https://www.freebsd.org/cgi/man.cgi?query=ee&amp;sektion=1"><code>ee(1)</code></a> text editor to edit the file, adding a list of ports for poudriere to manage. Above is an example image including Firefox, the i3 windows manager, irssi, and tmux. Ports can be added to the list by using the port origin (category/name).</li>
	<li>Type <code>ESCAPE</code> and then <code>ENTER</code> twice to exit and save changes to the configuration file.</li>
</ul>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Step 5: Configuring Poudriere Installation Options</strong></h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p class="has-text-align-center"><em><code>This step is optional unless manual configuration is needed.</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>While poudriere can be used to automate bulk port management, it still allows users to manually configure each port. However, this step can be done before installation instead of having to be present for the entirety of the process. If, for instance, the user wants to edit <code><a href="https://www.freebsd.org/cgi/man.cgi?query=tmux&amp;sektion=1&amp;apropos=0&amp;manpath=FreeBSD+9.0-RELEASE+and+Ports">tmux(1)</a></code>, use the command:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># poudriere options  -c sysutils/tmux</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Then, using the installation prompts (arrows keys to navigate, space to select) the port can be manually edited. This process can be done for each port that poudriere manages.</li>
</ul>
<p></section>
<section class="block block-core-spacer"></p>
<div class="wp-block-spacer" aria-hidden="true"> </div>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading"><strong>Step 6: Using Poudriere to Manage Ports</strong></h2>
<p></section>
<div class="wp-block-image"><section class="block block-core-image"></p>
<figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" class="wp-image-9842" src="https://staging.freebsdfoundation.org/wp-content/uploads/2021/08/Screenshot-2021-08-06-125500.png" alt="" width="520" height="229" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2021/08/Screenshot-2021-08-06-125500.png 798w, https://staging.freebsdfoundation.org/wp-content/uploads/2021/08/Screenshot-2021-08-06-125500-300x132.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></figure>
<p></section></div>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>With configuration complete, installing the entire list of ports can be done with just one command:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># poudriere bulk -j 91x64 -f poudriere-list</code></em></p>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>Poudriere will take some time to complete the bulk process,  but unlike manually building and installing ports, it can do all the work without needing user inputs. Poudriere also offers a text-based visual display of the installation process. It will allow users to have greater control over their ports without sacrificing automation.</li>
	<li>If an update is needed to the port list, poudriere can update the port collection with the commands:</li>
</ul>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># cd /usr/local/etc</code></em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em><code># poudriere bulk -j 91x64 -f poudriere-list</code></em></p>
<p></section><section class="block block-classic-editor"></p></section><p>The post <a href="https://staging.freebsdfoundation.org/resource/bulk-port-management-with-poudriere/">Bulk Port Management With Poudriere</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Building a Physical FreeBSD Build Status Dashboard</title>
		<link>https://staging.freebsdfoundation.org/resource/building-a-physical-freebsd-build-status-dashboard/</link>
		
		<dc:creator><![CDATA[Anne Dickison]]></dc:creator>
		<pubDate>Mon, 15 Aug 2022 15:51:46 +0000</pubDate>
				<guid isPermaLink="false">https://freebsdfoundation.org/?post_type=resource&#038;p=11551</guid>

					<description><![CDATA[<p>FreeBSD now has a number of continuous integration jobs on Jenkins CI to build and test FreeBSD on various architectures, and the newly implemented Tinderbox View presents a high-level, simple dashboard to the real-time FreeBSD CI build status.</p>
<p>The post <a href="https://staging.freebsdfoundation.org/resource/building-a-physical-freebsd-build-status-dashboard/">Building a Physical FreeBSD Build Status Dashboard</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></description>
										<content:encoded><![CDATA[<section class="block block-classic-editor"><p></section><section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Introduction</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>FreeBSD now has a number of continuous integration jobs on Jenkins CI to build and test FreeBSD on various architectures, and the newly implemented <a href="https://ci.freebsd.org/tinderbox/">Tinderbox View</a> presents a high-level, simple dashboard to the real-time <a href="https://ci.freebsd.org/">FreeBSD CI</a> build status.</p>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="953" height="758" class="wp-image-5320" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/tinderbox.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/tinderbox.jpg 953w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/tinderbox-300x239.jpg 300w" sizes="(max-width: 953px) 100vw, 953px" /></figure>
<p></section>
<section class="block block-core-paragraph"></p>
<p>This display is so useful that we wanted a physical version in our office to monitor the build status more easily. What started as a side project during my first few weeks of interning at The FreeBSD Foundation, has become a useful LED display of the current <a href="https://ci.freebsd.org/">FreeBSD CI</a> (continuous integration) build status, and is running 24/7 in the Foundation Kitchener office, proudly running FreeBSD on a BeagleBone Green.</p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Prerequisites</h2>
<p></section>
<section class="block block-core-list"></p>
<ul class="wp-block-list">
	<li>A working installation of FreeBSD</li>
	<li>BeagleBone Green with a 4GB micro-SD card, a serial cable and Internet connection</li>
	<li>An addressable LED RGB strip. This project uses an APA102 LED strip from <a href="https://www.sparkfun.com/products/14015">Sparkfun</a></li>
</ul>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Steps</h2>
<p></section>
<section class="block block-core-heading"></p>
<h3 class="wp-block-heading">Install FreeBSD on the micro-SD card</h3>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">1. Build or download a FreeBSD image</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>To get started, you can download an image from the <a href="https://download.freebsd.org/ftp/snapshots/ISO-IMAGES/">FreeBSD Snapshot</a> site with filename labeled as BeagleBone. In this case, we download:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">FreeBSD-12.0-CURRENT-arm-armv6-BEAGLEBONE-20170519-r318502.img.xz
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>then extract it:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">$ unxz FreeBSD-12.0-CURRENT-arm-armv6-BEAGLEBONE-20170519-r318502.img.xz
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>to get the <code>.img</code> image.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>You can always choose to build FreeBSD from source code if you want to experience the latest changes for the support of BeagleBone and are comfortable with the process. <a href="https://github.com/freebsd/crochet">Crochet</a> is the tool to use, and you can find a detailed guide on GitHub.</p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">2. Install the image</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The <a href="https://www.freebsd.org/cgi/man.cgi?query=dd&amp;sektion=1">dd(1)</a> utility is used for raw data copying such as, initializing a disk from a raw image.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><code>dd</code> requires specifying <code>if</code> (input file), <code>of</code> (output file) and <code>bs</code> (copy block size). These arguments should be changed to match the actual file and device name.</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">$ dd if=FreeBSD-BeagleBone.img of=/dev/da0 bs=8m
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>Specifying a block size is not necessary, but the default setting will result in very slow operation.</em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>If you are not sure of which device it is, simply run:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">$ tail /var/log/messages
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>right after inserting the micro-SD, or:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">$ sudo camcontrol devlist</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>to see the corresponding device name.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>After the operation finishes, you can insert the micro-SD card into the BeagleBone.</p>
<p></section>
<section class="block block-core-heading"></p>
<h3 class="wp-block-heading">Boot the BeagleBone Green</h3>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">1. Connect the serial cable</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>A serial cable might not be necessary as you can wait until it boots and try to <code>ssh</code> to it (the system configuration might prevent you from logging in as root with <code>ssh</code> though). However, since BeagleBone Green doesn&#8217;t have an HDMI output, you can see what is going on through the whole booting process with a serial cable, making it much easier to diagnose if something goes wrong.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The serial console of BeagleBone Green is exposed on a 6-pin header.</p>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="800" height="533" class="wp-image-5319" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/serial_header.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/serial_header.jpg 800w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/serial_header-300x200.jpg 300w" sizes="(max-width: 800px) 100vw, 800px" /></figure>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="800" height="533" class="wp-image-5318" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/serial_connected.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/serial_connected.jpg 800w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/serial_connected-300x200.jpg 300w" sizes="(max-width: 800px) 100vw, 800px" /></figure>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The built-in <a href="https://www.freebsd.org/cgi/man.cgi?query=cu&amp;sektion=1">cu(1)</a> utility can be used for serial communications. <code>cu</code> can only access the <code>/var/spool/lock</code> directory via user <code>uucp</code> and group <code>dialer</code>. Use the <code>dialer</code> group to control who has access to the modem or remote systems by adding user accounts to <code>dialer</code> using <a href="https://www.freebsd.org/cgi/man.cgi?query=pw&amp;sektion=8">pw(8)</a>:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">$ sudo pw groupmod dialer -m guangyuan # Use your own username
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Then log out and log in again to make the above change live.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Connect the USB to TTL cable to BeagleBone and computer, then run the <code>cu</code> utility and specify the line speed of 115200 baud.</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">$ cu -s 115200 -l /dev/cuaU0 # Or appropriate device
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>You won&#8217;t see any output yet.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>Note: Using <code>sudo</code> to use <code>cu</code> is not a good practice, instead you should add the user to the <code>dialer</code> group as above stated, or grant everyone&#8217;s access as an alternative by running:</em></p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><em>$ </em>chmod<em> 4511 /</em>usr<em>/bin/</em>cu</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>For more info about serial communications, see <a href="https://www.freebsd.org/doc/faq/serial.html">FreeBSD Serial Communications</a>.</p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">2. Boot up and log in</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The BeagleBone Black can boot from either the onboard eMMC or a micro-SD card. By default it boots from eMMC. To boot from micro-SD, first hold down the boot switch, then apply power. Don&#8217;t release the button until you see it starts booting FreeBSD (or count to 5).</p>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="700" height="321" class="wp-image-5310" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/bbg_layout.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/bbg_layout.jpg 700w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/bbg_layout-300x138.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></figure>
<p></section>
<section class="block block-core-paragraph"></p>
<p><small>(image from <a href="http://wiki.seeed.cc/BeagleBone_Green/">http://wiki.seeed.cc/BeagleBone_Green/</a>)</small></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The boot switch is just above the micro-SD slot.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>After booting, log in as root (the default password is &#8220;root&#8221; as well).</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>Tip: Making a BeagleBone Black Always Boot From the Micro-SD</em><br />
<em>The AM335x chip on board actually boots from the first partition that has the active flag set. After using the &#8220;holding the boot button&#8221; method described above to boot FreeBSD and log in as root, you will be able to turn off the bootable flag of the onboard eMMC to make it always boot from the micro-SD:</em></p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> <em>$ gpart unset -a active -i 1 mmcsd1
</em></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>To restore this change and make the eMMC available again do:</em></p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><em> $ gpart set -a active -i 1 mmcsd1</em></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>Alternatively, you can copy the FreeBSD image to eMMC so no pressing the button is needed.</em></p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">3. Sync system clock</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The system may refuse to proceed on some commands if the system clock is wrong.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>In FreeBSD, it is recommended to use both <code>ntpdate</code> and <code>ntpd</code>. <code>ntpdate</code> will set the clock when you first boot so it&#8217;s close enough that <code>ntpd</code> will work with it. Add the following to <code>/etc/rc.conf</code>:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> ntpd_enable="YES"
 ntpdate_enable="YES"
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Then read through <code>/etc/ntp.conf</code>. It&#8217;s pretty well documented so it should be obvious what to set.</p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">4. Enable root login via ssh</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Open <code>/etc/ssh/sshd_config</code> and change this line:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> #PermitRootLogin no
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>to:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> PermitRootLogin yes
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>then, restart the <code>ssh</code> daemon:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> $ /etc/rc.d/sshd restart</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>and you will be able to login as root via <code>ssh</code>.</p>
<p></section>
<section class="block block-core-heading"></p>
<h3 class="wp-block-heading">Test the GPIO on board</h3>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Let us start from mastering the control of an external LED.</p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">1. GPIO wiring</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>First let&#8217;s take a look at Beaglebone Green&#8217;s pin map:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><img loading="lazy" decoding="async" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/bbg_pinmap.jpg" alt="" width="800" height="605" /><br />
<small>(image from <a href="http://wiki.seeed.cc/BeagleBone_Green/">http://wiki.seeed.cc/BeagleBone_Green/</a>)</small></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Now we connect a LED and a 200Ω resistor using jumper wires.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><img loading="lazy" decoding="async" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/led_wiring-1024x673.jpg" alt="" width="1024" height="673" /><br />
<small>(image from <a href="https://learn.adafruit.com/blinking-an-led-with-beaglebone-black/wiring">https://learn.adafruit.com/blinking-an-led-with-beaglebone-black/wiring</a>)</small></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The top two connections on the BeagleBone expansion header are both GND. The other lead is connected to a pin of your choice.</p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">2. Send test signals</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>No programming is required at this moment, as FreeBSD provides us with the <a href="https://www.freebsd.org/cgi/man.cgi?query=gpioctl&amp;sektion=8">gpioctl(8)</a> utility which could be used to list available pins and manage GPIO pins from userland.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Let&#8217;s list all the available pins defined by device <code>/dev/gpioc0</code>:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> $ gpioctl -f /dev/gpioc0 -l
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>By default, all the IO pins are set to be inputs. This does not work for our LED. Instead, we need the pin it is connected to be an output, so we configure that:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> $ gpioctl -f /dev/gpioc0 -c 3 OUT # Assuming pin 3 is the one used
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The pin should be output mode now, but the LED should still be off. To turn it on, type:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> $ gpioctl -f /dev/gpioc0 3 1 # Assuming pin 3 is the one used</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Now we have set the logical value of pin 3 to be 1, and the LED is on! To turn it off again, type:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> $ gpioctl -f /dev/gpioc0 3 0 # Assuming pin 3 is the one used
</pre>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="850" height="566" class="wp-image-5316" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/led_up.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/led_up.jpg 850w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/led_up-300x200.jpg 300w" sizes="(max-width: 850px) 100vw, 850px" /></figure>
<p></section>
<section class="block block-core-paragraph"></p>
<p>You can try blinking the LED by writing a bash script with a simple loop.</p>
<p></section>
<section class="block block-core-heading"></p>
<h3 class="wp-block-heading">SPI bit banging</h3>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Awesome! GPIO is working well with BeagleBone, it&#8217;s time to start using the addressible LED strip.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>The LED RGB strip we used is packed with 60 APA102s and can be controlled with a standard SPI interface. However, at this moment, FreeBSD has no userland support for SPI devices. We used <a href="https://en.wikipedia.org/wiki/Bit_banging">Bit banging</a> to simulate the <a href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus">SPI Protocol</a> as a workaround.</p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">1. Wire LED strip to the BeagleBone</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p><img loading="lazy" decoding="async" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/apa102_layout.jpg" alt="" width="600" height="600" /><br />
<small>(image from <a href="https://www.sparkfun.com/products/14015">https://www.sparkfun.com/products/14015</a>)</small></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Using the pin map, we connected:<br />
VCC -&gt; SYS_5V<br />
CI -&gt; GPIO of your choice<br />
DI -&gt; GPIO of your choice<br />
GND -&gt; DGND</p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">2. Install Python development environment</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>We used Python and the <code>fbsd_gpio</code> python bindings for the code. Install Python and <code>pip</code> first, and then <code>cffi</code> and <code>fbsd_gpio</code> libraries via PyPI.</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> $ pkg install python py27-pip
 $ pip install --user cffi fbsd_gpio</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>Note: You may encounter an error when using `pip` which will give an error like:</em></p>
<p></section>
<section class="block block-core-code"></p>
<pre class="wp-block-code"><code>unable to execute '/nxb-bin/usr/bin/cc': No such file or directory</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>This is because FreeBSD uses some cross-compile tools on some embedded platforms (mips, arm, aarch64, etc.) which aren’t used in this setup and will cause build errors. The bug has not been fixed yet (<a href="https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=208282">Bug 208282</a>), but in the meantime, we could just change all references in <code>/usr/local/lib/python2.7/_sysconfigdata.py</code> as a workaround:</em></p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><em> $ sed -i '' 's/\/nxb-bin\/usr\/bin\/cc/\/usr\/bin\/cc/g' /usr/local/lib/python2.7/_sysconfigdata.py</em></pre>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">3. Write SPI bit banging functions</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>There is a SPI bit banging abstraction in the <code>fbsd_gpio</code> package used below but has not been documented yet. You can use that abstraction and skip this step, or you can still choose to follow it as a good learning practice.</em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Import the library and create a controller:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> from fbsd_gpio import GpioController
 gpioc = GpioController(0) # Using gpio controller unit 0 (/dev/gpioc0)
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Set which pins we are using:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> SCLK = 2 # CI (Blue)
 MOSI = 3 # DI (Green)</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>Note:</em><br />
<em>SCLK: Serial Clock (output from master)</em><br />
<em>MOSI: Master Output Slave Input (data output from master), or DI from LED</em></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Provide SPI init and write functions (it&#8217;s better to use bitwise operators when working with bits):</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> def spi_init():
     gpioc.pin_output(SCLK)
     gpioc.pin_output(MOSI)
     gpioc.pin_set(SCLK, 0)
     gpioc.pin_set(MOSI, 0)


 def spi_write_byte(b):
     for i in xrange(7, -1, -1):
         gpioc.pin_set(SCLK, 0)
         gpioc.pin_set(MOSI, (b &gt;&gt; i) &amp; 1)
         gpioc.pin_set(SCLK, 1)


 def spi_write(buf):
     for i in buf:
         spi_write_byte(i)
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>A complete description of <code>fbsd_gpio</code> can be found in the <a href="https://pypi.python.org/pypi/fbsd_gpio/0.4.0">fbsd_gpio documentation</a> on PyPI.</em></p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">4. Work with APA102 LEDs</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Once we set up the SPI functions, we were ready to send SPI data, but first we needed to figure out what to send in order to light up the LEDs we want. Follow the <a href="https://cdn-shop.adafruit.com/datasheets/APA102.pdf">APA102 Manual</a> to find out the data format:</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><img loading="lazy" decoding="async" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/apa102_format.jpg" alt="" width="860" height="421" /><br />
<small>(image from <a href="https://cdn-shop.adafruit.com/datasheets/APA102.pdf">https://cdn-shop.adafruit.com/datasheets/APA102.pdf</a>)</small></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Each update consists of a start frame of 32 zeroes, 32 bits for every LED, and an end frame of 32 ones. So our send function will most likely to work as follows:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> # Start Frame
 spi_write([0b00000000, 0b00000000, 0b00000000, 0b00000000])

 # LED Frames
 spi_write([0b11111111, 0b00000001, 0b00000000, 0b00000000]) # First LED, brightness full, blue
 ...

 # End Frame
 spi_write([0b11111111, 0b11111111, 0b11111111, 0b11111111])</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Read this article if you want to <a href="https://cpldcpu.com/2014/11/30/understanding-the-apa102-superled/">Understand the APA102 “Superled”</a> better.</p>
<p></section>
<section class="block block-core-heading"></p>
<h3 class="wp-block-heading">Display the status</h3>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">1. Get data from Jenkins</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Many objects of Jenkins provide remote access APIs. We used the provided Python one to get status of all jobs:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> import ast
 import urllib
 JENKINS_URL = "https://ci.freebsd.org/api/python?tree=jobs[name,color]"
 data = ast.literal_eval(urllib.urlopen(JENKINS_URL).read())["jobs"]
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>This is how the data will look like:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> {
   "_class" : "hudson.model.Hudson",
   "jobs" : [
     {
       "_class" : "hudson.model.FreeStyleProject",
       "name" : "FreeBSD-doc-head",
       "color" : "blue"
     },
     {
       "_class" : "hudson.model.FreeStyleProject",
       "name" : "FreeBSD-doc-head-igor",
       "color" : "blue_anime"
     },
     ...
   ]
 }
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>And the latest status could be extracted from <code>color</code> attribute in <code>data["jobs"]</code> and stored in a dictionary called <code>status</code>.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><em>The Jenkins API manual can be found in the <a href="https://ci.freebsd.org/api/">Jenkins CI API reference</a>.</em></p>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">2. Light up the LEDs</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Recalling the APA102 data format, we wrote some predefined data frames:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> # Variables
 BRT = 224 + 16 # Brightness, 0~31 decimal

 # Predefined data frames
 START_FRAME = [0, 0, 0, 0]
 END_FRAME = [255, 255, 255, 255]
 BLUE_LED_FRAME = [BRT, 1, 0, 0]
 GREEN_LED_FRAME = [BRT, 0, 1, 0]
 RED_LED_FRAME = [BRT, 0, 0, 1]
 YELLOW_LED_FRAME = [BRT, 0, 1, 1]
 OFF_LED_FRAME = [224, 0, 0, 0]
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>and some send functions:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"><code>def led_send_start():</code> <code> 
spi_write(START_FRAME)


</code><code>def led_send_end():</code> <code> 
spi_write(END_FRAME)</code> <code> 


def led_send(status):</code> <code> 
    if status in ["blue", "blue_anime"]:</code> <code> 
        spi_write(GREEN_LED_FRAME)</code> <code> 
    elif status in ["red", "red_anime"]:</code> <code> 
        spi_write(RED_LED_FRAME)</code> <code> 
    elif status in ["dne"]:</code> <code> 
        spi_write(OFF_LED_FRAME)</code> <code> 
    else:</code> <code> 
        spi_write(YELLOW_LED_FRAME)</code> <code> 


def led_send_all(jobs):</code> <code> 
    led_send_start()</code> <code> 
    for job in jobs:</code> <code> 
        led_send(job["status"])</code> <code> 
        led_send_end()</code></pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>so that once we updated the <code>status</code> dictionary, we were able to use <code>led_send(status)</code> to update the display:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> if __name__ == "__main__":
     spi_init()
     while True:
         status = ... # Fetch the data
         led_send_all(status) # Update
         time.sleep(10) # or any other interval
</pre>
<p></section>
<section class="block block-core-heading"></p>
<h4 class="wp-block-heading">3. Let them blink!</h4>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Now the display works really well with the static states of the job. However, we noticed that the <code>blue_anime</code> and <code>red_anime</code> colours in Jenkins, which indicate a project is in the process of building (and should be blinking), were treated as static status in the code.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>How can we make the LEDs blink while keeping their current status? We added a <code>blink_flag</code> boolean inside the loop, reversed it each time, and decided if we should turn the lights off based on that.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Add the flag to the LED updating loop:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> blink_flag = False
 while True:
     status = ... # Fetch the data
     blink_flag = not blink_flag
     led_send_all(status, blink_flag) # Update
     time.sleep(10) # or any other interval
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>and reflect changes in the send function:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted"> def led_send_all(jobs, blink_flag):
     led_send_start()
     for job in jobs:
         if "anime" in job["status"]:
             if blink_flag:
                 led_send(job["status"])
             else:
                 led_send("dne")
          else:
              led_send(job["status"])
     led_send_end()</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>We considered splitting the data fetching and the LED updating process, since blinking requires updating the LEDs every 0.5s, but fetching data should be every 20s or even longer. This could be achieved by simply adding a nested loop (for example, 40 led updates, 1 data updates, loop), but I chose to use threading so both jobs will not affect each other if one gets stuck.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Move the LED updating process into a controller class and run it separately:</p>
<p></section>
<section class="block block-core-preformatted"></p>
<pre class="wp-block-preformatted">import threading
class Led_controller(threading.Thread):
    def run(self):
        blink_flag = False
        while True:
            blink_flag = not blink_flag
            led_send_all(status, blink_flag)
            time.sleep(0.5)

if __name__ == "__main__":
    spi_init()
    led_controller = Led_controller()
    led_controller.start()

while True:
    status = ... # Fetch the data
    time.sleep(10) # or any other interval
</pre>
<p></section>
<section class="block block-core-paragraph"></p>
<p>And the LEDs should be able to blink at an interval of 0.5s.</p>
<p></section>
<section class="block block-core-heading"></p>
<h3 class="wp-block-heading">Add some final touches</h3>
<p></section>
<section class="block block-core-paragraph"></p>
<p>We cut the strip to parts and stuck them inside a picture frame.</p>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1200" height="800" class="wp-image-5313" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_1.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_1.jpg 1200w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_1-300x200.jpg 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_1-1024x683.jpg 1024w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1200" height="800" class="wp-image-5314" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_2.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_2.jpg 1200w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_2-300x200.jpg 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_2-1024x683.jpg 1024w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1200" height="800" class="wp-image-5315" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_3.jpg" alt="" srcset="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_3.jpg 1200w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_3-300x200.jpg 300w, https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish_3-1024x683.jpg 1024w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>
<p></section>
<section class="block block-core-image"></p>
<figure class="wp-block-image"><img loading="lazy" decoding="async" width="800" height="533" class="wp-image-5312" src="https://staging.freebsdfoundation.org/wp-content/uploads/2017/05/finish.gif" alt="" /></figure>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Looking good!</p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Further reading</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>My implementation of this project: <a href="https://github.com/yzgyyang/freebsd-ci-ledstrip">yzgyyang/freebsd-ci-ledstrip</a></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>FreeBSD&#8217;s support for BeagleBone: <a href="https://wiki.freebsd.org/FreeBSD/arm/BeagleBoneBlack">FreeBSD/arm/BeagleBoneBlack</a></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>A guide of building, installing and updating FreeBSD on a BeagleBone:<br />
<a href="https://staging.freebsdfoundation.org/wp-content/uploads/2015/12/vol1_no1_beaglebone_dkr.pdf">Getting Started with FreeBSD on BeagleBone Black</a></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>Official BeagleBone Green Document: <a href="http://wiki.seeed.cc/BeagleBone_Green/">BeagleBone Green</a></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><a href="https://cdn-shop.adafruit.com/datasheets/APA102.pdf">APA102 Manual</a></p>
<p></section>
<section class="block block-core-paragraph"></p>
<p><a href="https://cpldcpu.com/2014/11/30/understanding-the-apa102-superled/">Understanding the APA102 “Superled”</a></p>
<p></section>
<section class="block block-core-heading"></p>
<h2 class="wp-block-heading">Thanks</h2>
<p></section>
<section class="block block-core-paragraph"></p>
<p>I would like to thank my supervisor <a href="https://twitter.com/ed_maste">Ed Maste</a> for his guidance and support on my work. I would also like to thank <a href="https://github.com/sivamahadevan">Siva Mahadevan</a>, my colleague and friend, for the help and useful suggestions.</p>
<p></section>
<section class="block block-core-paragraph"></p>
<p>– Contributed by <a href="http://charlieyang.me/">Guangyuan (Charlie) Yang</a></p>
<p></section><section class="block block-classic-editor"></p></section><p>The post <a href="https://staging.freebsdfoundation.org/resource/building-a-physical-freebsd-build-status-dashboard/">Building a Physical FreeBSD Build Status Dashboard</a> first appeared on <a href="https://staging.freebsdfoundation.org">FreeBSD Foundation</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
