Skip to content

Encrypting the whole system after the installation by using an external device

Hello. I have an arch linux system with a dual boot with windows and i want to transfer only the arch linux at an external drive, reformat and encrypt the old one and then re-transfer the system back where it was (with dual boot still working)

Here I wrote the steps that I think I need to do for that procedure. Please take a look at them and if you can, inform me for any misconception or suggest anything else.

  1. Back up the whole system into external drive from a LIVE USB of ubuntu.

    rsync -aAXv --exclude={"/dev/","/proc/","/sys/","/tmp/","/run/","/mnt/","/media/*","/lost+found"} /

    /mnt/usbDisk/oldSys

  2. Umount the /mnt/usbDisk

    umount /mnt/usbDisk

  3. Delete all the existing linux partitions and overwrite the merged partition (sda4) with random data

[info] /dev/sda1,2,3 are the partitions for the windows.

#dd if=/dev/urandom of=/dev/sda4 bs=1M
  1. Create new partition table with a boot partition and an LVM one with cfdisk a) /dev/sda5 - 512M - bootable - Partition type: Linux (83) b) /dev/sda6 - 230G - no bootable - Partition type: Linux (83)

  2. Load the kernel module for dm_crypt

    modprobe dm_crypt

  3. Encrypt the whole partition NOT the bootable one

    cryptsetup -c aes-xts-plain64 -s 512 -h sha512 -i 5000 -y luksFormat /dev/sda6

  4. Check if everything went ok with encrypting. This should return data about encryption type etc.

    cryptsetup luksDump /dev/sda6

  5. Mount the encrypted disk /dev/mapper/lvm-crypt

    cryptsetup luksOpen /dev/sda6 lvm-crypt

  6. Setting up LVM in the /dev/mapper/lvm-crypt

    lvm pvcreate /dev/mapper/lvm-crypt

    lvm vgcreate lvmpool /dev/mapper/lvm-crypt

  7. Create all logical volumes needed

    lvm lvcreate -L 100GB -n root lvmpool

    lvm lvcreate -L 4GB -n swap lvmpool

    lvm lvcreate -l 100%FREE -n home lvmpool

  8. Format all the partitions

    mkfs.ext4 /dev/sda5 # boot partition

    mkfs.ext4 /dev/mapper/lvm-crypt/root

    mkfs.ext4 /dev/mapper/lvm-crypt/home

    mkswap /dev/mapper/lvm-crypt/swap

  9. Mount back the external Disk with the backup file system

    mount /dev/sdb1 /media/usbDisk

  10. Mount all LVMs and transfer the old system. ( I have doubts for this step. What is your opinion ? )

    mount /dev/mapper/lvm-crypt/root /mnt # / partition

    mkdir /mnt/home

    mount /dev/mapper/lvm-crypt/home /mnt/home # home partition

    mkdir /mnt/boot

    mount /dev/sda5 /mnt/boot # boot partition

    rsync -axX /media/usbDisk/oldSys /mnt

Also create the folders i didn't get

#mkdir /mnt/dev /mnt/proc /mnt/sys /mnt/tmp /mnt/run /mnt/mnt /mnt/media /mnt/lost+found
  1. Edit bootloader ( I have doubts for this step. What is your opinion ? )

    vim /mnt/boot/grub/grub.cfg

here is my current grub.cfg http://pastebin.com/hkACD6Z8 and change the line 15

linux   /vmlinuz-linux root=UUID=27ae6f98-7203-480e-abb1-097e606d9e01 rw  quiet

to

linux   /vmlinuz-linux cryptdevice=UUID=<u-u-i-d>:<n-a-m-e> root=/dev/mapper/lvm-crypt/root rw quiet
  1. Create a new fstab file

    genfstab -U -p /mnt >> /mnt/etc/fstab

  2. Create a new mkinitcpio.conf

    chroot /mnt

Add the appropriate hooks to the /etc/mkinitcpio.conf

HOOKS="base udev autodetect modconf block keymap encrypt lvm2 filesystems keyboard fsck"

mkinitcpio -p linux

Finally remove the /etc/machine-id so that a new one to be created.

  1. Reboot

Umount all and reboot

Edited 16 Dec 2016. We only hold this version.

4 points6 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
4 · 100% up
Kind
Text
ID
5iox77

Author

9
posts
4
comments
0
media
View profile

7 comments

Looks like you've done your homework. After copying your file system (step 13), I would also set up your /etc/crypttab so it will know how to decrypt your drives on boot.

If it works, it could turn out to be a guide.

1 points

You think that the steps where i have doubts, are right ?

1 points

It looks right. Although I haven't used GRUB that much lately.

1 points

4 deletes your windows partitions, in 17 remaking those folders is unnecessary, and you're never installing a bootloader.

1 points

Why you think that step 4 deletes windows partitions ? Can you please be more specific about bootloader ? You suggest something else in bootloader steps ?

1 points

Making a new partition table deletes all partitions that exist on the disk.

You never install a bootloader, creating a new partition table will also delete the old bootloader. You don't specify UEFI or MBR, but using ext4 for your boot partition suggests MBR, in which case even if you don't delete the partition table you'll need to restamp the bootloader onto the MBR. And if it's UEFI, the new partition table wipes your esp, and without that step you still will need to do something to tell the EFI where to boot.

2 points
unknown author

Deleted before we saved it.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.