From bbf7974715b9a43bab207df75ef69209cdf13850 Mon Sep 17 00:00:00 2001 From: "David T. Sadler" Date: Mon, 17 May 2021 15:59:24 +0100 Subject: Move to building localy rather than on remote server --- www/css/site.css | 3 + www/images/favicon.png | Bin 0 -> 190 bytes www/index.html | 23 + .../index.html | 119 ++++++ .../adding-a-user-in-arch-linux/index.html | 30 ++ .../index.html | 25 ++ .../index.html | 32 ++ .../pacman-cheat-sheet-for-ubuntu-users/index.html | 45 ++ .../enabling-audio-in-arch-linux/index.html | 27 ++ .../index.html | 34 ++ www/posts/arch/atom.xml | 216 ++++++++++ www/posts/arch/index.html | 23 + www/posts/atom.xml | 471 +++++++++++++++++++++ .../index.html | 80 ++++ www/posts/gemini/atom.xml | 74 ++++ www/posts/gemini/index.html | 23 + www/posts/index.html | 23 + .../scheduling-posts-in-jigsaw/index.html | 37 ++ www/posts/jigsaw/atom.xml | 31 ++ www/posts/jigsaw/index.html | 23 + .../index.html | 42 ++ .../index.html | 75 ++++ www/posts/laravel/atom.xml | 96 +++++ www/posts/laravel/index.html | 23 + .../index.html | 24 ++ www/posts/linux/atom.xml | 18 + www/posts/linux/index.html | 23 + .../creating-an-ebook-with-markdown/index.html | 59 +++ www/posts/markdown/atom.xml | 53 +++ www/posts/markdown/index.html | 23 + .../index.html | 23 + www/posts/netlify/atom.xml | 17 + www/posts/netlify/index.html | 23 + .../index.html | 23 + www/posts/nextcloud/atom.xml | 17 + www/posts/nextcloud/index.html | 23 + .../installing-php-8-for-windows-10/index.html | 27 ++ www/posts/php/atom.xml | 21 + www/posts/php/index.html | 23 + 39 files changed, 1972 insertions(+) create mode 100644 www/css/site.css create mode 100644 www/images/favicon.png create mode 100644 www/index.html create mode 100644 www/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/index.html create mode 100644 www/posts/arch/2020-06-15/adding-a-user-in-arch-linux/index.html create mode 100644 www/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/index.html create mode 100644 www/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/index.html create mode 100644 www/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/index.html create mode 100644 www/posts/arch/2020-08-31/enabling-audio-in-arch-linux/index.html create mode 100644 www/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/index.html create mode 100644 www/posts/arch/atom.xml create mode 100644 www/posts/arch/index.html create mode 100644 www/posts/atom.xml create mode 100644 www/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/index.html create mode 100644 www/posts/gemini/atom.xml create mode 100644 www/posts/gemini/index.html create mode 100644 www/posts/index.html create mode 100644 www/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.html create mode 100644 www/posts/jigsaw/atom.xml create mode 100644 www/posts/jigsaw/index.html create mode 100644 www/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/index.html create mode 100644 www/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/index.html create mode 100644 www/posts/laravel/atom.xml create mode 100644 www/posts/laravel/index.html create mode 100644 www/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.html create mode 100644 www/posts/linux/atom.xml create mode 100644 www/posts/linux/index.html create mode 100644 www/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/index.html create mode 100644 www/posts/markdown/atom.xml create mode 100644 www/posts/markdown/index.html create mode 100644 www/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/index.html create mode 100644 www/posts/netlify/atom.xml create mode 100644 www/posts/netlify/index.html create mode 100644 www/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/index.html create mode 100644 www/posts/nextcloud/atom.xml create mode 100644 www/posts/nextcloud/index.html create mode 100644 www/posts/php/2021-01-18/installing-php-8-for-windows-10/index.html create mode 100644 www/posts/php/atom.xml create mode 100644 www/posts/php/index.html (limited to 'www') diff --git a/www/css/site.css b/www/css/site.css new file mode 100644 index 0000000..8e80eca --- /dev/null +++ b/www/css/site.css @@ -0,0 +1,3 @@ +section a { + display: block; +} diff --git a/www/images/favicon.png b/www/images/favicon.png new file mode 100644 index 0000000..4909792 Binary files /dev/null and b/www/images/favicon.png differ diff --git a/www/index.html b/www/index.html new file mode 100644 index 0000000..90fb068 --- /dev/null +++ b/www/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler + + + + + + + + + + + + + + +

The Home of David T. Sadler

Hello and welcome to my little bit of the internet where I occasionally write about things that interest me. You might find my posts interesting or you might not and that's okay.

Latest Posts

2021-02-15 - Accessing Nextcloud With WebDAV on Arch2021-02-08 - How to Host Your Own Gemini Site in the Cloud2021-01-18 - Installing PHP 8 for Windows 102020-12-21 - Installing Laravel Homestead in Arch Linux2020-12-14 - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed2020-09-07 - Installing Zsh and Powerlevel10k on Arch Linux2020-08-31 - Enabling Audio in Arch Linux2020-08-24 - Pacman Cheat Sheet For Ubuntu Users2020-08-17 - Installing ST, DMENU and DWM in Arch Linux2020-07-13 - Sudo: sorry, you must have a tty to run sudo2020-06-22 - Granting Sudo Access to a User in Arch Linux2020-06-15 - Adding a User in Arch Linux2020-06-08 - Publishing Jigsaw Posts With Netlify Build Hooks2020-06-01 - Scheduling Posts in Jigsaw2020-05-25 - Installing Arch Linux on a Thinkpad X2202020-03-30 - Creating an Ebook With Markdown

All Posts

Post Archive

Tags

Arch.Gemini.Jigsaw.Laravel.Linux.Markdown.Netlify.Nextcloud.PHP.

Where to Find Me

GitHub.Gemini site.Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

+ + diff --git a/www/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/index.html b/www/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/index.html new file mode 100644 index 0000000..f2a2d21 --- /dev/null +++ b/www/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/index.html @@ -0,0 +1,119 @@ + + + + + + Installing Arch Linux on a Thinkpad X220 + + + + + + + + + + + + + + +

Installing Arch Linux on a Thinkpad X220

Mon 25th May 2020 By David T. Sadler.

Introduction

So I purchased a used Thinkpad X220 for about £90 on eBay and decided to install Arch Linux onto it. This guide is the steps that I took to achieve this.

Now when it comes to Linux there is always more than one way of doing things and this guide is just my preferred way. Feel free to follow it for your own installation, just keep in mind that you may have to change some of the steps to suit your own circumstances. Also there is every chance that the information presented here will be out of date so I recommend that you at least read the through the official installation guide for the most up-to-date information.

Download the Arch Linux ISO Image

The Arch Linux download page provides direct download and torrent links. You should also download the PGP signature to the same location and use the gpg command to verify that the ISO has not been compromised.

$ gpg --keyserver-options auto-key-retrieve --verify archlinux-2020.05.01-x86_64.iso.sig

Create a Live USB of Arch Linux

Flash the image to a USB drive using Etcher. Alternatively you can use the dd command. Just ensure that /path/to/archlinux.iso is to where you have downloaded the image and that /dev/sdx is your USB drive.

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress && sync

Boot the Live Environment

I wanted to make sure that the Thinkpad was using UEFI as I would be using EFISTUB to load the Linux kernel as an EFI executable. This is done through the BIOS which can be gotten to by pressing the ThinkVantage button as the machine is booting before pressing F1 to get to the BIOS settings. From there navigate to Startup and changed the UEFI/Legacy Boot option to be UEFI Only. Press F10 to save and exit the BIOS and then power down the machine.

With the USB drive plugged in power the machine back on, all the while pressing F12 until the boot menu appears and select USB HDD: Mass Storage Device and wait for the installation image to boot. When prompted select Arch Linux archiso X86_64 UEFI CD where you will be take to the live environment's terminal.

Set the Keyboard Layout

The default console map is US which meant that for me pressing Shift+3 was displaying the hash symbol (#) instead of the pound symbol (£). So the UK keyboard layout needed to be loaded.

$ loadkeys uk

You can get a list of supported keyboard layouts if you need to load a different one.

ls /usr/share/kbd/keymaps/**/*.map.gz

Verify the Boot Mode

To verify that the Thinkpad has UEFI enabled check that the efivars directory exists.

$ ls /sys/firmware/efi/efivars

Connect to the Internet

Verify that the machine can connect to the internet with the ping command.

$ ping -c3 davidtsadler.com

Before booting the machine I plugged in an Ethernet cable that was connected directly to my home network's router. The installation environment detected the network connection and obtained an IP address via DHCP.

Update the System Clock

Ensure the system clock is correct.

$ timedatectl set-ntp true

Partition the Disks

Use the lsblk command to determine which disks and partitions exist on the system.

$ lsblk
+
+NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
+loop0    7:0    0   535M  1 loop /run/archiso/sfs/airootfs
+sda      8:0    0 298.1G  0 disk
+sdb      8:16   1   7.4G  0 disk
+├─sdb1   8:17   1   652M  0 part /run/archiso/bootmnt
+└─sdb2   8:18   1    64M  0 part

From the above output I could see that my hard drive was sda as sdb was the USB drive and loop0 could just be ignored.

I knew that I wanted to have an encrypted partition and make use of LVM on it so my disk layout would be.

+-------------------+ +--------------------------------------------------------+
+| Boot partition    | | Logical volume 1 | Logical volume 2 | Logical volume 3 |
+|                   | |                  |                  |                  |
+| /boot             | | /                | [SWAP]           | /home            |
+|                   | |                  |                  |                  |
+|                   | | 50G              | 16G              | 200G             |
+|                   | |                  |                  |                  |
+|                   | | /dev/vg0/root    | /dev/vg0/swap    | /dev/vg0/home    |
+|                   | |_ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ |
+|                   | |                                                        |
+|                   | |              LUKS2 encrypted partition                 |
+| /dev/sda1 (512MB) | |                    /dev/sda2                           |
++-------------------+ +--------------------------------------------------------+

The hard drive would be split into two partitions. The first, sdb1 would be 512MB in size and mounted in the file system at /boot. This would be the EFI system partition. The reminder of the disk space would be given to the partition sda2 and encrypted using LUKS2. LVM would then be used to create the volume group vg0 that would be divided into three partitions as logical volumes.

Use fdisk to create the partitions.

$ fdisk /dev/sda

Enter g to create a new empty GPT partition table

Command (m for help): g
+Created a new GPT disklabel (GUID: 6987D065-936E-1547-9F02-F78145025A96).

Since this is a UEFI system there must be a EFI partition at the beginning of the disk. Enter n to add a new partition and enter 1 to assign it as the first partition. Use the default value for the first sector but enter +512M for the last sector.

Command (m for help): n
+Partition number (1-128, default 1): 1
+First sector (2048-625142414, default 2048):
+Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-625142414, default 625142414): +512M
+
+Created a new partition 1 of type 'Linux filesystem' and of size 512 MiB.

Enter t to change the partition type and enter 1 to make it an EFI System. You can also get a list of partition types by pressing L.

Command (m for help): t
+Selected partition 1
+Partition type (type L to list all types): 1
+Changed type of partition 'Linux filesystem' to 'EFI System'.

To create the second partition enter n again to add another partition, and then enter 2 to assign it as the second partition. Use the default values for both first and last sectors to allocate the remainder of the drive.

Command (m for help): n
+Partition number (2-128, default 2): 2
+First sector (1050624-625142414, default 1050624):
+Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-625142414, default 625142414):
+
+Created a new partition 2 of type 'Linux filesystem' and of size 297.6 GiB.

Enter w to write the changes and quit.

Command (m for help): w
+The partition table has been altered.
+Calling ioctl() to re-read partition table.
+Syncing disks.

Use lsblk to confirm that two partitions have been created.

$ lsblk /dev/sda
+
+NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
+sda      8:0    0 298.1G  0 disk
+├─sda1   8:1    0   512M  0 part
+└─sda2   8:2    0 297.6G  0 part

LUKS

Encrypt the second partition with the cryptsetup command.

$ cryptsetup luksFormat /dev/sda2

When prompted enter YES in capitals to overwrite any data that is currently on the partition.

WARNING!
+========
+This will overwrite data on /dev/sda2 irrevocably.
+
+Are you sure? (Type 'yes' in capital letters): YES

Enter and verify a passphrase. Whenever the machine is now booted you will be prompted to enter this passphrase in order for the partition to be decrypted.

Enter passphrase for /dev/sda2:
+Verify passphrase:
+cryptsetup luksFormat /dev/sda2  17.01s user 1.05s system 105% cpu 17.106 total

LVM on LUKS

Before setting up LVM decrypt the partition.

$ cryptsetup open /dev/sda2 cryptlvm

You will be prompted to enter the passphrase that you set up earlier.

Enter passphrase for /dev/sda2:
+cryptsetup open /dev/sda2 cryptlvm  6.48s user 0.36s system 92% cpu 7.436 total

Create a physical volume.

$ pvcreate /dev/mapper/cryptlvm

Create a volume group called vg0.

$ vgcreate vg0 /dev/mapper/cryptlvm

Create three logical volumes for the root, swap and home partitions.

$ lvcreate -L 50G vg0 -n root
+$ lvcreate -L 16G vg0 -n swap
+$ lvcreate -L 200G vg0 -n home

Make use of lsblk again to verify that LVM has been setup as expected.

$ lsblk /dev/sda
+
+NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
+sda              8:0    0 298.1G  0 disk
+├─sda1           8:1    0   512M  0 part
+└─sda2           8:2    0 297.6G  0 part
+└─cryptlvm   254:0    0 297.6G  0 crypt
+├─vg0-root 254:1    0    50G  0 lvm
+├─vg0-swap 254:2    0    16G  0 lvm
+└─vg0-home 254:3    0   200G  0 lvm

Format the Partitions

Format the boot partition at /dev/sda1 with a FAT32 file system as the UEFI specification requires the usage of it.

$ mkfs.fat -F32 /dev/sda1

The root and home partitions can be formatted with ext4.

$ mkfs.ext4 /dev/vg0/root
+$ mkfs.ext4 /dev/vg0/home

Initialise the swap partition.

$ mkswap /dev/vg0/swap
+$ swapon /dev/vg0/swap

Mount the File Systems

Mount the root partition into /mnt.

$ mount /dev/vg0/root /mnt

Mount the boot partition into /mnt/boot.

$ mkdir /mnt/boot
+$ mount /dev/sda1 /mnt/boot

Finally mount the home partition into /mnt/home.

$ mkdir /mnt/home
+$ mount /dev/vg0/home /mnt/home

Select the Mirrors

All mirror servers defined in /etc/pacman.d/mirrorlist where done at the time the installation image was built. Since it's ideal to try and use servers that are close to your location you can rebuild the list using the rankmirrors utility. This is not included by default on the live environment so you will need to download it.

First sync the pacman repository.

pacman -Syy

Then download the pacmain-contrib package which contains the rankmirrors utility.

$ pacman -S pacman-contrib

The official Pacman Mirrorlist Generator can be used to get an up-to-date list of servers for your country. The below command obtains a list of UK servers that support https and pass it to rankmirrors to obtain the 5 fastest.

$ curl -s "https://www.archlinux.org/mirrorlist/?country=GB&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 - > /etc/pacman.d/mirrorlist

Install Essential Packages

The pacstrap script is used to install the base package, Linux kernel and firmware.

$ pacstrap /mnt base linux linux-firmware neovim wpa_supplicant dhcpcd cryptsetup lvm2 efibootmgr intel-ucode

I also installed a few other packages that I knew I was going to need.

Fstab

Create a fstab file on the new system.

$ genfstab -U /mnt >> /mnt/etc/fstab

Chroot

Use arch-chroot to enter the new system as the root user. From now on you will be configuring the new system.

$ arch-chroot /mnt

Time Zone

Setup the timezone. Replace Europe/London with your timezone.

$ ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

Update the hardware clock.

$ hwclock --systohc

Localization

Use nvim to edit /etc/locale.gen.

$ nvim /etc/locale.gen

Uncomment your preferred language. For me this meant en_GB.UTF-8 UTF-8. Save the file and exit before generating the locales.

$ locale-gen

Edit /etc/locale.conf.

$ nvim /etc/locale.conf

Add the below line. Replace en_GB.UTF-8 with the language that you chose earlier.

LANG=en_GB.UTF-8

If you used loadkeys earlier you will need to edit /etc/vconsole.conf and add your chosen keymap.

$ nvim /etc/vconsole.conf

For me this meant adding the UK keymap.

KEYMAP=uk

Network Configuration

Create the file /etc/hostname and add an entry to it. This hostname will be the name of the machine on your network. I tend to name by devices after characters from the book Howl's Moving Castle https://en.wikipedia.org/wiki/Howl%27s_Moving_Castle).

$ echo suliman > /etc/hostname

You then need to edit the /etc/hosts file.

$ nvim /etc/hosts

Add the following lines to this file. Replace suliman with the hostname you set up earlier.

127.0.0.1	localhost
+::1		    localhost
+127.0.0.1	suliman.localdomain suliman

Wireless

Use the ip command to determine the name of the wireless network interface.

$ip link
+
+1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
+link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
+2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
+link/ether f0:de:f1:86:e1:75 brd ff:ff:ff:ff:ff:ff
+3: wwp0s29u1u4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
+link/ether 86:06:37:c4:9b:41 brd ff:ff:ff:ff:ff:ff
+4: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
+link/ether 08:11:96:02:10:ac brd ff:ff:ff:ff:ff:ff

Looking at the output of the ip command this is wlan0. This name however will not be the name of the interface once the installation has been completed. You see the Arch installation environment does not use predictable names for interfaces. This is due to it using iwd which is unable to cope with interface renaming and so it is disabled for wireless interfaces. When the system boots into the installed system predictable names for interfaces will be enabled and wlan0 will be assigned a different name.

In order to find out what name will be assigned use the udevadm command.

$ udevadm test-builtin net_id /sys/class/net/wlan0
+
+Load module index
+Parsed configuration file /usr/lib/systemd/network/99-default.link
+Parsed configuration file /usr/lib/systemd/network/80-iwd.link
+Created link configuration context.
+Using default interface naming scheme 'v245'.
+ID_NET_NAMING_SCHEME=v245
+ID_NET_NAME_MAC=wlx0811960210ac
+ID_OUI_FROM_DATABASE=Intel Corporate
+ID_NET_NAME_PATH=wlp3s0
+Unload module index
+Unloaded link configuration context.

What we are interested in is the value of ID_NET_NAME_PATH which is wlp3s0.

My wireless network is a WPA2 protected network with a hidden SSID. Since wpa_supplicant has been installed when running pacstrap it is possible to use wpa_passphrase to generate the configuration file that wpa_supplicant will use to connect to the wireless network. Replace &lt;SSID&gt; and &lt;PASSWORD&gt; with your details. Note that the name of the configuration file contains the name of the network interface wlp3s0. Replace this with the name of your network interface.

$ wpa_passphrase <SSID> <PASSWORD> > /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf

If your wireless network uses a hidden SSID you will need to edit the configuration file.

$ nvim /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf

And add the below line.

scan_ssid=1

Make sure that wpa_supplicant starts at boot.

$ systemctl enable wpa_supplicant@wlp3s0.service

Have an IP address assigned via DHCP during booting.

$ systemctl enable dhcpcd@wlp3s0.service

Initramfs

You will need to rebuild the initial ramdisk and the current one is not aware that the filesystem will be encrypted. Before rebuilding it some configuration changes need to be made.

$ nvim /etc/mkinitcpio.conf

Locate the section where the HOOKS are configured and replace it with the line below.

HOOKS=(base udev autodetect keyboard keymap modconf block encrypt lvm2 filesystems fsck)

This ensures that the keyboard is present before the filesystem is detected so that you are enter the passphrase to decrypt the partition. It also ensures that the decryption is done before the LVM is handled.

Save the changes and exist before rebuilding with the mkinitcpio command.

mkinitcpio -P

EFISTUB Booting and Microcode

The Thinkpad X220 UEFI implementation allows an operating system to be booted without the need for an intermediate bootloader such as GRUB. It is possible to add a UEFI boot entry to the motherboard itself and have Arch booted directly.

Modifying the motherboard boot entries is done using efibootmgr. However usage of this command can be quite verbose so it is recommended to create a shell script instead.

nvim /usr/local/sbin/mkefibootentry

The shell script will call efibootmgr with the required arguments.

#!/bin/sh
+
+# Determine the UUID of the partition that is encrypted
+PARTUUID=`blkid /dev/sda2 -s PARTUUID -o value`
+
+efibootmgr \
+--disk /dev/sda --part 1 \
+--create --label "Arch Linux" \
+--loader /vmlinuz-linux \
+--unicode 'cryptdevice=PARTUUID='$PARTUUID':cryptlvm root=/dev/vg0/root rw initrd=\intel-ucode.img initrd=\initramfs-linux.img' \
+--verbose 

The --unicode argument is where the kernel parameters are specified. This tells the system that the partition identified by PARTUUID is encrypted and that the root filesystem to mount is the logical volume called root that is part of the volume group vg0. The microcode is also loaded with initrd=\intel-ucode.img.

Make this script executable.

chmod u+x /usr/local/sbin/mkefibootentry

Run the script to add to the motherboard boot entries.

$ mkefibootentry

Root Password

Create a secure password for the root user.

$ passwd

Reboot

Return to the Arch live installation environment.

$ exit

Unmount the partitions.

$ umount -R /mnt

Restart the machine with reboot. Remember to remove any installation media such as a USB drive.

$ reboot

Provided nothing has gone wrong your machine will boot into a fresh installation of Arch Linux. Don't forget that during the boot you will be prompted to enter the passphrase to decrypt the system partition.

Following this guide will leave you with a very minimal system where you can login as the root user. From this point how you configure the system is up to you as it will be very different to how I configure my own. If you interested in seeing how I do it then see my other posts on the subject.

Links

Offical Arch Installation Guide.Arch Linux Download Page.Etcher.Pacman Mirrorlist Generator.Wikipedia Entry for Howl's Moving Castle.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/arch/2020-06-15/adding-a-user-in-arch-linux/index.html b/www/posts/arch/2020-06-15/adding-a-user-in-arch-linux/index.html new file mode 100644 index 0000000..c294c31 --- /dev/null +++ b/www/posts/arch/2020-06-15/adding-a-user-in-arch-linux/index.html @@ -0,0 +1,30 @@ + + + + + + Adding a User in Arch Linux + + + + + + + + + + + + + + +

Adding a User in Arch Linux

Mon 15th June 2020 By David T. Sadler.

In a previous post I installed Arch Linux on my Thinkpad X220. Since it was a very minimal install there are no user accounts except for the root user. So to add myself as a user I need to use the useradd command.

$ useradd -m -s /bin/bash david

I used the below options with the command.

This creates a new account for me and also ensures that a home directory is created as /home/david.

The new account will require a password so assign one with the passwd command.

$ passwd david
+
+New password:
+Retype new password:
+passwd: password updated successfully

Now all I have to do is logout of the root account.

$ logout

Then login with the new credentials to confirm that everything is okay.

suliman login: david
+Password:
+
+david@suliman:$

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/index.html b/www/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/index.html new file mode 100644 index 0000000..7072ec7 --- /dev/null +++ b/www/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/index.html @@ -0,0 +1,25 @@ + + + + + + Granting Sudo Access to a User in Arch Linux + + + + + + + + + + + + + + +

Granting Sudo Access to a User in Arch Linux

