<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about boot)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/boot.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2022 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Sun, 27 Feb 2022 04:05:06 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Auto mount a disk that is encrypted with luks</title><link>https://bgstack15.ddns.net/blog/posts/2017/07/28/auto-mount-a-disk-that-is-encrypted-with-luks/</link><dc:creator>bgstack15</dc:creator><description>&lt;h2&gt;Overview&lt;/h2&gt;
&lt;p&gt;The anaconda installer can ask you if you want to encrypt a partition when you
are setting up a new system. What if after the fact you want to add an
encrypted disk that is auto-mounted at boot? This post explains how to prepare
a new partition that is encrypted and configure your system to mount it at
boot. This guide is aimed at Fedora -based systems like RHEL and CentOS, and
tested specifically on CentOS 7.3.&lt;/p&gt;
&lt;h2&gt;Preparing the system and disk&lt;/h2&gt;
&lt;p&gt;Ensure package cryptsetup is installed.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;yum -y install cryptsetup
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Prepare a valid disk and partition which the system can find. Make a partition
of the preferred size and of type Linux filesystem or Linux reserved.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;# &lt;span class="nv"&gt;sudo&lt;/span&gt; &lt;span class="nv"&gt;fdisk&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;dev&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;vdb&lt;/span&gt;
&lt;span class="nv"&gt;Command&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;m&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;help&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;: &lt;span class="nv"&gt;p&lt;/span&gt;
&lt;span class="nv"&gt;Disk&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;dev&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;vdb&lt;/span&gt;: &lt;span class="mi"&gt;16&lt;/span&gt;.&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="nv"&gt;GB&lt;/span&gt;, &lt;span class="mi"&gt;16106127360&lt;/span&gt; &lt;span class="nv"&gt;bytes&lt;/span&gt;, &lt;span class="mi"&gt;31457280&lt;/span&gt; &lt;span class="nv"&gt;sectors&lt;/span&gt;
&lt;span class="nv"&gt;Units&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;sectors&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt; &lt;span class="nv"&gt;bytes&lt;/span&gt;
&lt;span class="nv"&gt;Sector&lt;/span&gt; &lt;span class="nv"&gt;size&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;logical&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;physical&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;: &lt;span class="mi"&gt;512&lt;/span&gt; &lt;span class="nv"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt; &lt;span class="nv"&gt;bytes&lt;/span&gt;
&lt;span class="nv"&gt;I&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;O&lt;/span&gt; &lt;span class="nv"&gt;size&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;minimum&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;optimal&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;: &lt;span class="mi"&gt;512&lt;/span&gt; &lt;span class="nv"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt; &lt;span class="nv"&gt;bytes&lt;/span&gt;
&lt;span class="nv"&gt;Disk&lt;/span&gt; &lt;span class="nv"&gt;label&lt;/span&gt; &lt;span class="nv"&gt;type&lt;/span&gt;: &lt;span class="nv"&gt;gpt&lt;/span&gt;
#         &lt;span class="nv"&gt;Start&lt;/span&gt;          &lt;span class="k"&gt;End&lt;/span&gt;    &lt;span class="nv"&gt;Size&lt;/span&gt;  &lt;span class="nv"&gt;Type&lt;/span&gt;            &lt;span class="nv"&gt;Name&lt;/span&gt;
 &lt;span class="mi"&gt;1&lt;/span&gt;         &lt;span class="mi"&gt;2048&lt;/span&gt;     &lt;span class="mi"&gt;31457246&lt;/span&gt;     &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="nv"&gt;G&lt;/span&gt;  &lt;span class="nv"&gt;Linux&lt;/span&gt; &lt;span class="nv"&gt;reserved&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The example partition in this post is /dev/vdb1.&lt;/p&gt;
&lt;h2&gt;Initializing the encrypted partition&lt;/h2&gt;
&lt;p&gt;Perform the initial setup of the encrypted partition. The dash here means it
will prompt for a password (or accept it from standard input).&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;cryptsetup luksFormat /dev/vdb1 -


# cryptsetup luksFormat /dev/vdb1 -

WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase:
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Get the UUID of the partition using the blkid command.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;blkid


