Difference between revisions of "Removing System Encryption"

From ArchWiki
Jump to: navigation, search
(Note About Different Setups: fixed some typos, added some details)
(some style fixes, poorly written)
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
=Prerequisites=
+
[[Category:Security]]
 +
{{Poor writing|written in first person.}}
 +
 
 +
Removing system encryption with [[dm-crypt with LUKS|dm-crypt and LUKS]].
 +
 
 +
== Prerequisites==
 
*an encrypted root filesystem or other filesystem you cannot umount while booted into your operating system
 
*an encrypted root filesystem or other filesystem you cannot umount while booted into your operating system
 
*enough drive space somewhere to store a backup
 
*enough drive space somewhere to store a backup
Line 5: Line 10:
 
*a few hours
 
*a few hours
  
=Boot into a Live Environment=
+
==Boot into a Live Environment==
 
Download and burn the latest archlive cd, stick it in, reboot your system and boot to cd
 
Download and burn the latest archlive cd, stick it in, reboot your system and boot to cd
=Activate Your Partitions=
+
 
==Note About Different Setups==
+
==Activate Your Partitions==
 +
 
 +
===Note About Different Setups===
 
I'm using a setup that looks like this:
 
I'm using a setup that looks like this:
 
{|border=1 style="text-align: center;"
 
{|border=1 style="text-align: center;"
Line 25: Line 32:
  
 
Disregard the grey stuff, it only adds a frame of reference.
 
Disregard the grey stuff, it only adds a frame of reference.
The green partitons are the ones we're going to be modifying.  you should make sure any green text matches your system's setup.
+
The green partitons are the ones we are going to be modifying.  you should make sure any green text matches your system's setup.
the yellow parition is the one we're going to be using as storage space.  you should feel free to change this at will.
+
the yellow parition is the one we are going to be using as storage space.  you should feel free to change this at will.
  
 
on my system, I have
 
on my system, I have
<span style="color: green;">myvg</span> contains lvs called <span style="color: green;">cryptroot</span> and <span style="color: green;">cryptswap</span>.  they are located at <span style="color: green;">/dev/mapper/myvg_cryptroot</span> and <span style="color: green;">/dev/mapper/myvg_cryptswap</span>.  Upon boot, luks is used along with a few crypttab entries to create <span style="color: green;">/dev/mapper/root</span> and <span style="color: green;">/dev/mapper/swap</span>.  I won't be unencrypting my swap as part of this guide, as undoing the swap encryption doesn't require any complex backup or restoration.
+
<span style="color: green;">myvg</span> contains lvs called <span style="color: green;">cryptroot</span> and <span style="color: green;">cryptswap</span>.  they are located at <span style="color: green;">/dev/mapper/myvg_cryptroot</span> and <span style="color: green;">/dev/mapper/myvg_cryptswap</span>.  Upon boot, luks is used along with a few crypttab entries to create <span style="color: green;">/dev/mapper/root</span> and <span style="color: green;">/dev/mapper/swap</span>.  I will not be unencrypting my swap as part of this guide, as undoing the swap encryption does not require any complex backup or restoration.
  
 
Your setup WILL be different.  different filesystems require different tools to effectively backup and restore their data.  Most of you will not be using LVM and can ignore that part.
 
Your setup WILL be different.  different filesystems require different tools to effectively backup and restore their data.  Most of you will not be using LVM and can ignore that part.
 
XFS requires xfs_copy to ensure an effective backup and restore.  DD is insufficient.  you can use DD with ext2,3,and 4.  (Someone please comment on jfs, reiserfs and reiser4fs)
 
XFS requires xfs_copy to ensure an effective backup and restore.  DD is insufficient.  you can use DD with ext2,3,and 4.  (Someone please comment on jfs, reiserfs and reiser4fs)
  
==Now That You Know Where Your Partitions Are...==
+
===Now That You Know Where Your Partitions Are...===
  
Load necessary modules
+
Load necessary modules:
 
  modprobe dm-mod #device mapper/lvm
 
  modprobe dm-mod #device mapper/lvm
 
  modprobe dm-crypt #luks
 
  modprobe dm-crypt #luks
  
activate your lvm volume group
+
Activate your lvm volume group:
 
  pvscan #scan for Physical Volumes
 
  pvscan #scan for Physical Volumes
 
  vgscan #scan for volume groups
 
  vgscan #scan for volume groups
 
  lvscan #scan for logical volumes
 
  lvscan #scan for logical volumes
 
  lvchange -ay <span style="color: green;">myvg/cryptroot</span>
 
  lvchange -ay <span style="color: green;">myvg/cryptroot</span>
open the encrypted filesystem with luks so we can read it
+
Open the encrypted filesystem with luks so we can read it:
 
  cryptSetup luksOpen <span style="color: green;">/dev/mapper/myvg_cryptroot</span> root
 
  cryptSetup luksOpen <span style="color: green;">/dev/mapper/myvg_cryptroot</span> root
enter your password.
+
Enter your password.
Note: do not mount the partitions you intend to operate on except the backup partition. if you've already mounted a partition other than your backup partition, you can safely umount it now.
+
Note: Do not mount the partitions you intend to operate on except the backup partition. If you have already mounted a partition other than your backup partition, you can safely umount it now.
Once you've identifed and activated your partitions, you're ready to move on to step 3
+
Once you have identifed and activated your partitions, you are ready to move on to step 3.
  
 
Mounting your backup space
 
Mounting your backup space
  
Only if you're using NTFS to store your backup
+
Only if you are using NTFS to store your backup
  # pacman -Sy ntfs-3g
+
  # pacman -S ntfs-3g
  
 
This step will look different for you, but it is important.
 
This step will look different for you, but it is important.
Line 63: Line 70:
 
TODO: add netcat instructions.
 
TODO: add netcat instructions.
  
=Backup Your Data=
+
==Backup Your Data==
using xfs_copy:
+
Using xfs_copy:
 
  xfs_copy -db <span style="color: green;">/dev/mapper/root</span> <u>/media/Shared/backup_root.img</u>
 
  xfs_copy -db <span style="color: green;">/dev/mapper/root</span> <u>/media/Shared/backup_root.img</u>
note: -d tells xfs_copy to preserve uuids and -b tells xfs_copy to work with filesystems that don't allow direct io (like ntfs-3g).
+
Note: -d tells xfs_copy to preserve uuids and -b tells xfs_copy to work with filesystems that do not allow direct io (like ntfs-3g).
  
using dd:
+
Using dd:
 
  dd if=<span style="color: green;">/dev/mapper/root</span> of=<u>/media/Shared/backup_root.img</u>
 
  dd if=<span style="color: green;">/dev/mapper/root</span> of=<u>/media/Shared/backup_root.img</u>
Now walk away, get yourself something to eat or drink, or do some homework. this will take a while.
+
Now walk away. Get yourself something to eat or drink, or do some homework. This will take a while.
  
=Undo Encryption=
+
==Undo Encryption==
Now the crucial moment, the point of no return if you will.  Make sure you're ready to do this, if you plan to un-do this later, you'll have to almost start from scratch. you know how fun that is.
+
Now the crucial moment, the point of no return if you will.  Make sure you are ready to do this. If you plan to undo this later, you will have to almost start from scratch. You know how fun that is.
 
  cryptsetup luksClose root
 
  cryptsetup luksClose root
 
  lvm lvremove <span style="color: green;">myvg/cryptroot</span>
 
  lvm lvremove <span style="color: green;">myvg/cryptroot</span>
  
=Restore Data=
+
==Restore Data==
now we have to create a new logical volume to house our root filesystem and restore our filesystem.
+
We have to create a new logical volume to house our root filesystem, then we restore our filesystem.
 
  lvm lvcreate <span style="color: green;">-l 100%FREE -n root myvg</span>
 
  lvm lvcreate <span style="color: green;">-l 100%FREE -n root myvg</span>
 
  xfs_copy -db <u>/media/Shared/backup_root.img</u> <span style="color: green;">/dev/mapper/myvg-root</span> #notice the second drive name is changed now.
 
  xfs_copy -db <u>/media/Shared/backup_root.img</u> <span style="color: green;">/dev/mapper/myvg-root</span> #notice the second drive name is changed now.
  
=Reconfigure the Operating System=
+
==Reconfigure the Operating System==
you need to boot into your operating system and edit /etc/crypttab, /etc/mkinitcpio.conf, /etc/fstab, and possibly /boot/grub/menu.lst
+
You need to boot into your operating system and edit /etc/crypttab, /etc/mkinitcpio.conf, /etc/fstab, and possibly /boot/grub/menu.lst.

Revision as of 15:13, 6 July 2012

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: written in first person. (Discuss in Talk:Removing System Encryption#)

Removing system encryption with dm-crypt and LUKS.

Prerequisites

  • an encrypted root filesystem or other filesystem you cannot umount while booted into your operating system
  • enough drive space somewhere to store a backup
  • an Arch Linux (or other) live CD
  • a few hours

Boot into a Live Environment

Download and burn the latest archlive cd, stick it in, reboot your system and boot to cd

Activate Your Partitions

Note About Different Setups

I'm using a setup that looks like this:

disk
ntfs myvg(lvm) ntfs
other os cryptswap(lv) cryptroot(lv) Shared
luks luks
swap root(xfs)

Disregard the grey stuff, it only adds a frame of reference. The green partitons are the ones we are going to be modifying. you should make sure any green text matches your system's setup. the yellow parition is the one we are going to be using as storage space. you should feel free to change this at will.

on my system, I have myvg contains lvs called cryptroot and cryptswap. they are located at /dev/mapper/myvg_cryptroot and /dev/mapper/myvg_cryptswap. Upon boot, luks is used along with a few crypttab entries to create /dev/mapper/root and /dev/mapper/swap. I will not be unencrypting my swap as part of this guide, as undoing the swap encryption does not require any complex backup or restoration.

Your setup WILL be different. different filesystems require different tools to effectively backup and restore their data. Most of you will not be using LVM and can ignore that part. XFS requires xfs_copy to ensure an effective backup and restore. DD is insufficient. you can use DD with ext2,3,and 4. (Someone please comment on jfs, reiserfs and reiser4fs)

Now That You Know Where Your Partitions Are...

Load necessary modules:

modprobe dm-mod #device mapper/lvm
modprobe dm-crypt #luks

Activate your lvm volume group:

pvscan #scan for Physical Volumes
vgscan #scan for volume groups
lvscan #scan for logical volumes
lvchange -ay myvg/cryptroot

Open the encrypted filesystem with luks so we can read it:

cryptSetup luksOpen /dev/mapper/myvg_cryptroot root

Enter your password. Note: Do not mount the partitions you intend to operate on except the backup partition. If you have already mounted a partition other than your backup partition, you can safely umount it now. Once you have identifed and activated your partitions, you are ready to move on to step 3.

Mounting your backup space

Only if you are using NTFS to store your backup

# pacman -S ntfs-3g

This step will look different for you, but it is important. Without it, where will you store your backup?

# mount -t ntfs-3g -o rw /dev/sda5 /media/Shared

or you can use netcat to store your backup on a remote system

TODO: add netcat instructions.

Backup Your Data

Using xfs_copy:

xfs_copy -db /dev/mapper/root /media/Shared/backup_root.img

Note: -d tells xfs_copy to preserve uuids and -b tells xfs_copy to work with filesystems that do not allow direct io (like ntfs-3g).

Using dd:

dd if=/dev/mapper/root of=/media/Shared/backup_root.img

Now walk away. Get yourself something to eat or drink, or do some homework. This will take a while.

Undo Encryption

Now the crucial moment, the point of no return if you will. Make sure you are ready to do this. If you plan to undo this later, you will have to almost start from scratch. You know how fun that is.

cryptsetup luksClose root
lvm lvremove myvg/cryptroot

Restore Data

We have to create a new logical volume to house our root filesystem, then we restore our filesystem.

lvm lvcreate -l 100%FREE -n root myvg
xfs_copy -db /media/Shared/backup_root.img /dev/mapper/myvg-root #notice the second drive name is changed now.

Reconfigure the Operating System

You need to boot into your operating system and edit /etc/crypttab, /etc/mkinitcpio.conf, /etc/fstab, and possibly /boot/grub/menu.lst.