Mon 22nd 2020 By David T. Sadler.

So by the end of my last post my minimal installation of Arch Linux had a user account that I could log into instead of the root user. However in order to do anything useful on the system I need to be able to run commands such as pacman that only the root user can do. Now one way to solve this is to change to the root user with su before running the command, but this defeats the point in creating a non-root user account in the first place. Instead a better way is to make use of sudo.

Sudo (su "do") gives the ability for a user (or groups of users) to run some (or all) commands as root and also provides an audit trail of the commands and their arguments. Usage is very simple, you enter sudo followed by the command that you want to run. For example,

$ sudo pacman -Syu

Configuration is done in the file /etc/sudoers. This is where you can specify which users or groups can use sudo and what commands they can run. However, you must be careful when editing this file as any syntax errors will make sudo unusable. Therefore it is strongly recommended to do any editing via the visudo command. This locks the sudoers file, saves edits to a temporary file, and checks that file's grammar before copying it to /etc/sudoers.

Traditionally in Linux systems users that should have privileged administrator rights are added to the wheel group which is then given sudo access. As the root user the first thing that I needed to do was add my user account to the wheel group with the usermod command.

$ usermod -aG wheel david

I used the below options with the command.

The sudo package then needed to be installed.

$ pacman -S sudo

Next I needed to grant sudo access to the wheel group by editing /etc/sudoers with visudo. Note that the default editor for visudo is vi. Since this has not been installed on my system I can change the editor to be nvim by first setting the variable EDITOR.

$ EDITOR=nvim visudo

Once the file was opened I located and uncommented the below line before saving and exiting nvim. This allows members of the wheel group to execute any command without having to enter their password.

%wheel ALL(ALL) NOPASSWD: ALL

I checked that I had sudo access by running the below command while logged into my user account.

$ sudo pwd
+
+/home/david

Since I wasn't prompted for my password and the command was executed I knew that I now had sudo access.

Links

Adding a User in Arch Linux.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/index.html b/www/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/index.html new file mode 100644 index 0000000..b61891c --- /dev/null +++ b/www/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/index.html @@ -0,0 +1,32 @@ + + + + + + Installing ST, DMENU and DWM in Arch Linux + + + + + + + + + + + + + + +

Installing ST, DMENU and DWM in Arch Linux

Mon 17th August 2020 By David T. Sadler.

Continuing my Arch Linux installation I now have a user account for daily use. However this only provides me with a terminal. What I would like is a traditional multi-window desktop environment which will require me to install two things. A window system of some sort and a layout manager. For this installation I'm going with Xorg and dwm. For those that are not aware dwm is dynamic window manager for Xorg that has been developed by Suckless. Since by default dwm expects st to be installed as the system's terminal and also makes use dmenu to allow you to launch applications I will installed both of them in addition to dwm.

Install Dependencies

Firt off I need to install the dependencies required by st, dmenu and dwm. Since this is Arch Linux I use pacman to do this.

$ sudo pacman -S base-devel git libx11 libxft xorg-server xorg-xinit terminus-font

Download Git Repositories

The source code for the software is avialable from the Suckless git repositories so I simply clone them.

$ mkdir -p ~/.local/src
+
+$ git clone git://git.suckless.org/st ~/.local/src/st
+$ git clone git://git.suckless.org/dmenu ~/.local/src/dmenu
+$ git clone git://git.suckless.org/dwm ~/.local/src/dwm

Install ST

I install st by first moving to the directory created when cloning the repository.

$ cd ~/.local/src/st

Then its as simple as compiling and instaling the software with the below commands.

$ make clean
+$ sudo make install

Configure and Install DMENU

Again move to the directory created earlier.

$ cd ~/.local/src/dmenu

Before compiling a small edit needs to be made to the file config.mk.

$ nvim config.mk

Since I have not installed Xinerama on this system I need to comment out any flags that reference this otherwise dmenu will fail during the compiling.

# XINERAMALIBS  = -lXinerama
+# XINERAMAFLAGS = -DXINERAMA

Again compiling and installing is done with the below commands.

$ make clean
+$ sudo make install

Configure and Install DWM

For the final time move to the directory created earlier.

$ cd ~/.local/src/dwm

As with dmenu the same edit needs to be made to the file config.mk.

$ nvim config.mk
# XINERAMALIBS  = -lXinerama
+# XINERAMAFLAGS = -DXINERAMA

Compile and install as usual.

$ make clean
+$ sudo make install

Starting DWM

Since I have installed xorg-xinit I need to create a .xinitrc in my home folder.

$ nvim ~/.xinitrc

The contents of this file is just.

exec dwm

I can now start xorg and dwm with the below command.

$ startx

Links

Installing Arch Linux on a Thinkpad X220.Dynamic Window Manager (DWM).Suckless Software.Simple Terminal.DMenu.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/index.html b/www/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/index.html new file mode 100644 index 0000000..e11103e --- /dev/null +++ b/www/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/index.html @@ -0,0 +1,45 @@ + + + + + + Pacman Cheat Sheet For Ubuntu Users + + + + + + + + + + + + + + +

Pacman Cheat Sheet For Ubuntu Users

Mon 24th August 2020 By David T. Sadler.

As a regular Ubuntu user I am used to using apt for system maintenance. But now that I've installed Arch Linux I will be using pacman and so below is a cheat sheet for myself that shows the pacman equivalent of some common apt actions.

Action                     | Apt                            | Pacman                     |
+---------------------------|--------------------------------|----------------------------|
+Install a package          | apt install <package name>     | pacman -S <package name>   |
+Remove a package           | apt remove <package name>      | pacman -Rs <package name>  |
+Search for a package       | apt serch <search term>        | pacman -Ss <regexp>        |
+Upgrade packages           | apt update && apt upgrade      | pacman -Syu                |
+Upgrade distribution       | apt update && apt dist-upgrade | pacman -Syu                |
+Clean up local caches      | apt autoclean                  | pacman -Scc                |
+Remove unused dependencies | apt autoremove                 | pacman -Qmq | pacman -Rs - |

Install a Package

$ pacman --sync <package name>
+
+$ pacman -S <package name>

Installs a package and its dependencies.

Remove a Package

$ pacman --remove --recursive <package name>
+
+$ pacman -Rs <package name>

Removes a package and all its dependencies, provided that (A) they are not required by other packages; and (B) they were not explicitly installed by the user.

Search For a Package

$ pacman --sync --search <regexp>
+
+$ pacman -Ss <regexp>

Searches in the sync database for packages with a name or description that match the regexp.

Upgrade Packages

$ pacman --sync --refresh --sysupgrade
+
+$ pacman -Syu

Downloads a fresh copy of the master package database and then upgrades all out-of-date packages.

Upgrade Distribution

$ pacman --sync --refresh --sysupgrade
+
+$ pacman -Syu

Since Arch uses a rolling release system there is no distribution version as you just upgrade your packages to their latest versions.

Clean Up Local Caches

$ pacman --sync --clean --clean
+
+$ pacman -Scc

Free up disk space by removing from the cache any packages that are no longer installed. Also removes any cached sync databases.

Remove Used Dependencies

$ pacman --query --deps --unrequired --quiet | pacman --remove --recursive -
+
+$ pacman -Qdtq | pacman -Rs -

Remove dependencies that are no longer needed, because e.g. the package which needed the dependencies was removed.

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/arch/2020-08-31/enabling-audio-in-arch-linux/index.html b/www/posts/arch/2020-08-31/enabling-audio-in-arch-linux/index.html new file mode 100644 index 0000000..413b436 --- /dev/null +++ b/www/posts/arch/2020-08-31/enabling-audio-in-arch-linux/index.html @@ -0,0 +1,27 @@ + + + + + + Enabling Audio in Arch Linux + + + + + + + + + + + + + + +

Enabling Audio in Arch Linux

Mon 31st August 2020 By David T. Sadler.

If you have recently installed Arch Linux you may have found that there is no sound when playing media. This is because by default ALSA has all channels muted.

Installing the ALSA Utilities

The Advanced Linux Sound Architecture (ALSA) is the part of the Linux kernel that manages the sound devices on your system. In addition to this the project also provides several command-line utilities that allow you to configure these devices. These can be installed with pacman.

$ sudo pacman -S alsa-utils

Unmuting The Channels

Channels can be unmuted with amixer.

$ amixer sset Master unmute
+$ amixer sset Speaker unmute
+$ amixer sset Headphone unmute

You can test that the speakers are working with the speaker-test command.

$ speaker-test -c 2

If you are still getting no sound then it could be that the volume has been set to zero. Use amixer again to increase the volume.

$ amixer sset Master 100%
+$ amixer sset Speaker 100%
+$ amixer sset Headphone 100%

Unmute with Alsamixer

If you prefer a more intuitive ncurses interface you can use alsamixer.

$ alsamixer

Channels that are muted will have the MM label below them. Unmuted channels have 00.

Use the ← and → keys to scroll to the muted channel and press m to unmute it.

The volume can be increased and decreased with the ↑ and ↓ keys.

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/index.html b/www/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/index.html new file mode 100644 index 0000000..f3640a2 --- /dev/null +++ b/www/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/index.html @@ -0,0 +1,34 @@ + + + + + + Installing Zsh and Powerlevel10k on Arch Linux + + + + + + + + + + + + + + +

Installing Zsh and Powerlevel10k on Arch Linux

Mon 7th September 2020 By David T. Sadler.

I have been a bash user ever since I started using Linux. But after installing Arch Linux I wanted to give another shell a try and so decided on Zsh. Below is how I went about replacing bash with Zsh.

Installing Zsh

Zsh is installed via pacman.

$ sudo pacman -S zsh

Check that Zsh has been installed by running it from the terminal.

$ zsh

Since this is the first time that Zsh has been run you should now see zsh-newuser-install which will allow you to setup some basic configuration. If you wish to skip this just press the q key. You can always manually run this with the below commands at a later date.

$ autoload -Uz zsh-newuser-install
+$ zsh-newuser-install -f

Changing The Default Shell

Installing Zsh does not automatically make it the system's default shell. The next time you log back in you will find that your current shell is still in use. You can check which shell is been used by looking at the SHELL environment variable.

$ echo $SHELL
+
+/bin/bash

To see a list of shells that have been installed use the chsh command.

$ chsh -l
+
+/bin/sh
+/bin/bash
+/usr/bin/git-shell
+/bin/zsh
+/usr/bin/zsh

The same command can be used to change the default shell by providing it with the full path to the shell.

$ chsh -s /bin/zsh

Note that this change is not instant and you will need to log out and log in again for it to take affect. Once you have done that check the SHELL environment variable again to confirm the change.

$ echo $SHELL
+
+/bin/ksh

Installing Powerlevel10k

Powerlevel10k is a theme for Zsh and in order to make the most of it you should install the Meslo Nerd Font that has been patched for Powerlevel10k.

$ yay -Sy --noconfirm ttf-meslo-nerd-font-powerlevel10k

You need to configure your terminal to use this font. How this is done is dependant upon what terminal you are using. Since I use st from suckless I need to edit the file config.h and specify MesloLGS NF in the font settings.

static char *font = "MesloLGS NF:pixelsize=14:antialias=true:autohint=true";

Before rebuilding st.

$ sudo make install

Now that the dependences have been meet Powerlevel10k can be installed.

$ yay -Sy --noconfirm zsh-theme-powerlevel10k-git

Once it has been installed ensure that Zsh loads Powerlevel10k.

$ echo 'source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme' >>! ~/.zshrc

You can now open a new terminal which will start the Powerlevel10k configuration wizard. This will ask you a few questions and configure your prompt. If it doesn't trigger automatically, type p10k configure.

Once the configuration wizard has finished open a new terminal and you should see the Powerlevel10k theme been used.

Links

Installing Arch Linux on a Thinkpad X220.Zsh.Powerlevel10k.Simple Terminal.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/arch/atom.xml b/www/posts/arch/atom.xml new file mode 100644 index 0000000..53408ef --- /dev/null +++ b/www/posts/arch/atom.xml @@ -0,0 +1,216 @@ + + + The Home of David T. Sadler - All Posts About Arch + https://davidtsadler.com/posts/arch/atom.xml + + + 2020-09-07T12:00:00Z + + Installing Zsh and Powerlevel10k on Arch Linux + https://davidtsadler.com/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/index.html + + David T. Sadler. + 2020-09-07T12:00:00Z + 2020-09-07T12:00:00Z + ![CDATA[

Installing Zsh and Powerlevel10k on Arch Linux

Mon 7th September 2020 By David T. Sadler.

I have been a bash user ever since I started using Linux. But after installing Arch Linux I wanted to give another shell a try and so decided on Zsh. Below is how I went about replacing bash with Zsh.

Installing Zsh

Zsh is installed via pacman.

$ sudo pacman -S zsh

Check that Zsh has been installed by running it from the terminal.

$ zsh

Since this is the first time that Zsh has been run you should now see zsh-newuser-install which will allow you to setup some basic configuration. If you wish to skip this just press the q key. You can always manually run this with the below commands at a later date.

$ autoload -Uz zsh-newuser-install
+$ zsh-newuser-install -f

Changing The Default Shell

Installing Zsh does not automatically make it the system's default shell. The next time you log back in you will find that your current shell is still in use. You can check which shell is been used by looking at the SHELL environment variable.

$ echo $SHELL
+
+/bin/bash

To see a list of shells that have been installed use the chsh command.

$ chsh -l
+
+/bin/sh
+/bin/bash
+/usr/bin/git-shell
+/bin/zsh
+/usr/bin/zsh

The same command can be used to change the default shell by providing it with the full path to the shell.

$ chsh -s /bin/zsh

Note that this change is not instant and you will need to log out and log in again for it to take affect. Once you have done that check the SHELL environment variable again to confirm the change.

$ echo $SHELL
+
+/bin/ksh

Installing Powerlevel10k

Powerlevel10k is a theme for Zsh and in order to make the most of it you should install the Meslo Nerd Font that has been patched for Powerlevel10k.

$ yay -Sy --noconfirm ttf-meslo-nerd-font-powerlevel10k

You need to configure your terminal to use this font. How this is done is dependant upon what terminal you are using. Since I use st from suckless I need to edit the file config.h and specify MesloLGS NF in the font settings.

static char *font = "MesloLGS NF:pixelsize=14:antialias=true:autohint=true";

Before rebuilding st.

$ sudo make install

Now that the dependences have been meet Powerlevel10k can be installed.

$ yay -Sy --noconfirm zsh-theme-powerlevel10k-git

Once it has been installed ensure that Zsh loads Powerlevel10k.

$ echo 'source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme' >>! ~/.zshrc

You can now open a new terminal which will start the Powerlevel10k configuration wizard. This will ask you a few questions and configure your prompt. If it doesn't trigger automatically, type p10k configure.

Once the configuration wizard has finished open a new terminal and you should see the Powerlevel10k theme been used.

Links

Installing Arch Linux on a Thinkpad X220.Zsh.Powerlevel10k.Simple Terminal.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Enabling Audio in Arch Linux + https://davidtsadler.com/posts/arch/2020-08-31/enabling-audio-in-arch-linux/index.html + + David T. Sadler. + 2020-08-31T12:00:00Z + 2020-08-31T12:00:00Z + ![CDATA[

Enabling Audio in Arch Linux

Mon 31st August 2020 By David T. Sadler.

If you have recently installed Arch Linux you may have found that there is no sound when playing media. This is because by default ALSA has all channels muted.

Installing the ALSA Utilities

The Advanced Linux Sound Architecture (ALSA) is the part of the Linux kernel that manages the sound devices on your system. In addition to this the project also provides several command-line utilities that allow you to configure these devices. These can be installed with pacman.

$ sudo pacman -S alsa-utils

Unmuting The Channels

Channels can be unmuted with amixer.

$ amixer sset Master unmute
+$ amixer sset Speaker unmute
+$ amixer sset Headphone unmute

You can test that the speakers are working with the speaker-test command.

$ speaker-test -c 2

If you are still getting no sound then it could be that the volume has been set to zero. Use amixer again to increase the volume.

$ amixer sset Master 100%
+$ amixer sset Speaker 100%
+$ amixer sset Headphone 100%

Unmute with Alsamixer

If you prefer a more intuitive ncurses interface you can use alsamixer.

$ alsamixer

Channels that are muted will have the MM label below them. Unmuted channels have 00.

Use the ← and → keys to scroll to the muted channel and press m to unmute it.

The volume can be increased and decreased with the ↑ and ↓ keys.

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Pacman Cheat Sheet For Ubuntu Users + https://davidtsadler.com/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/index.html + + David T. Sadler. + 2020-08-24T12:00:00Z + 2020-08-24T12:00:00Z + ![CDATA[

Pacman Cheat Sheet For Ubuntu Users

Mon 24th August 2020 By David T. Sadler.

As a regular Ubuntu user I am used to using apt for system maintenance. But now that I've installed Arch Linux I will be using pacman and so below is a cheat sheet for myself that shows the pacman equivalent of some common apt actions.

Action                     | Apt                            | Pacman                     |
+---------------------------|--------------------------------|----------------------------|
+Install a package          | apt install <package name>     | pacman -S <package name>   |
+Remove a package           | apt remove <package name>      | pacman -Rs <package name>  |
+Search for a package       | apt serch <search term>        | pacman -Ss <regexp>        |
+Upgrade packages           | apt update && apt upgrade      | pacman -Syu                |
+Upgrade distribution       | apt update && apt dist-upgrade | pacman -Syu                |
+Clean up local caches      | apt autoclean                  | pacman -Scc                |
+Remove unused dependencies | apt autoremove                 | pacman -Qmq | pacman -Rs - |

Install a Package

$ pacman --sync <package name>
+
+$ pacman -S <package name>

Installs a package and its dependencies.

Remove a Package

$ pacman --remove --recursive <package name>
+
+$ pacman -Rs <package name>

Removes a package and all its dependencies, provided that (A) they are not required by other packages; and (B) they were not explicitly installed by the user.

Search For a Package

$ pacman --sync --search <regexp>
+
+$ pacman -Ss <regexp>

Searches in the sync database for packages with a name or description that match the regexp.

Upgrade Packages

$ pacman --sync --refresh --sysupgrade
+
+$ pacman -Syu

Downloads a fresh copy of the master package database and then upgrades all out-of-date packages.

Upgrade Distribution

$ pacman --sync --refresh --sysupgrade
+
+$ pacman -Syu

Since Arch uses a rolling release system there is no distribution version as you just upgrade your packages to their latest versions.

Clean Up Local Caches

$ pacman --sync --clean --clean
+
+$ pacman -Scc

Free up disk space by removing from the cache any packages that are no longer installed. Also removes any cached sync databases.

Remove Used Dependencies

$ pacman --query --deps --unrequired --quiet | pacman --remove --recursive -
+
+$ pacman -Qdtq | pacman -Rs -

Remove dependencies that are no longer needed, because e.g. the package which needed the dependencies was removed.

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Installing ST, DMENU and DWM in Arch Linux + https://davidtsadler.com/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/index.html + + David T. Sadler. + 2020-08-17T12:00:00Z + 2020-08-17T12:00:00Z + ![CDATA[

Installing ST, DMENU and DWM in Arch Linux

Mon 17th August 2020 By David T. Sadler.

Continuing my Arch Linux installation I now have a user account for daily use. However this only provides me with a terminal. What I would like is a traditional multi-window desktop environment which will require me to install two things. A window system of some sort and a layout manager. For this installation I'm going with Xorg and dwm. For those that are not aware dwm is dynamic window manager for Xorg that has been developed by Suckless. Since by default dwm expects st to be installed as the system's terminal and also makes use dmenu to allow you to launch applications I will installed both of them in addition to dwm.

Install Dependencies

Firt off I need to install the dependencies required by st, dmenu and dwm. Since this is Arch Linux I use pacman to do this.

$ sudo pacman -S base-devel git libx11 libxft xorg-server xorg-xinit terminus-font
  • base-devel Since I will be installing from source this package contains various tools to compile software.
  • git Is needed to get the source code from the suckless git repositories.
  • libx11 and libxft Dependanices required by dwm oherwise it will fail when trying to compile it.
  • xorg-server Is the display server that provides the windows that dwm will manage.
  • xorg-xinit Allows us to start the display server.
  • terminus-font Dwm is configured to use a monospaced font and since I installed a barebones system I need to install such a font now.

Download Git Repositories

The source code for the software is avialable from the Suckless git repositories so I simply clone them.

$ mkdir -p ~/.local/src
+
+$ git clone git://git.suckless.org/st ~/.local/src/st
+$ git clone git://git.suckless.org/dmenu ~/.local/src/dmenu
+$ git clone git://git.suckless.org/dwm ~/.local/src/dwm

Install ST

I install st by first moving to the directory created when cloning the repository.

$ cd ~/.local/src/st

Then its as simple as compiling and instaling the software with the below commands.

$ make clean
+$ sudo make install

Configure and Install DMENU

Again move to the directory created earlier.

$ cd ~/.local/src/dmenu

Before compiling a small edit needs to be made to the file config.mk.

$ nvim config.mk

Since I have not installed Xinerama on this system I need to comment out any flags that reference this otherwise dmenu will fail during the compiling.

# XINERAMALIBS  = -lXinerama
+# XINERAMAFLAGS = -DXINERAMA

Again compiling and installing is done with the below commands.

$ make clean
+$ sudo make install

Configure and Install DWM

For the final time move to the directory created earlier.

$ cd ~/.local/src/dwm

As with dmenu the same edit needs to be made to the file config.mk.

$ nvim config.mk
# XINERAMALIBS  = -lXinerama
+# XINERAMAFLAGS = -DXINERAMA

Compile and install as usual.

$ make clean
+$ sudo make install

Starting DWM

Since I have installed xorg-xinit I need to create a .xinitrc in my home folder.

$ nvim ~/.xinitrc

The contents of this file is just.

exec dwm

I can now start xorg and dwm with the below command.

$ startx

Links

Installing Arch Linux on a Thinkpad X220.Dynamic Window Manager (DWM).Suckless Software.Simple Terminal.DMenu.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Granting Sudo Access to a User in Arch Linux + https://davidtsadler.com/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/index.html + + David T. Sadler. + 2020-06-22T12:00:00Z + 2020-06-22T12:00:00Z + ![CDATA[

Granting Sudo Access to a User in Arch Linux

Mon 22nd 2020 By David T. Sadler.

So by the end of my last post my minimal installation of Arch Linux had a user account that I could log into instead of the root user. However in order to do anything useful on the system I need to be able to run commands such as pacman that only the root user can do. Now one way to solve this is to change to the root user with su before running the command, but this defeats the point in creating a non-root user account in the first place. Instead a better way is to make use of sudo.

Sudo (su "do") gives the ability for a user (or groups of users) to run some (or all) commands as root and also provides an audit trail of the commands and their arguments. Usage is very simple, you enter sudo followed by the command that you want to run. For example,

$ sudo pacman -Syu

Configuration is done in the file /etc/sudoers. This is where you can specify which users or groups can use sudo and what commands they can run. However, you must be careful when editing this file as any syntax errors will make sudo unusable. Therefore it is strongly recommended to do any editing via the visudo command. This locks the sudoers file, saves edits to a temporary file, and checks that file's grammar before copying it to /etc/sudoers.

Traditionally in Linux systems users that should have privileged administrator rights are added to the wheel group which is then given sudo access. As the root user the first thing that I needed to do was add my user account to the wheel group with the usermod command.

$ usermod -aG wheel david

I used the below options with the command.

  • -a Modifies the -G argument so that the user is added to the specified groups and not removed from any existing ones.
  • -G The list of supplementary groups that the user will be made a member of. In this case it's just wheel. Note that you need to pass -a otherwise the user will be removed from any group that is not listed.

The sudo package then needed to be installed.

$ pacman -S sudo

Next I needed to grant sudo access to the wheel group by editing /etc/sudoers with visudo. Note that the default editor for visudo is vi. Since this has not been installed on my system I can change the editor to be nvim by first setting the variable EDITOR.

$ EDITOR=nvim visudo

Once the file was opened I located and uncommented the below line before saving and exiting nvim. This allows members of the wheel group to execute any command without having to enter their password.

%wheel ALL(ALL) NOPASSWD: ALL

I checked that I had sudo access by running the below command while logged into my user account.

$ sudo pwd
+
+/home/david

Since I wasn't prompted for my password and the command was executed I knew that I now had sudo access.

Links

Adding a User in Arch Linux.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Adding a User in Arch Linux + https://davidtsadler.com/posts/arch/2020-06-15/adding-a-user-in-arch-linux/index.html + + David T. Sadler. + 2020-06-15T12:00:00Z + 2020-06-15T12:00:00Z + ![CDATA[

Adding a User in Arch Linux

Mon 15th June 2020 By David T. Sadler.

In a previous post I installed Arch Linux on my Thinkpad X220. Since it was a very minimal install there are no user accounts except for the root user. So to add myself as a user I need to use the useradd command.

$ useradd -m -s /bin/bash david

I used the below options with the command.

  • -m Create the home directory for this account.
  • -s /bin/bash Make bash the login shell for this account.
  • david The name of the new user.

This creates a new account for me and also ensures that a home directory is created as /home/david.

The new account will require a password so assign one with the passwd command.

$ passwd david
+
+New password:
+Retype new password:
+passwd: password updated successfully

Now all I have to do is logout of the root account.

$ logout

Then login with the new credentials to confirm that everything is okay.

suliman login: david
+Password:
+
+david@suliman:$

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Installing Arch Linux on a Thinkpad X220 + https://davidtsadler.com/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/index.html + + David T. Sadler. + 2020-05-25T12:00:00Z + 2020-05-25T12:00:00Z + ![CDATA[

Installing Arch Linux on a Thinkpad X220

Mon 25th May 2020 By David T. Sadler.

Introduction

So I purchased a used Thinkpad X220 for about £90 on eBay and decided to install Arch Linux onto it. This guide is the steps that I took to achieve this.

Now when it comes to Linux there is always more than one way of doing things and this guide is just my preferred way. Feel free to follow it for your own installation, just keep in mind that you may have to change some of the steps to suit your own circumstances. Also there is every chance that the information presented here will be out of date so I recommend that you at least read the through the official installation guide for the most up-to-date information.

Download the Arch Linux ISO Image

The Arch Linux download page provides direct download and torrent links. You should also download the PGP signature to the same location and use the gpg command to verify that the ISO has not been compromised.

$ gpg --keyserver-options auto-key-retrieve --verify archlinux-2020.05.01-x86_64.iso.sig

Create a Live USB of Arch Linux

Flash the image to a USB drive using Etcher. Alternatively you can use the dd command. Just ensure that /path/to/archlinux.iso is to where you have downloaded the image and that /dev/sdx is your USB drive.

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress && sync

Boot the Live Environment

I wanted to make sure that the Thinkpad was using UEFI as I would be using EFISTUB to load the Linux kernel as an EFI executable. This is done through the BIOS which can be gotten to by pressing the ThinkVantage button as the machine is booting before pressing F1 to get to the BIOS settings. From there navigate to Startup and changed the UEFI/Legacy Boot option to be UEFI Only. Press F10 to save and exit the BIOS and then power down the machine.

With the USB drive plugged in power the machine back on, all the while pressing F12 until the boot menu appears and select USB HDD: Mass Storage Device and wait for the installation image to boot. When prompted select Arch Linux archiso X86_64 UEFI CD where you will be take to the live environment's terminal.

Set the Keyboard Layout

The default console map is US which meant that for me pressing Shift+3 was displaying the hash symbol (#) instead of the pound symbol (£). So the UK keyboard layout needed to be loaded.

$ loadkeys uk

You can get a list of supported keyboard layouts if you need to load a different one.

ls /usr/share/kbd/keymaps/**/*.map.gz

Verify the Boot Mode

To verify that the Thinkpad has UEFI enabled check that the efivars directory exists.

$ ls /sys/firmware/efi/efivars

Connect to the Internet

Verify that the machine can connect to the internet with the ping command.

$ ping -c3 davidtsadler.com

Before booting the machine I plugged in an Ethernet cable that was connected directly to my home network's router. The installation environment detected the network connection and obtained an IP address via DHCP.

Update the System Clock

Ensure the system clock is correct.

$ timedatectl set-ntp true

Partition the Disks

Use the lsblk command to determine which disks and partitions exist on the system.

$ lsblk
+
+NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
+loop0    7:0    0   535M  1 loop /run/archiso/sfs/airootfs
+sda      8:0    0 298.1G  0 disk
+sdb      8:16   1   7.4G  0 disk
+├─sdb1   8:17   1   652M  0 part /run/archiso/bootmnt
+└─sdb2   8:18   1    64M  0 part

From the above output I could see that my hard drive was sda as sdb was the USB drive and loop0 could just be ignored.

I knew that I wanted to have an encrypted partition and make use of LVM on it so my disk layout would be.

+-------------------+ +--------------------------------------------------------+
+| Boot partition    | | Logical volume 1 | Logical volume 2 | Logical volume 3 |
+|                   | |                  |                  |                  |
+| /boot             | | /                | [SWAP]           | /home            |
+|                   | |                  |                  |                  |
+|                   | | 50G              | 16G              | 200G             |
+|                   | |                  |                  |                  |
+|                   | | /dev/vg0/root    | /dev/vg0/swap    | /dev/vg0/home    |
+|                   | |_ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ |
+|                   | |                                                        |
+|                   | |              LUKS2 encrypted partition                 |
+| /dev/sda1 (512MB) | |                    /dev/sda2                           |
++-------------------+ +--------------------------------------------------------+

The hard drive would be split into two partitions. The first, sdb1 would be 512MB in size and mounted in the file system at /boot. This would be the EFI system partition. The reminder of the disk space would be given to the partition sda2 and encrypted using LUKS2. LVM would then be used to create the volume group vg0 that would be divided into three partitions as logical volumes.

  • /dev/vg0/root 50G root partition.
  • /dev/vg0/swap 16G swap partition.
  • /dev/vg0/home 200G home partition.

Use fdisk to create the partitions.

$ fdisk /dev/sda

Enter g to create a new empty GPT partition table

Command (m for help): g
+Created a new GPT disklabel (GUID: 6987D065-936E-1547-9F02-F78145025A96).

Since this is a UEFI system there must be a EFI partition at the beginning of the disk. Enter n to add a new partition and enter 1 to assign it as the first partition. Use the default value for the first sector but enter +512M for the last sector.

Command (m for help): n
+Partition number (1-128, default 1): 1
+First sector (2048-625142414, default 2048):
+Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-625142414, default 625142414): +512M
+
+Created a new partition 1 of type 'Linux filesystem' and of size 512 MiB.

Enter t to change the partition type and enter 1 to make it an EFI System. You can also get a list of partition types by pressing L.

Command (m for help): t
+Selected partition 1
+Partition type (type L to list all types): 1
+Changed type of partition 'Linux filesystem' to 'EFI System'.

To create the second partition enter n again to add another partition, and then enter 2 to assign it as the second partition. Use the default values for both first and last sectors to allocate the remainder of the drive.

Command (m for help): n
+Partition number (2-128, default 2): 2
+First sector (1050624-625142414, default 1050624):
+Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-625142414, default 625142414):
+
+Created a new partition 2 of type 'Linux filesystem' and of size 297.6 GiB.

Enter w to write the changes and quit.

Command (m for help): w
+The partition table has been altered.
+Calling ioctl() to re-read partition table.
+Syncing disks.

Use lsblk to confirm that two partitions have been created.

$ lsblk /dev/sda
+
+NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
+sda      8:0    0 298.1G  0 disk
+├─sda1   8:1    0   512M  0 part
+└─sda2   8:2    0 297.6G  0 part

LUKS

Encrypt the second partition with the cryptsetup command.

$ cryptsetup luksFormat /dev/sda2

When prompted enter YES in capitals to overwrite any data that is currently on the partition.

WARNING!
+========
+This will overwrite data on /dev/sda2 irrevocably.
+
+Are you sure? (Type 'yes' in capital letters): YES

Enter and verify a passphrase. Whenever the machine is now booted you will be prompted to enter this passphrase in order for the partition to be decrypted.

Enter passphrase for /dev/sda2:
+Verify passphrase:
+cryptsetup luksFormat /dev/sda2  17.01s user 1.05s system 105% cpu 17.106 total

LVM on LUKS

Before setting up LVM decrypt the partition.

$ cryptsetup open /dev/sda2 cryptlvm

You will be prompted to enter the passphrase that you set up earlier.

Enter passphrase for /dev/sda2:
+cryptsetup open /dev/sda2 cryptlvm  6.48s user 0.36s system 92% cpu 7.436 total

Create a physical volume.

$ pvcreate /dev/mapper/cryptlvm

Create a volume group called vg0.

$ vgcreate vg0 /dev/mapper/cryptlvm

Create three logical volumes for the root, swap and home partitions.

$ lvcreate -L 50G vg0 -n root
+$ lvcreate -L 16G vg0 -n swap
+$ lvcreate -L 200G vg0 -n home

Make use of lsblk again to verify that LVM has been setup as expected.

$ lsblk /dev/sda
+
+NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
+sda              8:0    0 298.1G  0 disk
+├─sda1           8:1    0   512M  0 part
+└─sda2           8:2    0 297.6G  0 part
+└─cryptlvm   254:0    0 297.6G  0 crypt
+├─vg0-root 254:1    0    50G  0 lvm
+├─vg0-swap 254:2    0    16G  0 lvm
+└─vg0-home 254:3    0   200G  0 lvm

Format the Partitions

Format the boot partition at /dev/sda1 with a FAT32 file system as the UEFI specification requires the usage of it.

$ mkfs.fat -F32 /dev/sda1

The root and home partitions can be formatted with ext4.

$ mkfs.ext4 /dev/vg0/root
+$ mkfs.ext4 /dev/vg0/home

Initialise the swap partition.

$ mkswap /dev/vg0/swap
+$ swapon /dev/vg0/swap

Mount the File Systems

Mount the root partition into /mnt.

$ mount /dev/vg0/root /mnt

Mount the boot partition into /mnt/boot.

$ mkdir /mnt/boot
+$ mount /dev/sda1 /mnt/boot

Finally mount the home partition into /mnt/home.

$ mkdir /mnt/home
+$ mount /dev/vg0/home /mnt/home

Select the Mirrors

All mirror servers defined in /etc/pacman.d/mirrorlist where done at the time the installation image was built. Since it's ideal to try and use servers that are close to your location you can rebuild the list using the rankmirrors utility. This is not included by default on the live environment so you will need to download it.

First sync the pacman repository.

pacman -Syy

Then download the pacmain-contrib package which contains the rankmirrors utility.

$ pacman -S pacman-contrib

The official Pacman Mirrorlist Generator can be used to get an up-to-date list of servers for your country. The below command obtains a list of UK servers that support https and pass it to rankmirrors to obtain the 5 fastest.

$ curl -s "https://www.archlinux.org/mirrorlist/?country=GB&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 - > /etc/pacman.d/mirrorlist

Install Essential Packages

The pacstrap script is used to install the base package, Linux kernel and firmware.

$ pacstrap /mnt base linux linux-firmware neovim wpa_supplicant dhcpcd cryptsetup lvm2 efibootmgr intel-ucode

I also installed a few other packages that I knew I was going to need.

  • neovim. Allows you to edit files instead of using nano.
  • wpa_supplicant. Provides tools for connecting to a WPA2 protected wireless network.
  • dhcpcd. Needed so that you machine can obtain an IP address from your home router via dhcp.
  • cryptsetup. Since the partition is encrypted this package is required in order for it to be decrypted during booting.
  • lvm2. Provides the LVM tools to manage the LVM partition.
  • efibootmgr. Needed to configure the system to boot via UEFI.
  • intel-ucode. Enables microcode updates during boot.

Fstab

Create a fstab file on the new system.

$ genfstab -U /mnt >> /mnt/etc/fstab

Chroot

Use arch-chroot to enter the new system as the root user. From now on you will be configuring the new system.

$ arch-chroot /mnt

Time Zone

Setup the timezone. Replace Europe/London with your timezone.

$ ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

Update the hardware clock.

$ hwclock --systohc

Localization

Use nvim to edit /etc/locale.gen.

$ nvim /etc/locale.gen

Uncomment your preferred language. For me this meant en_GB.UTF-8 UTF-8. Save the file and exit before generating the locales.

$ locale-gen

Edit /etc/locale.conf.

$ nvim /etc/locale.conf

Add the below line. Replace en_GB.UTF-8 with the language that you chose earlier.

LANG=en_GB.UTF-8

If you used loadkeys earlier you will need to edit /etc/vconsole.conf and add your chosen keymap.

$ nvim /etc/vconsole.conf

For me this meant adding the UK keymap.

KEYMAP=uk

Network Configuration

Create the file /etc/hostname and add an entry to it. This hostname will be the name of the machine on your network. I tend to name by devices after characters from the book Howl's Moving Castle https://en.wikipedia.org/wiki/Howl%27s_Moving_Castle).

$ echo suliman > /etc/hostname

You then need to edit the /etc/hosts file.

$ nvim /etc/hosts

Add the following lines to this file. Replace suliman with the hostname you set up earlier.

127.0.0.1	localhost
+::1		    localhost
+127.0.0.1	suliman.localdomain suliman

Wireless

Use the ip command to determine the name of the wireless network interface.

$ip link
+
+1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
+link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
+2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
+link/ether f0:de:f1:86:e1:75 brd ff:ff:ff:ff:ff:ff
+3: wwp0s29u1u4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
+link/ether 86:06:37:c4:9b:41 brd ff:ff:ff:ff:ff:ff
+4: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
+link/ether 08:11:96:02:10:ac brd ff:ff:ff:ff:ff:ff

Looking at the output of the ip command this is wlan0. This name however will not be the name of the interface once the installation has been completed. You see the Arch installation environment does not use predictable names for interfaces. This is due to it using iwd which is unable to cope with interface renaming and so it is disabled for wireless interfaces. When the system boots into the installed system predictable names for interfaces will be enabled and wlan0 will be assigned a different name.

In order to find out what name will be assigned use the udevadm command.

$ udevadm test-builtin net_id /sys/class/net/wlan0
+
+Load module index
+Parsed configuration file /usr/lib/systemd/network/99-default.link
+Parsed configuration file /usr/lib/systemd/network/80-iwd.link
+Created link configuration context.
+Using default interface naming scheme 'v245'.
+ID_NET_NAMING_SCHEME=v245
+ID_NET_NAME_MAC=wlx0811960210ac
+ID_OUI_FROM_DATABASE=Intel Corporate
+ID_NET_NAME_PATH=wlp3s0
+Unload module index
+Unloaded link configuration context.

What we are interested in is the value of ID_NET_NAME_PATH which is wlp3s0.

My wireless network is a WPA2 protected network with a hidden SSID. Since wpa_supplicant has been installed when running pacstrap it is possible to use wpa_passphrase to generate the configuration file that wpa_supplicant will use to connect to the wireless network. Replace &lt;SSID&gt; and &lt;PASSWORD&gt; with your details. Note that the name of the configuration file contains the name of the network interface wlp3s0. Replace this with the name of your network interface.

$ wpa_passphrase <SSID> <PASSWORD> > /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf

If your wireless network uses a hidden SSID you will need to edit the configuration file.

$ nvim /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf

And add the below line.

scan_ssid=1

Make sure that wpa_supplicant starts at boot.

$ systemctl enable wpa_supplicant@wlp3s0.service

Have an IP address assigned via DHCP during booting.

$ systemctl enable dhcpcd@wlp3s0.service

Initramfs

You will need to rebuild the initial ramdisk and the current one is not aware that the filesystem will be encrypted. Before rebuilding it some configuration changes need to be made.

$ nvim /etc/mkinitcpio.conf

Locate the section where the HOOKS are configured and replace it with the line below.

HOOKS=(base udev autodetect keyboard keymap modconf block encrypt lvm2 filesystems fsck)

This ensures that the keyboard is present before the filesystem is detected so that you are enter the passphrase to decrypt the partition. It also ensures that the decryption is done before the LVM is handled.

Save the changes and exist before rebuilding with the mkinitcpio command.

mkinitcpio -P

EFISTUB Booting and Microcode

The Thinkpad X220 UEFI implementation allows an operating system to be booted without the need for an intermediate bootloader such as GRUB. It is possible to add a UEFI boot entry to the motherboard itself and have Arch booted directly.

Modifying the motherboard boot entries is done using efibootmgr. However usage of this command can be quite verbose so it is recommended to create a shell script instead.

nvim /usr/local/sbin/mkefibootentry

The shell script will call efibootmgr with the required arguments.

#!/bin/sh
+
+# Determine the UUID of the partition that is encrypted
+PARTUUID=`blkid /dev/sda2 -s PARTUUID -o value`
+
+efibootmgr \
+--disk /dev/sda --part 1 \
+--create --label "Arch Linux" \
+--loader /vmlinuz-linux \
+--unicode 'cryptdevice=PARTUUID='$PARTUUID':cryptlvm root=/dev/vg0/root rw initrd=\intel-ucode.img initrd=\initramfs-linux.img' \
+--verbose 

The --unicode argument is where the kernel parameters are specified. This tells the system that the partition identified by PARTUUID is encrypted and that the root filesystem to mount is the logical volume called root that is part of the volume group vg0. The microcode is also loaded with initrd=\intel-ucode.img.

Make this script executable.

chmod u+x /usr/local/sbin/mkefibootentry

Run the script to add to the motherboard boot entries.

$ mkefibootentry

Root Password

Create a secure password for the root user.

$ passwd

Reboot

Return to the Arch live installation environment.

$ exit

Unmount the partitions.

$ umount -R /mnt

Restart the machine with reboot. Remember to remove any installation media such as a USB drive.

$ reboot

Provided nothing has gone wrong your machine will boot into a fresh installation of Arch Linux. Don't forget that during the boot you will be prompted to enter the passphrase to decrypt the system partition.

Following this guide will leave you with a very minimal system where you can login as the root user. From this point how you configure the system is up to you as it will be very different to how I configure my own. If you interested in seeing how I do it then see my other posts on the subject.

Links

Offical Arch Installation Guide.Arch Linux Download Page.Etcher.Pacman Mirrorlist Generator.Wikipedia Entry for Howl's Moving Castle.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/arch/index.html b/www/posts/arch/index.html new file mode 100644 index 0000000..7e093b2 --- /dev/null +++ b/www/posts/arch/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Arch + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Arch

2020-09-07 - Installing Zsh and Powerlevel10k on Arch Linux2020-08-31 - Enabling Audio in Arch Linux2020-08-24 - Pacman Cheat Sheet For Ubuntu Users2020-08-17 - Installing ST, DMENU and DWM in Arch Linux2020-06-22 - Granting Sudo Access to a User in Arch Linux2020-06-15 - Adding a User in Arch Linux2020-05-25 - Installing Arch Linux on a Thinkpad X220The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/atom.xml b/www/posts/atom.xml new file mode 100644 index 0000000..ef94171 --- /dev/null +++ b/www/posts/atom.xml @@ -0,0 +1,471 @@ + + + The Home of David T. Sadler - All Posts + https://davidtsadler.com/posts/atom.xml + + + 2021-02-15T12:00:00Z + + Accessing Nextcloud With WebDAV on Arch + https://davidtsadler.com/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/index.html + + David T. Sadler. + 2021-02-15T12:00:00Z + 2021-02-15T12:00:00Z + ![CDATA[

Accessing Nextcloud With WebDAV on Arch

Mon 15th February 2021 By David T. Sadler.

I have a Nextcloud instance and I want to mount it as a directory on my local machine. Since Nextcloud cloud supports the WebDAV protocol its possible to do this by installing davfs2 which can mount a WebDAV resource.

The first thing I had to do was install davfs2.

$ sudo pacman -S davfs2

Next I created the directory where Nextcloud would be mounted.

$ mkdir -p .local/share/nextcloud

I then needed to tell Arch how to mount Nextcloud by adding the below line to the /etc/fstab file.

https://my-nextcloud-server.com/path /home/david/.local/share/nextcloud davfs rw,user,uid=david,noauto 0 0

Since access to Nextcloud is controlled by a username and password these where added to the ~/.davfs2 file.

https://my-nextcloud-server.com/path username password

I made sure this file had the correct permissions to ensure security.

$ chmod 600 ~/.davfs2/secrets

Now I can mount Nextcloud and access my files just like any others.

$ mount .local/share/nextcloud
Nextcloud - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ How to Host Your Own Gemini Site in the Cloud + https://davidtsadler.com/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/index.html + + David T. Sadler. + 2021-02-08T12:00:00Z + 2021-02-08T12:00:00Z + ![CDATA[

How to Host Your Own Gemini Site in the Cloud

Mon 8th February 2021 By David T. Sadler.

So I have a Gemini site over at gemini://davidtsadler.co.uk and I thought I'd write up how I achieved this in case anyone was interested in doing the same.

I would say that from purchasing the domain name to having a complete server hosting the site took about 30 minutes in total.

Purchasing a Domain Name

I decided that for the moment I would keep my traditional "Big Web" content hosted at davidtsadler.com and use a different domain name for my new Gemini site. Since this meant purchasing a new one I popped over to Gandi.net to acquire davidtsadler.co.uk. Side note: I used to own this but decided not to renew it for some crazy reason.

Creating a cloud sever

My cloud provider of choice is Hetzner and creating a new server is done in eight steps.

1. Location

Hetzner provide a few locations in Europe as to where the server is hosted. For this server I chose Helsinki.

2. Image

I chose Ubuntu 20.04 as the operating system as this is the one I'm most familiar with.

3. Type

As this server is only going to a host a Gemini site I don't need a overly powerful system so I chose their most basic CX11 configuration. For €2.99 a month this gives me:

  • 1 virtual CPU.
  • 2GB ram.
  • 20GB SSD .
  • 20 TB of network traffic a month.

4. Volume

You have the option of attaching additional storage to the server. I skipped this step as for the time been the 20GB SSD that comes with the server should be enough for my needs.

5. Network.

I skipped this step as its not needed.

6. Additional features

Again I skipped this step but select any if you believe that you will need them.

7. SSH Key

When a server is created a root user is added and a password is emailed to you so that you can login. However if you provide a SSH key it will be installed on the server instead of creating a password.

I like to use separate keys for each server that I manage so I tend store the them in a directory named after the hostname.

$ mkdir ~/.ssh/davidtsadler.co.uk
+
+$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/davidtsadler.co.uk/id_rsa

The SSH key is added by clicking + ADD SSH KEY and then copying and pasting the contents of the id_rsa.pub file.

8. Name

I name my servers after the hostname so for this I called it davidtsadler.co.uk. I then created the server by clicking CREATE & BUY NOW.

SSH

Once the server was created I took the allocated IP address and ensured that I could access it via SSH using the key that I had provided.

$ ssh root@135.181.201.71 -i ~/.ssh/davidtsadler.co.uk/id_rsa

Resolve the Domain Name to the Server

In my Gandi.net account I went to the DNS Records section for the domain name I had purchased. There I deleted everything except for the @ (A) and www (CNAME) records which was configured as follows:

  • @ (A) 135.181.201.71
  • www (CNAME) davidtsadler.co.uk.

The A record is configured with the IPv4 address of my new server and the CNAME with the domain name. Note that the CNAME must end with a period!

After saving the changes it was just a matter of waiting for it to propagate through the DNS system. At which point I could use the domain name when logging in via SSH.

$ ssh root@davidtsadler.co.uk -i ~/.ssh/davidtsadler.co.uk/id_rsa

Securing the Server

At a bare minimum I setup a firewall and harden SSH. I may at a later date go further, such as installing fail2ban.

Configure a Firewall

This setup will deny any incoming requests unless they were first initiated by a request from the server. Since I need to be able to access the server I allow SSH. The Gemini protocol uses port 1965 so that is also allowed.

$ ufw default allow outgoing
+$ ufw default deny incoming
+$ ufw allow OpenSSH
+$ ufw allow 1965
+$ ufw enable

Harden SSH

I edited the /etc/ssh/sshd_config file.

$ vim /etc/ssh/sshd_config

I added the two below options so that the root user is not allowed to access the sever via SSH and other users may only access using keys.

PermitRootLogin no
+PasswordAuthentication no

Since I'd made changes to the configuration I needed to restart the SSH service.

$ service sshd restart

Create non-root User

Whenever I access a server I like to login as a non-root user that is able to run sudo on the system.

$ adduser gemini
+
+$ usermod -aG sudo gemini

As the SSH key is already on the server I can copy it to the non-root user account.

$ rsync --archive --chown=gemini:gemini ~/.ssh /home/gemini

On my local system I confirm that I can log in as the new user without a password.

$ ssh gemini@davidtsadler.co.uk -i ~/.ssh/davidtsadler.co.uk/id_rsa

I also confirm that I have sudo access.

$ sudo ls

Installing a Gemini Site and Server

Directory structure

I decided to go with a very simple directory structure. Each site will be a sub-directory in ~/sites that will be named after the domain name. Then each site will have the following sub-directories. The idea is that I may want to host more than one site in the future.

  • bin This will contain the Gemini server binary.
  • certs TLS certificates for the site are kept here.
  • public This will contain the .gmi files of the site.
  • scripts Contains scripts used to start the Gemini server.

I created the directory structure with the below command.

$ mkdir -p ~/sites/davidtsadler.co.uk/{bin,certs,public,scripts}

Install certificates

Sine the Gemini protocol encourages using a self-signed certificate I installed one with the openssl command.

$ openssl req -x509 \
+-newkey rsa:4096 \
+-keyout ~/sites/davidtsadler.co.uk/certs/key.rsa \
+-out ~/sites/davidtsadler.co.uk/certs/cert.pem \
+-days 3650 \
+-nodes \
+-subj "/CN=davidtsadler.co.uk"

Create Some Test Content

I created a very simple index.gmi file purely for testing.

$ cat << EOF > ~/sites/davidtsadler.co.uk/public/index.gmi
+# Welcome
+
+Hello world!
+EOF

Install the Gemini Server Binary

I decided to go with agate as the Gemini server as its very simple to install and configure. Installing it was a matter of downloading the binary archive into the bin directory and setting the executable permission on it.

$ cd ~/sites/davidtsadler.co.uk/bin
+
+$ wget https://github.com/mbrubeck/agate/releases/download/v2.3.0/agate.x86_64-unknown-linux-gnu.gz
+
+$ gunzip agate.x86_64-unknown-linux-gnu.gz
+
+$ mv agate.x86_64-unknown-linux-gnu agate
+
+$ chmod u+x agate

I wrote a very simple bash script to run agate and have it serve the site.

$ cat << EOF > ~/sites/davidtsadler.co.uk/scripts/start
+#!/bin/bash
+
+/home/gemini/sites/davidtsadler.co.uk/bin/agate \
+--content /home/gemini/sites/davidtsadler.co.uk/public/ \
+--key /home/gemini/sites/davidtsadler.co.uk/certs/key.rsa \
+--cert /home/gemini/sites/davidtsadler.co.uk/certs/cert.pem \
+--addr [::]:1965 \
+--addr 0.0.0.0:1965 \
+--hostname davidtsadler.co.uk \
+--lang en-GB
+EOF
+
+$ chmod u+x ~/sites/davidtsadler.co.uk/scripts/start

Testing the Site

At this point I have the Gemini server installed and a site available for testing.

I first started agate with the bash script.

$ ~/sites/davidtsadler.co.uk/scripts/start
+
+[2021-02-05T17:26:56Z INFO  agate] Listening on [[::]:1965, 0.0.0.0:1965]...

With agate up and running I pointed my Gemini client to gemini://davidtsadler.co.uk and confirmed I was able to access the site before entering Ctrl-C to halt agate.

Configure Systemd

Since I was happy that agate was able to serve my new site I created a systemd unit to ensure that agate was started whenever the system was rebooted.

$ sudo vim /etc/systemd/system/agate.service

The unit is very simple and just runs the bash script to start agate once the network is available.

[Unit]
+Description=Agate Gemini Server
+After=network.target
+
+[Service]
+Type=simple
+User=gemini
+Group=gemini
+ExecStart=/home/gemini/sites/davidtsadler.co.uk/scripts/start
+
+[Install]
+WantedBy=default.target

I then started this service and confirmed it was working.

$ sudo systemctl start agate.service
+
+$ sudo systemctl status agate.service
+
+Active: active (running)

The final step was to have this service start when the system is rebooted.

$ sudo systemctl enable agate.service

Conclusion

Setting up a Gemini site was easy to do and I hope this guide shows it. I have several ideas about how I'm going to use this new site and I'm excited to see where this leads to.

Links

Gandi.net - My domain registrar of choice.Hetzner - My cloud server provider.Agate - A simple Gemini server.davidtsadler.co.uk - My Gemini site.Gemini - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Installing PHP 8 for Windows 10 + https://davidtsadler.com/posts/php/2021-01-18/installing-php-8-for-windows-10/index.html + + David T. Sadler. + 2021-01-18T12:00:00Z + 2021-01-18T12:00:00Z + ![CDATA[

Installing PHP 8 for Windows 10

Mon 18th January 2021 By David T. Sadler.

Getting Started

The PHP For Windows site provides pre-built Windows binaries for you to download. Which version you download depends upon two things.

1. Is your system a 64 or 32 bit machine.

2. Are you planning to use IIS or Apache as the web server.

For 64 bit systems the x64 file should be downloaded. If you plan to use IIS then get the Non Thread Safe (NTS) version otherwise use the Thread Safe (TS) version.

The PHP 8 binaries require to have the Visual C++ Redistributable for Visual Studio 2015-2019 be installed as well.

Download and Installation

1. Download the Visual C++ Redistributable for Visual Studio 2015-2019 executable and install it.

2. Download the appropriate PHP 8 Zip archive for your Windows system.

3. Extract the Zip archive into a folder called php in your user folder. This should result in a folder at C:\Users\[username]\php.

Configuring Windows

In order to run the PHP executable from the command line the path to where the Zip archive was extracted to needs to be added to the Windows Path environment variable.

1. Right click on the start menu and select System.

2. Type Control Panel into the search field and select the Control Panel option when it appears.

3. Click System and Security and then the System option.

4. Click Advanced system settings from the left side menu to bring up a dialog box.

5. Select the Advanced tab and then click Environment Variables.

6. Select the Path option from the User variables list and click Edit.

7. Click New and enter the path to where you extracted the Zip archive. This should be C:\Users\[username]\php. You can also click Browse instead and navigate to the folder.

8. Click OK to close the Edit environment variable dialog.

9. Click OK again to close the Environment Variables dialog.

10. Click OK for a third time to close the System Properties dialog.

Checking Installation

Open up either PowerShell or the Command Prompt and enter php -v to verify that PHP was installed correctly. You should see output similar to that shown below.

C:\Users\dev>php -v
+
+PHP 8.0.1 (cli) (built: Jan 5 2021 23:43:33) ( NTS Visual C++ 2019 x64 )
+Copyright (c) The PHP Group
+Zend Engine v4.0.1, Copyright (c) Zend Technologies

Links

PHP For Windows.PHP - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Installing Laravel Homestead in Arch Linux + https://davidtsadler.com/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/index.html + + David T. Sadler. + 2020-12-21T12:00:00Z + 2020-12-21T12:00:00Z + ![CDATA[

Installing Laravel Homestead in Arch Linux

Mon 21st December 2020 By David T. Sadler.

Introduction

Laravel Homestead is a pre-packaged Vagrant box that gives you a development environment with PHP, a web server, and several other server software already installed. This guide explains how I install and configure it on my Arch Linux system. I install Homestead in such a way that enables me to add multiple projects to the single instance of Homestead. Because of this you may find that you will need to adapt the guide to how you prefer to manage your projects.

Installing Dependencies

Vagrant will need to be installed since Laravel Homestead is a pre-configured Vagrant box. Select virtualbox if you are prompted for which provider Vagrant should use.

$ sudo pacman -S vagrant

Install Virtualbox as this will be used as a provider by Vagrant. When prompted select the virtualbox-host-modules-arch package.

$ sudo pacman -S virtualbox

Install Homestead

Homestead is installed by cloning the repository onto your host machine.

$ git clone https://github.com/laravel/homestead.git ~/.local/share/homestead

The cloned repository defaults to the latest master branch. As this can be considered unstable it is recommended to checkout a tagged version of Homestead or the release branch as this will always be the latest stable version.

$ cd ~/.local/share/homestead
+
+$ git checkout release

Create the Homestead.yaml file by using the init.sh command.

$ bash init.sh

Configuring the host machine

Before I launch Homestead for the first time there are a few things that I like to do first on the host machine.

Creating a host project

One of the advantages with Homestead is that it allows you to share a directory on your host machine with the virtual guest machine and have that served by the web server.

For this guide the commands below will create a very simple PHP site.

$ mkdir -p ~/projects/testsite/public
+
+$ echo "<?php phpinfo();" > ~/projects/testsite/public/index.php

Setting up SSH

I like to use unique ssh keys for servers that I connect to and that includes any virtual machines running on my local machine. The ssh-keygen command generates a new key that I store in a directory separate from my other ones.

$ mkdir  ~/.ssh/homestead
+
+$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/homestead/id_rsa

Hostname Resolution

Since I am using one instance of Homestead for multiple sites I need to configure the host machine so that requests are directed to the correct site on the virtual machine. This is done by adding an entry into the /etc/hosts file for each site.

First I need to know the IP address of the virtual machine. This can be done by looking in the Homestead.yaml file for the ip entry.

ip: "192.168.10.10"

Then for each site that will be hosted on the virtual machine add it's domain and ip to the /etc/hosts file.

$ sudo nvim /etc/hosts
192.168.10.10 testsite.local

Configuring Homestead

Homestead is configured by editing the Homestead.yaml file that was created with the init.sh command earlier.

$ cd ~/.local/share/homestead
+
+$ nvim Homestead.yaml

First tell Vagrant that Virtualbox will be providing the virtual machine.

set provider: virtualbox

Vagrant needs to setup the ssh keys between the host and the guest so that you can connect via ssh. Enter the path to the one created earlier.

authorize: ~/.ssh/homestead/id_rsa.pub
+
+keys:
+- ~/.ssh/homestead/id_rsa

Share the project folder with the virtual machine. This setting will make the directory /home/vagrant/projects/testsite available in the virtual machine. The contents of this directory will be shared with the host machine directory ~/projects/testsite.

folders:
+- map: ~/projects/testsite
+to: /home/vagrant/projects/testsite

Setup Homestead so that it can serve the application through the 'domain' testsite.local. Note how this matches the name added to /etc/hosts earlier.

sites:
+- map: testsite.local
+to: /home/vagrant/projects/testsite/public

Have Homestead create a database for our application.

databases:
+- testsite

Since I'm using a database ensure that a database server is installed on the virtual machine.

features:
+- mariadb: true

Launching Homestead

Homestead is started with the vagrant up command. It may take a while for Homestead to launch if this is the first time running this command as Vagrant has to first download the actual virtual machine file.

$ cd ~/.local/share/homestead
+
+$ vagrant up

Once the machine is booted I can browse to http://testsite.local/ to see the simple site that is now served by Homestead.

Installing a Laravel Site

Now that Homestead is installed and serving a simple site its time to move onto installing the first Laravel application. Since Homestead provides all the tools required to do this the first thing to do is connect to the virtual machine.

$ cd ~/.local/share/homestead
+
+$ vagrant ssh

Once connected to the virtual machine navigate to the project folder of the site. Remember that this is the folder that is also been shared with the host machine.

$ cd ~/projects/testsite

Clear the contents of this folder otherwise composer will complain about a non-empty directory.

$ rm -rf public

Use composer to install a Laravel project.

$ composer create-project laravel/laravel .

Setting Up The Application Database

Once Larvel is installed a database needs to be created for the application. Connect to the database server with the mysql command.

$ mysql -uhomestead -psecret

Check that the application's database was created when the virtual machine was first booted.

SHOW DATABASES;
+
++--------------------+
+| Database           |
++--------------------+
+| homestead          |
+| information_schema |
+| mysql              |
+| performance_schema |
+| sys                |
+| testsite           |
++--------------------+

If the database does not exist create it with the below SQL.

CREATE DATABASE testsite;

Create a MySQL user for the application and grant permissions to use the application database.

CREATE USER 'testsite'@'localhost' IDENTIFIED BY 'testsite';
+
+GRANT ALL PRIVILEGES ON testsite.* TO 'testsite'@'localhost';

Exit the database server.

exit

To check the new MySql user account simply connect as that user with the credentials used earlier.

$ mysql -utestsite -ptestsite

The result of the SHOW DATABASE sql should show that the user account can see the application database.

SHOW DATABASES;
+
++--------------------+
+| Database           |
++--------------------+
+| information_schema |
+| testsite           |
++--------------------+

Configuring The Laravel Application

Edit the supplied .env file.

$ vim .env

If one does not exist then copy the example file.

$ cp .env.example .env

Change the environment variables to match those below. Some of changes ensure that Laravel can connect to the database created earlier.

APP_NAME='Test Site'
+
+APP_URL=http://testsite.local
+
+DB_CONNECTION=mysql
+DB_HOST=127.0.0.1
+DB_PORT=3306
+DB_DATABASE=testsite
+DB_USERNAME=testsite
+DB_PASSWORD=testsite

Now when you browse to http://testsite.local you will see the Laravel welcome page.

Simplified SSH

I prefer to just use the host system's ssh command to connect to Homestead as it cuts out having to navigate to the Homestead directory and running vagrant ssh.

To simplify ssh I first add a hostname for the virtual machine to the file /etc/hosts/

192.168.10.10 homestead

I then edit ~/.ssh/config and add the below configuration. This tells ssh to automatically use the keys and username specified when connecting to the virtual machine.

Host homestead
+IdentityFile ~/.ssh/homestead/id_rsa
+User vagrant

From now on I can simply do ssh homestead from any directory to connect to the Homestead virtual machine.

Links

Laravel HomesteadLaravel - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed + https://davidtsadler.com/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/index.html + + David T. Sadler. + 2020-12-14T12:00:00Z + 2020-12-14T12:00:00Z + ![CDATA[

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed

Mon 14th December 2020 By David T. Sadler.

One of the first things you do when creating a new Larvel application is run php artisan migrate to create the application database tables. However you may come across the below message.

$ php artisan migrate
+
+Illuminate\Database\QueryException
+
+SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = testsite and table_name = migrations and table_type = 'BASE TABLE')
+
+at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
+674▕         // If an exception occurs when attempting to run a query, we'll format the error
+675▕         // message to include the bindings with SQL, which will make this exception a
+676▕         // lot more helpful to the developer instead of just the database's errors.
+677▕         catch (Exception $e) {
+678▕             throw new QueryException(
+679▕                 $query, $this->prepareBindings($bindings), $e
+680▕             );
+681▕         }
+682▕
+
++33 vendor frames
+34  artisan:37
+Illuminate\Foundation\Console\Kernel::handle()

