Skip to content

Instantly share code, notes, and snippets.

@setkeh
Last active May 11, 2020 03:09
Show Gist options
  • Save setkeh/42b1d6a86bf31001b797e991ae7296d8 to your computer and use it in GitHub Desktop.
Save setkeh/42b1d6a86bf31001b797e991ae7296d8 to your computer and use it in GitHub Desktop.
Gentoo LVM Luks Systemd setup Guide

Full Setup Steps

First Setup Disks Change this step howevery you need

parted -a optimal /dev/sdX

unit mib                     # Run in the Parted Shell
mklabel gpt                  # Run in the Parted Shell

mkpart primary 1 3           # Run in the Parted Shell
name 1 grub                  # Run in the Parted Shell
set 1 bios_grub on           # Run in the Parted Shell

mkpart primary fat32 3 515   # Run in the Parted Shell               
name 2 boot                  # Run in the Parted Shell
set 2 BOOT on                # Run in the Parted Shell   

mkpart primary 515 -1        # Run in the Parted Shell
name 3 lvm                   # Run in the Parted Shell
set 3 lvm on                 # Run in the Parted Shell

quit                         # Quit parted shell

Second Setup Disk Partitions also setup to personal needs

mkfs.vfat -F32 /dev/sdX2

cryptsetup luksFormat -c aes-xts-plain64:sha256 -s 256 /dev/sdX3

cryptsetup luksOpen /dev/sdX3 lvm

lvm pvcreate /dev/mapper/lvm
vgcreate vg0 /dev/mapper/lvm
lvcreate -L 25G -n root vg0
lvcreate -L 40G -n var vg0
lvcreate -l 100%FREE -n home vg0

mkfs.ext4 /dev/mapper/vg0-root
mkfs.ext4 /dev/mapper/vg0-home
mkswap /dev/mapper/vg0-swap
swapon /dev/mapper/vg0-swap

Mount the Disks, Swap and tmp spaces

cryptsetup luksOpen /dev/sdx3 lvm 

mount /dev/mapper/vg0-root /mnt/gentoo 
mount /dev/sda2 /mnt/gentoo/boot
mount -t proc /proc /mnt/gentoo/proc 
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount -t tmpfs -o nosuid,nodev,noexec shm /dev/shm 
chmod 1777 /dev/shm

OPTIONAL: Setup Wireless

wpa_passphrase "SSID" > /etc/wpa_supplicant/wpa_supplicant.conf         # This Command will hang waiting for SDIN input Type you're Wireless PSK (Password) and press enter
wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlp2s0  # Change wlp2s0 to your wireless dev
dhcpcd                                                                  #On Wired Networks this *should* be uneeded

Fetch the Systemd Stage3 and Untar it

cd /mnt/gentoo
wget https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/20200430/systemd/stage3-amd64-systemd-20200430.tar.bz2
tar xvjpf stage3-*.tar.bz2 --xattrs --numeric-owner

Chroot Setup

mkdir /mnt/gentoo/etc/portage/repos.conf
cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf

cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

chroot /mnt/gentoo /bin/bash
source /etc/profile

System Setup

emerge-webrsync
eselect profile list # Just check and make sure the systemd profile is selected

echo Australia/Sydney > /etc/timezone
emerge --config sys-libs/timezone-data

/#nano -w /etc/locale.gen
/#locale-gen

eselect locale list
eselect locale set 1

env-update && source /etc/profile 

blkid

# create /etc/fstab wit the foloowing swapping out ID's from command above
# <fs>                                          <mountpoint>    <type>          <opts>          <dump/pass>
UUID=DB1D-89C5                                  /boot           vfat            noauto,noatime      1 2
UUID=6bedbbd8-cea9-4734-9c49-8e985c61c120       /               ext4            defaults            0 1
UUID=61e4cc83-a1ee-4190-914b-4b62b49ac77f       none            swap            swap                0 0
UUID=5d6ff087-50ce-400f-91c4-e3378be23c00       /home           ext4            defaults            0 1
# tmps
tmpfs                                           /tmp            tmpfs           size=4G             0 0
tmpfs                                           /run            tmpfs           size=100M           0 0
# shm
shm                                             /dev/shm        tmpfs           nodev,nosuid,noexec 0 0

emerge -av sys-kernel/gentoo-sources
emerge -av sys-kernel/genkernel-next
emerge -av sys-fs/cryptsetup
emerge -av sys-fs/udev
emerge -av net-wireless/wpa_supplicant # only required for Laptops with wireless networking
emerge -av net-misc/dhcpcd

genkernel --udev --luks --lvm --no-zfs --bootloader=grub2 --gpg --install --makeopts=-j16 --clean all

Bootloader setup

echo "sys-boot/grub:2 device-mapper" >> /etc/portage/package.use/sys-boot
emerge -av grub

# Add the folowing to /etc/default/grub swapp the id for /dev/sdx2 from blkid
GRUB_CMDLINE_LINUX="dolvm crypt_root=UUID=6a7a642a-3262-4f87-9540-bcd53969343b root=/dev/mapper/vg0-root"

grub-install --target=x86_64-efi --efi-directory=/boot 
grub-mkconfig -o /boot/grub/grub.cfg

Final Steps to ensure we have everything we need and change root Password

passwd

systemctl enable lv2-monitor.service

# Dont forget to add global systemd use to /etc/portage/make.conf and set global Makeopts

#Lets just make sure @world is upto date
emerge -avDN @world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment