{"id":518,"date":"2021-12-09T11:32:08","date_gmt":"2021-12-09T11:32:08","guid":{"rendered":"https:\/\/andrejacobs.org\/?p=518"},"modified":"2022-04-11T20:22:59","modified_gmt":"2022-04-11T20:22:59","slug":"installing-ubuntu-server-20-04-part-3","status":"publish","type":"post","link":"https:\/\/andrejacobs.org\/linux\/installing-ubuntu-server-20-04-part-3\/","title":{"rendered":"Installing Ubuntu Server 20.04 – part 3"},"content":{"rendered":"\n
Photo by Denny M\u00fcller<\/a> on Unsplash<\/a><\/p>\n\n\n\n The plan for today:<\/p>\n At least that was the plan when I started documenting my process. However not long after running the setup I received this email:<\/p>\n Now do you understand why it is MEGA important to setup email notifications!?<\/strong><\/p>\n One of the Western Digital 2TB "green" BS drives developed a couple of faults (as verified previously using SMART) and I thought it would be ok for a bit longer … but I was totally wrong and the disk start failing big time.<\/p>\n I decided to replace the 2x 2TB crappy drives with 2x 4TB Seagate IronWolf Pro drives.<\/p>\n But why stop there? I ended up also upgrading the memory to 64GB using Corsair Vengeance LPX DDR4 DRAM 2400MHz C16.<\/p>\n I also installed a Crucial 500GB NVMe M.2 drive and cloned over the OS install from my previous SSD (using a combination of Clonezilla and Gparted as bootable USB drives).<\/p>\n The remainder of this post can still be followed to see the process I followed to get to a workable Time Machine backup solution.<\/p>\n I disconnected the power and SATA cables from the hard drives to ensure that while I am formatting the SSD that nothing can go wrong in the process.<\/p>\n Now it is time to reconnect them and ensure the drives can be unlocked and mounted correctly.<\/p>\n Things to do:<\/p>\n <\/p>\n From the First I will check that the drives can be manually unlocked and the file system mounted before continuing to add the keyfile’s required to do this process automatically at boot time after the OS disk has been unlocked.<\/p>\n I want the disks to spin down and use as little energy as possible after being idle for 30 minutes.<\/p>\n I will be using Samba for sharing files to my Macs and PCs on the local network.<\/p>\nOverview<\/h2>\n
\n
Plan Detour<\/h2>\n
This is an automatically generated mail message from mdadm\nrunning on _____\n\nA Fail event had been detected on md device \/dev\/md2.\n\nIt could be related to component device \/dev\/sdf1.\n\nFaithfully yours, etc.\n<\/code><\/pre>\n
Adding back the existing hard drives<\/h2>\n
\n
\n
\/media\/megalodon<\/code>.<\/li>\n
\n
\/media\/hammerhead<\/code>.<\/li>\n<\/ul>\n<\/li>\n
\n
\/media\/timemachine<\/code>.<\/li>\n<\/ul>\n<\/li>\n
\n
\/media\/lemon<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n
\n
sudo shutdown -h now<\/code> and reconnect the drives.<\/li>\n
$ lsblk\n\n# 240 GB SSD that contains the OS\nsdb 8:16 0 223.6G 0 disk\n\u251c\u2500sdb1 8:17 0 1M 0 part\n\u251c\u2500sdb2 8:18 0 1G 0 part \/boot\n\u2514\u2500sdb3 8:19 0 222.6G 0 part\n \u2514\u2500dm_crypt-0 253:0 0 222.6G 0 crypt\n \u2514\u2500ubuntu--vg-ubuntu--lv 253:1 0 222.6G 0 lvm \/\n\n# 14TB Megalodon\nsdc 8:32 0 12.8T 0 disk\n\u2514\u2500sdc1 8:33 0 12.8T 0 part\n \u2514\u2500md127 9:127 0 12.8T 0 raid1\nsdd 8:48 0 12.8T 0 disk\n\u2514\u2500sdd1 8:49 0 12.8T 0 part\n \u2514\u2500md127 9:127 0 12.8T 0 raid1\n\n# 4TB Lemon\nsde 8:64 0 3.7T 0 disk\n\u2514\u2500sde1 8:65 0 3.7T 0 part\n\n# 2TB Timemachine\nsdf 8:80 1 1.8T 0 disk\n\u2514\u2500sdf1 8:81 1 1.8T 0 part\n \u2514\u2500md126 9:126 0 1.8T 0 raid1\nsdg 8:96 1 1.8T 0 disk\n\u2514\u2500sdg1 8:97 1 1.8T 0 part\n \u2514\u2500md126 9:126 0 1.8T 0 raid1\n\n# 3TB Hammerhead\nsdh 8:112 1 2.7T 0 disk\n\u2514\u2500sdh1 8:113 1 2.7T 0 part\n \u2514\u2500md125 9:125 0 2.7T 0 raid1\nsdi 8:128 1 2.7T 0 disk\n\u2514\u2500sdi1 8:129 1 2.7T 0 part\n \u2514\u2500md125 9:125 0 2.7T 0 raid1\n\n# Check the RAID status\n$ cat \/proc\/mdstat\nPersonalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]\nmd125 : active (auto-read-only) raid1 sdi1[0] sdh1[1]\n 2930037760 blocks super 1.2 [2\/2] [UU]\n bitmap: 0\/22 pages [0KB], 65536KB chunk\n\nmd126 : active (auto-read-only) raid1 sdg1[1] sdf1[0]\n 1953285120 blocks super 1.2 [2\/2] [UU]\n bitmap: 0\/15 pages [0KB], 65536KB chunk\n\nmd127 : active (auto-read-only) raid1 sdd1[1] sdc1[0]\n 13672054784 blocks super 1.2 [2\/2] [UU]\n bitmap: 0\/102 pages [0KB], 65536KB chunk\n\nunused devices: <none>\n<\/code><\/pre>\n
\n
Setting up the RAID arrays<\/h3>\n
lsblk<\/code> output I can see that currently the drives are mapped as
\/dev\/md127<\/code> etc. and I would like this to be
\/dev\/md0<\/code> (md1 and md2). So first thing to do is to remap all the arrays to the device names I like to use.<\/p>\n
\n
# In this example I will show you how you can double check UUIDs\n$ sudo mdadm --detail \/dev\/md127\n...\n Name : server:5 (local to host server)\n UUID : 4b2397d7:5cb88116:eee8b5a1:1c72b091\n\n# This can be verified with\n# Note that mdadm uses : for the UUID seperator and lsblk uses -\n$ lsblk -f\n...\nsdc\n\u2514\u2500sdc1 linux_raid_me server:5 4b2397d7-5cb8-8116-eee8-b5a11c72b091\n \u2514\u2500md127 crypto_LUKS e75d3baa-fc9d-4993-a0f0-e9b81b490354\nsdd\n\u2514\u2500sdd1 linux_raid_me server:5 4b2397d7-5cb8-8116-eee8-b5a11c72b091\n \u2514\u2500md127 crypto_LUKS e75d3baa-fc9d-4993-a0f0-e9b81b490354\n<\/code><\/pre>\n
\n
\/etc\/mdadm\/mdadm.conf<\/code>.\nSince I don’t have any configuration specified in that file already, I can just concat info into the file and then edit.<\/li>\n<\/ul>\n
# Become root\n$ sudo -s -H\n# Scan the arrays and append the info to the config file\nroot$ mdadm --detail --scan >> \/etc\/mdadm\/mdadm.conf\nroot$ vi \/etc\/mdadm\/mdadm.conf\n\n# Setup where email is sent to for errors\nMAILADDR user@somewhere.com\n\n# Only change the \/dev\/md\/server:X bits to \/dev\/mdN\n\n# Megalodon 14TB\nARRAY \/dev\/md0 metadata=1.2 name=simba:5 UUID=4b2397d7:5cb88116:eee8b5a1:1c72b091\n# Hammerhead 3TB\nARRAY \/dev\/md1 metadata=1.2 name=simba:1 UUID=11a0d9f1:49b7ccf4:313c4161:871a3c6b\n# Timemachine 2TB\nARRAY \/dev\/md2 metadata=1.2 name=simba:3 UUID=e659b734:4dc6956e:7b6e6df7:3d3da262\n<\/code><\/pre>\n
\n
root$ update-initramfs -u -k all\nroot$ etckeeper commit "Remapped mdadm arrays"\n\n# Reboot and verify\nroot$ reboot now\n\n# After reboot and unlocking the OS disk\n$ lsblk\n\nsdc 8:32 0 12.8T 0 disk\n\u2514\u2500sdc1 8:33 0 12.8T 0 part\n \u2514\u2500md0 9:0 0 12.8T 0 raid1\nsdd 8:48 0 12.8T 0 disk\n\u2514\u2500sdd1 8:49 0 12.8T 0 part\n \u2514\u2500md0 9:0 0 12.8T 0 raid1\n\n$ cat \/proc\/mdstat\n\nPersonalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]\nmd1 : active raid1 sdi1[0] sdh1[1]\n 2930037760 blocks super 1.2 [2\/2] [UU]\n bitmap: 0\/22 pages [0KB], 65536KB chunk\n\nmd2 : active raid1 sdf1[0] sdg1[1]\n 1953285120 blocks super 1.2 [2\/2] [UU]\n bitmap: 0\/15 pages [0KB], 65536KB chunk\n\nmd0 : active raid1 sdc1[0] sdd1[1]\n 13672054784 blocks super 1.2 [2\/2] [UU]\n bitmap: 0\/102 pages [0KB], 65536KB chunk\n<\/code><\/pre>\n
Decrypting the drives<\/h3>\n
\n
# Decrypt drive\n$ sudo cryptsetup luksOpen \/dev\/md0 temp\nEnter passphrase for \/dev\/md0: # Paste from my password manager\n\n$ ls -la \/dev\/mapper\n...\nlrwxrwxrwx 1 root root 7 Nov 3 12:55 temp -> ..\/dm-2\n\n# Verify\n$ sudo cryptsetup -v status temp\n\n\/dev\/mapper\/temp is active.\n type: LUKS1\n cipher: aes-xts-plain64\n keysize: 512 bits\n key location: dm-crypt\n device: \/dev\/md0\n sector size: 512\n offset: 4096 sectors\n size: 27344105472 sectors\n mode: read\/write\nCommand successful.\n\n# Only do this once, create a place to mount at\n$ sudo mkdir \/media\/temp\n\n# Mount the file system\n$ sudo mount \/dev\/mapper\/temp \/media\/temp\n$ df -H | grep temp\n# Go and check \/media\/temp that the expected files exist\n\n# Unmount and lock again\n$ sudo umount \/media\/temp && sudo cryptsetup luksClose temp\n<\/code><\/pre>\n
\n
$ sudo mkdir \/media\/megalodon\n$ sudo mkdir \/media\/hammerhead\n$ sudo mkdir \/media\/timemachine\n$ sudo mkdir \/media\/lemon\n<\/code><\/pre>\n
\n
$ sudo mkdir \/root\/secrets\n$ sudo chmod 0600 \/root\/secrets\n\n# Copy the backed up header-<name> and keyfile-<name> files into \/root\/secrets\n# I stored my keyfile and headers in my password manager\n\n# Ensure only root can read these secrets\n$ sudo -s -H\nroot$ chmod 0400 \/root\/secrets\/*\nroot$ exit\n<\/code><\/pre>\n
\n
$ sudo cryptsetup --key-file \/root\/secrets\/keyfile-megalodon luksOpen \/dev\/md0 megalodon\n$ sudo cryptsetup luksClose megalodon\n<\/code><\/pre>\n
\n
\/etc\/crypttab<\/code> so that the drives can be unlocked at boot using the keyfile.<\/li>\n<\/ul>\n
# Get the UUID that is required\n$ lsblk -f\n...\nsdc\n\u2514\u2500sdc1 linux_raid_mem simba:5 4b2397d7-5cb8-8116-eee8-b5a11c72b091\n \u2514\u2500md0 crypto_LUKS e75d3baa-fc9d-4993-a0f0-e9b81b490354\n\n# You want the UUID for the ones that say crypto_LUKS\n\n$ sudo vi \/etc\/crypttab\n\n# \/dev\/md0 Megalodon 14TB\nmegalodon UUID=e75d3baa-fc9d-4993-a0f0-e9b81b490354 \/root\/secrets\/keyfile-megalodon luks,discard\n# \/dev\/md1 Hammerhead 3TB\nhammerhead UUID=084d2da7-c40f-408d-b16c-67a33217a75f \/root\/secrets\/keyfile-hammerhead luks,discard\n# \/dev\/md2 Timemachine 2TB\ntimemachine UUID=fb4d1341-d253-40ce-a592-8b20c2a5efa6 \/root\/secrets\/keyfile-timemachine luks,discard\n# \/dev\/sde1 Lemon 4TB\nlemon UUID=1bac3dab-2262-45de-b9e1-ff361b17241f \/root\/secrets\/keyfile-lemon luks,discard\n<\/code><\/pre>\n
\n
\/etc\/fstab<\/code> so that the file systems can be mounted at boot.<\/li>\n<\/ul>\n
$ sudo vi \/etc\/fstab\n\n# Megalodon 14TB\n\/dev\/mapper\/megalodon \/media\/megalodon ext4 defaults 0 2\n# Hammerhead 3TB\n\/dev\/mapper\/hammerhead \/media\/hammerhead ext4 defaults 0 2\n# Timemachine 2TB\n\/dev\/mapper\/timemachine \/media\/timemachine ext4 defaults 0 2\n# Lemon 4TB\n\/dev\/mapper\/lemon \/media\/lemon ext4 defaults 0 2\n<\/code><\/pre>\n
\n
$ sudo cryptdisks_start megalodon\n* Starting crypto disk...\n* megalodon (starting)...\n* megalodon (started)... [ OK ]\n\n$ sudo cryptdisks_start hammerhead\n$ sudo cryptdisks_start timemachine\n$ sudo cryptdisks_start lemon\n\n# Mount all file systems\n$ sudo mount -a\n\n# Go check all the drives have been mounted and the file are as expected\n<\/code><\/pre>\n
\n
$ sudo update-initramfs -u -k all\n$ sudo etckeeper commit "Drives have been added and can be unlocked and mounted"\n<\/code><\/pre>\n
\n
Save energy by spinning down idle disks<\/h2>\n
\n
$ ls \/dev\/disk\/by-id\/ata*\n<\/code><\/pre>\n
\n
hdparm.conf<\/code>.<\/li>\n<\/ul>\n
$ sudo vi \/etc\/hdparm.conf\n\n# For each of the disks\n\/dev\/disk\/by-id\/ata-ST14000NE0008-2RX103_ZL2ALN47 {\n # 30 minutes\n spindown_time = 241\n # advanced power management with spin down\n apm = 127\n}\n<\/code><\/pre>\n
\n
sudo powertop<\/code> again. I noticed that by only doing the hdparm.conf changes that the drives were still using more power than they used to in the previous OS setup. However after running powertop and tuning everything to say "good" reduced the usage by about 10 – 15 watts again.<\/li>\n
Samba file sharing<\/h2>\n
\n
# Normal user that will have a \/home and be able to login via shell\n$ sudo adduser maverick\n\n# User that will not be able to use a shell\n$ sudo adduser goose --shell \/usr\/sbin\/nologin\n<\/code><\/pre>\n
\n
$ sudo apt install samba\n<\/code><\/pre>\n
\n
\/etc\/passwd<\/code>)<\/li>\n<\/ul>\n
$ sudo smbpasswd -a USERNAME\n<\/code><\/pre>\n