The cause of this issue is due to a change introduced to the .env.example file. This changed the environment variable DB_HOST from 127.0.0.1 to mysql. The reason for this change is to support [Laravel Sail](https://laravel.com/docs/8.x/sail) which is a Docker development environment for Laravel.

The change means your Laravel application will try and connect to a database server with the hostname of mysql. Unless this exists then the application can't connect.

To resolve the issue just change the value back to 127.0.0.1

DB_HOST=127.0.0.1

Links

Commit that changed .env.example.Laravel SailLaravel - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Installing Zsh and Powerlevel10k on Arch Linux + https://davidtsadler.com/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/index.html + + David T. Sadler. + 2020-09-07T12:00:00Z + 2020-09-07T12:00:00Z + ![CDATA[

Installing Zsh and Powerlevel10k on Arch Linux

Mon 7th September 2020 By David T. Sadler.

I have been a bash user ever since I started using Linux. But after installing Arch Linux I wanted to give another shell a try and so decided on Zsh. Below is how I went about replacing bash with Zsh.

Installing Zsh

Zsh is installed via pacman.

$ sudo pacman -S zsh

Check that Zsh has been installed by running it from the terminal.

$ zsh

Since this is the first time that Zsh has been run you should now see zsh-newuser-install which will allow you to setup some basic configuration. If you wish to skip this just press the q key. You can always manually run this with the below commands at a later date.

$ autoload -Uz zsh-newuser-install
+$ zsh-newuser-install -f

Changing The Default Shell

Installing Zsh does not automatically make it the system's default shell. The next time you log back in you will find that your current shell is still in use. You can check which shell is been used by looking at the SHELL environment variable.

$ echo $SHELL
+
+/bin/bash

To see a list of shells that have been installed use the chsh command.

$ chsh -l
+
+/bin/sh
+/bin/bash
+/usr/bin/git-shell
+/bin/zsh
+/usr/bin/zsh

The same command can be used to change the default shell by providing it with the full path to the shell.

$ chsh -s /bin/zsh

Note that this change is not instant and you will need to log out and log in again for it to take affect. Once you have done that check the SHELL environment variable again to confirm the change.

$ echo $SHELL
+
+/bin/ksh

Installing Powerlevel10k

Powerlevel10k is a theme for Zsh and in order to make the most of it you should install the Meslo Nerd Font that has been patched for Powerlevel10k.

$ yay -Sy --noconfirm ttf-meslo-nerd-font-powerlevel10k

You need to configure your terminal to use this font. How this is done is dependant upon what terminal you are using. Since I use st from suckless I need to edit the file config.h and specify MesloLGS NF in the font settings.

static char *font = "MesloLGS NF:pixelsize=14:antialias=true:autohint=true";

Before rebuilding st.

$ sudo make install

Now that the dependences have been meet Powerlevel10k can be installed.

$ yay -Sy --noconfirm zsh-theme-powerlevel10k-git

Once it has been installed ensure that Zsh loads Powerlevel10k.

$ echo 'source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme' >>! ~/.zshrc

You can now open a new terminal which will start the Powerlevel10k configuration wizard. This will ask you a few questions and configure your prompt. If it doesn't trigger automatically, type p10k configure.

Once the configuration wizard has finished open a new terminal and you should see the Powerlevel10k theme been used.

Links

Installing Arch Linux on a Thinkpad X220.Zsh.Powerlevel10k.Simple Terminal.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Enabling Audio in Arch Linux + https://davidtsadler.com/posts/arch/2020-08-31/enabling-audio-in-arch-linux/index.html + + David T. Sadler. + 2020-08-31T12:00:00Z + 2020-08-31T12:00:00Z + ![CDATA[

Enabling Audio in Arch Linux

Mon 31st August 2020 By David T. Sadler.

If you have recently installed Arch Linux you may have found that there is no sound when playing media. This is because by default ALSA has all channels muted.

Installing the ALSA Utilities

The Advanced Linux Sound Architecture (ALSA) is the part of the Linux kernel that manages the sound devices on your system. In addition to this the project also provides several command-line utilities that allow you to configure these devices. These can be installed with pacman.

$ sudo pacman -S alsa-utils

Unmuting The Channels

Channels can be unmuted with amixer.

$ amixer sset Master unmute
+$ amixer sset Speaker unmute
+$ amixer sset Headphone unmute

You can test that the speakers are working with the speaker-test command.

$ speaker-test -c 2

If you are still getting no sound then it could be that the volume has been set to zero. Use amixer again to increase the volume.

$ amixer sset Master 100%
+$ amixer sset Speaker 100%
+$ amixer sset Headphone 100%

Unmute with Alsamixer

If you prefer a more intuitive ncurses interface you can use alsamixer.

$ alsamixer

Channels that are muted will have the MM label below them. Unmuted channels have 00.

Use the ← and → keys to scroll to the muted channel and press m to unmute it.

The volume can be increased and decreased with the ↑ and ↓ keys.

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Pacman Cheat Sheet For Ubuntu Users + https://davidtsadler.com/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/index.html + + David T. Sadler. + 2020-08-24T12:00:00Z + 2020-08-24T12:00:00Z + ![CDATA[

Pacman Cheat Sheet For Ubuntu Users

Mon 24th August 2020 By David T. Sadler.

As a regular Ubuntu user I am used to using apt for system maintenance. But now that I've installed Arch Linux I will be using pacman and so below is a cheat sheet for myself that shows the pacman equivalent of some common apt actions.

Action                     | Apt                            | Pacman                     |
+---------------------------|--------------------------------|----------------------------|
+Install a package          | apt install <package name>     | pacman -S <package name>   |
+Remove a package           | apt remove <package name>      | pacman -Rs <package name>  |
+Search for a package       | apt serch <search term>        | pacman -Ss <regexp>        |
+Upgrade packages           | apt update && apt upgrade      | pacman -Syu                |
+Upgrade distribution       | apt update && apt dist-upgrade | pacman -Syu                |
+Clean up local caches      | apt autoclean                  | pacman -Scc                |
+Remove unused dependencies | apt autoremove                 | pacman -Qmq | pacman -Rs - |

Install a Package

$ pacman --sync <package name>
+
+$ pacman -S <package name>

Installs a package and its dependencies.

Remove a Package

$ pacman --remove --recursive <package name>
+
+$ pacman -Rs <package name>

Removes a package and all its dependencies, provided that (A) they are not required by other packages; and (B) they were not explicitly installed by the user.

Search For a Package

$ pacman --sync --search <regexp>
+
+$ pacman -Ss <regexp>

Searches in the sync database for packages with a name or description that match the regexp.

Upgrade Packages

$ pacman --sync --refresh --sysupgrade
+
+$ pacman -Syu

Downloads a fresh copy of the master package database and then upgrades all out-of-date packages.

Upgrade Distribution

$ pacman --sync --refresh --sysupgrade
+
+$ pacman -Syu

Since Arch uses a rolling release system there is no distribution version as you just upgrade your packages to their latest versions.

Clean Up Local Caches

$ pacman --sync --clean --clean
+
+$ pacman -Scc

Free up disk space by removing from the cache any packages that are no longer installed. Also removes any cached sync databases.

Remove Used Dependencies

$ pacman --query --deps --unrequired --quiet | pacman --remove --recursive -
+
+$ pacman -Qdtq | pacman -Rs -

Remove dependencies that are no longer needed, because e.g. the package which needed the dependencies was removed.

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Installing ST, DMENU and DWM in Arch Linux + https://davidtsadler.com/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/index.html + + David T. Sadler. + 2020-08-17T12:00:00Z + 2020-08-17T12:00:00Z + ![CDATA[

Installing ST, DMENU and DWM in Arch Linux

Mon 17th August 2020 By David T. Sadler.

Continuing my Arch Linux installation I now have a user account for daily use. However this only provides me with a terminal. What I would like is a traditional multi-window desktop environment which will require me to install two things. A window system of some sort and a layout manager. For this installation I'm going with Xorg and dwm. For those that are not aware dwm is dynamic window manager for Xorg that has been developed by Suckless. Since by default dwm expects st to be installed as the system's terminal and also makes use dmenu to allow you to launch applications I will installed both of them in addition to dwm.

Install Dependencies

Firt off I need to install the dependencies required by st, dmenu and dwm. Since this is Arch Linux I use pacman to do this.

$ sudo pacman -S base-devel git libx11 libxft xorg-server xorg-xinit terminus-font
  • base-devel Since I will be installing from source this package contains various tools to compile software.
  • git Is needed to get the source code from the suckless git repositories.
  • libx11 and libxft Dependanices required by dwm oherwise it will fail when trying to compile it.
  • xorg-server Is the display server that provides the windows that dwm will manage.
  • xorg-xinit Allows us to start the display server.
  • terminus-font Dwm is configured to use a monospaced font and since I installed a barebones system I need to install such a font now.

Download Git Repositories

The source code for the software is avialable from the Suckless git repositories so I simply clone them.

$ mkdir -p ~/.local/src
+
+$ git clone git://git.suckless.org/st ~/.local/src/st
+$ git clone git://git.suckless.org/dmenu ~/.local/src/dmenu
+$ git clone git://git.suckless.org/dwm ~/.local/src/dwm

Install ST

I install st by first moving to the directory created when cloning the repository.

$ cd ~/.local/src/st

Then its as simple as compiling and instaling the software with the below commands.

$ make clean
+$ sudo make install

Configure and Install DMENU

Again move to the directory created earlier.

$ cd ~/.local/src/dmenu

Before compiling a small edit needs to be made to the file config.mk.

$ nvim config.mk

Since I have not installed Xinerama on this system I need to comment out any flags that reference this otherwise dmenu will fail during the compiling.

# XINERAMALIBS  = -lXinerama
+# XINERAMAFLAGS = -DXINERAMA

Again compiling and installing is done with the below commands.

$ make clean
+$ sudo make install

Configure and Install DWM

For the final time move to the directory created earlier.

$ cd ~/.local/src/dwm

As with dmenu the same edit needs to be made to the file config.mk.

$ nvim config.mk
# XINERAMALIBS  = -lXinerama
+# XINERAMAFLAGS = -DXINERAMA

Compile and install as usual.

$ make clean
+$ sudo make install

Starting DWM

Since I have installed xorg-xinit I need to create a .xinitrc in my home folder.

$ nvim ~/.xinitrc

The contents of this file is just.

exec dwm

I can now start xorg and dwm with the below command.

$ startx

Links

Installing Arch Linux on a Thinkpad X220.Dynamic Window Manager (DWM).Suckless Software.Simple Terminal.DMenu.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Sudo: sorry, you must have a tty to run sudo + https://davidtsadler.com/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.html + + David T. Sadler. + 2020-07-13T12:00:00Z + 2020-07-13T12:00:00Z + ![CDATA[

Sudo: sorry, you must have a tty to run sudo

Mon 13th July 2020 By David T. Sadler.

I have found Deployer to be a great tool for deploying PHP applications. However when first setting out to use it I soon came across the error message 'sudo: sorry, you must have a tty to run sudo'. After some investigation I found that the error was triggered when Deployer was running commands via sudo. For those that don't know Deployer works by executing commands on your servers via ssh and depending on your server's configuration there could be issues when sudo is one of those commands.

What is meant by 'sudo: sorry, you must have a tty to run sudo'?

When sudo is executed the file /etc/sudoers is read to determine which users or groups can use sudo and what commands they can run. It actually does a bit more than that and you should read the manual for more information.

If you examine the sudoers file you will find that it contains the setting Defaults requiretty. This means that sudo can only be ran from a real tty. In other words if a user wants to run sudo they must have logged into a terminal before hand. This is normally a security feature so that sudo can't be ran from things such as cron jobs. However, it also means that you will have issues when running sudo from another machine via ssh as you also won't be logged into an actual terminal.

How to resolve the issue?

If you're happy to change the setting for all users simply use visudo to edit /etc/sudoers and change Defaults requiretty to Defaults !requiretty. Alternatively you can remove the tty requirement for a single user. In fact that is what I do when using Deployer. Since it connects to the server using a user called deployer I add the below configuration with visudo.

Defaults:deployer !requiretty
+deployer ALL=(ALL) NOPASSWD:/usr/bin/chown, /usr/bin/tee, /usr/sbin/apachectl

This configuration allows the deployer user to execute sudo when not logged into a real terminal and additionally not prompt for a password when executing chown, tee, and apachectl.

Using Pseudo-tty

An alternative is to use the pseudo-tty option when connecting via ssh.

$ ssh -t user@example.com sudo apachectl restart

Links

Deployer - A Deployment Tool for PHP.Sudo Manual.Linux - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Granting Sudo Access to a User in Arch Linux + https://davidtsadler.com/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/index.html + + David T. Sadler. + 2020-06-22T12:00:00Z + 2020-06-22T12:00:00Z + ![CDATA[

Granting Sudo Access to a User in Arch Linux

Mon 22nd 2020 By David T. Sadler.

So by the end of my last post my minimal installation of Arch Linux had a user account that I could log into instead of the root user. However in order to do anything useful on the system I need to be able to run commands such as pacman that only the root user can do. Now one way to solve this is to change to the root user with su before running the command, but this defeats the point in creating a non-root user account in the first place. Instead a better way is to make use of sudo.

Sudo (su "do") gives the ability for a user (or groups of users) to run some (or all) commands as root and also provides an audit trail of the commands and their arguments. Usage is very simple, you enter sudo followed by the command that you want to run. For example,

$ sudo pacman -Syu

Configuration is done in the file /etc/sudoers. This is where you can specify which users or groups can use sudo and what commands they can run. However, you must be careful when editing this file as any syntax errors will make sudo unusable. Therefore it is strongly recommended to do any editing via the visudo command. This locks the sudoers file, saves edits to a temporary file, and checks that file's grammar before copying it to /etc/sudoers.

Traditionally in Linux systems users that should have privileged administrator rights are added to the wheel group which is then given sudo access. As the root user the first thing that I needed to do was add my user account to the wheel group with the usermod command.

$ usermod -aG wheel david

I used the below options with the command.

  • -a Modifies the -G argument so that the user is added to the specified groups and not removed from any existing ones.
  • -G The list of supplementary groups that the user will be made a member of. In this case it's just wheel. Note that you need to pass -a otherwise the user will be removed from any group that is not listed.

The sudo package then needed to be installed.

$ pacman -S sudo

Next I needed to grant sudo access to the wheel group by editing /etc/sudoers with visudo. Note that the default editor for visudo is vi. Since this has not been installed on my system I can change the editor to be nvim by first setting the variable EDITOR.

$ EDITOR=nvim visudo

Once the file was opened I located and uncommented the below line before saving and exiting nvim. This allows members of the wheel group to execute any command without having to enter their password.

%wheel ALL(ALL) NOPASSWD: ALL

I checked that I had sudo access by running the below command while logged into my user account.

$ sudo pwd
+
+/home/david

Since I wasn't prompted for my password and the command was executed I knew that I now had sudo access.

Links

Adding a User in Arch Linux.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Adding a User in Arch Linux + https://davidtsadler.com/posts/arch/2020-06-15/adding-a-user-in-arch-linux/index.html + + David T. Sadler. + 2020-06-15T12:00:00Z + 2020-06-15T12:00:00Z + ![CDATA[

Adding a User in Arch Linux

Mon 15th June 2020 By David T. Sadler.

In a previous post I installed Arch Linux on my Thinkpad X220. Since it was a very minimal install there are no user accounts except for the root user. So to add myself as a user I need to use the useradd command.

$ useradd -m -s /bin/bash david

I used the below options with the command.

  • -m Create the home directory for this account.
  • -s /bin/bash Make bash the login shell for this account.
  • david The name of the new user.

This creates a new account for me and also ensures that a home directory is created as /home/david.

The new account will require a password so assign one with the passwd command.

$ passwd david
+
+New password:
+Retype new password:
+passwd: password updated successfully

Now all I have to do is logout of the root account.

$ logout

Then login with the new credentials to confirm that everything is okay.

suliman login: david
+Password:
+
+david@suliman:$

Links

Installing Arch Linux on a Thinkpad X220.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Publishing Jigsaw Posts With Netlify Build Hooks + https://davidtsadler.com/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/index.html + + David T. Sadler. + 2020-06-08T12:00:00Z + 2020-06-08T12:00:00Z + ![CDATA[

Publishing Jigsaw Posts With Netlify Build Hooks

Mon 8th June 2020 By David T. Sadler.

A previous post talks about how I use Jigsaw's filtering to schedule future posts. However because Jigsaw is a static site builder I have to run Jigsaw in order to generate the HTML for the site. So if for example I have scheduled three posts to be published over three consecutive weeks I would need to build and deploy the site on each of the scheduled dates in order for the posts to be published. This kind of defeats the point of scheduling posts. So what I needed was some way to automatically trigger new builds of the site and since I use Netlify to host the site I can make use of their build hooks to do this.

For those that don't know build hooks are URLs you can use to trigger new builds and deployments in Netlify. By making a HTTP POST request to a URL, Netlify will pull down the latest master branch of your site, build it, and then deploy it.

Creating the build hook was simple. After logging into my Netlify account I went to Settings > Build & deploy > Continuous deployment > Build hooks.

From there I clicked Add build hook where I could then provide a name and select which GitHub branch would be used to build the site.

Clicking Save creates the build hook and you are given a unique URL that can be used to trigger it.

What is very handy about Netlify is that they provide you with an example of calling the URL with cURL. With this I simply setup a cron on a server that requests this URL every Monday at 8am.

8 * * 1 curl -X POST -d {} https://api.netlify.com/build_hooks/111111111111111111111111

The result is that every week posts that have been scheduled for that day will now be published when the site is built and deployed by the build hook.

Links

2020-06-01 - Scheduling Posts in JigsawJigsaw - Static Site Generator for PHP Developers.Netlify - Serverless Platform for Static Websites.Build Hooks in Netlify.Netlify - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Scheduling Posts in Jigsaw + https://davidtsadler.com/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.html + + David T. Sadler. + 2020-06-01T12:00:00Z + 2020-06-01T12:00:00Z + ![CDATA[

Scheduling Posts in Jigsaw

Mon 1st June 2020 By David T. Sadler.

Jigsaw is a static site generator that I use for my site and one of its features is the ability to create a filter that determines which items in a collection will be included in the final build.

It works by you adding a filter key to a collection's array in your config.php file, and specifying a callable that accepts an item from the collection and that returns a boolean. By returning false an item will not be built.

Below is how I have setup my config.production.php file which is used when building the site for deployment.

<?php
+
+use Carbon\Carbon;
+
+return [
+'collections' => [
+'posts' => [
+'filter' => function ($item) {
+$date = $item->date ? Carbon::createFromFormat('U', $item->date) : null;
+// Only publish posts that have a date and which is not in the future.
+return $date ? $date <= Carbon::now() : false;
+}
+],
+],
+];

When deploying the site each post is passed to this filter. The first thing it does is convert the date that has been specified in the post's YAML front matter into a Carbon instance. It then returns true if the date is on or before the current date, I.e. when the site is been deployed.

With this filter I can specify future dates for several posts and they will only published once that date comes around. Posts are also exluded if a date has not been specified. This allows me to have posts that are a work in progress and shouldn't be published.

Links

Jigsaw - Static Site Generator for PHP Developers.Using Filters in Jigsaw.Carbon - PHP API Extension for DateTime.Jigsaw - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Installing Arch Linux on a Thinkpad X220 + https://davidtsadler.com/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/index.html + + David T. Sadler. + 2020-05-25T12:00:00Z + 2020-05-25T12:00:00Z + ![CDATA[

Installing Arch Linux on a Thinkpad X220

Mon 25th May 2020 By David T. Sadler.

Introduction

So I purchased a used Thinkpad X220 for about £90 on eBay and decided to install Arch Linux onto it. This guide is the steps that I took to achieve this.

Now when it comes to Linux there is always more than one way of doing things and this guide is just my preferred way. Feel free to follow it for your own installation, just keep in mind that you may have to change some of the steps to suit your own circumstances. Also there is every chance that the information presented here will be out of date so I recommend that you at least read the through the official installation guide for the most up-to-date information.

Download the Arch Linux ISO Image

The Arch Linux download page provides direct download and torrent links. You should also download the PGP signature to the same location and use the gpg command to verify that the ISO has not been compromised.

$ gpg --keyserver-options auto-key-retrieve --verify archlinux-2020.05.01-x86_64.iso.sig

Create a Live USB of Arch Linux

Flash the image to a USB drive using Etcher. Alternatively you can use the dd command. Just ensure that /path/to/archlinux.iso is to where you have downloaded the image and that /dev/sdx is your USB drive.

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress && sync

Boot the Live Environment

I wanted to make sure that the Thinkpad was using UEFI as I would be using EFISTUB to load the Linux kernel as an EFI executable. This is done through the BIOS which can be gotten to by pressing the ThinkVantage button as the machine is booting before pressing F1 to get to the BIOS settings. From there navigate to Startup and changed the UEFI/Legacy Boot option to be UEFI Only. Press F10 to save and exit the BIOS and then power down the machine.

With the USB drive plugged in power the machine back on, all the while pressing F12 until the boot menu appears and select USB HDD: Mass Storage Device and wait for the installation image to boot. When prompted select Arch Linux archiso X86_64 UEFI CD where you will be take to the live environment's terminal.

Set the Keyboard Layout

The default console map is US which meant that for me pressing Shift+3 was displaying the hash symbol (#) instead of the pound symbol (£). So the UK keyboard layout needed to be loaded.

$ loadkeys uk

You can get a list of supported keyboard layouts if you need to load a different one.

ls /usr/share/kbd/keymaps/**/*.map.gz

Verify the Boot Mode

To verify that the Thinkpad has UEFI enabled check that the efivars directory exists.

$ ls /sys/firmware/efi/efivars

Connect to the Internet

Verify that the machine can connect to the internet with the ping command.

$ ping -c3 davidtsadler.com

Before booting the machine I plugged in an Ethernet cable that was connected directly to my home network's router. The installation environment detected the network connection and obtained an IP address via DHCP.

Update the System Clock

Ensure the system clock is correct.

$ timedatectl set-ntp true

Partition the Disks

Use the lsblk command to determine which disks and partitions exist on the system.

$ lsblk
+
+NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
+loop0    7:0    0   535M  1 loop /run/archiso/sfs/airootfs
+sda      8:0    0 298.1G  0 disk
+sdb      8:16   1   7.4G  0 disk
+├─sdb1   8:17   1   652M  0 part /run/archiso/bootmnt
+└─sdb2   8:18   1    64M  0 part

From the above output I could see that my hard drive was sda as sdb was the USB drive and loop0 could just be ignored.

I knew that I wanted to have an encrypted partition and make use of LVM on it so my disk layout would be.

+-------------------+ +--------------------------------------------------------+
+| Boot partition    | | Logical volume 1 | Logical volume 2 | Logical volume 3 |
+|                   | |                  |                  |                  |
+| /boot             | | /                | [SWAP]           | /home            |
+|                   | |                  |                  |                  |
+|                   | | 50G              | 16G              | 200G             |
+|                   | |                  |                  |                  |
+|                   | | /dev/vg0/root    | /dev/vg0/swap    | /dev/vg0/home    |
+|                   | |_ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ |
+|                   | |                                                        |
+|                   | |              LUKS2 encrypted partition                 |
+| /dev/sda1 (512MB) | |                    /dev/sda2                           |
++-------------------+ +--------------------------------------------------------+

The hard drive would be split into two partitions. The first, sdb1 would be 512MB in size and mounted in the file system at /boot. This would be the EFI system partition. The reminder of the disk space would be given to the partition sda2 and encrypted using LUKS2. LVM would then be used to create the volume group vg0 that would be divided into three partitions as logical volumes.

  • /dev/vg0/root 50G root partition.
  • /dev/vg0/swap 16G swap partition.
  • /dev/vg0/home 200G home partition.

Use fdisk to create the partitions.

$ fdisk /dev/sda

Enter g to create a new empty GPT partition table

Command (m for help): g
+Created a new GPT disklabel (GUID: 6987D065-936E-1547-9F02-F78145025A96).

Since this is a UEFI system there must be a EFI partition at the beginning of the disk. Enter n to add a new partition and enter 1 to assign it as the first partition. Use the default value for the first sector but enter +512M for the last sector.

Command (m for help): n
+Partition number (1-128, default 1): 1
+First sector (2048-625142414, default 2048):
+Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-625142414, default 625142414): +512M
+
+Created a new partition 1 of type 'Linux filesystem' and of size 512 MiB.

Enter t to change the partition type and enter 1 to make it an EFI System. You can also get a list of partition types by pressing L.

Command (m for help): t
+Selected partition 1
+Partition type (type L to list all types): 1
+Changed type of partition 'Linux filesystem' to 'EFI System'.

To create the second partition enter n again to add another partition, and then enter 2 to assign it as the second partition. Use the default values for both first and last sectors to allocate the remainder of the drive.

Command (m for help): n
+Partition number (2-128, default 2): 2
+First sector (1050624-625142414, default 1050624):
+Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-625142414, default 625142414):
+
+Created a new partition 2 of type 'Linux filesystem' and of size 297.6 GiB.

Enter w to write the changes and quit.

Command (m for help): w
+The partition table has been altered.
+Calling ioctl() to re-read partition table.
+Syncing disks.

Use lsblk to confirm that two partitions have been created.

$ lsblk /dev/sda
+
+NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
+sda      8:0    0 298.1G  0 disk
+├─sda1   8:1    0   512M  0 part
+└─sda2   8:2    0 297.6G  0 part

LUKS

Encrypt the second partition with the cryptsetup command.

$ cryptsetup luksFormat /dev/sda2

When prompted enter YES in capitals to overwrite any data that is currently on the partition.

WARNING!
+========
+This will overwrite data on /dev/sda2 irrevocably.
+
+Are you sure? (Type 'yes' in capital letters): YES

Enter and verify a passphrase. Whenever the machine is now booted you will be prompted to enter this passphrase in order for the partition to be decrypted.

Enter passphrase for /dev/sda2:
+Verify passphrase:
+cryptsetup luksFormat /dev/sda2  17.01s user 1.05s system 105% cpu 17.106 total

LVM on LUKS

Before setting up LVM decrypt the partition.

$ cryptsetup open /dev/sda2 cryptlvm

You will be prompted to enter the passphrase that you set up earlier.

Enter passphrase for /dev/sda2:
+cryptsetup open /dev/sda2 cryptlvm  6.48s user 0.36s system 92% cpu 7.436 total

Create a physical volume.

$ pvcreate /dev/mapper/cryptlvm

Create a volume group called vg0.

$ vgcreate vg0 /dev/mapper/cryptlvm

Create three logical volumes for the root, swap and home partitions.

$ lvcreate -L 50G vg0 -n root
+$ lvcreate -L 16G vg0 -n swap
+$ lvcreate -L 200G vg0 -n home

Make use of lsblk again to verify that LVM has been setup as expected.

$ lsblk /dev/sda
+
+NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
+sda              8:0    0 298.1G  0 disk
+├─sda1           8:1    0   512M  0 part
+└─sda2           8:2    0 297.6G  0 part
+└─cryptlvm   254:0    0 297.6G  0 crypt
+├─vg0-root 254:1    0    50G  0 lvm
+├─vg0-swap 254:2    0    16G  0 lvm
+└─vg0-home 254:3    0   200G  0 lvm

Format the Partitions

Format the boot partition at /dev/sda1 with a FAT32 file system as the UEFI specification requires the usage of it.

$ mkfs.fat -F32 /dev/sda1

The root and home partitions can be formatted with ext4.

$ mkfs.ext4 /dev/vg0/root
+$ mkfs.ext4 /dev/vg0/home

Initialise the swap partition.

$ mkswap /dev/vg0/swap
+$ swapon /dev/vg0/swap

Mount the File Systems

Mount the root partition into /mnt.

$ mount /dev/vg0/root /mnt

Mount the boot partition into /mnt/boot.

$ mkdir /mnt/boot
+$ mount /dev/sda1 /mnt/boot

Finally mount the home partition into /mnt/home.

$ mkdir /mnt/home
+$ mount /dev/vg0/home /mnt/home

Select the Mirrors

All mirror servers defined in /etc/pacman.d/mirrorlist where done at the time the installation image was built. Since it's ideal to try and use servers that are close to your location you can rebuild the list using the rankmirrors utility. This is not included by default on the live environment so you will need to download it.

First sync the pacman repository.

pacman -Syy

Then download the pacmain-contrib package which contains the rankmirrors utility.

$ pacman -S pacman-contrib

The official Pacman Mirrorlist Generator can be used to get an up-to-date list of servers for your country. The below command obtains a list of UK servers that support https and pass it to rankmirrors to obtain the 5 fastest.

$ curl -s "https://www.archlinux.org/mirrorlist/?country=GB&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 - > /etc/pacman.d/mirrorlist

Install Essential Packages

The pacstrap script is used to install the base package, Linux kernel and firmware.

$ pacstrap /mnt base linux linux-firmware neovim wpa_supplicant dhcpcd cryptsetup lvm2 efibootmgr intel-ucode

I also installed a few other packages that I knew I was going to need.

  • neovim. Allows you to edit files instead of using nano.
  • wpa_supplicant. Provides tools for connecting to a WPA2 protected wireless network.
  • dhcpcd. Needed so that you machine can obtain an IP address from your home router via dhcp.
  • cryptsetup. Since the partition is encrypted this package is required in order for it to be decrypted during booting.
  • lvm2. Provides the LVM tools to manage the LVM partition.
  • efibootmgr. Needed to configure the system to boot via UEFI.
  • intel-ucode. Enables microcode updates during boot.

Fstab

Create a fstab file on the new system.

$ genfstab -U /mnt >> /mnt/etc/fstab

Chroot

Use arch-chroot to enter the new system as the root user. From now on you will be configuring the new system.

$ arch-chroot /mnt

Time Zone

Setup the timezone. Replace Europe/London with your timezone.

$ ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

Update the hardware clock.

$ hwclock --systohc

Localization

Use nvim to edit /etc/locale.gen.

$ nvim /etc/locale.gen

Uncomment your preferred language. For me this meant en_GB.UTF-8 UTF-8. Save the file and exit before generating the locales.

$ locale-gen

Edit /etc/locale.conf.

$ nvim /etc/locale.conf

Add the below line. Replace en_GB.UTF-8 with the language that you chose earlier.

LANG=en_GB.UTF-8

If you used loadkeys earlier you will need to edit /etc/vconsole.conf and add your chosen keymap.

$ nvim /etc/vconsole.conf

For me this meant adding the UK keymap.

KEYMAP=uk

Network Configuration

Create the file /etc/hostname and add an entry to it. This hostname will be the name of the machine on your network. I tend to name by devices after characters from the book Howl's Moving Castle https://en.wikipedia.org/wiki/Howl%27s_Moving_Castle).

$ echo suliman > /etc/hostname

You then need to edit the /etc/hosts file.

$ nvim /etc/hosts

Add the following lines to this file. Replace suliman with the hostname you set up earlier.

127.0.0.1	localhost
+::1		    localhost
+127.0.0.1	suliman.localdomain suliman

Wireless

Use the ip command to determine the name of the wireless network interface.

$ip link
+
+1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
+link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
+2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
+link/ether f0:de:f1:86:e1:75 brd ff:ff:ff:ff:ff:ff
+3: wwp0s29u1u4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
+link/ether 86:06:37:c4:9b:41 brd ff:ff:ff:ff:ff:ff
+4: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
+link/ether 08:11:96:02:10:ac brd ff:ff:ff:ff:ff:ff

Looking at the output of the ip command this is wlan0. This name however will not be the name of the interface once the installation has been completed. You see the Arch installation environment does not use predictable names for interfaces. This is due to it using iwd which is unable to cope with interface renaming and so it is disabled for wireless interfaces. When the system boots into the installed system predictable names for interfaces will be enabled and wlan0 will be assigned a different name.

In order to find out what name will be assigned use the udevadm command.

$ udevadm test-builtin net_id /sys/class/net/wlan0
+
+Load module index
+Parsed configuration file /usr/lib/systemd/network/99-default.link
+Parsed configuration file /usr/lib/systemd/network/80-iwd.link
+Created link configuration context.
+Using default interface naming scheme 'v245'.
+ID_NET_NAMING_SCHEME=v245
+ID_NET_NAME_MAC=wlx0811960210ac
+ID_OUI_FROM_DATABASE=Intel Corporate
+ID_NET_NAME_PATH=wlp3s0
+Unload module index
+Unloaded link configuration context.

What we are interested in is the value of ID_NET_NAME_PATH which is wlp3s0.

My wireless network is a WPA2 protected network with a hidden SSID. Since wpa_supplicant has been installed when running pacstrap it is possible to use wpa_passphrase to generate the configuration file that wpa_supplicant will use to connect to the wireless network. Replace &lt;SSID&gt; and &lt;PASSWORD&gt; with your details. Note that the name of the configuration file contains the name of the network interface wlp3s0. Replace this with the name of your network interface.

$ wpa_passphrase <SSID> <PASSWORD> > /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf

If your wireless network uses a hidden SSID you will need to edit the configuration file.

$ nvim /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf

And add the below line.

scan_ssid=1

Make sure that wpa_supplicant starts at boot.

$ systemctl enable wpa_supplicant@wlp3s0.service

Have an IP address assigned via DHCP during booting.

$ systemctl enable dhcpcd@wlp3s0.service

Initramfs

You will need to rebuild the initial ramdisk and the current one is not aware that the filesystem will be encrypted. Before rebuilding it some configuration changes need to be made.

$ nvim /etc/mkinitcpio.conf

Locate the section where the HOOKS are configured and replace it with the line below.

HOOKS=(base udev autodetect keyboard keymap modconf block encrypt lvm2 filesystems fsck)

This ensures that the keyboard is present before the filesystem is detected so that you are enter the passphrase to decrypt the partition. It also ensures that the decryption is done before the LVM is handled.

Save the changes and exist before rebuilding with the mkinitcpio command.

mkinitcpio -P

EFISTUB Booting and Microcode

The Thinkpad X220 UEFI implementation allows an operating system to be booted without the need for an intermediate bootloader such as GRUB. It is possible to add a UEFI boot entry to the motherboard itself and have Arch booted directly.

Modifying the motherboard boot entries is done using efibootmgr. However usage of this command can be quite verbose so it is recommended to create a shell script instead.

nvim /usr/local/sbin/mkefibootentry

The shell script will call efibootmgr with the required arguments.

#!/bin/sh
+
+# Determine the UUID of the partition that is encrypted
+PARTUUID=`blkid /dev/sda2 -s PARTUUID -o value`
+
+efibootmgr \
+--disk /dev/sda --part 1 \
+--create --label "Arch Linux" \
+--loader /vmlinuz-linux \
+--unicode 'cryptdevice=PARTUUID='$PARTUUID':cryptlvm root=/dev/vg0/root rw initrd=\intel-ucode.img initrd=\initramfs-linux.img' \
+--verbose 

The --unicode argument is where the kernel parameters are specified. This tells the system that the partition identified by PARTUUID is encrypted and that the root filesystem to mount is the logical volume called root that is part of the volume group vg0. The microcode is also loaded with initrd=\intel-ucode.img.

Make this script executable.

chmod u+x /usr/local/sbin/mkefibootentry

Run the script to add to the motherboard boot entries.

$ mkefibootentry

Root Password

Create a secure password for the root user.

$ passwd

Reboot

Return to the Arch live installation environment.

$ exit

Unmount the partitions.

$ umount -R /mnt

Restart the machine with reboot. Remember to remove any installation media such as a USB drive.

$ reboot

Provided nothing has gone wrong your machine will boot into a fresh installation of Arch Linux. Don't forget that during the boot you will be prompted to enter the passphrase to decrypt the system partition.

Following this guide will leave you with a very minimal system where you can login as the root user. From this point how you configure the system is up to you as it will be very different to how I configure my own. If you interested in seeing how I do it then see my other posts on the subject.

Links

Offical Arch Installation Guide.Arch Linux Download Page.Etcher.Pacman Mirrorlist Generator.Wikipedia Entry for Howl's Moving Castle.Arch - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ Creating an Ebook With Markdown + https://davidtsadler.com/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/index.html + + David T. Sadler. + 2020-03-30T12:00:00Z + 2020-03-30T12:00:00Z + ![CDATA[

Creating an Ebook With Markdown

Mon 30th March 2020 By David T. Sadler.

Pandoc is a great tool for converting a file in one markup format into another. This means we can use it to convert a file written in Markdown into an EPUB file that is supported by many e-readers.

Lets start by writting a very simple markdown file called example_ebook.md.

---
+title:
+- type: main
+text: Example Ebook
+- type: subtitle
+text: An Ebook created from a Markdown file
+creator:
+- role: author
+text: David Sadler
+publisher: Published by myself
+---
+
+This is an introduction.
+
+# Chapter 1
+
+This is the first paragraph of chapter 1.
+
+This is the second paragraph of chapter 1.
+
+Below is a list.
+
+- Item One
+- Item Two
+- Item Three
+
+# Chapter 2
+
+This is the first paragraph of chapter 2.
+
+This is the second paragraph of chapter 2.
+
+# Chapter 3
+
+This is the first paragraph of chapter 3.
+
+This is the second paragraph of chapter 3.

Note that the file begins with a YAML metadata block that starts and ends with three hyphens (---). This allows you to specify EPUB metadata such as the title and author.

Converting this to EPUB is done by running pandoc.

$ pandoc example_ebook.md -t epub3 --toc -o example_ebook.epub

There are several options that need to be passed to pandoc.

  • example_ebook.md - This argument is the file that you are converting.
  • -t epub3 - Set the output format to be EPUB v3 book.
  • --toc - Include a table of contents in the output document. This will be derived from the H1 headers in the markdown.
  • -o example_ebook.epub - Tell pandoc to output the conversion to the named file instead of stdout.

You can now copy the file example_ebook.epub to any device that supports the format or use one of the many software readers such as Calibre. However, if you wish to read this on a Kindle device you will need to convert it to the Mobi format.

Amazon provides a command line tool called KindleGen that can convert our EPUB file into the Mobi format. After downloading the tool just run it as shown below.

$ kindlegen example_ebook.epub

This will create a file called example_ebook.mobi that you can copy to your Kindle to read.

Links

Pandoc.Markdown.EPUB.YAML metadata block.EPUB metadata.EPUB v3 book.Calibre Application.Mobi Format.KindleGen Application.Markdown - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/index.html b/www/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/index.html new file mode 100644 index 0000000..f92d177 --- /dev/null +++ b/www/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/index.html @@ -0,0 +1,80 @@ + + + + + + How to Host Your Own Gemini Site in the Cloud + + + + + + + + + + + + + + +

How to Host Your Own Gemini Site in the Cloud

Mon 8th February 2021 By David T. Sadler.

So I have a Gemini site over at gemini://davidtsadler.co.uk and I thought I'd write up how I achieved this in case anyone was interested in doing the same.

I would say that from purchasing the domain name to having a complete server hosting the site took about 30 minutes in total.

Purchasing a Domain Name

I decided that for the moment I would keep my traditional "Big Web" content hosted at davidtsadler.com and use a different domain name for my new Gemini site. Since this meant purchasing a new one I popped over to Gandi.net to acquire davidtsadler.co.uk. Side note: I used to own this but decided not to renew it for some crazy reason.

Creating a cloud sever

My cloud provider of choice is Hetzner and creating a new server is done in eight steps.

1. Location

Hetzner provide a few locations in Europe as to where the server is hosted. For this server I chose Helsinki.

2. Image

I chose Ubuntu 20.04 as the operating system as this is the one I'm most familiar with.

3. Type

As this server is only going to a host a Gemini site I don't need a overly powerful system so I chose their most basic CX11 configuration. For €2.99 a month this gives me:

4. Volume

You have the option of attaching additional storage to the server. I skipped this step as for the time been the 20GB SSD that comes with the server should be enough for my needs.

5. Network.

I skipped this step as its not needed.

6. Additional features

Again I skipped this step but select any if you believe that you will need them.

7. SSH Key

When a server is created a root user is added and a password is emailed to you so that you can login. However if you provide a SSH key it will be installed on the server instead of creating a password.

I like to use separate keys for each server that I manage so I tend store the them in a directory named after the hostname.

$ mkdir ~/.ssh/davidtsadler.co.uk
+
+$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/davidtsadler.co.uk/id_rsa

The SSH key is added by clicking + ADD SSH KEY and then copying and pasting the contents of the id_rsa.pub file.

8. Name

I name my servers after the hostname so for this I called it davidtsadler.co.uk. I then created the server by clicking CREATE & BUY NOW.

SSH

Once the server was created I took the allocated IP address and ensured that I could access it via SSH using the key that I had provided.

$ ssh root@135.181.201.71 -i ~/.ssh/davidtsadler.co.uk/id_rsa

Resolve the Domain Name to the Server

In my Gandi.net account I went to the DNS Records section for the domain name I had purchased. There I deleted everything except for the @ (A) and www (CNAME) records which was configured as follows:

The A record is configured with the IPv4 address of my new server and the CNAME with the domain name. Note that the CNAME must end with a period!

After saving the changes it was just a matter of waiting for it to propagate through the DNS system. At which point I could use the domain name when logging in via SSH.

$ ssh root@davidtsadler.co.uk -i ~/.ssh/davidtsadler.co.uk/id_rsa

Securing the Server

At a bare minimum I setup a firewall and harden SSH. I may at a later date go further, such as installing fail2ban.

Configure a Firewall

This setup will deny any incoming requests unless they were first initiated by a request from the server. Since I need to be able to access the server I allow SSH. The Gemini protocol uses port 1965 so that is also allowed.

$ ufw default allow outgoing
+$ ufw default deny incoming
+$ ufw allow OpenSSH
+$ ufw allow 1965
+$ ufw enable

Harden SSH

I edited the /etc/ssh/sshd_config file.

$ vim /etc/ssh/sshd_config

I added the two below options so that the root user is not allowed to access the sever via SSH and other users may only access using keys.

PermitRootLogin no
+PasswordAuthentication no

Since I'd made changes to the configuration I needed to restart the SSH service.

$ service sshd restart

Create non-root User

Whenever I access a server I like to login as a non-root user that is able to run sudo on the system.

$ adduser gemini
+
+$ usermod -aG sudo gemini

As the SSH key is already on the server I can copy it to the non-root user account.

$ rsync --archive --chown=gemini:gemini ~/.ssh /home/gemini

On my local system I confirm that I can log in as the new user without a password.

$ ssh gemini@davidtsadler.co.uk -i ~/.ssh/davidtsadler.co.uk/id_rsa

I also confirm that I have sudo access.

$ sudo ls

Installing a Gemini Site and Server

Directory structure

I decided to go with a very simple directory structure. Each site will be a sub-directory in ~/sites that will be named after the domain name. Then each site will have the following sub-directories. The idea is that I may want to host more than one site in the future.

I created the directory structure with the below command.

$ mkdir -p ~/sites/davidtsadler.co.uk/{bin,certs,public,scripts}

Install certificates

Sine the Gemini protocol encourages using a self-signed certificate I installed one with the openssl command.

$ openssl req -x509 \
+-newkey rsa:4096 \
+-keyout ~/sites/davidtsadler.co.uk/certs/key.rsa \
+-out ~/sites/davidtsadler.co.uk/certs/cert.pem \
+-days 3650 \
+-nodes \
+-subj "/CN=davidtsadler.co.uk"

Create Some Test Content

I created a very simple index.gmi file purely for testing.

$ cat << EOF > ~/sites/davidtsadler.co.uk/public/index.gmi
+# Welcome
+
+Hello world!
+EOF

Install the Gemini Server Binary

I decided to go with agate as the Gemini server as its very simple to install and configure. Installing it was a matter of downloading the binary archive into the bin directory and setting the executable permission on it.

$ cd ~/sites/davidtsadler.co.uk/bin
+
+$ wget https://github.com/mbrubeck/agate/releases/download/v2.3.0/agate.x86_64-unknown-linux-gnu.gz
+
+$ gunzip agate.x86_64-unknown-linux-gnu.gz
+
+$ mv agate.x86_64-unknown-linux-gnu agate
+
+$ chmod u+x agate

I wrote a very simple bash script to run agate and have it serve the site.

$ cat << EOF > ~/sites/davidtsadler.co.uk/scripts/start
+#!/bin/bash
+
+/home/gemini/sites/davidtsadler.co.uk/bin/agate \
+--content /home/gemini/sites/davidtsadler.co.uk/public/ \
+--key /home/gemini/sites/davidtsadler.co.uk/certs/key.rsa \
+--cert /home/gemini/sites/davidtsadler.co.uk/certs/cert.pem \
+--addr [::]:1965 \
+--addr 0.0.0.0:1965 \
+--hostname davidtsadler.co.uk \
+--lang en-GB
+EOF
+
+$ chmod u+x ~/sites/davidtsadler.co.uk/scripts/start

Testing the Site

At this point I have the Gemini server installed and a site available for testing.

I first started agate with the bash script.

$ ~/sites/davidtsadler.co.uk/scripts/start
+
+[2021-02-05T17:26:56Z INFO  agate] Listening on [[::]:1965, 0.0.0.0:1965]...

With agate up and running I pointed my Gemini client to gemini://davidtsadler.co.uk and confirmed I was able to access the site before entering Ctrl-C to halt agate.

Configure Systemd

Since I was happy that agate was able to serve my new site I created a systemd unit to ensure that agate was started whenever the system was rebooted.

$ sudo vim /etc/systemd/system/agate.service

The unit is very simple and just runs the bash script to start agate once the network is available.

[Unit]
+Description=Agate Gemini Server
+After=network.target
+
+[Service]
+Type=simple
+User=gemini
+Group=gemini
+ExecStart=/home/gemini/sites/davidtsadler.co.uk/scripts/start
+
+[Install]
+WantedBy=default.target

I then started this service and confirmed it was working.

$ sudo systemctl start agate.service
+
+$ sudo systemctl status agate.service
+
+Active: active (running)

The final step was to have this service start when the system is rebooted.

$ sudo systemctl enable agate.service

Conclusion

Setting up a Gemini site was easy to do and I hope this guide shows it. I have several ideas about how I'm going to use this new site and I'm excited to see where this leads to.

Links

Gandi.net - My domain registrar of choice.Hetzner - My cloud server provider.Agate - A simple Gemini server.davidtsadler.co.uk - My Gemini site.Gemini - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/gemini/atom.xml b/www/posts/gemini/atom.xml new file mode 100644 index 0000000..79ac301 --- /dev/null +++ b/www/posts/gemini/atom.xml @@ -0,0 +1,74 @@ + + + The Home of David T. Sadler - All Posts About Gemini + https://davidtsadler.com/posts/gemini/atom.xml + + + 2021-02-08T12:00:00Z + + How to Host Your Own Gemini Site in the Cloud + https://davidtsadler.com/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/index.html + + David T. Sadler. + 2021-02-08T12:00:00Z + 2021-02-08T12:00:00Z + ![CDATA[

How to Host Your Own Gemini Site in the Cloud

Mon 8th February 2021 By David T. Sadler.

So I have a Gemini site over at gemini://davidtsadler.co.uk and I thought I'd write up how I achieved this in case anyone was interested in doing the same.

I would say that from purchasing the domain name to having a complete server hosting the site took about 30 minutes in total.

Purchasing a Domain Name

I decided that for the moment I would keep my traditional "Big Web" content hosted at davidtsadler.com and use a different domain name for my new Gemini site. Since this meant purchasing a new one I popped over to Gandi.net to acquire davidtsadler.co.uk. Side note: I used to own this but decided not to renew it for some crazy reason.

Creating a cloud sever

My cloud provider of choice is Hetzner and creating a new server is done in eight steps.

1. Location

Hetzner provide a few locations in Europe as to where the server is hosted. For this server I chose Helsinki.

2. Image

I chose Ubuntu 20.04 as the operating system as this is the one I'm most familiar with.

3. Type

As this server is only going to a host a Gemini site I don't need a overly powerful system so I chose their most basic CX11 configuration. For €2.99 a month this gives me:

  • 1 virtual CPU.
  • 2GB ram.
  • 20GB SSD .
  • 20 TB of network traffic a month.

4. Volume

You have the option of attaching additional storage to the server. I skipped this step as for the time been the 20GB SSD that comes with the server should be enough for my needs.

5. Network.

I skipped this step as its not needed.

6. Additional features

Again I skipped this step but select any if you believe that you will need them.

7. SSH Key

When a server is created a root user is added and a password is emailed to you so that you can login. However if you provide a SSH key it will be installed on the server instead of creating a password.

I like to use separate keys for each server that I manage so I tend store the them in a directory named after the hostname.

$ mkdir ~/.ssh/davidtsadler.co.uk
+
+$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/davidtsadler.co.uk/id_rsa

The SSH key is added by clicking + ADD SSH KEY and then copying and pasting the contents of the id_rsa.pub file.

8. Name

I name my servers after the hostname so for this I called it davidtsadler.co.uk. I then created the server by clicking CREATE & BUY NOW.

SSH

Once the server was created I took the allocated IP address and ensured that I could access it via SSH using the key that I had provided.

$ ssh root@135.181.201.71 -i ~/.ssh/davidtsadler.co.uk/id_rsa

Resolve the Domain Name to the Server

In my Gandi.net account I went to the DNS Records section for the domain name I had purchased. There I deleted everything except for the @ (A) and www (CNAME) records which was configured as follows:

  • @ (A) 135.181.201.71
  • www (CNAME) davidtsadler.co.uk.

The A record is configured with the IPv4 address of my new server and the CNAME with the domain name. Note that the CNAME must end with a period!

After saving the changes it was just a matter of waiting for it to propagate through the DNS system. At which point I could use the domain name when logging in via SSH.

$ ssh root@davidtsadler.co.uk -i ~/.ssh/davidtsadler.co.uk/id_rsa

Securing the Server

At a bare minimum I setup a firewall and harden SSH. I may at a later date go further, such as installing fail2ban.

Configure a Firewall

This setup will deny any incoming requests unless they were first initiated by a request from the server. Since I need to be able to access the server I allow SSH. The Gemini protocol uses port 1965 so that is also allowed.

$ ufw default allow outgoing
+$ ufw default deny incoming
+$ ufw allow OpenSSH
+$ ufw allow 1965
+$ ufw enable

Harden SSH

I edited the /etc/ssh/sshd_config file.

$ vim /etc/ssh/sshd_config

I added the two below options so that the root user is not allowed to access the sever via SSH and other users may only access using keys.

PermitRootLogin no
+PasswordAuthentication no

Since I'd made changes to the configuration I needed to restart the SSH service.

$ service sshd restart

Create non-root User

Whenever I access a server I like to login as a non-root user that is able to run sudo on the system.

$ adduser gemini
+
+$ usermod -aG sudo gemini

As the SSH key is already on the server I can copy it to the non-root user account.

$ rsync --archive --chown=gemini:gemini ~/.ssh /home/gemini

On my local system I confirm that I can log in as the new user without a password.

$ ssh gemini@davidtsadler.co.uk -i ~/.ssh/davidtsadler.co.uk/id_rsa

I also confirm that I have sudo access.

$ sudo ls

Installing a Gemini Site and Server

Directory structure

I decided to go with a very simple directory structure. Each site will be a sub-directory in ~/sites that will be named after the domain name. Then each site will have the following sub-directories. The idea is that I may want to host more than one site in the future.

  • bin This will contain the Gemini server binary.
  • certs TLS certificates for the site are kept here.
  • public This will contain the .gmi files of the site.
  • scripts Contains scripts used to start the Gemini server.

I created the directory structure with the below command.

$ mkdir -p ~/sites/davidtsadler.co.uk/{bin,certs,public,scripts}

Install certificates

Sine the Gemini protocol encourages using a self-signed certificate I installed one with the openssl command.

$ openssl req -x509 \
+-newkey rsa:4096 \
+-keyout ~/sites/davidtsadler.co.uk/certs/key.rsa \
+-out ~/sites/davidtsadler.co.uk/certs/cert.pem \
+-days 3650 \
+-nodes \
+-subj "/CN=davidtsadler.co.uk"

Create Some Test Content

I created a very simple index.gmi file purely for testing.

$ cat << EOF > ~/sites/davidtsadler.co.uk/public/index.gmi
+# Welcome
+
+Hello world!
+EOF

Install the Gemini Server Binary

I decided to go with agate as the Gemini server as its very simple to install and configure. Installing it was a matter of downloading the binary archive into the bin directory and setting the executable permission on it.

$ cd ~/sites/davidtsadler.co.uk/bin
+
+$ wget https://github.com/mbrubeck/agate/releases/download/v2.3.0/agate.x86_64-unknown-linux-gnu.gz
+
+$ gunzip agate.x86_64-unknown-linux-gnu.gz
+
+$ mv agate.x86_64-unknown-linux-gnu agate
+
+$ chmod u+x agate

I wrote a very simple bash script to run agate and have it serve the site.

$ cat << EOF > ~/sites/davidtsadler.co.uk/scripts/start
+#!/bin/bash
+
+/home/gemini/sites/davidtsadler.co.uk/bin/agate \
+--content /home/gemini/sites/davidtsadler.co.uk/public/ \
+--key /home/gemini/sites/davidtsadler.co.uk/certs/key.rsa \
+--cert /home/gemini/sites/davidtsadler.co.uk/certs/cert.pem \
+--addr [::]:1965 \
+--addr 0.0.0.0:1965 \
+--hostname davidtsadler.co.uk \
+--lang en-GB
+EOF
+
+$ chmod u+x ~/sites/davidtsadler.co.uk/scripts/start

Testing the Site

At this point I have the Gemini server installed and a site available for testing.

I first started agate with the bash script.

$ ~/sites/davidtsadler.co.uk/scripts/start
+
+[2021-02-05T17:26:56Z INFO  agate] Listening on [[::]:1965, 0.0.0.0:1965]...

With agate up and running I pointed my Gemini client to gemini://davidtsadler.co.uk and confirmed I was able to access the site before entering Ctrl-C to halt agate.

