<?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>nedos.net &#187; privacy</title>
	<atom:link href="http://nedos.net/category/privacy/feed/" rel="self" type="application/rss+xml" />
	<link>http://nedos.net</link>
	<description>Dmitry Nedospasov&#039;s Blog</description>
	<lastBuildDate>Tue, 25 May 2010 00:37:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ubuntu 9.10 Karmic LUKS + LVM Root Encryption with Desktop or Netinstall CD</title>
		<link>http://nedos.net/2010/01/21/ubuntu-luks-lvm/</link>
		<comments>http://nedos.net/2010/01/21/ubuntu-luks-lvm/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 10:00:19 +0000</pubDate>
		<dc:creator>Dmitry Nedospasov</dc:creator>
				<category><![CDATA[*nix]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://nedos.net/?p=138</guid>
		<description><![CDATA[LUKS + LVM root on Debian is a breeze, in fact the installer does everything for you. And the Ubuntu Desktop CD? Well, not so much, unfortunately. You could use the alternate or server CD, but this was not possible for me, I only had the desktop CD on a USB Stick. In any case, since Ubuntu also uses apt, its really just more or less a matter of installing what's missing, dpkg will do the rest!]]></description>
			<content:encoded><![CDATA[<p>So after recently migrating my backup server to a Debian LUKS set up, i decided to move my Ubuntu desktop to such a setup as well. If there are so many great free open-source encryption solutions, why doesn&#8217;t everyone use them?</p>
<p>In any case setting up a LUKS + LVM root on Debian is a breeze, in fact the installer does everything for you. And the Ubuntu Desktop CD? Well, not so much, unfortunately. You could use the alternate or server CD, but this was not possible for me, I only had the desktop CD on a USB Stick. In any case, since Ubuntu also uses apt, its really just more or less a matter of installing what&#8217;s missing, <code>dpkg</code> will do the rest!</p>
<p>It goes a little something like this&#8230;</p>
<h2>Pre-flight</h2>
<h3>Before we begin&#8230;</h3>
<ol>
<li>Boot the Ubuntu Karmic CD into the &#8220;LiveCD&#8221; mode this is the one called, <em>&#8220;Try Ubuntu without any change to your computer&#8221;</em>.</li>
<li>You will need an internet connection to download the latest versions of the missing programs, make sure you have connectivity from the LiveCD.</li>
<li>Make sure you know what the drive name is of the drive you are installing to in this <em>howto</em> it will be <code>/dev/sda</code></li>
<li>You will need a <em>separate unencrypted</em> boot partition, it is entirely possible to have this on a different device, such as a USB Stick, however here we assume that the boot partition is the first partition of the internal harddrive, i.e. <code>/dev/sda1</code></li>
<li>Open up a Terminal (Man up sissy boy &#8211; Applications &gt; Accessories &gt; Terminal)</li>
<li>(Optional) fill your drive with random data <code>dd if=/dev/urandom of=/dev/sda</code>. This prevents people from seeing <em>how much data</em>, but not what data has been written to the drive. This will take forever, especially if you have a large drive, like a 1TB.</li>
</ol>
<h3>Getting the tools</h3>
<p>Now we need to get the tools, this is relatively simple to do. Since we will need root privileges for almost the entire process, i recommend dropping to root immediately. To do this, simply type:<br />
<code><br />
sudo su -l<br />
</code></p>
<p><em><strong>We will assume that you are root for all commands below!!!</strong></em></p>
<p>Now we need to update the packages and install <code>cryptsetup</code> and <code>lvm2</code>. To do this first type in:</p>
<ol>
<li><code>apt-get update</code></li>
<li><code>apt-get install cryptsetup lvm2</code></li>
</ol>
<h2>Setting up the encrypted volume</h2>
<h3>Partitioning the disk</h3>
<p>First we need to create a partition table, to do this we fire up fdisk. In this tutorial the disk we will partitioning is <code>/dev/sda</code>.</p>
<ol>
<li>type: <code>fdisk /dev/sda</code></li>
<li>Type in <code>p</code> to print the current partition table and use <code>d</code> to delete any existing partitions: <code>Command (m for help): p</code></li>
<li>Create the first, primary, bootable, 250MB partition.
<ol>
<li>type: <code>n</code></li>
<li>then: <code>p</code></li>
<li>then: <code>1</code></li>
<li>then hit enter</li>
<li>then type: <code>+250M</code></li>
<li>then: <code>a</code></li>
<li>then: <code>1</code></li>
<li>and type: <code>p</code>, you should get something like:<br />
<code><br />
Device Boot      Start         End      Blocks   Id  System<br />
/dev/sda1   *           1          33      265041   83  Linux<br />
</code></li>
</ol>
</li>
<li>Now create a single partition, taking up the rest of the space:
<ol>
<li>type: <code>n</code></li>
<li>then: <code>p</code></li>
<li>then: <code>2</code></li>
<li>then hit enter</li>
<li>then hit enter again</li>
<li>and type: <code>p</code>, you should get something like:<br />
<code><br />
Device Boot      Start         End      Blocks   Id  System<br />
/dev/sda1   *           1          33      265041   83  Linux<br />
/dev/sda2              34        2610    20699752+  83  Linux<br />
</code></li>
</ol>
</li>
<li>now press <code>w</code></li>
</ol>
<h3>Create the encrypted Volume</h3>
<p>Next step is to setup the encrypted volume. We &#8220;luksFormat&#8221; the partition we want to be our encrypted volume, in this example this is <code>/dev/sda2</code>. To encrypt the volume, you should select a nice password. If you are not good at making your own pseudo-random passwords, download pwgen <strong>AND DON&#8217;T LOSE THIS PASSWORD!!!</strong></p>
<ol>
<li><code>apt-get install pwgen</code></li>
<li><code>pwgen 20</code></li>
</ol>
<p>Now we wipe the partition. Enter your super-duper password at the prompt for the LUKS volume.<br />
<code><br />
cryptsetup luksFormat /dev/sda2<br />
</code></p>
<h3>Mount the encrypted volume</h3>
<p>Now all that is left is mounting the encrypted volume. The first parameter of the command is the physical partition or device that the encrypted volume resides on, the second parameter is the alias for the decrypted volume in <code>/dev/mapper</code>. In this example I called my decrypted volume <code>sda2_crypt</code> (this happens to also be the Debian naming scheme) however you can chose whatever you want. Enter the LUKS volume password at the prompt.<br />
<code><br />
cryptsetup luksOpen /dev/sda2 sda2_crypt<br />
</code></p>
<p>Now that we should have the encrypted volume up and running, we can check by typing <code>cryptsetup status /dev/mapper/sda2_crypt</code>. You should see a similar output.</p>
<p><code><br />
/dev/mapper//dev/mapper/sda2_crypt is active:<br />
cipher:  aes-cbc-essiv:sha256<br />
keysize: 128 bits<br />
device:  /dev/sda2<br />
offset:  1032 sectors<br />
size:    41398473 sectors<br />
mode:    read/write<br />
</code></p>
<h2>Setting up LVM</h2>
<p>Perfect, now we can make this a physical volume for LVM. If you have never used LVM before, its about time! I&#8217;m not gonna go into great detail about how it works, there are plenty of resources online explaining the differences between physical volumes, volume groups and logical volumes. Very briefly though, <em>each</em> logical volume resides on a <em>single</em> volume group which reside on <em>one or more</em> physical volumes. So a volume group is a pool of physical devices which we can use to create logical volumes. In our case we will have <em>one</em> physical volume (<code>/dev/mapper/sda2_crypt</code>), <em>one</em> volume group (i called mine <code>crypto</code> in this example) and <em>several</em> logical volumes.</p>
<h3>Create the Physical Volume</h3>
<p>Lets go! Create the physical volume with:<br />
<code><br />
pvcreate /dev/mapper/sda2_crypt<br />
</code></p>
<h3>Create the Volume Group</h3>
<p>Create a volume group with:<br />
<code><br />
vgcreate crypto /dev/mapper/sda2_crypt<br />
</code></p>
<h3>Create the Logical Volumes</h3>
<p>And now create your logical volumes. You need at least a root and a swap, but you can create more. In this example i also created a <code>/home</code> and a <code>/tmp</code> partition (albeit pretty small). To create a logical volume use <code>lvcreate -n&lt;volume_name&gt; -L&lt;volume_size&gt; crypto</code>, where <code>&lt;volume_name&gt;</code> is the name of the volume (i.e. root), where <code>&lt;volume_size&gt;</code> is size of the volume (i.e 10G or 512M) and where crypto is, of course, the example name of our volume group from the previous step.<br />
<code><br />
root@ubuntu:~# lvcreate -nroot -L10G crypto<br />
Logical volume "root" created<br />
root@ubuntu:~# lvcreate -nswap -L1G crypto<br />
Logical volume "swap" created<br />
root@ubuntu:~# lvcreate -nhome -L4G crypto<br />
Logical volume "home" created<br />
root@ubuntu:~# lvcreate -ntmp -L4G crypto<br />
Logical volume "tmp" created<br />
</code></p>
<p>Now we&#8217;re ready to install!</p>
<h2>Installation</h2>
<p>The installation should be completely normal, the only changes you have to make are at the Partitioning screen.</p>
<h3>Partitioning</h3>
<div id="attachment_141" class="wp-caption alignnone" style="width: 514px"><a href="http://nedos.net/images/Ubuntu-64-bit-2.png"><img class="size-full wp-image-141  " title="Prepare Disk Space" src="http://nedos.net/images/Ubuntu-64-bit-2.png" alt="Select: Specify Partitions manually at this screen" width="504" height="410" /></a><p class="wp-caption-text">Select: Specify Partitions manually at this screen</p></div>
<h3>Formatting</h3>
<p>At the next screen remember to set mountpoints for your partitions and for them to be formatted. I chose to use <code>ext2</code> for my boot partition (<code>/dev/sda1</code>), mostly for legacy reasons. Make sure the <code>swap</code> logical volume is formatted <code>swap</code>, otherwise format the other partitions (i.e. <code>root</code>, <code>tmp</code> and <code>home</code>) whatever you want, i chose ext4. Again, <strong>MAKE SURE YOU ARE SETTING MOUNTPOINTS</strong> and <strong>DO NOT</strong> format <code>/dev/sda2</code>!!!</p>
<div id="attachment_144" class="wp-caption alignnone" style="width: 514px"><a href="http://nedos.net/images/Ubuntu-64-bit-21.png"><img class="size-full wp-image-144  " title="Prepare Partitions" src="http://nedos.net/images/Ubuntu-64-bit-21.png" alt="Remember to select mountpoints, filesystems and format the partitions at this screen." width="504" height="410" /></a><p class="wp-caption-text">Remember to select mountpoints, filesystems and format the partitions at this screen.</p></div>
<h3>Finishing the Installation</h3>
<p>Now click forward and let the installer finish. Remember to <strong>NOT RESTART</strong> at the very end, select &#8220;Continue Testing&#8221;.</p>
<div id="attachment_146" class="wp-caption alignnone" style="width: 514px"><a href="http://nedos.net/images/Ubuntu-64-bit-22.png"><img class="size-full wp-image-146  " title="Installation Complete" src="http://nedos.net/images/Ubuntu-64-bit-22.png" alt="Select &quot;Continue Testing&quot; here!" width="504" height="410" /></a><p class="wp-caption-text">Select &quot;Continue Testing&quot; here!</p></div>
<h2>Getting the missing bits and pieces</h2>
<p>Now, fire up a Terminal again, drop to root (<code>sudo su -l</code>). We will need to mount the new system, create an <code>/etc/crypttab</code> entry and install some missing packages.</p>
<h3>Mount the new system</h3>
<p>To mount the partitions do the following</p>
<ol>
<li>create a mount point: <code>mkdir -p /mnt/newroot</code></li>
<li>mount the root: <code>mount /dev/crypto/root /mnt/newroot</code></li>
<li>mount proc: <code>mount /proc /mnt/newroot/proc -t proc</code></li>
<li>mount your boot partition: <code>mount /dev/sda1 /mnt/newroot/boot</code></li>
<li>mount any other partitions (i.e. /tmp, /home, /var&#8230;): <code>mount /dev/crypto/&lt;vol_name&gt; /mnt/newroot/&lt;mount_name&gt;</code></li>
</ol>
<h3><code>chroot</code> into the new environment</h3>
<p>Now we are going to chroot into this environment, to do this type: chroot /mnt/newroot if you got no errors, and the command pwd returns /, you should be good.</p>
<h3>Create an <code>/etc/crypttab</code></h3>
<p>Now we need to create the <code>/etc/crypttab</code> entry and install the missing packages:</p>
<p>To create an entry in <code>/etc/crypttab</code> simply (replacing any discrepancies in naming) do:<br />
<code><br />
echo "sda2_crypt /dev/sda2 none luks" &gt;&gt; /etc/crypttab<br />
</code></p>
<p>Your /etc/crypttab should now look something like this, when you type <code>cat /etc/crypttab</code>.<br />
<code><br />
# &lt;target name&gt;    &lt;source device&gt;        &lt;key file&gt;    &lt;options&gt;<br />
sda2_crypt /dev/sda2 none luks<br />
</code></p>
<h3>Install the missing packages</h3>
<p>Now we only need to install the missing packages, the rest will be done by dpkg&#8217;s scripts.</p>
<ol>
<li>apt-get update</li>
<li>apt-get install lvm2 cryptsetup</li>
</ol>
<h3>Unmount the partitions</h3>
<p>Thats it! Now exit chroot and unmount all the volumes</p>
<ol>
<li>to exit <code>chroot</code> simply type: <code>exit</code></li>
<li>to <code>unmount</code> all the mountpoints within <code>/mnt/newroot</code>, type comma-seperated in curly-brackets what you want to unmount: <code>umount /mnt/newroot/{boot,home,tmp,proc}</code></li>
<li>you should now be able to unmount <code>/mnt/newroot</code>, if not check if you unmounted all partitions in step 2: <code>umount /mnt/newroot</code></li>
</ol>
<h3>Reboot&#8230; pray</h3>
<p>Now type in <code>reboot</code> and cross your fingers! Hopefully you are welcomed by a screen like this:</p>
<div id="attachment_148" class="wp-caption alignnone" style="width: 514px"><a href="http://nedos.net/images/Ubuntu-64-bit-23.png"><img class="size-full wp-image-148  " title="Enter Passphrase" src="http://nedos.net/images/Ubuntu-64-bit-23.png" alt="If all went well, Ubuntu's splash screen should ask you for the password" width="504" height="410" /></a><p class="wp-caption-text">If all went well, Ubuntu&#39;s splash screen should ask you for the password</p></div>
<h3>Troubleshooting</h3>
<p>Ideally it all went well, and you don&#8217;t have any complaints, however, I will create a troubleshooting section as comments rain in, so please do comment.</p>
<p>Thanks for reading, can&#8217;t wait to see some comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://nedos.net/2010/01/21/ubuntu-luks-lvm/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
