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.
-
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
-
Umount the /mnt/usbDisk
umount /mnt/usbDisk
-
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
-
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)
-
Load the kernel module for dm_crypt
modprobe dm_crypt
-
Encrypt the whole partition NOT the bootable one
cryptsetup -c aes-xts-plain64 -s 512 -h sha512 -i 5000 -y luksFormat /dev/sda6
-
Check if everything went ok with encrypting. This should return data about encryption type etc.
cryptsetup luksDump /dev/sda6
-
Mount the encrypted disk /dev/mapper/lvm-crypt
cryptsetup luksOpen /dev/sda6 lvm-crypt
-
Setting up LVM in the /dev/mapper/lvm-crypt
lvm pvcreate /dev/mapper/lvm-crypt
lvm vgcreate lvmpool /dev/mapper/lvm-crypt
-
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
-
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
-
Mount back the external Disk with the backup file system
mount /dev/sdb1 /media/usbDisk
-
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
-
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
-
Create a new fstab file
genfstab -U -p /mnt >> /mnt/etc/fstab
-
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.
- Reboot
Umount all and reboot
Edited 16 Dec 2016. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 4 · 100% up
- Kind
- Text
- ID
- 5iox77
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.
You think that the steps where i have doubts, are right ?
It looks right. Although I haven't used GRUB that much lately.
4 deletes your windows partitions, in 17 remaking those folders is unnecessary, and you're never installing a bootloader.
Why you think that step 4 deletes windows partitions ? Can you please be more specific about bootloader ? You suggest something else in bootloader steps ?
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.
Deleted before we saved it.