Configure Systemd

Since I was happy that agate was able to serve my new site I created a systemd unit to ensure that agate was started whenever the system was rebooted.

$ sudo vim /etc/systemd/system/agate.service

The unit is very simple and just runs the bash script to start agate once the network is available.

[Unit]
+Description=Agate Gemini Server
+After=network.target
+
+[Service]
+Type=simple
+User=gemini
+Group=gemini
+ExecStart=/home/gemini/sites/davidtsadler.co.uk/scripts/start
+
+[Install]
+WantedBy=default.target

I then started this service and confirmed it was working.

$ sudo systemctl start agate.service
+
+$ sudo systemctl status agate.service
+
+Active: active (running)

The final step was to have this service start when the system is rebooted.

$ sudo systemctl enable agate.service

Conclusion

Setting up a Gemini site was easy to do and I hope this guide shows it. I have several ideas about how I'm going to use this new site and I'm excited to see where this leads to.

Links

Gandi.net - My domain registrar of choice.Hetzner - My cloud server provider.Agate - A simple Gemini server.davidtsadler.co.uk - My Gemini site.Gemini - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/gemini/index.html b/www/posts/gemini/index.html new file mode 100644 index 0000000..7e4cfe9 --- /dev/null +++ b/www/posts/gemini/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Gemini + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Gemini

2021-02-08 - How to Host Your Own Gemini Site in the CloudThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/index.html b/www/posts/index.html new file mode 100644 index 0000000..669dc92 --- /dev/null +++ b/www/posts/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts

2021-02-15 - Accessing Nextcloud With WebDAV on Arch2021-02-08 - How to Host Your Own Gemini Site in the Cloud2021-01-18 - Installing PHP 8 for Windows 102020-12-21 - Installing Laravel Homestead in Arch Linux2020-12-14 - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed2020-09-07 - Installing Zsh and Powerlevel10k on Arch Linux2020-08-31 - Enabling Audio in Arch Linux2020-08-24 - Pacman Cheat Sheet For Ubuntu Users2020-08-17 - Installing ST, DMENU and DWM in Arch Linux2020-07-13 - Sudo: sorry, you must have a tty to run sudo2020-06-22 - Granting Sudo Access to a User in Arch Linux2020-06-15 - Adding a User in Arch Linux2020-06-08 - Publishing Jigsaw Posts With Netlify Build Hooks2020-06-01 - Scheduling Posts in Jigsaw2020-05-25 - Installing Arch Linux on a Thinkpad X2202020-03-30 - Creating an Ebook With MarkdownThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.html b/www/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.html new file mode 100644 index 0000000..e0f467b --- /dev/null +++ b/www/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.html @@ -0,0 +1,37 @@ + + + + + + Scheduling Posts in Jigsaw + + + + + + + + + + + + + + +

Scheduling Posts in Jigsaw

Mon 1st June 2020 By David T. Sadler.

Jigsaw is a static site generator that I use for my site and one of its features is the ability to create a filter that determines which items in a collection will be included in the final build.

It works by you adding a filter key to a collection's array in your config.php file, and specifying a callable that accepts an item from the collection and that returns a boolean. By returning false an item will not be built.

Below is how I have setup my config.production.php file which is used when building the site for deployment.

<?php
+
+use Carbon\Carbon;
+
+return [
+'collections' => [
+'posts' => [
+'filter' => function ($item) {
+$date = $item->date ? Carbon::createFromFormat('U', $item->date) : null;
+// Only publish posts that have a date and which is not in the future.
+return $date ? $date <= Carbon::now() : false;
+}
+],
+],
+];

When deploying the site each post is passed to this filter. The first thing it does is convert the date that has been specified in the post's YAML front matter into a Carbon instance. It then returns true if the date is on or before the current date, I.e. when the site is been deployed.

With this filter I can specify future dates for several posts and they will only published once that date comes around. Posts are also exluded if a date has not been specified. This allows me to have posts that are a work in progress and shouldn't be published.

Links

Jigsaw - Static Site Generator for PHP Developers.Using Filters in Jigsaw.Carbon - PHP API Extension for DateTime.Jigsaw - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/jigsaw/atom.xml b/www/posts/jigsaw/atom.xml new file mode 100644 index 0000000..1929fae --- /dev/null +++ b/www/posts/jigsaw/atom.xml @@ -0,0 +1,31 @@ + + + The Home of David T. Sadler - All Posts About Jigsaw + https://davidtsadler.com/posts/jigsaw/atom.xml + + + 2020-06-01T12:00:00Z + + Scheduling Posts in Jigsaw + https://davidtsadler.com/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/index.html + + David T. Sadler. + 2020-06-01T12:00:00Z + 2020-06-01T12:00:00Z + ![CDATA[

Scheduling Posts in Jigsaw

Mon 1st June 2020 By David T. Sadler.

Jigsaw is a static site generator that I use for my site and one of its features is the ability to create a filter that determines which items in a collection will be included in the final build.

It works by you adding a filter key to a collection's array in your config.php file, and specifying a callable that accepts an item from the collection and that returns a boolean. By returning false an item will not be built.

Below is how I have setup my config.production.php file which is used when building the site for deployment.

<?php
+
+use Carbon\Carbon;
+
+return [
+'collections' => [
+'posts' => [
+'filter' => function ($item) {
+$date = $item->date ? Carbon::createFromFormat('U', $item->date) : null;
+// Only publish posts that have a date and which is not in the future.
+return $date ? $date <= Carbon::now() : false;
+}
+],
+],
+];

When deploying the site each post is passed to this filter. The first thing it does is convert the date that has been specified in the post's YAML front matter into a Carbon instance. It then returns true if the date is on or before the current date, I.e. when the site is been deployed.

With this filter I can specify future dates for several posts and they will only published once that date comes around. Posts are also exluded if a date has not been specified. This allows me to have posts that are a work in progress and shouldn't be published.

Links

Jigsaw - Static Site Generator for PHP Developers.Using Filters in Jigsaw.Carbon - PHP API Extension for DateTime.Jigsaw - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/jigsaw/index.html b/www/posts/jigsaw/index.html new file mode 100644 index 0000000..e80ae7b --- /dev/null +++ b/www/posts/jigsaw/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Jigsaw + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Jigsaw

2020-06-01 - Scheduling Posts in JigsawThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/index.html b/www/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/index.html new file mode 100644 index 0000000..0cb27d1 --- /dev/null +++ b/www/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/index.html @@ -0,0 +1,42 @@ + + + + + + SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed + + + + + + + + + + + + + + +

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed

Mon 14th December 2020 By David T. Sadler.

One of the first things you do when creating a new Larvel application is run php artisan migrate to create the application database tables. However you may come across the below message.

$ php artisan migrate
+
+Illuminate\Database\QueryException
+
+SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = testsite and table_name = migrations and table_type = 'BASE TABLE')
+
+at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
+674▕         // If an exception occurs when attempting to run a query, we'll format the error
+675▕         // message to include the bindings with SQL, which will make this exception a
+676▕         // lot more helpful to the developer instead of just the database's errors.
+677▕         catch (Exception $e) {
+678▕             throw new QueryException(
+679▕                 $query, $this->prepareBindings($bindings), $e
+680▕             );
+681▕         }
+682▕
+
++33 vendor frames
+34  artisan:37
+Illuminate\Foundation\Console\Kernel::handle()

The cause of this issue is due to a change introduced to the .env.example file. This changed the environment variable DB_HOST from 127.0.0.1 to mysql. The reason for this change is to support [Laravel Sail](https://laravel.com/docs/8.x/sail) which is a Docker development environment for Laravel.

The change means your Laravel application will try and connect to a database server with the hostname of mysql. Unless this exists then the application can't connect.

To resolve the issue just change the value back to 127.0.0.1

DB_HOST=127.0.0.1

Links

Commit that changed .env.example.Laravel SailLaravel - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/index.html b/www/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/index.html new file mode 100644 index 0000000..f85bf66 --- /dev/null +++ b/www/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/index.html @@ -0,0 +1,75 @@ + + + + + + Installing Laravel Homestead in Arch Linux + + + + + + + + + + + + + + +

Installing Laravel Homestead in Arch Linux

Mon 21st December 2020 By David T. Sadler.

Introduction

Laravel Homestead is a pre-packaged Vagrant box that gives you a development environment with PHP, a web server, and several other server software already installed. This guide explains how I install and configure it on my Arch Linux system. I install Homestead in such a way that enables me to add multiple projects to the single instance of Homestead. Because of this you may find that you will need to adapt the guide to how you prefer to manage your projects.

Installing Dependencies

Vagrant will need to be installed since Laravel Homestead is a pre-configured Vagrant box. Select virtualbox if you are prompted for which provider Vagrant should use.

$ sudo pacman -S vagrant

Install Virtualbox as this will be used as a provider by Vagrant. When prompted select the virtualbox-host-modules-arch package.

$ sudo pacman -S virtualbox

Install Homestead

Homestead is installed by cloning the repository onto your host machine.

$ git clone https://github.com/laravel/homestead.git ~/.local/share/homestead

The cloned repository defaults to the latest master branch. As this can be considered unstable it is recommended to checkout a tagged version of Homestead or the release branch as this will always be the latest stable version.

$ cd ~/.local/share/homestead
+
+$ git checkout release

Create the Homestead.yaml file by using the init.sh command.

$ bash init.sh

Configuring the host machine

Before I launch Homestead for the first time there are a few things that I like to do first on the host machine.

Creating a host project

One of the advantages with Homestead is that it allows you to share a directory on your host machine with the virtual guest machine and have that served by the web server.

For this guide the commands below will create a very simple PHP site.

$ mkdir -p ~/projects/testsite/public
+
+$ echo "<?php phpinfo();" > ~/projects/testsite/public/index.php

Setting up SSH

I like to use unique ssh keys for servers that I connect to and that includes any virtual machines running on my local machine. The ssh-keygen command generates a new key that I store in a directory separate from my other ones.

$ mkdir  ~/.ssh/homestead
+
+$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/homestead/id_rsa

Hostname Resolution

Since I am using one instance of Homestead for multiple sites I need to configure the host machine so that requests are directed to the correct site on the virtual machine. This is done by adding an entry into the /etc/hosts file for each site.

First I need to know the IP address of the virtual machine. This can be done by looking in the Homestead.yaml file for the ip entry.

ip: "192.168.10.10"

Then for each site that will be hosted on the virtual machine add it's domain and ip to the /etc/hosts file.

$ sudo nvim /etc/hosts
192.168.10.10 testsite.local

Configuring Homestead

Homestead is configured by editing the Homestead.yaml file that was created with the init.sh command earlier.

$ cd ~/.local/share/homestead
+
+$ nvim Homestead.yaml

First tell Vagrant that Virtualbox will be providing the virtual machine.

set provider: virtualbox

Vagrant needs to setup the ssh keys between the host and the guest so that you can connect via ssh. Enter the path to the one created earlier.

authorize: ~/.ssh/homestead/id_rsa.pub
+
+keys:
+- ~/.ssh/homestead/id_rsa

Share the project folder with the virtual machine. This setting will make the directory /home/vagrant/projects/testsite available in the virtual machine. The contents of this directory will be shared with the host machine directory ~/projects/testsite.

folders:
+- map: ~/projects/testsite
+to: /home/vagrant/projects/testsite

Setup Homestead so that it can serve the application through the 'domain' testsite.local. Note how this matches the name added to /etc/hosts earlier.

sites:
+- map: testsite.local
+to: /home/vagrant/projects/testsite/public

Have Homestead create a database for our application.

databases:
+- testsite

Since I'm using a database ensure that a database server is installed on the virtual machine.

features:
+- mariadb: true

Launching Homestead

Homestead is started with the vagrant up command. It may take a while for Homestead to launch if this is the first time running this command as Vagrant has to first download the actual virtual machine file.

$ cd ~/.local/share/homestead
+
+$ vagrant up

Once the machine is booted I can browse to http://testsite.local/ to see the simple site that is now served by Homestead.

Installing a Laravel Site

Now that Homestead is installed and serving a simple site its time to move onto installing the first Laravel application. Since Homestead provides all the tools required to do this the first thing to do is connect to the virtual machine.

$ cd ~/.local/share/homestead
+
+$ vagrant ssh

Once connected to the virtual machine navigate to the project folder of the site. Remember that this is the folder that is also been shared with the host machine.

$ cd ~/projects/testsite

Clear the contents of this folder otherwise composer will complain about a non-empty directory.

$ rm -rf public

Use composer to install a Laravel project.

$ composer create-project laravel/laravel .

Setting Up The Application Database

Once Larvel is installed a database needs to be created for the application. Connect to the database server with the mysql command.

$ mysql -uhomestead -psecret

Check that the application's database was created when the virtual machine was first booted.

SHOW DATABASES;
+
++--------------------+
+| Database           |
++--------------------+
+| homestead          |
+| information_schema |
+| mysql              |
+| performance_schema |
+| sys                |
+| testsite           |
++--------------------+

If the database does not exist create it with the below SQL.

CREATE DATABASE testsite;

Create a MySQL user for the application and grant permissions to use the application database.

CREATE USER 'testsite'@'localhost' IDENTIFIED BY 'testsite';
+
+GRANT ALL PRIVILEGES ON testsite.* TO 'testsite'@'localhost';

Exit the database server.

exit

To check the new MySql user account simply connect as that user with the credentials used earlier.

$ mysql -utestsite -ptestsite

The result of the SHOW DATABASE sql should show that the user account can see the application database.

SHOW DATABASES;
+
++--------------------+
+| Database           |
++--------------------+
+| information_schema |
+| testsite           |
++--------------------+

Configuring The Laravel Application

Edit the supplied .env file.

$ vim .env

If one does not exist then copy the example file.

$ cp .env.example .env

Change the environment variables to match those below. Some of changes ensure that Laravel can connect to the database created earlier.

APP_NAME='Test Site'
+
+APP_URL=http://testsite.local
+
+DB_CONNECTION=mysql
+DB_HOST=127.0.0.1
+DB_PORT=3306
+DB_DATABASE=testsite
+DB_USERNAME=testsite
+DB_PASSWORD=testsite

Now when you browse to http://testsite.local you will see the Laravel welcome page.

Simplified SSH

I prefer to just use the host system's ssh command to connect to Homestead as it cuts out having to navigate to the Homestead directory and running vagrant ssh.

To simplify ssh I first add a hostname for the virtual machine to the file /etc/hosts/

192.168.10.10 homestead

I then edit ~/.ssh/config and add the below configuration. This tells ssh to automatically use the keys and username specified when connecting to the virtual machine.

Host homestead
+IdentityFile ~/.ssh/homestead/id_rsa
+User vagrant

From now on I can simply do ssh homestead from any directory to connect to the Homestead virtual machine.

Links

Laravel HomesteadLaravel - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/laravel/atom.xml b/www/posts/laravel/atom.xml new file mode 100644 index 0000000..1bc5601 --- /dev/null +++ b/www/posts/laravel/atom.xml @@ -0,0 +1,96 @@ + + + The Home of David T. Sadler - All Posts About Laravel + https://davidtsadler.com/posts/laravel/atom.xml + + + 2020-12-21T12:00:00Z + + Installing Laravel Homestead in Arch Linux + https://davidtsadler.com/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/index.html + + David T. Sadler. + 2020-12-21T12:00:00Z + 2020-12-21T12:00:00Z + ![CDATA[

Installing Laravel Homestead in Arch Linux

Mon 21st December 2020 By David T. Sadler.

Introduction

Laravel Homestead is a pre-packaged Vagrant box that gives you a development environment with PHP, a web server, and several other server software already installed. This guide explains how I install and configure it on my Arch Linux system. I install Homestead in such a way that enables me to add multiple projects to the single instance of Homestead. Because of this you may find that you will need to adapt the guide to how you prefer to manage your projects.

Installing Dependencies

Vagrant will need to be installed since Laravel Homestead is a pre-configured Vagrant box. Select virtualbox if you are prompted for which provider Vagrant should use.

$ sudo pacman -S vagrant

Install Virtualbox as this will be used as a provider by Vagrant. When prompted select the virtualbox-host-modules-arch package.

$ sudo pacman -S virtualbox

Install Homestead

Homestead is installed by cloning the repository onto your host machine.

$ git clone https://github.com/laravel/homestead.git ~/.local/share/homestead

The cloned repository defaults to the latest master branch. As this can be considered unstable it is recommended to checkout a tagged version of Homestead or the release branch as this will always be the latest stable version.

$ cd ~/.local/share/homestead
+
+$ git checkout release

Create the Homestead.yaml file by using the init.sh command.

$ bash init.sh

Configuring the host machine

Before I launch Homestead for the first time there are a few things that I like to do first on the host machine.

Creating a host project

One of the advantages with Homestead is that it allows you to share a directory on your host machine with the virtual guest machine and have that served by the web server.

For this guide the commands below will create a very simple PHP site.

$ mkdir -p ~/projects/testsite/public
+
+$ echo "<?php phpinfo();" > ~/projects/testsite/public/index.php

Setting up SSH

I like to use unique ssh keys for servers that I connect to and that includes any virtual machines running on my local machine. The ssh-keygen command generates a new key that I store in a directory separate from my other ones.

$ mkdir  ~/.ssh/homestead
+
+$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/homestead/id_rsa

Hostname Resolution

Since I am using one instance of Homestead for multiple sites I need to configure the host machine so that requests are directed to the correct site on the virtual machine. This is done by adding an entry into the /etc/hosts file for each site.

First I need to know the IP address of the virtual machine. This can be done by looking in the Homestead.yaml file for the ip entry.

ip: "192.168.10.10"

Then for each site that will be hosted on the virtual machine add it's domain and ip to the /etc/hosts file.

$ sudo nvim /etc/hosts
192.168.10.10 testsite.local

Configuring Homestead

Homestead is configured by editing the Homestead.yaml file that was created with the init.sh command earlier.

$ cd ~/.local/share/homestead
+
+$ nvim Homestead.yaml

First tell Vagrant that Virtualbox will be providing the virtual machine.

set provider: virtualbox

Vagrant needs to setup the ssh keys between the host and the guest so that you can connect via ssh. Enter the path to the one created earlier.

authorize: ~/.ssh/homestead/id_rsa.pub
+
+keys:
+- ~/.ssh/homestead/id_rsa

Share the project folder with the virtual machine. This setting will make the directory /home/vagrant/projects/testsite available in the virtual machine. The contents of this directory will be shared with the host machine directory ~/projects/testsite.

folders:
+- map: ~/projects/testsite
+to: /home/vagrant/projects/testsite

Setup Homestead so that it can serve the application through the 'domain' testsite.local. Note how this matches the name added to /etc/hosts earlier.

sites:
+- map: testsite.local
+to: /home/vagrant/projects/testsite/public

Have Homestead create a database for our application.

databases:
+- testsite

Since I'm using a database ensure that a database server is installed on the virtual machine.

features:
+- mariadb: true

Launching Homestead

Homestead is started with the vagrant up command. It may take a while for Homestead to launch if this is the first time running this command as Vagrant has to first download the actual virtual machine file.

$ cd ~/.local/share/homestead
+
+$ vagrant up

Once the machine is booted I can browse to http://testsite.local/ to see the simple site that is now served by Homestead.

Installing a Laravel Site

Now that Homestead is installed and serving a simple site its time to move onto installing the first Laravel application. Since Homestead provides all the tools required to do this the first thing to do is connect to the virtual machine.

$ cd ~/.local/share/homestead
+
+$ vagrant ssh

Once connected to the virtual machine navigate to the project folder of the site. Remember that this is the folder that is also been shared with the host machine.

$ cd ~/projects/testsite

Clear the contents of this folder otherwise composer will complain about a non-empty directory.

$ rm -rf public

Use composer to install a Laravel project.

$ composer create-project laravel/laravel .

Setting Up The Application Database

Once Larvel is installed a database needs to be created for the application. Connect to the database server with the mysql command.

$ mysql -uhomestead -psecret

Check that the application's database was created when the virtual machine was first booted.

SHOW DATABASES;
+
++--------------------+
+| Database           |
++--------------------+
+| homestead          |
+| information_schema |
+| mysql              |
+| performance_schema |
+| sys                |
+| testsite           |
++--------------------+

If the database does not exist create it with the below SQL.

CREATE DATABASE testsite;

Create a MySQL user for the application and grant permissions to use the application database.

CREATE USER 'testsite'@'localhost' IDENTIFIED BY 'testsite';
+
+GRANT ALL PRIVILEGES ON testsite.* TO 'testsite'@'localhost';

Exit the database server.

exit

To check the new MySql user account simply connect as that user with the credentials used earlier.

$ mysql -utestsite -ptestsite

The result of the SHOW DATABASE sql should show that the user account can see the application database.

SHOW DATABASES;
+
++--------------------+
+| Database           |
++--------------------+
+| information_schema |
+| testsite           |
++--------------------+

Configuring The Laravel Application

Edit the supplied .env file.

$ vim .env

If one does not exist then copy the example file.

$ cp .env.example .env

Change the environment variables to match those below. Some of changes ensure that Laravel can connect to the database created earlier.

APP_NAME='Test Site'
+
+APP_URL=http://testsite.local
+
+DB_CONNECTION=mysql
+DB_HOST=127.0.0.1
+DB_PORT=3306
+DB_DATABASE=testsite
+DB_USERNAME=testsite
+DB_PASSWORD=testsite

Now when you browse to http://testsite.local you will see the Laravel welcome page.

Simplified SSH

I prefer to just use the host system's ssh command to connect to Homestead as it cuts out having to navigate to the Homestead directory and running vagrant ssh.

To simplify ssh I first add a hostname for the virtual machine to the file /etc/hosts/

192.168.10.10 homestead

I then edit ~/.ssh/config and add the below configuration. This tells ssh to automatically use the keys and username specified when connecting to the virtual machine.

Host homestead
+IdentityFile ~/.ssh/homestead/id_rsa
+User vagrant

From now on I can simply do ssh homestead from any directory to connect to the Homestead virtual machine.

Links

Laravel HomesteadLaravel - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+ SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed + https://davidtsadler.com/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/index.html + + David T. Sadler. + 2020-12-14T12:00:00Z + 2020-12-14T12:00:00Z + ![CDATA[

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed

Mon 14th December 2020 By David T. Sadler.

One of the first things you do when creating a new Larvel application is run php artisan migrate to create the application database tables. However you may come across the below message.

$ php artisan migrate
+
+Illuminate\Database\QueryException
+
+SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = testsite and table_name = migrations and table_type = 'BASE TABLE')
+
+at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
+674▕         // If an exception occurs when attempting to run a query, we'll format the error
+675▕         // message to include the bindings with SQL, which will make this exception a
+676▕         // lot more helpful to the developer instead of just the database's errors.
+677▕         catch (Exception $e) {
+678▕             throw new QueryException(
+679▕                 $query, $this->prepareBindings($bindings), $e
+680▕             );
+681▕         }
+682▕
+
++33 vendor frames
+34  artisan:37
+Illuminate\Foundation\Console\Kernel::handle()

