{"id":4196,"date":"2016-11-26T07:49:39","date_gmt":"2016-11-26T12:49:39","guid":{"rendered":"https:\/\/www.summet.com\/blog\/?p=4196"},"modified":"2021-06-05T16:30:40","modified_gmt":"2021-06-05T21:30:40","slug":"installing-an-encrypted-partition-with-lvm-dual-boot-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/www.summet.com\/blog\/2016\/11\/26\/installing-an-encrypted-partition-with-lvm-dual-boot-on-ubuntu-16-04\/","title":{"rendered":"Installing an Encrypted Partition with LVM dual boot on Ubuntu 16.04"},"content":{"rendered":"<p>The Ubuntu 16.04 installer has the option to install full disk encryption using LVM if you are erasing everything on the hard drive. However, if you want to dual boot (use some of the hard drive for Windows, and the rest for Linux) the automated installer won&#8217;t allow you to automagically use full disk encryption.<\/p>\n<p>You can still make it work, but have to do a lot of manual work using a terminal from the Live CD environment. \u00a0 Here is a log of what I had to do to get it working for me.<\/p>\n<p><!--more--><\/p>\n<p>Use gparted to create an ext4 \/boot partition (I used 400 MB in size).<br \/>\nUse gparted to create a &#8220;physical volume for encryption&#8221;<\/p>\n<p>Open a terminal and use the following commands to set up the volume with LUKS encryption, and then create sub-volumes of swap and root. \u00a0 (The directions below assume your encrypted partiton is \/dev\/sda6, change that as needed.)<\/p>\n<p><code>sudo cryptsetup luksFormat \/dev\/sda6<\/code><br \/>\nYou will have to type YES and enter a passphrase twice to encrypt your disk.<\/p>\n<p><code>sudo cryptsetup luksOpen \/dev\/sda6 \u00a0 crypt6<\/code><br \/>\nYou will be asked to re-enter the passphrase above&#8230; crypt6 is just a name I picked, you can pick any unique name here instead&#8230;<\/p>\n<p>Then we set up LVM inside the encrypted partition with the following commands. I used the name vgpool for my &#8220;volume group pool&#8221; but you could use any unique name.<\/p>\n<p><code>sudo pvcreate \/dev\/mapper\/crypt6<br \/>\nsudo vgcreate vgpool \/dev\/mapper\/crypt6<\/code><\/p>\n<p>Then we create the swap partition inside (I used 3G for 3 gigs)<\/p>\n<p><code>lvcreate -L 3G -n swap vgpool<\/code><\/p>\n<p>I used the rest of the available space for the \/root partition.<\/p>\n<p><code>lvcreate -n root -l 100%FREE vgpool<\/code><\/p>\n<p>Then I formatted both of them&#8230;<\/p>\n<p><code>mkswap \/dev\/vgpool\/swap<\/code><\/p>\n<p>mkfs -t ext4 \/dev\/vgpool\/root<\/p>\n<p>At this point, I was able to go back into the Ubuntu installer and select<br \/>\n&#8220;Something else&#8221; for the formatting options and use the &#8220;change&#8221; option to mount the swap and root and boot partitions appropriately and proceed with the install.<\/p>\n<p>You have to tell Linux to mount the encrypted filesystems upon bootup, so before you reboot for the first time at the end of the install, you need to tweak a few config files (inside the chrooted environment) \u00a0 as follows:<\/p>\n<p>Use the &#8220;sudo blkid&#8221; command to find the UUID&#8217;s of your physical partition used for encryption&#8230;<\/p>\n<p>(my UUID was for \/dev\/sda6 which is the physical deviced used for \/dev\/mapper\/crypt6&#8230;)<\/p>\n<p>Add an \/etc\/crypttab file with an entry to unencrypt and mount the LVM.<\/p>\n<p><code>crypt6 UUID=&lt;myUUIDfoundAbove&gt; \u00a0 \u00a0  \u00a0none \u00a0 \u00a0  \u00a0luks<\/code><\/p>\n<p>(I \u00a0 verified that \/dev\/mapper\/vgpool-root was being mounted as \/ and<br \/>\n\/dev\/mapper\/vgpool-swap was being mounted as swap in the fstab file&#8230;<br \/>\nas well as the \/boot partition.)<\/p>\n<p>Then I had to do some fancy work to get my \/dev\/sda5 boot partition mounted under the \/mnt\/root\/boot name, and then chmod into \/mnt\/root, making it my new \/<br \/>\nand update the initramfs image. I also updated the grub install, which may or may not be strictly necessary&#8230;<\/p>\n<p><code>sudo mkdir \/mnt\/root<\/code><\/p>\n<p>sudo mount \/dev\/mapper\/vgpool-root \/mnt\/root<br \/>\nsudo mount \/dev\/sda5 \/mnt\/root\/boot<\/p>\n<p>sudo mount &#8211;bind \/dev \/mnt\/root\/dev<br \/>\nsudo mount &#8211;bind \/dev\/pts \/mnt\/root\/dev\/pts<br \/>\nsudo mount &#8211;bind \/proc \u00a0 \/mnt\/root\/proc<br \/>\nsudo mount &#8211;bind \/sys \/mnt\/root\/sys<br \/>\nsudo mount &#8211;bind \/run \/mnt\/root\/run<\/p>\n<p>sudo chroot \/mnt\/root<\/p>\n<p>update-grub<\/p>\n<p>grub-install \/dev\/sda<\/p>\n<p>update-initramfs -u -k all<br \/>\n#check your work:<br \/>\nlsinitramfs \/boot\/initrd* | grep cryptsetup<\/p>\n<p>After all of this work, I was able to reboot and the Linux system would prompt me for the full disk encryption pass-phrase and then boot normally.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ubuntu 16.04 installer has the option to install full disk encryption using LVM if you are erasing everything on the hard drive. However, if you want to dual boot (use some of the hard drive for Windows, and the &hellip; <a href=\"https:\/\/www.summet.com\/blog\/2016\/11\/26\/installing-an-encrypted-partition-with-lvm-dual-boot-on-ubuntu-16-04\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[26],"class_list":["post-4196","post","type-post","status-publish","format-standard","hentry","category-linux","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/posts\/4196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/comments?post=4196"}],"version-history":[{"count":4,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/posts\/4196\/revisions"}],"predecessor-version":[{"id":5406,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/posts\/4196\/revisions\/5406"}],"wp:attachment":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/media?parent=4196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/categories?post=4196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/tags?post=4196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}