<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.w9cr.net/index.php?action=history&amp;feed=atom&amp;title=Encrypted_VM</id>
	<title>Encrypted VM - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.w9cr.net/index.php?action=history&amp;feed=atom&amp;title=Encrypted_VM"/>
	<link rel="alternate" type="text/html" href="https://wiki.w9cr.net/index.php?title=Encrypted_VM&amp;action=history"/>
	<updated>2026-04-17T14:28:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>https://wiki.w9cr.net/index.php?title=Encrypted_VM&amp;diff=8102&amp;oldid=prev</id>
		<title>Bryan at 19:12, 8 September 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.w9cr.net/index.php?title=Encrypted_VM&amp;diff=8102&amp;oldid=prev"/>
		<updated>2024-09-08T19:12:18Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 19:12, 8 September 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Keekles Infrastructure]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;I've done this with a 5 dollar VPS that has VNC access and a recovery ISO boot option.   &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;I've done this with a 5 dollar VPS that has VNC access and a recovery ISO boot option.   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Bryan</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.w9cr.net/index.php?title=Encrypted_VM&amp;diff=7606&amp;oldid=prev</id>
		<title>Bryan: Created page with &quot;I've done this with a 5 dollar VPS that has VNC access and a recovery ISO boot option.    https://www.cyberciti.biz/security/how-to-unlock-luks-using-dropbear-ssh-keys-remotel...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.w9cr.net/index.php?title=Encrypted_VM&amp;diff=7606&amp;oldid=prev"/>
		<updated>2023-10-01T18:09:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;I&amp;#039;ve done this with a 5 dollar VPS that has VNC access and a recovery ISO boot option.    https://www.cyberciti.biz/security/how-to-unlock-luks-using-dropbear-ssh-keys-remotel...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;I've done this with a 5 dollar VPS that has VNC access and a recovery ISO boot option.  &lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/security/how-to-unlock-luks-using-dropbear-ssh-keys-remotely-in-linux/&lt;br /&gt;
&lt;br /&gt;
https://blog.kamens.us/2017/07/25/howto-converting-an-unencrypted-ubuntu-root-disk-to-encrypted/&lt;br /&gt;
&lt;br /&gt;
This is a cleaned up version of my notes, you will need to really understand linux boot.&lt;br /&gt;
&lt;br /&gt;
Basically:&lt;br /&gt;
&lt;br /&gt;
* First you need to test ssh to the server, and VNC.  Ensure you can boot the recovery.  You'll need another server to bounce shit off of.&lt;br /&gt;
&lt;br /&gt;
* I had a 25g partition as / on this.  I need to resize this so I can move shit around.&lt;br /&gt;
&lt;br /&gt;
'''How to resize it'''&lt;br /&gt;
&lt;br /&gt;
    Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
    Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
    Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
    I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
    Disklabel type: gpt&lt;br /&gt;
    Disk identifier: &lt;br /&gt;
    &lt;br /&gt;
    Device Start End Sectors Size Type&lt;br /&gt;
    /dev/vda1 2048 4095 2048 1M BIOS boot&lt;br /&gt;
    /dev/vda2 4096 50329087 50324992 24G Linux filesystem&lt;br /&gt;
    /dev/vda3 50329088 52426239 2097152 1G Linux swap&lt;br /&gt;
    &lt;br /&gt;
'''First boot to rescue'''&lt;br /&gt;
&lt;br /&gt;
'''Then e2fsck -f /dev/vda2'''&lt;br /&gt;
&lt;br /&gt;
    rescue # e2fsck -f /dev/vda2&lt;br /&gt;
    e2fsck 1.43.4 (31-Jan-2017)&lt;br /&gt;
    Pass 1: Checking inodes, blocks, and sizes&lt;br /&gt;
    Pass 2: Checking directory structure&lt;br /&gt;
    Pass 3: Checking directory connectivity&lt;br /&gt;
    Pass 4: Checking reference counts&lt;br /&gt;
    Pass 5: Checking group summary information&lt;br /&gt;
    /dev/vda2: 161363/1572864 files (0.5% non-contiguous), 1070470/6290624 blocks&lt;br /&gt;
    &lt;br /&gt;