The cause of this issue is due to a change introduced to the .env.example file. This changed the environment variable DB_HOST from 127.0.0.1 to mysql. The reason for this change is to support [Laravel Sail](https://laravel.com/docs/8.x/sail) which is a Docker development environment for Laravel.

The change means your Laravel application will try and connect to a database server with the hostname of mysql. Unless this exists then the application can't connect.

To resolve the issue just change the value back to 127.0.0.1

DB_HOST=127.0.0.1

Links

Commit that changed .env.example.Laravel SailLaravel - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/laravel/index.html b/www/posts/laravel/index.html new file mode 100644 index 0000000..a5295c4 --- /dev/null +++ b/www/posts/laravel/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Laravel + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Laravel

2020-12-21 - Installing Laravel Homestead in Arch Linux2020-12-14 - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failedThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.html b/www/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.html new file mode 100644 index 0000000..88f1a78 --- /dev/null +++ b/www/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.html @@ -0,0 +1,24 @@ + + + + + + Sudo: sorry, you must have a tty to run sudo + + + + + + + + + + + + + + +

Sudo: sorry, you must have a tty to run sudo

Mon 13th July 2020 By David T. Sadler.

I have found Deployer to be a great tool for deploying PHP applications. However when first setting out to use it I soon came across the error message 'sudo: sorry, you must have a tty to run sudo'. After some investigation I found that the error was triggered when Deployer was running commands via sudo. For those that don't know Deployer works by executing commands on your servers via ssh and depending on your server's configuration there could be issues when sudo is one of those commands.

What is meant by 'sudo: sorry, you must have a tty to run sudo'?

When sudo is executed the file /etc/sudoers is read to determine which users or groups can use sudo and what commands they can run. It actually does a bit more than that and you should read the manual for more information.

If you examine the sudoers file you will find that it contains the setting Defaults requiretty. This means that sudo can only be ran from a real tty. In other words if a user wants to run sudo they must have logged into a terminal before hand. This is normally a security feature so that sudo can't be ran from things such as cron jobs. However, it also means that you will have issues when running sudo from another machine via ssh as you also won't be logged into an actual terminal.

How to resolve the issue?

If you're happy to change the setting for all users simply use visudo to edit /etc/sudoers and change Defaults requiretty to Defaults !requiretty. Alternatively you can remove the tty requirement for a single user. In fact that is what I do when using Deployer. Since it connects to the server using a user called deployer I add the below configuration with visudo.

Defaults:deployer !requiretty
+deployer ALL=(ALL) NOPASSWD:/usr/bin/chown, /usr/bin/tee, /usr/sbin/apachectl

This configuration allows the deployer user to execute sudo when not logged into a real terminal and additionally not prompt for a password when executing chown, tee, and apachectl.

Using Pseudo-tty

An alternative is to use the pseudo-tty option when connecting via ssh.

$ ssh -t user@example.com sudo apachectl restart

Links

Deployer - A Deployment Tool for PHP.Sudo Manual.Linux - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/linux/atom.xml b/www/posts/linux/atom.xml new file mode 100644 index 0000000..e56ccbb --- /dev/null +++ b/www/posts/linux/atom.xml @@ -0,0 +1,18 @@ + + + The Home of David T. Sadler - All Posts About Linux + https://davidtsadler.com/posts/linux/atom.xml + + + 2020-07-13T12:00:00Z + + Sudo: sorry, you must have a tty to run sudo + https://davidtsadler.com/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.html + + David T. Sadler. + 2020-07-13T12:00:00Z + 2020-07-13T12:00:00Z + ![CDATA[

Sudo: sorry, you must have a tty to run sudo

Mon 13th July 2020 By David T. Sadler.

I have found Deployer to be a great tool for deploying PHP applications. However when first setting out to use it I soon came across the error message 'sudo: sorry, you must have a tty to run sudo'. After some investigation I found that the error was triggered when Deployer was running commands via sudo. For those that don't know Deployer works by executing commands on your servers via ssh and depending on your server's configuration there could be issues when sudo is one of those commands.

What is meant by 'sudo: sorry, you must have a tty to run sudo'?

When sudo is executed the file /etc/sudoers is read to determine which users or groups can use sudo and what commands they can run. It actually does a bit more than that and you should read the manual for more information.

If you examine the sudoers file you will find that it contains the setting Defaults requiretty. This means that sudo can only be ran from a real tty. In other words if a user wants to run sudo they must have logged into a terminal before hand. This is normally a security feature so that sudo can't be ran from things such as cron jobs. However, it also means that you will have issues when running sudo from another machine via ssh as you also won't be logged into an actual terminal.

How to resolve the issue?

If you're happy to change the setting for all users simply use visudo to edit /etc/sudoers and change Defaults requiretty to Defaults !requiretty. Alternatively you can remove the tty requirement for a single user. In fact that is what I do when using Deployer. Since it connects to the server using a user called deployer I add the below configuration with visudo.

Defaults:deployer !requiretty
+deployer ALL=(ALL) NOPASSWD:/usr/bin/chown, /usr/bin/tee, /usr/sbin/apachectl

This configuration allows the deployer user to execute sudo when not logged into a real terminal and additionally not prompt for a password when executing chown, tee, and apachectl.

Using Pseudo-tty

An alternative is to use the pseudo-tty option when connecting via ssh.

$ ssh -t user@example.com sudo apachectl restart

Links

Deployer - A Deployment Tool for PHP.Sudo Manual.Linux - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/linux/index.html b/www/posts/linux/index.html new file mode 100644 index 0000000..42229b7 --- /dev/null +++ b/www/posts/linux/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Linux + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Linux

2020-07-13 - Sudo: sorry, you must have a tty to run sudoThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/index.html b/www/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/index.html new file mode 100644 index 0000000..b60c238 --- /dev/null +++ b/www/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/index.html @@ -0,0 +1,59 @@ + + + + + + Creating an Ebook With Markdown + + + + + + + + + + + + + + +

Creating an Ebook With Markdown

Mon 30th March 2020 By David T. Sadler.

Pandoc is a great tool for converting a file in one markup format into another. This means we can use it to convert a file written in Markdown into an EPUB file that is supported by many e-readers.

Lets start by writting a very simple markdown file called example_ebook.md.

---
+title:
+- type: main
+text: Example Ebook
+- type: subtitle
+text: An Ebook created from a Markdown file
+creator:
+- role: author
+text: David Sadler
+publisher: Published by myself
+---
+
+This is an introduction.
+
+# Chapter 1
+
+This is the first paragraph of chapter 1.
+
+This is the second paragraph of chapter 1.
+
+Below is a list.
+
+- Item One
+- Item Two
+- Item Three
+
+# Chapter 2
+
+This is the first paragraph of chapter 2.
+
+This is the second paragraph of chapter 2.
+
+# Chapter 3
+
+This is the first paragraph of chapter 3.
+
+This is the second paragraph of chapter 3.

Note that the file begins with a YAML metadata block that starts and ends with three hyphens (---). This allows you to specify EPUB metadata such as the title and author.

Converting this to EPUB is done by running pandoc.

$ pandoc example_ebook.md -t epub3 --toc -o example_ebook.epub

There are several options that need to be passed to pandoc.

You can now copy the file example_ebook.epub to any device that supports the format or use one of the many software readers such as Calibre. However, if you wish to read this on a Kindle device you will need to convert it to the Mobi format.

Amazon provides a command line tool called KindleGen that can convert our EPUB file into the Mobi format. After downloading the tool just run it as shown below.

$ kindlegen example_ebook.epub

This will create a file called example_ebook.mobi that you can copy to your Kindle to read.

Links

Pandoc.Markdown.EPUB.YAML metadata block.EPUB metadata.EPUB v3 book.Calibre Application.Mobi Format.KindleGen Application.Markdown - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/markdown/atom.xml b/www/posts/markdown/atom.xml new file mode 100644 index 0000000..280c723 --- /dev/null +++ b/www/posts/markdown/atom.xml @@ -0,0 +1,53 @@ + + + The Home of David T. Sadler - All Posts About Markdown + https://davidtsadler.com/posts/markdown/atom.xml + + + 2020-03-30T12:00:00Z + + Creating an Ebook With Markdown + https://davidtsadler.com/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/index.html + + David T. Sadler. + 2020-03-30T12:00:00Z + 2020-03-30T12:00:00Z + ![CDATA[

Creating an Ebook With Markdown

Mon 30th March 2020 By David T. Sadler.

Pandoc is a great tool for converting a file in one markup format into another. This means we can use it to convert a file written in Markdown into an EPUB file that is supported by many e-readers.

Lets start by writting a very simple markdown file called example_ebook.md.

---
+title:
+- type: main
+text: Example Ebook
+- type: subtitle
+text: An Ebook created from a Markdown file
+creator:
+- role: author
+text: David Sadler
+publisher: Published by myself
+---
+
+This is an introduction.
+
+# Chapter 1
+
+This is the first paragraph of chapter 1.
+
+This is the second paragraph of chapter 1.
+
+Below is a list.
+
+- Item One
+- Item Two
+- Item Three
+
+# Chapter 2
+
+This is the first paragraph of chapter 2.
+
+This is the second paragraph of chapter 2.
+
+# Chapter 3
+
+This is the first paragraph of chapter 3.
+
+This is the second paragraph of chapter 3.

Note that the file begins with a YAML metadata block that starts and ends with three hyphens (---). This allows you to specify EPUB metadata such as the title and author.

Converting this to EPUB is done by running pandoc.

$ pandoc example_ebook.md -t epub3 --toc -o example_ebook.epub

There are several options that need to be passed to pandoc.

  • example_ebook.md - This argument is the file that you are converting.
  • -t epub3 - Set the output format to be EPUB v3 book.
  • --toc - Include a table of contents in the output document. This will be derived from the H1 headers in the markdown.
  • -o example_ebook.epub - Tell pandoc to output the conversion to the named file instead of stdout.

You can now copy the file example_ebook.epub to any device that supports the format or use one of the many software readers such as Calibre. However, if you wish to read this on a Kindle device you will need to convert it to the Mobi format.

Amazon provides a command line tool called KindleGen that can convert our EPUB file into the Mobi format. After downloading the tool just run it as shown below.

$ kindlegen example_ebook.epub

This will create a file called example_ebook.mobi that you can copy to your Kindle to read.

Links

Pandoc.Markdown.EPUB.YAML metadata block.EPUB metadata.EPUB v3 book.Calibre Application.Mobi Format.KindleGen Application.Markdown - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/markdown/index.html b/www/posts/markdown/index.html new file mode 100644 index 0000000..c9ac93b --- /dev/null +++ b/www/posts/markdown/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Markdown + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Markdown

2020-03-30 - Creating an Ebook With MarkdownThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/index.html b/www/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/index.html new file mode 100644 index 0000000..1a128ae --- /dev/null +++ b/www/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/index.html @@ -0,0 +1,23 @@ + + + + + + Publishing Jigsaw Posts With Netlify Build Hooks + + + + + + + + + + + + + + +

Publishing Jigsaw Posts With Netlify Build Hooks

Mon 8th June 2020 By David T. Sadler.

A previous post talks about how I use Jigsaw's filtering to schedule future posts. However because Jigsaw is a static site builder I have to run Jigsaw in order to generate the HTML for the site. So if for example I have scheduled three posts to be published over three consecutive weeks I would need to build and deploy the site on each of the scheduled dates in order for the posts to be published. This kind of defeats the point of scheduling posts. So what I needed was some way to automatically trigger new builds of the site and since I use Netlify to host the site I can make use of their build hooks to do this.

For those that don't know build hooks are URLs you can use to trigger new builds and deployments in Netlify. By making a HTTP POST request to a URL, Netlify will pull down the latest master branch of your site, build it, and then deploy it.

Creating the build hook was simple. After logging into my Netlify account I went to Settings > Build & deploy > Continuous deployment > Build hooks.

From there I clicked Add build hook where I could then provide a name and select which GitHub branch would be used to build the site.

Clicking Save creates the build hook and you are given a unique URL that can be used to trigger it.

What is very handy about Netlify is that they provide you with an example of calling the URL with cURL. With this I simply setup a cron on a server that requests this URL every Monday at 8am.

8 * * 1 curl -X POST -d {} https://api.netlify.com/build_hooks/111111111111111111111111

The result is that every week posts that have been scheduled for that day will now be published when the site is built and deployed by the build hook.

Links

2020-06-01 - Scheduling Posts in JigsawJigsaw - Static Site Generator for PHP Developers.Netlify - Serverless Platform for Static Websites.Build Hooks in Netlify.Netlify - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/netlify/atom.xml b/www/posts/netlify/atom.xml new file mode 100644 index 0000000..b7776ce --- /dev/null +++ b/www/posts/netlify/atom.xml @@ -0,0 +1,17 @@ + + + The Home of David T. Sadler - All Posts About Netlify + https://davidtsadler.com/posts/netlify/atom.xml + + + 2020-06-08T12:00:00Z + + Publishing Jigsaw Posts With Netlify Build Hooks + https://davidtsadler.com/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/index.html + + David T. Sadler. + 2020-06-08T12:00:00Z + 2020-06-08T12:00:00Z + ![CDATA[

Publishing Jigsaw Posts With Netlify Build Hooks

Mon 8th June 2020 By David T. Sadler.

A previous post talks about how I use Jigsaw's filtering to schedule future posts. However because Jigsaw is a static site builder I have to run Jigsaw in order to generate the HTML for the site. So if for example I have scheduled three posts to be published over three consecutive weeks I would need to build and deploy the site on each of the scheduled dates in order for the posts to be published. This kind of defeats the point of scheduling posts. So what I needed was some way to automatically trigger new builds of the site and since I use Netlify to host the site I can make use of their build hooks to do this.

For those that don't know build hooks are URLs you can use to trigger new builds and deployments in Netlify. By making a HTTP POST request to a URL, Netlify will pull down the latest master branch of your site, build it, and then deploy it.

Creating the build hook was simple. After logging into my Netlify account I went to Settings > Build & deploy > Continuous deployment > Build hooks.

From there I clicked Add build hook where I could then provide a name and select which GitHub branch would be used to build the site.

Clicking Save creates the build hook and you are given a unique URL that can be used to trigger it.

What is very handy about Netlify is that they provide you with an example of calling the URL with cURL. With this I simply setup a cron on a server that requests this URL every Monday at 8am.

8 * * 1 curl -X POST -d {} https://api.netlify.com/build_hooks/111111111111111111111111

The result is that every week posts that have been scheduled for that day will now be published when the site is built and deployed by the build hook.

Links

2020-06-01 - Scheduling Posts in JigsawJigsaw - Static Site Generator for PHP Developers.Netlify - Serverless Platform for Static Websites.Build Hooks in Netlify.Netlify - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/netlify/index.html b/www/posts/netlify/index.html new file mode 100644 index 0000000..27add2d --- /dev/null +++ b/www/posts/netlify/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Netlify + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Netlify

2020-06-08 - Publishing Jigsaw Posts With Netlify Build HooksThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/index.html b/www/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/index.html new file mode 100644 index 0000000..203a309 --- /dev/null +++ b/www/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/index.html @@ -0,0 +1,23 @@ + + + + + + Accessing Nextcloud With WebDAV on Arch + + + + + + + + + + + + + + +

Accessing Nextcloud With WebDAV on Arch

Mon 15th February 2021 By David T. Sadler.

I have a Nextcloud instance and I want to mount it as a directory on my local machine. Since Nextcloud cloud supports the WebDAV protocol its possible to do this by installing davfs2 which can mount a WebDAV resource.

The first thing I had to do was install davfs2.

$ sudo pacman -S davfs2

Next I created the directory where Nextcloud would be mounted.

$ mkdir -p .local/share/nextcloud

I then needed to tell Arch how to mount Nextcloud by adding the below line to the /etc/fstab file.

https://my-nextcloud-server.com/path /home/david/.local/share/nextcloud davfs rw,user,uid=david,noauto 0 0

Since access to Nextcloud is controlled by a username and password these where added to the ~/.davfs2 file.

https://my-nextcloud-server.com/path username password

I made sure this file had the correct permissions to ensure security.

$ chmod 600 ~/.davfs2/secrets

Now I can mount Nextcloud and access my files just like any others.

$ mount .local/share/nextcloud
Nextcloud - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/nextcloud/atom.xml b/www/posts/nextcloud/atom.xml new file mode 100644 index 0000000..0c30a53 --- /dev/null +++ b/www/posts/nextcloud/atom.xml @@ -0,0 +1,17 @@ + + + The Home of David T. Sadler - All Posts About Nextcloud + https://davidtsadler.com/posts/nextcloud/atom.xml + + + 2021-02-15T12:00:00Z + + Accessing Nextcloud With WebDAV on Arch + https://davidtsadler.com/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/index.html + + David T. Sadler. + 2021-02-15T12:00:00Z + 2021-02-15T12:00:00Z + ![CDATA[

Accessing Nextcloud With WebDAV on Arch

Mon 15th February 2021 By David T. Sadler.

I have a Nextcloud instance and I want to mount it as a directory on my local machine. Since Nextcloud cloud supports the WebDAV protocol its possible to do this by installing davfs2 which can mount a WebDAV resource.

The first thing I had to do was install davfs2.

$ sudo pacman -S davfs2

Next I created the directory where Nextcloud would be mounted.

$ mkdir -p .local/share/nextcloud

I then needed to tell Arch how to mount Nextcloud by adding the below line to the /etc/fstab file.

https://my-nextcloud-server.com/path /home/david/.local/share/nextcloud davfs rw,user,uid=david,noauto 0 0

Since access to Nextcloud is controlled by a username and password these where added to the ~/.davfs2 file.

https://my-nextcloud-server.com/path username password

I made sure this file had the correct permissions to ensure security.

$ chmod 600 ~/.davfs2/secrets

Now I can mount Nextcloud and access my files just like any others.

$ mount .local/share/nextcloud
Nextcloud - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/nextcloud/index.html b/www/posts/nextcloud/index.html new file mode 100644 index 0000000..f127105 --- /dev/null +++ b/www/posts/nextcloud/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About Nextcloud + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About Nextcloud

2021-02-15 - Accessing Nextcloud With WebDAV on ArchThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/php/2021-01-18/installing-php-8-for-windows-10/index.html b/www/posts/php/2021-01-18/installing-php-8-for-windows-10/index.html new file mode 100644 index 0000000..cc7d147 --- /dev/null +++ b/www/posts/php/2021-01-18/installing-php-8-for-windows-10/index.html @@ -0,0 +1,27 @@ + + + + + + Installing PHP 8 for Windows 10 + + + + + + + + + + + + + + +

Installing PHP 8 for Windows 10

Mon 18th January 2021 By David T. Sadler.

Getting Started

The PHP For Windows site provides pre-built Windows binaries for you to download. Which version you download depends upon two things.

1. Is your system a 64 or 32 bit machine.

2. Are you planning to use IIS or Apache as the web server.

For 64 bit systems the x64 file should be downloaded. If you plan to use IIS then get the Non Thread Safe (NTS) version otherwise use the Thread Safe (TS) version.

The PHP 8 binaries require to have the Visual C++ Redistributable for Visual Studio 2015-2019 be installed as well.

Download and Installation

1. Download the Visual C++ Redistributable for Visual Studio 2015-2019 executable and install it.

2. Download the appropriate PHP 8 Zip archive for your Windows system.

3. Extract the Zip archive into a folder called php in your user folder. This should result in a folder at C:\Users\[username]\php.

Configuring Windows

In order to run the PHP executable from the command line the path to where the Zip archive was extracted to needs to be added to the Windows Path environment variable.

1. Right click on the start menu and select System.

2. Type Control Panel into the search field and select the Control Panel option when it appears.

3. Click System and Security and then the System option.

4. Click Advanced system settings from the left side menu to bring up a dialog box.

5. Select the Advanced tab and then click Environment Variables.

6. Select the Path option from the User variables list and click Edit.

7. Click New and enter the path to where you extracted the Zip archive. This should be C:\Users\[username]\php. You can also click Browse instead and navigate to the folder.

8. Click OK to close the Edit environment variable dialog.

9. Click OK again to close the Environment Variables dialog.

10. Click OK for a third time to close the System Properties dialog.

Checking Installation

Open up either PowerShell or the Command Prompt and enter php -v to verify that PHP was installed correctly. You should see output similar to that shown below.

C:\Users\dev>php -v
+
+PHP 8.0.1 (cli) (built: Jan 5 2021 23:43:33) ( NTS Visual C++ 2019 x64 )
+Copyright (c) The PHP Group
+Zend Engine v4.0.1, Copyright (c) Zend Technologies

Links

PHP For Windows.PHP - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + diff --git a/www/posts/php/atom.xml b/www/posts/php/atom.xml new file mode 100644 index 0000000..d64aca0 --- /dev/null +++ b/www/posts/php/atom.xml @@ -0,0 +1,21 @@ + + + The Home of David T. Sadler - All Posts About PHP + https://davidtsadler.com/posts/php/atom.xml + + + 2021-01-18T12:00:00Z + + Installing PHP 8 for Windows 10 + https://davidtsadler.com/posts/php/2021-01-18/installing-php-8-for-windows-10/index.html + + David T. Sadler. + 2021-01-18T12:00:00Z + 2021-01-18T12:00:00Z + ![CDATA[

Installing PHP 8 for Windows 10

Mon 18th January 2021 By David T. Sadler.

Getting Started

The PHP For Windows site provides pre-built Windows binaries for you to download. Which version you download depends upon two things.

1. Is your system a 64 or 32 bit machine.

2. Are you planning to use IIS or Apache as the web server.

For 64 bit systems the x64 file should be downloaded. If you plan to use IIS then get the Non Thread Safe (NTS) version otherwise use the Thread Safe (TS) version.

The PHP 8 binaries require to have the Visual C++ Redistributable for Visual Studio 2015-2019 be installed as well.

Download and Installation

1. Download the Visual C++ Redistributable for Visual Studio 2015-2019 executable and install it.

2. Download the appropriate PHP 8 Zip archive for your Windows system.

3. Extract the Zip archive into a folder called php in your user folder. This should result in a folder at C:\Users\[username]\php.

Configuring Windows

In order to run the PHP executable from the command line the path to where the Zip archive was extracted to needs to be added to the Windows Path environment variable.

1. Right click on the start menu and select System.

2. Type Control Panel into the search field and select the Control Panel option when it appears.

3. Click System and Security and then the System option.

4. Click Advanced system settings from the left side menu to bring up a dialog box.

5. Select the Advanced tab and then click Environment Variables.

6. Select the Path option from the User variables list and click Edit.

7. Click New and enter the path to where you extracted the Zip archive. This should be C:\Users\[username]\php. You can also click Browse instead and navigate to the folder.

8. Click OK to close the Edit environment variable dialog.

9. Click OK again to close the Environment Variables dialog.

10. Click OK for a third time to close the System Properties dialog.

Checking Installation

Open up either PowerShell or the Command Prompt and enter php -v to verify that PHP was installed correctly. You should see output similar to that shown below.

C:\Users\dev>php -v
+
+PHP 8.0.1 (cli) (built: Jan 5 2021 23:43:33) ( NTS Visual C++ 2019 x64 )
+Copyright (c) The PHP Group
+Zend Engine v4.0.1, Copyright (c) Zend Technologies

Links

PHP For Windows.PHP - Read More Posts.

I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.

Email david@davidtsadler.comThe contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.]]
+
+
\ No newline at end of file diff --git a/www/posts/php/index.html b/www/posts/php/index.html new file mode 100644 index 0000000..bd735c9 --- /dev/null +++ b/www/posts/php/index.html @@ -0,0 +1,23 @@ + + + + + + The Home of David T. Sadler - All Posts About PHP + + + + + + + + + + + + + + +

The Home of David T. Sadler - All Posts About PHP

2021-01-18 - Installing PHP 8 for Windows 10The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Copyright © 2021 David T. Sadler.

Return to Homepage.
+ + -- cgit v1.2.3-13-gbd6f