Skip to content

Instantly share code, notes, and snippets.

@ichramm
Last active November 4, 2016 19:55
Show Gist options
  • Select an option

  • Save ichramm/6c89f83e907eb6ff89a846e41cfdf88c to your computer and use it in GitHub Desktop.

Select an option

Save ichramm/6c89f83e907eb6ff89a846e41cfdf88c to your computer and use it in GitHub Desktop.
Setup Encrypted LVM
root@neon:~# cryptsetup luksFormat -c aes-xts-plain64:sha512 -h sha512 /dev/sda3
WARNING!
========
This will overwrite data on /dev/sda3 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
root@neon:~# cryptsetup luksOpen /dev/sda3 sda3-crypt
Enter passphrase for /dev/sda3:
root@neon:~# pvcreate /dev/mapper/sda3-crypt
Physical volume "/dev/mapper/sda3-crypt" successfully created
root@neon:~# vgcreate eigenvol /dev/mapper/sda3-crypt
Volume group "eigenvol" successfully created
root@neon:~# lvcreate -C y -L 4G eigenvol -n swap
Logical volume "swap" created.
root@neon:~# lvcreate -C n -L 20G eigenvol -n root
Logical volume "root" created.
root@neon:~# lvcreate -C n -l 100%FREE eigenvol -n home
Logical volume "home" created.
root@neon:~# lvscan
ACTIVE '/dev/eigenvol/swap' [4.00 GiB] contiguous
ACTIVE '/dev/eigenvol/root' [20.00 GiB] inherit
ACTIVE '/dev/eigenvol/home' [422.62 GiB] inherit
root@neon:/# vi /etc/crypttab
root@neon:/# cat /etc/crypttab
sda3-crypt UUID=748b122f-6fbd-4d3e-ae89-b898c25005c3 none luks,allow_discards
root@neon:/# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.4.0-45-generic
root@neon:/# grub-install --recheck /dev/sda
Installing for x86_64-efi platform.
Installation finished. No error reported.
root@neon:/# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
grub-probe: error: cannot find a GRUB drive for /dev/sdb1. Check your device.map.
Adding boot menu entry for EFI firmware configuration
done
root@neon:~# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-937703054, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-937703054, default = 937703054) or {+-}size{KMGTP}: +256M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): ef00
Changed type of partition to 'EFI System'
Command (? for help): n
Partition number (2-128, default 2):
First sector (34-937703054, default = 526336) or {+-}size{KMGTP}:
Last sector (526336-937703054, default = 937703054) or {+-}size{KMGTP}: +256M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): n
Partition number (3-128, default 3):
First sector (34-937703054, default = 1050624) or {+-}size{KMGTP}:
Last sector (1050624-937703054, default = 937703054) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'
Command (? for help): p
Disk /dev/sda: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 383D03D0-C33C-41A8-AE68-13E1CB86F0A5
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 526335 256.0 MiB EF00 EFI System
2 526336 1050623 256.0 MiB 8300 Linux filesystem
3 1050624 937703054 446.6 GiB 8E00 Linux LVM
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.
root@neon:~#
root@neon:~#
root@neon:~#
root@neon:~# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/sda: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 383D03D0-C33C-41A8-AE68-13E1CB86F0A5
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 526335 256.0 MiB EF00 EFI System
2 526336 1050623 256.0 MiB 8300 Linux filesystem
3 1050624 937703054 446.6 GiB 8E00 Linux LVM
Command (? for help): q
root@neon:~#
root@neon:~#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment