You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This gist is my notebook about how to setup Linux machine to my liking.
The setup assumes full disk encryption.
Due to partitioning and encryption, I have come to conclude I need to do this manually.
However, I'm happy to remove parts of the this page, as long as there is better way to do it.
Please note that Debian and Arch Linux have more comprehensive guides.
sudo -i # if not root
apt update
apt install openssh-server
# add password for Debian live user
passwd user
Connect to it
ssh <ip-address> -l user -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
# in the server over the ssh
sudo -i
Fix link MTU if wrong
# find route mtu
ip route
# set link mtu
ip link set<dev> mtu <mtu>
ifdown <dev>; ifup <dev>
Arch Linux
TODO
Prepare Storage
1. Prepare
Create a memory storage for secure files.
mkdir -p /prepare
mount -t tmpfs none /prepare
Install packages.
Debian
apt update
apt install -y cryptsetup gdisk dosfstools
apt install -y mdadm # if you are going to use raid
Arch Linux
TODO
Stop all RAIDs, if those were autodetected.
mdadm --stop --scan
Change the Live Linux's hostname to the target
hostnamectl # status
hostnamectl set-hostname <name>
2. Ensure you have correct devices
fdisk -l /dev/sd? /dev/nvme?n?
If you will do RAID, start partition from the smaller device (SSD/NVMe have tiny size differences).
4. Partition disks (use GPT)
The root partition is for OS and the home is for user files, but you may use a single partition instead (i.e., root).
The home could be on another device too.
Note that *fdisk and *gdisk tools are used for their specific purposes.
Some features are not available in fdisk family yet.
The partition label can't be set with fdisk tools. Partition labels are not very relevant though. However, sfdisk does copy labels.
The partition type Linux LUKS can't be set with cfdisk. You can set partition type with sfdisk --part-type /dev/correct-disk <partition-number> <GUID>.
When partitions are copied to another device, there is no tool in fdisk to reset GPT partition IDs.
If you setup RAID, use Linux RAID, gdisk fd00, GUID A19D880F-05FC-4D3B-A006-743F0F84911E) for root and home partitions.
For encrypted disks, use Linux LUKS gdisk 8309, GUID CA7D7CCB-63ED-4C53-861C-1742536059CC. This is good for swap too, as TPM and other alternative unlocking requires secondary key slots. There is also Linux dm-crypt, 8308, 7FFEC5C9-2D00-49B7-8941-3EA10A5586B7 for non-LUKS uses.
cgdisk /dev/correct-disk
# purpose size Type gdisk GUID# ESP 4G EFI System ef00 C12A7328-F81F-11D2-BA4B-00A0C93EC93B# root >30G Linux LUKS 8309 CA7D7CCB-63ED-4C53-861C-1742536059CC# home nG Linux LUKS 8309 CA7D7CCB-63ED-4C53-861C-1742536059CC# swap 8-64G Linux LUKS 8309 CA7D7CCB-63ED-4C53-861C-1742536059CC
# RAID for the root partition
mdadm -v -C /dev/md/root -e 1.2 -b internal -l 1 -n 2 /dev/first-device3 /dev/second-device3
# If you created home in the RAID disk
mdadm -v -C /dev/md/home -e 1.2 -b internal -l 1 -n 2 /dev/first-device4 /dev/second-device4
# When there is separate EFI and /boot, add v1.0 mirror for /boot
mdadm -v -C /dev/md/boot -e 1.0 -b none -l 1 -n 2 /dev/first-device2 /dev/second-device2
Note that we use version 1.0 for boot, so they can be read without using RAID, but we mount them with raid, so both disk have the same data when updated.
Note that we don't setup raid for EFI, as that device can be edited by multiple OSes and such. Instead, we will setup a copy hook later.
Converting plain disk to RAID later is quite hard, thus if you anticipate to add second disk later, you should create a single disk arrow now.
To do that, replace -n 2 with --force -n 1.
Later, you can add new disk with mdadm -a /dev/md/name /dev/second-deviceN and mdadm --frow -n 2 /dev/md/name.
If the RAID home host gets broken, then mdadm --assemble /dev/md/root --update=homehost will fix it.
6. Setup crypto
The boot-up partitions won't be encrypted (EFI and boot).
Therefore, run the following command for the other partitions (root, home and swap).
Use RAID devices /dev/md1[34], if you created those.
Create a nice password with pwqgen or come up with one.
I recommend to use multiple words and less special characters.
Consider that you should be able to write the password when the keyboard layout is not correct (i.e., just letters, numbers, comma, dot and space).
root UUID=cryptdev-0000-0000-0000-aaaaaaaaaaaa none luks,discard
home UUID=cryptdev-0000-0000-0000-bbbbbbbbbbbb /etc/crypttab_home.key luks,discard
# repeat for every disk with swap
swap0 UUID=cryptdev-0000-0000-0000-bbbbbbbbbbbb /etc/crypttab_swap.key luks,discard
Open created devices
TABFILE=/prepare/crypttab cryptdisks_start root # requires password
TABFILE=/prepare/crypttab cryptdisks_start home # unlocks with key# repeat for every swap
TABFILE=/prepare/crypttab cryptdisks_start swap0 # unlocks with key
7. Create filesystems and fstab
Create swaps
# repeat for every swap
mkswap -L swap0 /dev/mapper/swap0
Create actual filesystems
mkfs.ext4 -L boot </dev/correct-disk2 or /dev/md/boot>
mkfs.ext4 -L root /dev/mapper/root
mkfs.ext4 -L home -m 0 /dev/mapper/home
# repeat for every disk
mkfs.vfat -F 32 -n ESP0 /dev/disk1p1
Add all mounted filesystems to fstab
lsblk -o label,path,uuid,fstype -M | grep -E '(ext.|vfat|swap)$'| tee /prepare/fstab
Edit the /prepare/fstab file to look like:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# root /dev/mapper/root
UUID=filesyst-em00-0000-0000-aaaaaaaaaaaa / ext4 defaults,user_xattr,lazytime,commit=30,errors=remount-ro 0 1
# home /dev/mapper/home
UUID=filesyst-em00-0000-0000-dddddddddddd /home ext4 defaults,user_xattr,lazytime,nodev,nosuid,commit=30 0 2
## If only one EFI/boot
# ESP0 /dev/disk0p1 - first disk goes to /boot
UUID=DEAD-B11F /boot vfat defaults,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed 0 2
# ESP1 /dev/disk1p1 - rest go to /boot-N
UUID=DEAD-B22F /boot-1 vfat defaults,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed 0 2
## If separate /boot
# boot /dev/disk0p2 - mount the ext to /boot
UUID=filesyst-em00-0000-0000-bbbbbbbbbbbb /boot ext4 defaults,lazytime,nodev,nosuid,noexec,commit=60 0 2
# repeat for every efi device
# EFI0 /dev/disk0p1 - mount the efi to /efi, and rest to /efi-N
UUID=DEAD-BEEF /efi vfat defaults,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed 0 2
## repeat for every swap device
# swap0 /dev/mapper/swap0 - LUSK swaps have UUID
UUID=4f0a2053-0823-4669-8e75-014726676ff7 none swap sw 0 0
8. Prepare filesystems for chroot
Copy it for chroot mounting
cp /prepare/fstab /target.fstab
Edit /target.fstab to look like, i.e., prefix paths, drop swaps and add system mounts.
NOTE: above is required only for the first time. If you need to remount disks, following is enough.
However remember that /target.fstab doesn't persist over reboots on live installers and rescue systems.
# Add password for root
passwd
# Create user
adduser user
adduser user ssh
adduser user sudo
11. Setup networking
Configure network device, if needed
cat > /etc/systemd/network/ether.network <<EOF# see https://wiki.debian.org/SystemdNetworkd[Match]Name=enp*Type=ether[Link]#MTUBytes=9000[Network]DHCP=ipv4# Use this if you want to force DHCP-Registration with# the MAC-Address instead of duid (DHCP Unique Identifier)# This way you can pre-assign them in your DHCPD.#ClientIdentifier=macEOF
# For servers, enable networkd
systemctl enable systemd-networkd