'''Then resize2fs /dev/vda2 10G'''&lt;br /&gt;
&lt;br /&gt;
    rescue # resize2fs /dev/vda2 10G&lt;br /&gt;
    resize2fs 1.43.4 (31-Jan-2017)&lt;br /&gt;
    Resizing the filesystem on /dev/vda2 to 2621440 (4k) blocks.&lt;br /&gt;
    The filesystem on /dev/vda2 is now 2621440 (4k) blocks long.&lt;br /&gt;
    &lt;br /&gt;
'''Now knowing that the disk is in 512 byte blocks we need to resize it to fit'''&lt;br /&gt;
&lt;br /&gt;
    (50329087-4096)*512/4096 = 6,290,623.875 or 6290624&lt;br /&gt;
    2621440*4096 = 10,737,418,240 bytes&lt;br /&gt;
    10,737,418,240/512 = 20,971,520 512k blocks&lt;br /&gt;
    Add 4 more blocks to it&lt;br /&gt;
    20,971,524 blocks is the new length&lt;br /&gt;
    4096 + 20971524 = 20975616 last sector&lt;br /&gt;
    &lt;br /&gt;
    rescue # fdisk /dev/vda&lt;br /&gt;
    &lt;br /&gt;
    Welcome to fdisk (util-linux 2.29.2).&lt;br /&gt;
    Changes will remain in memory only, until you decide to write them.&lt;br /&gt;
    Be careful before using the write command.&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): p&lt;br /&gt;
    Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
    Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
    Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
    I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
    Disklabel type: gpt&lt;br /&gt;
    Disk identifier: &lt;br /&gt;
    &lt;br /&gt;
    Device Start End Sectors Size Type&lt;br /&gt;
    /dev/vda1 2048 4095 2048 1M BIOS boot&lt;br /&gt;
    /dev/vda2 4096 50329087 50324992 24G Linux filesystem&lt;br /&gt;
    /dev/vda3 50329088 52426239 2097152 1G Linux swap&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): d&lt;br /&gt;
    Partition number (1-3, default 3): 2&lt;br /&gt;
    &lt;br /&gt;
    Partition 2 has been deleted.&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): n&lt;br /&gt;
    Partition number (2,4-128, default 2): 2&lt;br /&gt;
    First sector (4096-52428766, default 4096): 4096&lt;br /&gt;
    &lt;br /&gt;
    Last sector, +sectors or +size{K,M,G,T,P} (4096-50329087, default 50329087): 20975616&lt;br /&gt;
    &lt;br /&gt;
    Created a new partition 2 of type 'Linux filesystem' and of size 10 GiB.&lt;br /&gt;
    Partition #2 contains a ext4 signature.&lt;br /&gt;
    &lt;br /&gt;
    Do you want to remove the signature? [Y]es/[N]o: n&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): p&lt;br /&gt;
    &lt;br /&gt;
    Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
    Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
    Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
    I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
    Disklabel type: gpt&lt;br /&gt;
    Disk identifier: &lt;br /&gt;
    &lt;br /&gt;
    Device Start End Sectors Size Type&lt;br /&gt;
    /dev/vda1 2048 4095 2048 1M BIOS boot&lt;br /&gt;
    /dev/vda2 4096 20975616 20971521 10G Linux filesystem&lt;br /&gt;
    /dev/vda3 50329088 52426239 2097152 1G Linux swap&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): w&lt;br /&gt;
    The partition table has been altered.&lt;br /&gt;
    Calling ioctl() to re-read partition table.&lt;br /&gt;
    Syncing disks.&lt;br /&gt;
    &lt;br /&gt;
    rescue # mount /dev/vda2 /mnt&lt;br /&gt;
    rescue # cd /mnt&lt;br /&gt;
    rescue # ls&lt;br /&gt;
    &lt;br /&gt;
    bin dev home initrd.img.old lib64 media opt root sbin srv tmp var vmlinuz.old&lt;br /&gt;
    boot etc initrd.img lib lost+found mnt proc run snap sys usr vmlinuz&lt;br /&gt;
    &lt;br /&gt;
    rescue # df -h&lt;br /&gt;
    Filesystem Size Used Avail Use% Mounted on&lt;br /&gt;
    udev 110M 0 110M 0% /dev&lt;br /&gt;
    tmpfs 25M 4.4M 20M 18% /run&lt;br /&gt;
    /dev/vdb1 1.1G 660M 375M 64% /&lt;br /&gt;
    tmpfs 121M 0 121M 0% /dev/shm&lt;br /&gt;
    tmpfs 5.0M 0 5.0M 0% /run/lock&lt;br /&gt;
    tmpfs 121M 0 121M 0% /sys/fs/cgroup&lt;br /&gt;
    tmpfs 25M 0 25M 0% /run/user/0&lt;br /&gt;
    /dev/vda2 9.8G 3.7G 5.7G 40% /mnt&lt;br /&gt;
    &lt;br /&gt;
   **Delete the swap**&lt;br /&gt;
    &lt;br /&gt;
   **Copy the file via ssh to backup host**&lt;br /&gt;
    &lt;br /&gt;
    dd if=/dev/vda2 | gzip -1 - | ssh $host dd of=/home/vda2.img.gz&lt;br /&gt;
&lt;br /&gt;
'''Ok, now we need to make a new partition layout'''&lt;br /&gt;
    &lt;br /&gt;
    1 - efi&lt;br /&gt;
    2 - boot&lt;br /&gt;
    3 - swap&lt;br /&gt;
    4 - root +20979713 (including extra space for LUKS)&lt;br /&gt;
    &lt;br /&gt;
    export PAGER='/bin/more’&lt;br /&gt;
    rescue # fdisk /dev/vda&lt;br /&gt;
    &lt;br /&gt;
    Welcome to fdisk (util-linux 2.29.2).&lt;br /&gt;
    Changes will remain in memory only, until you decide to write them.&lt;br /&gt;
    Be careful before using the write command.&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): p&lt;br /&gt;
    Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
    Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
    Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
    I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
    Disklabel type: gpt&lt;br /&gt;
    Disk identifier: &lt;br /&gt;
    &lt;br /&gt;
    Device Start End Sectors Size Type&lt;br /&gt;
    /dev/vda1 2048 4095 2048 1M BIOS boot&lt;br /&gt;
    /dev/vda2 4096 4198399 4194304 2G Linux filesystem&lt;br /&gt;
    /dev/vda3 4198400 8392703 4194304 2G Plan 9 partition&lt;br /&gt;
    /dev/vda4 8392704 29364223 20971520 10G Linux filesystem&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): t&lt;br /&gt;
    Partition number (1-4, default 4): 3&lt;br /&gt;
    &lt;br /&gt;
    Hex code (type L to list all codes): 19&lt;br /&gt;
    &lt;br /&gt;
    Changed type of partition 'Plan 9 partition' to 'Linux swap'.&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): p&lt;br /&gt;
    Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors&lt;br /&gt;
    Units: sectors of 1 * 512 = 512 bytes&lt;br /&gt;
    Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;
    I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;
    Disklabel type: gpt&lt;br /&gt;
    Disk identifier: &lt;br /&gt;
    &lt;br /&gt;
    Device Start End Sectors Size Type&lt;br /&gt;
    /dev/vda1 2048 4095 2048 1M BIOS boot&lt;br /&gt;
    /dev/vda2 4096 4198399 4194304 2G Linux filesystem&lt;br /&gt;
    /dev/vda3 4198400 8392703 4194304 2G Linux swap&lt;br /&gt;
    /dev/vda4 8392704 29364223 20971520 10G Linux filesystem&lt;br /&gt;
    &lt;br /&gt;
    Command (m for help): w&lt;br /&gt;
    The partition table has been altered.&lt;br /&gt;
    Calling ioctl() to re-read partition table.&lt;br /&gt;
    Syncing disks.&lt;br /&gt;
    &lt;br /&gt;
    Add crypt setup to the rescue&lt;br /&gt;
    apt-get install cryptsetup&lt;br /&gt;
&lt;br /&gt;
'''Now since we're on VNC, and it's unencrypted, use a temp passwd'''&lt;br /&gt;
&lt;br /&gt;
    rescue # cryptsetup luksFormat /dev/vda4&lt;br /&gt;
    &lt;br /&gt;
    WARNING!&lt;br /&gt;
    ========&lt;br /&gt;
    This will overwrite data on /dev/vda4 irrevocably.&lt;br /&gt;
    &lt;br /&gt;
    Are you sure? (Type uppercase yes): YES&lt;br /&gt;
    Enter passphrase: changeme&lt;br /&gt;
    Verify passphrase: changeme&lt;br /&gt;
    &lt;br /&gt;
    cryptsetup luksOpen /dev/vda4 rootencdev&lt;br /&gt;
    Enter passphrase for /dev/vda4:&lt;br /&gt;
    cryptsetup resize rootencdev&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''copy it all back to the server now'''&lt;br /&gt;
    &lt;br /&gt;
    ssh $SERVER &amp;quot;dd if=vda2.img.gz &amp;quot; | gunzip -c | dd of=/dev/mapper/rootencdev status=progress&lt;br /&gt;
    &lt;br /&gt;
    apt-get install vim rsync&lt;br /&gt;
&lt;br /&gt;
'''mnt/root/etc/crypttab'''&lt;br /&gt;
    &lt;br /&gt;
    rootencdev /dev/vda4 none luks,discard&lt;br /&gt;
    &lt;br /&gt;
'''After this mount it'''&lt;br /&gt;
    &lt;br /&gt;
    mkdir /mnt/root &amp;amp;&amp;amp; mount /dev/mapper/rootencdev /mnt/root&lt;br /&gt;
    &lt;br /&gt;
'''make a fs on the new boot'''&lt;br /&gt;
    &lt;br /&gt;
    rescue # mkfs.ext4 /dev/vda2&lt;br /&gt;
    &lt;br /&gt;
    mv -T /mnt/root/boot /mnt/root/boot.orig&lt;br /&gt;
    &lt;br /&gt;
    mkdir /mnt/root/boot &amp;amp;&amp;amp; mount /dev/vda2 /mnt/root/boot&lt;br /&gt;
    &lt;br /&gt;
    rsync -av /mnt/root/boot.orig/ /mnt/root/boot/&lt;br /&gt;
    &lt;br /&gt;
    for dir in /sys /proc /dev; do mount --bind $dir /mnt/root$dir; done&lt;br /&gt;
    &lt;br /&gt;
    chroot /mnt/root /bin/bash&lt;br /&gt;
    sudo apt update&lt;br /&gt;
    sudo apt upgrade&lt;br /&gt;
    sudo apt install dropbear-initramfs&lt;br /&gt;
    &lt;br /&gt;
    cd /etc/dropbear-initramfs&lt;br /&gt;
    &lt;br /&gt;
    vim config&lt;br /&gt;
    DROPBEAR_OPTIONS=&amp;quot;-I 180 -j -k -p 2222 -s”&lt;br /&gt;
    &lt;br /&gt;
    RESCUE ip config on kernel cmdline : ip=$IPv4::$GW:$MASK::eth0:none&lt;br /&gt;
    &lt;br /&gt;
    #vim /etc/initramfs-tools/initramfs.conf&lt;br /&gt;
    IP=$IPv4::$GW:$MASK:$HOSTNAME&lt;br /&gt;
    sudo update-initramfs -u -v&lt;br /&gt;
    &lt;br /&gt;
    cp /root/.ssh/authorized_keys /etc/dropbear-initramfs/&lt;br /&gt;
    &lt;br /&gt;
    update-initramfs -u -k all&lt;br /&gt;
    &lt;br /&gt;
    grub-install /dev/vda&lt;br /&gt;
    update-grub&lt;br /&gt;
    &lt;br /&gt;
    reboot&lt;br /&gt;
    &lt;br /&gt;
'''ssh in and unlock it.'''&lt;br /&gt;
    &lt;br /&gt;
    ssh -p 2222 $IP&lt;br /&gt;
    cryptroot-unlock&lt;br /&gt;
    &lt;br /&gt;
    cryptsetup luksChangeKey /dev/vda4&lt;br /&gt;
    &lt;br /&gt;
    Now add the crypto to the swap device&lt;br /&gt;
    vim /etc/crypttab&lt;br /&gt;
    &lt;br /&gt;
    # &amp;lt;target name&amp;gt; &amp;lt;source device&amp;gt; &amp;lt;key file&amp;gt; &amp;lt;options&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    rootencdev /dev/vda4 none luks,discard&lt;br /&gt;
    swap /dev/vda3 /dev/urandom swap,cipher=aes-xts-plain64,size=256&lt;br /&gt;
    &lt;br /&gt;
    root@$HOSTNAME:~# vim /etc/fstab&lt;br /&gt;
    /dev/mapper/swap swap swap defaults 0 0&lt;/div&gt;</summary>
		<author><name>Bryan</name></author>
		
	</entry>
</feed>