Start using Toolbox in Fedora Silverblue
Tags: linux, tutorial, opensource
Published: 2022-08-15 17:26:00

<!-- wp:paragraph -->
<p>This blog is the continuation of my previous article about <a href="https://qainsights.com/getting-started-with-fedora-silverblue/" target="_blank" rel="noreferrer noopener">Fedora Silverblue</a>. Just to recap, Fedora Silverblue is an immutable OS which provides stability,  reliability, security, and more. The package manager <code>rpm-ostree</code> behaves like a git but for the operating system. To create layered packages, use <code>rpm-ostree</code>, but to install CLI apps, container technologies, development tools, use Toolbox. In this blog article, let us dive into the toolbox and its usage in Fedora Silverblue.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"f7cc0abb"} -->
<h2 class="gb-headline gb-headline-f7cc0abb gb-headline-text">Download Fedora Silverblue</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>I am running Fedora Silverblue in my VMsare Workstation Player. To download the Fedora Silverblue ISO, head to https://silverblue.fedoraproject.org/download</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once it is installed, launch the terminal to check the status of the deployment using <code>rpm-ostree status</code></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9680,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/08/image.png"><img src="https://qainsights.com/wp-content/uploads/2022/08/image.png" alt="Start using Toolbox in Fedora Silverblue - rpm-ostree status" class="wp-image-9680"/></a><figcaption>Start using Toolbox in Fedora Silverblue - rpm-ostree status</figcaption></figure>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"40f4aec9"} -->
<h2 class="gb-headline gb-headline-40f4aec9 gb-headline-text">What is a Toolbox?</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Toolbox is a utility which comes out of the box in Fedora Silverblue. To install it in the older versions of Fedora Workstation use <code>sudo dnf install toolbox</code> or in Fedora Silverblue 30 or older using <code>sudo rpm-ostree install toolbox</code>. Here is the output of the <code>man toolbox</code> command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Toolbox enables developers to create containerized command-line environments for development and debugging using Podman. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9682,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/08/image-1.png"><img src="https://qainsights.com/wp-content/uploads/2022/08/image-1-1024x467.png" alt="man toolbox" class="wp-image-9682"/></a><figcaption>man toolbox</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Using the toolbox, it is easy to create and manage containerized workflows. Whenever you spin up a new container, it will get access to your home directory and other locations, username and permissions, systemctl, Kerberos, system and session D-Bus, and common tools like <code>dnf</code> and more.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"4ef42700"} -->
<h2 class="gb-headline gb-headline-4ef42700 gb-headline-text">Hello, Toolbox!</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>There are two primary commands you need to remember. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><code>toolbox create</code> and <code>toolbox enter</code></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Let us issue the <code>create</code> command to create an environment. Press <code>y</code> to the prompt to download the image. By default, it will download the Fedora image from the below registry.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9683,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/08/image-2.png"><img src="https://qainsights.com/wp-content/uploads/2022/08/image-2.png" alt="toolbox create" class="wp-image-9683"/></a><figcaption>toolbox create</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To view the list of images and containers, issue <code>toolbox list</code> as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9684,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/08/image-3.png"><img src="https://qainsights.com/wp-content/uploads/2022/08/image-3-1024x166.png" alt="toolbox list" class="wp-image-9684"/></a><figcaption>toolbox list</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Now, let us enter into the toolbox using the <code>toolbox enter</code> command. Here is the welcome message with the <code>diamond</code> prompt which indicates that we are inside the toolbox container. Clever, isn't it?</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9685,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/08/image-4.png"><img src="https://qainsights.com/wp-content/uploads/2022/08/image-4.png" alt="toolbox enter" class="wp-image-9685"/></a><figcaption>toolbox enter</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>In this container, let us install <code>k6</code> - a powerful load testing tool from Grafana.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>First issue the <code>sudo dnf update</code> command, then issue the below commands.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo dnf install https://dl.k6.io/rpm/repo.rpm
sudo dnf install k6
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>To validate the installation, issue <code>k6 version</code> command.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9687,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/08/image-5.png"><img src="https://qainsights.com/wp-content/uploads/2022/08/image-5.png" alt="k6 version" class="wp-image-9687"/></a><figcaption>k6 version</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>You can install the desired packages in this environment. To test this environment, let us run a quick smoke test using k6. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The below command will create a <code>loadtest.js</code> file in the current working directory. </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cat &lt;&lt; EOF &gt; loadtest.js
import http from 'k6/http';

export const options = {
  stages: &#91;
    { duration: '10s', target: 10 }
  ],
  thresholds: { http_req_duration: &#91;'avg&lt;100', 'p(95)&lt;200'] },
  noConnectionReuse: true,
  userAgent: 'MyK6UserAgentString/1.0',
};

export default function () {
  http.get('http://test.k6.io/');
}
EOF
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>To run the smoke test, issue the below command. This will run the script and store the results in <code>run1.csv</code></p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>k6 run --out csv=run1.csv loadtest.js</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Once the test is done, let us exit from the container using the <code>exit</code> command or by pressing <code>CTRL + D</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you type <code>less run1.csv</code>, you can see the results. No need to mount the volume to sync the content between the container and the host. It will be taken care by toolbox. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Let us create another container with a new name for jmeter using the below command. </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>toolbox create jmeter
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Once the container is created, enter <code>toolbox enter jmeter</code> command to login into it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now, let us install Java and JMeter using the below command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code># install Java
sudo dnf update
sudo dnf install java-11-openjdk.x86_64

# install JMeter
wget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.5.tgz
tar -xf apache-jmeter-5.5.tgz

# removing unnecessary artifacts
rm apache-jmeter-5.5.tgz
rm -r apache-jmeter-5.5/licenses/ apache-jmeter-5.5/docs/ apache-jmeter-5.5/printable_docs/ apache-jmeter-5.5/LICENSE apache-jmeter-5.5/README.md

# check JMeter version
apache-jmeter-5.5/bin/jmeter.sh -v

# run sample JMeter test
apache-jmeter-5.5/bin/jmeter.sh -n -t apache-jmeter-5.5/bin/examples/CSVSample.jmx -l Run1.jtl

# check the results
cat Run1.jtl
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Now we have two containers, completely isolated. If you somehow messed up, it is easy to spin up a new container either to debug or start from scratch.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Just to verify, exit from the container and issue <code>toolbox list</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9693,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/08/image-6.png"><img src="https://qainsights.com/wp-content/uploads/2022/08/image-6-1024x189.png" alt="toolbox list" class="wp-image-9693"/></a><figcaption>toolbox list</figcaption></figure>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"16991ae8"} -->
<h2 class="gb-headline gb-headline-16991ae8 gb-headline-text">Remove the container</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Once you are done with your work, you can easily remove the container using <code>toolbox rm jmeter</code>. But before that, you need to stop the container using <code>podman stop jmeter</code>, otherwise, you cannot remove it.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"35078e11"} -->
<h2 class="gb-headline gb-headline-35078e11 gb-headline-text">Final Words</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>As we have seen above, using the toolbox is a breeze and quick. It is swift in creating and managing containers. Thanks to podman. Toolbox works great for the Fedora ecosystem.  But if you want other distros, the toolbox needs work. Enter <code>distrobox</code> for your needs. I will post a new article soon. </p>
<!-- /wp:paragraph -->