Answer the question
In order to leave comments, you need to log in
How to encrypt a drive with Ubuntu 16.04 installed?
Hello!
I had such an idea - to transfer from the ubuntu desktop to a netbook and encrypt the disk in order to avoid.
There were no problems with the transfer and launch of the system - it works.
But here with enciphering I was a little confused. I found a couple of articles, but either I don’t fully understand the process, or it’s not quite what I need.
Articles:
Paranoid's Dream or Encryption Once Again
Encrypting Disks in Linux
It describes something like the following process:
Отформатировать диск->зашифровать диск->перенести систему->настроить загрузку с флешки
Answer the question
In order to leave comments, you need to log in
Attention: this instruction is relevant for Ubuntu 17.04 x64 on a UEFI system.
Warning #2: If this seems too complicated for you, you can always reinstall the system by choosing the encrypted installation option in the Ubuntu installer, although the configuration there will be less "clean" than here.
Attention number 3: I strongly recommend that you first install a similar system in a virtual machine and carry out all the necessary operations there, and only after making sure that everything worked out to do something with a live system.
Attention #4: always have a bootable Ubuntu flash drive on hand just in case, you can use it to work wonders :)
I have everything encrypted except for the boot flash drive, where is grub2, several modules and config that indicates how to find the disk that needs to be decrypted.
Without formatting, you can transfer, having a second disk nearby, otherwise I would say that no, having a second disk and the btrfs file system, you can generally transfer everything right from the working system back and forth.
In general, I did this (with BTRFS, because it's much easier, it also assumes that you have UEFI, otherwise it's even more difficult):
1) sudo cryptsetup -s 512 luksFormat /dev/nvme0n1
- this is for nvme SSD, replace it with your disk
2) Open the cryptocontainer, create a file system, then either mount and transfer files, or simply add this new partition to the existing file system and delete the old one (I don’t give commands, read https://wiki.archlinux.org/index.php/Dm-crypt/Encr... , there many examples, and https://btrfs.wiki.kernel.org/index.php/Main_Page , everything is there with examples too)
3) Edit /etc/crypttab
(create if not), my example is:
system UUID=739967f1-9770-470a-a031-8d8b8bcdb350 none luks,discard,keyscript=/etc/cryptroot/system.64.sh
and /etc/fstab
something like this:proc /proc proc nodev,noexec,nosuid 0 0
tmpfs /tmp tmpfs defaults 0 0
/dev/mapper/system / btrfs compress=lzo,noatime,ssd,subvol=/root 0 1
UUID=E495-1F0C /boot/efi vfat defaults,discard 0 0
/etc/cryptroot/system.64.sh
in the example above) that will output this key. To do this, we generate raw data for the key, turn the data into base64 so that it is easy to work with it in a shell script and create a shell script, then adjust the rights:sudo mkdir /etc/cryptroot
sudo dd bs=1024 count=4 if=/dev/urandom of=/etc/cryptroot/system
sudo cat /etc/cryptroot/system | base64 | sudo tee /etc/cryptroot/system.64
echo "echo '" | sudo tee /etc/cryptroot/system.64.sh
sudo cat /etc/cryptroot/system.64 | sudo tee --append /etc/cryptroot/system.64.sh
echo "'" | sudo tee --apppend /etc/cryptroot/system.64.sh
sudo chmod 400 /etc/cryptroot/system
sudo chmod 400 /etc/cryptroot/system.64
sudo chmod 500 /etc/cryptroot/system.64.sh
sudo cryptsetup luksAddKey /dev/nvme0n1 /etc/cryptroot/system.64
EFI/ubuntu
grubx64.efi, (should already be there), create a folder x86_64-efi
for modules, put the modules there that are necessary to open the luks container (you can take them in /boot/grub/x86_64-efi
):cryptodisk.mod
gcry_sha256.mod
luks.mod
procfs.mod
GRUB_ENABLE_CRYPTODISK=y
in /etc/default/grub
(somewhere right after GRUB_CMDLINE_LINUX
), create/edit /boot/efi/EFI/ubuntu/grub
with the following content:search.fs_uuid E495-1F0C boot
set prefix=($boot)'/EFI/ubuntu'
insmod luks
insmod gcry_sha256
cryptomount -u 739967f19770470aa0318d8b8bcdb350
search.fs_uuid 5170aca4-061a-4c6c-ab00-bd7fc8ae6030 root cryptouuid/739967f19770470aa0318d8b8bcdb350
set prefix=($root)'/root/boot/grub'
configfile $prefix/grub.cfg
E495-1F0C
is your ESP partition on the flash drive, 739967f19770470aa0318d8b8bcdb350
this is your crypto container, and 5170aca4-061a-4c6c-ab00-bd7fc8ae6030
this is the root file system. This config uses the modules copied earlier, tries to open the luks container and take the main grub config from there to display the menu and then boot. I would suggest making a copy of the config side by side just in case Ubuntu decides to overwrite it with the non-working version from above. sudo dpkg-reconfigure grub-efi-amd64
(make sure that the config we created was not overwritten), initramfssudo update-initramfs -u -k all
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question