# blkid
/dev/vdb1: UUID="b8f055d6-cd91-43e8-afbc-85fa1f6d3d7b" TYPE="crypto_LUKS" PARTUUID="6614fac8-8d0c-45dd-a1a7-b799248bc370"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To get just the sole output you need:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;thisblockid=$( blkid /dev/vdb1 -o value | head -n1 )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To open the encrypted partition, use luksOpen.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;­cryptsetup luksOpen /dev/vdb1 "luks-&lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;thisblockid&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;"


# cryptsetup luksOpen /dev/vdb1 luks-$( blkid /dev/vdb1 -o value | head -n1 )
Enter passphrase for /dev/vdb1: 
# ll /dev/mapper
lrwxrwxrwx. 1 root root       7 Jul  9 16:08 luks-b8f055d6-cd91-43e8-afbc-85fa1f6d3d7b -&amp;gt; ../dm-2
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now the &lt;strong&gt;/dev/mapper/luks-${thisblockid}&lt;/strong&gt; path exists. Make a filesystem of
your choice.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mkfs.ext4 /dev/mapper/luks-b8f055d6-cd91-43e8-afbc-85fa1f6d3d7b
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can mount this wherever you wish.&lt;/p&gt;
&lt;h2&gt;Mounting the encrypted partition automatically&lt;/h2&gt;
&lt;p&gt;To mount this encrypted partition at boot, you will need to modify /etc/fstab
and /etc/crypttab. Add to /etc/fstab an entry:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;/dev/mapper/luks-b8f055d6-cd91-43e8-afbc-85fa1f6d3d7b   /mnt/foo        ext4    defaul
ts        0 0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Add to /etc/crypttab an entry:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;luks-b8f055d6-cd91-43e8-afbc-85fa1f6d3d7b UUID=b8f055d6-cd91-43e8-afbc-85fa1f6d3d7b -
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now for each boot, you will be prompted to provide the luks passphrase before
it can mount the specified mount point (in this case, /mnt/foo). The system
will fail to boot completely if you do not provide the passphrase, even for an
unimportant directory like /mnt/foo: It will drop into single-user mode.&lt;/p&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;h3&gt;Weblinks&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Guide to placing a keyfile on a USB flash drive &lt;a href="https://askubuntu.com/a/90911/533065"&gt;https://askubuntu.com/a/90911/533065&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Inspiration for learning this topic &lt;a href="http://vsnapshots.blogspot.com/2014/07/well-i-thought-id-have-quiet-year-and.html"&gt;http://vsnapshots.blogspot.com/2014/07/well-i-thought-id-have-quiet-year-and.html&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Man pages&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://man.he.net/?topic=crypttab&amp;amp;section=all"&gt;crypttab&lt;/a&gt;
&lt;a href="http://man.he.net/?topic=cryptsetup&amp;amp;section=all"&gt;cryptsetup&lt;/a&gt;&lt;/p&gt;</description><category>boot</category><category>encryption</category><category>luks</category><category>rhcsa</category><guid>https://bgstack15.ddns.net/blog/posts/2017/07/28/auto-mount-a-disk-that-is-encrypted-with-luks/</guid><pubDate>Fri, 28 Jul 2017 13:08:10 GMT</pubDate></item><item><title>Boot systems into different targets manually</title><link>https://bgstack15.ddns.net/blog/posts/2017/07/12/boot-systems-into-different-targets-manually/</link><dc:creator>bgstack15</dc:creator><description>&lt;h2&gt;Boot system into different targets manually&lt;/h2&gt;
&lt;p&gt;You need to modify the boot command. On the grub2 screen where it shows the
boot options, press &lt;strong&gt;e&lt;/strong&gt; to edit. On the line that starts with linux16,
append one of these possible values:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;systemd.unit=emergency.target
systemd.unit=rescue.target
systemd.unit=multi-user.target
systemd.unit=graphical.target
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With one of those items added to the kernel instruction, press &lt;strong&gt;CTRL+X&lt;/strong&gt; to
boot the kernel.&lt;/p&gt;
&lt;h2&gt;Reference&lt;/h2&gt;
&lt;h3&gt;Weblinks&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=LgAI_n7NueY"&gt;https://www.youtube.com/watch?v=LgAI_n7NueY&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description><category>boot</category><category>rhcsa</category><category>systemd</category><guid>https://bgstack15.ddns.net/blog/posts/2017/07/12/boot-systems-into-different-targets-manually/</guid><pubDate>Wed, 12 Jul 2017 13:14:35 GMT</pubDate></item></channel></rss>