GNU/Linux documentation

Table of Contents

At the moment i am using Arch Linux and some of the examples will be related to Arch. But in many cases they are generic for all GNU/Linuz dists.

Sorting Unitime codes. Find the uniq ones and then sort them into a file.

cat codes.txt uscodes.txt | sed -n 's@\(^......$\).*@\U\1@g p' |  sort | uniq | tee uscodes.txt

1 Bash

To show all the variables in a shell use env.

To show the options for a shell use echo $SHELLOPTS.

$? Exit code of last application
$$ Process number of the shell
$_ Previous argument
!$ Previous argument
!! Previous command
!?string[?] Most reacent command that contains string
!emacs Last emacs command
!-n n th command back from current command
!<historynr> Run command from history
^oldnew^ Replace old with new in last command
&& If last command was successful, run the next

1.1 Bashrc

Change PS1 color and text

PS1="\[\033[1;31m\][\u@\h \w]$\[\033[0m\] "  # RED
PS1="\[\033[1;32m\][\u@\h \w]$\[\033[0m\] "  # GREEN
PS1="\[\033[1;34m\][\u@\h \w]$\[\033[0m\] "  # BLUE

1.2 Scripting and examples

Arguments to a bash script.

$* All parameters except script name
$# Parameter count - script name
$0 Script name
$1 First argument
${10} 10th argument

In if expressions.

(()) Test for numerical values
[[]] Test for string values

Example: if (( $# < 1 ))

How to debug a bash script:

bash -x <script.sh>

If you wanna have scripts in you home dir, ~/bin. You can add PATH=$PATH:$HOME/bin to ~/.bashrc.

1.2.1 Hello World

Simple Hello World example

#!/bin/bash
echo "Hello World"
exit 0

1.2.2 Input variables

Get stdin and echo it.

#!/bin/bash
echo -e "Enter your name: \c"
read INPUT_NAME
echo "Hello $INPUT_NAME"
exit 0

1.2.3 Script argument

Execute the script with a argument and the argument will be echoed.

#!/bin/bash
echo "Hello $1"
exit 0

1.2.4 Check script argument length

If arguments length is less than 1. Echo usage and exit. Else echo the first argument and exit.

#!/bin/bash
if (( $# < 1 ))  # Here we are checking the length of the arguments.
then
    echo "Usage: $0 <name>"
    exit 1
fi
echo "Hello $1"
exit 0

1.2.5 Case example

Show folders or link in /etc

#!/bin/bash
case $1 in
    "directory")
        find /etc -maxdepth 1 -type d
        ;;
    "link")
        find /etc -maxdepth 1 -type l
        ;;
    *)
        echo "Usage: $0 directory | link"
        ;;
esac
exit 0

1.2.6 Check if argument is a dir

Check if the argument is an argument.

#!/bin/bash
if [[ ! -d $1 ]]  # -d, directory. If $1 is not a dir.
then
    echo "Usage: $0 <dir>"
    exit 1
else
    cd $1 && echo $(pwd)
fi
echo "Done"
exit 0

1.2.7 While loop

#!/bin/bash
COUNT=10
while (( COUNT > 0 ))
do
    echo -e "$COUNT \c"
    sleep 0.1
    (( COUNT -- ))
done

1.2.8 Run script as root

Check if the script is running with root previlegies.

if [ "$(id -u)" != "0" ]; then
    echo ""
    echo " #### ! PLEASE, RUN THIS SCRIPT AS ROOT ! ####"
    echo ""
    exit
fi

2 Applications

2.1 find

find / -name "README.md"
find / -name "*.md"
find / -iname "readme.md"  # Ignore case
find / -name -not "readme.md"  # Not
find / -iname "*.md" ! -iname "readme.md"  # But is not
find / -iname "*.c" -o -name "*.h"  # Or
find . -type f -name "readme.md"  # Only files
find . -type d -name "src"  # Only dirs
find /etc -maxdepth 1 -perm /u=r  # Max depth and perm
find /bin -maxdepth 2 -perm /a=x  # Executable
find . -user bob  # Belongs to user
find / -mtime 50  # Modified 50 days back
find / -atime 50  # Accessed in 50 days back
find /home/bob -cmin -60  # files changed in last N minutes
find / -mmin -60  # modified in last hour
find / -amin -60  # modified in last hour
find / -size 50M  # files of given size
find / -size +100M -exec ls -lha {} \;  # +Size and ls -lha
find / -size +50M -size -100M  # files in a size range

# Run command
find . -type f -name "App*.java" -exec rm "{}" \;
find . -type d -name "target" -exec rm -r "{}" \;

# Delete:
find . -type f -name "*.pyc" -delete

2.1.1 Examples

Write this to /tmp/account.txt.

Rasmus,
Here's the stolen credit card info details that I told you about.
Have fun!
J-Man

1. James Colgan
Card# 6011-0001-0001-0001-0001
CVV: 444
Expiration: 12/14
Telephone: (212) 555-0879
SS# 123-45-6789
Email: something@google.com
IP: 127.0.0.1

2. Francis Bolger
Card# 53690001000100010001
CVV: 444
Expiration: 0113
Telephone: 6095551111
Email: something_else@student.school.org
IP: 192.168.0.1

Search for .txt files thats been access within the 3 last hours inside of /tmp.

find /tmp -name "*.txt" -atime -3 -maxdepth 1

Find email addressed within all .txt files inside of /tmp.

find /tmp -maxdepth 1 -type f -name "*.txt" -exec grep -n '[a-z0-9\.]*@[a-z0-9\.]*' {} \;
find /tmp -maxdepth 1 -type f -name "*.txt" | xargs grep '[a-z0-9\.]*@[a-z0-9\.]*' $1

Find bad login attempts

lastb
lastb | awk  '{print $1}' | sort | uniq
cat /var/log/auth.log | grep 'sshd.*Invalid'
cat /var/log/auth.log | grep 'sshd.*Invalid' | awk -F" " {print $8}
zcat /var/log/auth.log.*.gz | grep 'sshd*Invalid'

2.2 sed

Show only the mathing lines

sed -n "s@/unitime/@/api/@g p" test_api.py

Replace the matches and create a backup file

sed -i.bak "s@/unitime/@/api/@" test_api.py

2.3 lastb

Get bad login attemps

lastb

Get bad login names

lastb | awk  '{print $1}' | sort | uniq

2.4 rsync

-a archive mode
-v verbose
-z compress during transfer
   


3 Who is logged in now

who

4 Nginx

4.1 Find 200/404 requests

awk '$9 == 404 { print $0 } ' nginx-access.log | less
awk '$9 == 200 { print $0 } ' nginx-access.log | less

4.2 Count ip access log

This is a small awk script, name it count_ip_access_log.awk.

BEGIN { FS=" " }
{ ip[$1]++ }
END { for (i in ip)
        print ip[i], i
}

Run the script

awk -f count_ip_access_log.awk /var/log/nginx/access.log
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -k 1
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -k 0
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -k 1,1
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -t
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -k 1 -t ";"
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -k 1 -t ";"
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -t ";"
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -t " "
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -k 1 -f " "
awk -f count_ip_access_log.awk /var/log/nginx/access.log | sort -k 1 -t " "

5 Practical

Find 20 largest dirs.

du -a <path> | sort -n -r | head -n 20

How to find all files containing specific text

grep -rnw '/path/to/somewhere/' -e "pattern"
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

Find all email patterns in my home dir

find / -type f -exec egrep '[a-z0-9\.]*@[a-z0-9\.]*\.[a-z][a-z]+' {} --color 2> /dev/null \;

6 Systemd

6.1 journalctl

journalctl is the logging utility that comes with systemd.

List logs by service

journalctl -u nginx.service

List log entries today and for a specific service

journalctl -u nginx.service --since today

Display kenel messages

journalctl -k

All entries from siece a specific time

journalctl --since "2017-02-03 17:15:00"

Dump

journalctl
journalctl --utc    # Timestamps in UTC
journalctl -b       # Logs since most reacent boot

# When `Storage=persistent` in `/etc/systemd/journald.conf`
# This config saves all of the logfiles Then we can use:
journalctl --list-boots


journalctl --since "2015-01-10 17:15:00"
journalctl --since "2015-01-10" --until "2015-01-11 03:00"
journalctl --since yesterday
journalctl --since 09:00 --until "1 hour ago"

journalctl -u nginx.service
journalctl -u nginx.service --since today

journalctl -u nginx.service -u php-fpm.service --since today

6.2 Timers

List timers: systemctl list=timers.

7 Arch

7.1 Arch AUR

Install from Arch AUR.

git clone https://aur.archlinux.org/package_name.git
cd package_name
less PKGBUILD
less package_name.install
makepkg -si

8 SSH

Generate a new SSH key and copy the pub file to a new host.

ssh-keygen -t rsa -b 4096 -f <FILE> -C <COMMENT>
ssh-copy-id -i ~/.ssh/2016-07-arch.pub <USER>@<HOST>

9 Pacman

Pacman is the standard repo manager in Arch Linux.

S Synchronize packages.
u Upgrades
y Download fresh package database
w Retrieve all packages from the server, but do not install/upgrade anything.
Q Query the package database
i Display info about a given pacakge
   
pacman -Q                 # Search local?
pacman -Qi                # Search local installed
pacman -Si                # Display more info about package
pacman -Ss                # Search repo
pacman -Ql                # To retrieve a list of the files installed by a package

pacman -Qdt               # To list all packages no longer required as dependencies (orphans)
pacman -R package_name    # To remove a single package, leaving all of its dependencies installed
pacman -Rs                # To remove a package and its dependencies which are not required by any other installed package

9.1 Examples

Search for “dead” pacages.

In Arch, find the related executables to a package. Example find-related openssh will list the executables that came with openssh.

function find-related(){
    pacman -Ql $1 | grep '/usr/bin' | awk ' {print $2 } '
}

In Arch, find config files related to a package. Example find-related-config openssh will list the related config files to openssh.

function find-related-config(){
    pacman -Ql $1 | grep '/etc' | awk ' {print } ' | sort | uniq
}

10 Systemd tools

10.1 coredumpctl

coredumpctl
coredumpctl dump 'application' or 'pid'
coredumpctl dump_PID=1758
coredumpctl gdb 1758

10.2 bootctl

bootctl --path=/boot install

10.3 systemd-cgtop

10.4 Systemctl

List services

systemctl --type service

List timers

systemctl list-timers

11 Hardware info

pacman -S lshw
sudo lshw -class network
lshw
lsusb
lspci

cat /proc/cpuinfo
cat /proc/meminfo
df -h
lsmod
uname -a
dmesg

12 Tar

tar -zxvf <tar.gz>

13 User management

13.1 Create new user

13.2 Append user to group

Append the user to a group. the group wil be appended to users supplementary groups.

usermod -a -G <groupName> <userName>    # Append user to group

14 Show kernel modules that are in use

lspci -k

15 DD

Copy iso to a disk

sudo dd bs=512 if=<FILE>.iso of=/dev/sda1 status=progress && sync

Generate random text of 512 bytes

dd if=/dev/urandom bs=512 count=1 | hexdump -C

Investigate the head of a disk

dd if=/dev/sda1 | hexdump -C | head -n20

dd and nc can be used to transfer disk images over the network. This is not encrypted. Read more here ndchost.com

16 GPG

http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/

List keys

gpg --list-keys

Search for user

gpg --keyserver hkp://pgp.mit.edu --search-keys <EMAIL>

Export public key

gpg --export -a "User Name" > public.key

Export private key

gpg --export-secret-key -a "User Name" > private.key

17 Install Arch Linux on Dell XPS 9360

Install instructions for Arch Linux on a Dell XPS 9360

Thanks to: https://gist.github.com/binaerbaum/535884a7f5b8a8697557 for instructions

17.1 Instructions

# Install ARCH Linux with encrypted file-system and UEFI
# The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.

# Download the archiso image from https://www.archlinux.org/
# Copy to a usb-drive
dd if=archlinux.img of=/dev/sdX bs=16M && sync # on linux

# Boot from the usb. If the usb fails to boot, make sure that secure boot is disabled in the BIOS configuration.


# This assumes a wifi only system...
wifi-menu

# Create partitions
gdisk /dev/nvme0n1

# Create EFI partition
mkfs.fat -F32 /dev/nvme0n1p1

mkswap /dev/nvme0n1p2
swapon /dev/nvme0n1p2

# Create filesystems
mkfs.ext4 /dev/nvme0n1p3
mkfs.ext4 /dev/nvme0n1p4

# Create and mount partitions
mount /dev/nvme0n1p3 /mnt
cd !$
mkdir home boot
mount /dev/nvme0n1p4 /mnt/home
mount /dev/nvme0n1p1 /mnt/boot

# Install the system also includes stuff needed for starting wifi when first booting into the newly installed system
# Unless vim and zsh are desired these can be removed from the command. Dialog is needed by wifi-menu
pacstrap /mnt base git emacs sudo efibootmgr networkmanager openssh

# 'install' fstab
genfstab -pU /mnt >> /mnt/etc/fstab

# Enter the new system
arch-chroot /mnt /bin/bash

# Setup system clock
ln -s /usr/share/zoneinfo/Europe/Stockholm /etc/localtime
hwclock --systohc

# Set the hostname
echo arch > /etc/hostname

# Generate locale
#Uncomment wanted locales in /etc/locale.gen
emacs /etc/locale.gen
locale-gen

#To avoid problems with gnome-terminal set locale system wide
#Do NOT set LC_ALL=C. It overrides all the locale vars and messes up special characters
#Pay attention to the UTF-8. Capital letters !
echo LANG=en_US.UTF-8 >> /etc/locale.conf
echo LC_ALL= >> /etc/locale.conf


# Set password for root
passwd

# Add real user remove -s flag if you don't whish to use zsh
useradd -m -g users -G wheel nils
passwd MYUSERNAME


# Regenerate initrd image
mkinitcpio -p linux

# Setup systembootd (grub will not work on nvme at this moment)
bootctl --path=/boot install

# Create loader.conf
echo 'default arch' >> /boot/loader/loader.conf
echo 'timeout 5' >> /boot/loader/loader.conf

# Create arch.conf (or XYZ.conf for default XYZ in loader.conf)
emacs /boot/loader/entries/arch.conf

# Get the UUID
blkid -s PARTUUID -o value /dev/nvme0n1p3

# Add the following content to arch.conf
# <UUID> is the the one of the raw encrypted device (/dev/nvme0n1p2). It can be found with the 'blkid' command
# The UUID should be where / is located.
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=PARTUUID=<UUID> rw

# Exit new system and go into the cd shell
exit

# Unmount all partitions
umount -R /mnt

# Reboot into the new system, don't forget to remove the cd/usb
shutdown -r now


# Wifi connect

# Start and enable NetworkManager at boot.
systemctl start NetworkManager
systemctl enable NetworkManager

# Connect
nmcli radio wifi <on|off>
nmcli device wifi connect <SSID|BSSID> password <password>


# Installing mate

pacman -S xorg
# http://wiki.mate-desktop.org/archlinux_custom_repo
pacman -Syy mate mate-extra
pacman -Syy lightdm lightdm-gtk-greeter accountsservice
systemctl enable lightdm
systemctl enable accounts-daemon
pacman -S network-manager-applet

17.2 Reflector

pacman -S reflector
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
sudo reflector --latest 20 --age 24 --sort rate --save /etc/pacman.d/mirrorlist

18 Install Gentoo on Intel NUC

18.1 Gentoo

18.1.2 Portage

Gentoo’s package manager is called Portage and is written in Python.

emerge

18.1.3 Installation step

1 The user is in a working environment ready to install Gentoo.
2 The Internet connection is ready to install Gentoo.
3 The hard disks are initialized to host the Gentoo installation.
4 The installation environment is prepared and the user is ready to chroot into the new environment.
5 Core packages, which are the same on all Gentoo installations, are installed.
6 The Linux kernel is installed.
7 The user will have configured most of the Gentoo system configuration files.
8 The necessary system tools are installed.
9 The proper boot loader has been installed and configured.
10 The freshly installed Gentoo Linux environment is ready to be explored.
18.1.3.1 install-amd64-minimal-<release>.iso

Files available with the download.

.CONTENTS
listing all files available on the installation CD. This file can be useful to verify if particular firmware or drivers are available on the installation CD before downloading it.
.DIGESTS
contains the hash of the ISO file itself, in various hashing formats/algorithms. This file can be used to verify if the downloaded ISO file is corrupt or not.
.DIGESTS.asc
which not only contains the hash of the ISO file (like the .DIGESTS file), but also a cryptographic signature of that file. This can be used to both verify if the downloaded ISO file is corrupt or not, as well as verify that the download is indeed provided by the Gentoo Release Engineering team and has not been tampered with.

Dowloaded from :

Verify the downloaded iso

cd ~/downloads
curl -O http://mirror.mdfnet.se/gentoo/releases/amd64/autobuilds/20170403/systemd/stage3-amd64-systemd-20170403.tar.bz2
curl -O http://mirror.mdfnet.se/gentoo/releases/amd64/autobuilds/20170302/install-amd64-minimal-20170302.iso.CONTENTS
curl -O http://mirror.mdfnet.se/gentoo/releases/amd64/autobuilds/20170302/install-amd64-minimal-20170302.iso.DIGESTS
curl -O http://mirror.mdfnet.se/gentoo/releases/amd64/autobuilds/20170302/install-amd64-minimal-20170302.iso.DIGESTS.asc
gpg --keyserver hkps.pool.sks-keyservers.net --recv-keys 0xBB572E0E2D182910
gpg --verify install-amd64-minimal-20170302.iso.DIGESTS.asc
sha512sum -c install-amd64-minimal-20170302.iso.DIGESTS.asc
grep -A 1 -i sha512 install-amd64-minimal-20170302.iso.DIGESTS.asc | head -n 2
sha512sum install-amd64-minimal-20170302.iso
dd if=/tmp/install-amd64-minimal-YYYYMMDD.iso of=/dev/sdX bs=8192k && sync

18.2 Applications i wanna have

systemd
NetworkManager
Emacs
rsnapshot
 

18.3 Install note, Intel NUC

18.3.1 Partitioning

18.3.2 Intel NUC Arch Legacy MBR/BIOS

This is how the old paritioning looked like on Arch

Results of lshw.

arch
    description: Desktop Computer
    width: 4294967295 bits
    capabilities: smbios-3.0 dmi-3.0 smp vsyscall32
    configuration: boot=normal chassis=desktop uuid=31F1F621-D3C1-A98B-EBD1-B8AEED7C3BF0
  *-core
       description: Motherboard
       product: NUC6i5SYB
       vendor: Intel corporation
       physical id: 0
       version: H81131-502
       serial: GESY54800QGS
       slot: Default string
     *-firmware
          description: BIOS
          vendor: Intel Corp.
          physical id: 0
          version: SYSKLi35.86A.0042.2016.0409.1246
          date: 04/09/2016
          size: 64KiB
          capacity: 6080KiB
          capabilities: pci upgrade shadowing cdboot bootselect socketedrom edd int13floppy1200 int13floppy720 int13floppy2880 int5printscreen int14serial int17printer acpi usb biosbootspecification uefi
     *-cache:0
          description: L1 cache
          physical id: 22
          slot: L1 Cache
          size: 64KiB
          capacity: 64KiB
          capabilities: synchronous internal write-back data
          configuration: level=1
     *-cache:1
          description: L1 cache
          physical id: 23
          slot: L1 Cache
          size: 64KiB
          capacity: 64KiB
          capabilities: synchronous internal write-back instruction
          configuration: level=1
     *-cache:2
          description: L2 cache
          physical id: 24
          slot: L2 Cache
          size: 512KiB
          capacity: 512KiB
          capabilities: synchronous internal write-back unified
          configuration: level=2
     *-cache:3
          description: L3 cache
          physical id: 25
          slot: L3 Cache
          size: 4MiB
          capacity: 4MiB
          capabilities: synchronous internal write-back unified
          configuration: level=3
     *-cpu
          description: CPU
          product: Intel(R) Core(TM) i5-6260U CPU @ 1.80GHz
          vendor: Intel Corp.
          physical id: 26
          bus info: cpu@0
          version: Intel(R) Core(TM) i5-6260U CPU @ 1.80GHz
          serial: To Be Filled By O.E.M.
          slot: CPU1
          size: 2898MHz
          capacity: 2900MHz
          width: 64 bits
          clock: 100MHz
          capabilities: x86-64 fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp cpufreq
          configuration: cores=2 enabledcores=2 threads=4
     *-memory
          description: System Memory
          physical id: 27
          slot: System board or motherboard
          size: 16GiB
        *-bank:0
             description: SODIMM DDR4 Synchronous 2133 MHz (0.5 ns)
             product: CMSO16GX4M2A2133C15
             vendor: AMI
             physical id: 0
             serial: 00000000
             slot: ChannelA-DIMM0
             size: 8GiB
             width: 64 bits
             clock: 2133MHz (0.5ns)
        *-bank:1
             description: SODIMM DDR4 Synchronous 2133 MHz (0.5 ns)
             product: CMSO16GX4M2A2133C15
             vendor: AMI
             physical id: 1
             serial: 00000000
             slot: ChannelB-DIMM0
             size: 8GiB
             width: 64 bits
             clock: 2133MHz (0.5ns)
     *-pci
          description: Host bridge
          product: Skylake Host Bridge/DRAM Registers
          vendor: Intel Corporation
          physical id: 100
          bus info: pci@0000:00:00.0
          version: 09
          width: 32 bits
          clock: 33MHz
          configuration: driver=skl_uncore
          resources: irq:0
        *-display
             description: VGA compatible controller
             product: Iris Graphics 540
             vendor: Intel Corporation
             physical id: 2
             bus info: pci@0000:00:02.0
             version: 0a
             width: 64 bits
             clock: 33MHz
             capabilities: pciexpress msi pm vga_controller bus_master cap_list rom
             configuration: driver=i915 latency=0
             resources: irq:279 memory:de000000-deffffff memory:c0000000-cfffffff ioport:f000(size=64) memory:c0000-dffff
        *-usb
             description: USB controller
             product: Sunrise Point-LP USB 3.0 xHCI Controller
             vendor: Intel Corporation
             physical id: 14
             bus info: pci@0000:00:14.0
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi xhci bus_master cap_list
             configuration: driver=xhci_hcd latency=0
             resources: irq:274 memory:df130000-df13ffff
           *-usbhost:0
                product: xHCI Host Controller
                vendor: Linux 4.9.11-1-ARCH xhci-hcd
                physical id: 0
                bus info: usb@1
                logical name: usb1
                version: 4.09
                capabilities: usb-2.00
                configuration: driver=hub slots=12 speed=480Mbit/s
              *-usb:0
                   description: Mass storage device
                   product: Patriot Memory
                   physical id: 1
                   bus info: usb@1:1
                   version: 1.00
                   serial: 070B3695DB05D916
                   capabilities: usb-2.00 scsi
                   configuration: driver=usb-storage maxpower=200mA speed=480Mbit/s
              *-usb:1
                   description: USB hub
                   product: TUSB8041 4-Port Hub
                   vendor: Texas Instruments, Inc.
                   physical id: 4
                   bus info: usb@1:4
                   version: 1.00
                   serial: DB0A1089F8CE
                   capabilities: usb-2.10
                   configuration: driver=hub slots=4 speed=480Mbit/s
                 *-usb:0
                      description: Mouse
                      product: Microsoft 5-Button Mouse with IntelliEye(TM)
                      vendor: Microsoft
                      physical id: 2
                      bus info: usb@1:4.2
                      version: 3.00
                      capabilities: usb-1.10
                      configuration: driver=usbhid maxpower=100mA speed=2Mbit/s
                 *-usb:1
                      description: USB hub
                      product: Keyboard Hub
                      vendor: Apple Inc.
                      physical id: 3
                      bus info: usb@1:4.3
                      version: 96.15
                      serial: 000000000000
                      capabilities: usb-2.00
                      configuration: driver=hub maxpower=300mA slots=3 speed=480Mbit/s
                    *-usb
                         description: Keyboard
                         product: Apple Keyboard
                         vendor: Apple Inc.
                         physical id: 2
                         bus info: usb@1:4.3.2
                         version: 0.70
                         capabilities: usb-2.00
                         configuration: driver=usbhid maxpower=20mA speed=2Mbit/s
                 *-usb:2
                      description: USB hub
                      product: TUSB8041 4-Port Hub
                      vendor: Texas Instruments, Inc.
                      physical id: 4
                      bus info: usb@1:4.4
                      version: 1.00
                      serial: AB0A1079F8CE
                      capabilities: usb-2.10
                      configuration: driver=hub slots=2 speed=480Mbit/s
           *-usbhost:1
                product: xHCI Host Controller
                vendor: Linux 4.9.11-1-ARCH xhci-hcd
                physical id: 1
                bus info: usb@2
                logical name: usb2
                version: 4.09
                capabilities: usb-3.00
                configuration: driver=hub slots=6 speed=5000Mbit/s
              *-usb
                   description: USB hub
                   product: TUSB8041 4-Port Hub
                   vendor: Texas Instruments, Inc.
                   physical id: 4
                   bus info: usb@2:4
                   version: 1.00
                   capabilities: usb-3.00
                   configuration: driver=hub slots=4 speed=5000Mbit/s
                 *-usb
                      description: USB hub
                      product: TUSB8041 4-Port Hub
                      vendor: Texas Instruments, Inc.
                      physical id: 4
                      bus info: usb@2:4.4
                      version: 1.00
                      capabilities: usb-3.00
                      configuration: driver=hub slots=2 speed=5000Mbit/s
        *-generic:0
             description: Signal processing controller
             product: Sunrise Point-LP Thermal subsystem
             vendor: Intel Corporation
             physical id: 14.2
             bus info: pci@0000:00:14.2
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi bus_master cap_list
             configuration: driver=intel_pch_thermal latency=0
             resources: irq:18 memory:df150000-df150fff
        *-communication
             description: Communication controller
             product: Sunrise Point-LP CSME HECI #1
             vendor: Intel Corporation
             physical id: 16
             bus info: pci@0000:00:16.0
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi bus_master cap_list
             configuration: driver=mei_me latency=0
             resources: irq:276 memory:df14f000-df14ffff
        *-storage
             description: SATA controller
             product: Sunrise Point-LP SATA Controller [AHCI mode]
             vendor: Intel Corporation
             physical id: 17
             bus info: pci@0000:00:17.0
             version: 21
             width: 32 bits
             clock: 66MHz
             capabilities: storage msi pm ahci_1.0 bus_master cap_list
             configuration: driver=ahci latency=0
             resources: irq:275 memory:df148000-df149fff memory:df14e000-df14e0ff ioport:f090(size=8) ioport:f080(size=4) ioport:f060(size=32) memory:df14d000-df14d7ff
        *-pci
             description: PCI bridge
             product: Sunrise Point-LP PCI Express Root Port #5
             vendor: Intel Corporation
             physical id: 1c
             bus info: pci@0000:00:1c.0
             version: f1
             width: 32 bits
             clock: 33MHz
             capabilities: pci pciexpress msi pm normal_decode bus_master cap_list
             configuration: driver=pcieport
             resources: irq:16 memory:df000000-df0fffff
           *-network
                description: Wireless interface
                product: Wireless 8260
                vendor: Intel Corporation
                physical id: 0
                bus info: pci@0000:01:00.0
                logical name: wlp1s0
                version: 3a
                serial: a4:34:d9:2c:27:6b
                width: 64 bits
                clock: 33MHz
                capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
                configuration: broadcast=yes driver=iwlwifi driverversion=4.9.11-1-ARCH firmware=22.391740.0 ip=192.168.1.229 latency=0 link=yes multicast=yes wireless=IEEE 802.11
                resources: irq:278 memory:df000000-df001fff
        *-generic:1
             description: Signal processing controller
             product: Sunrise Point-LP Serial IO UART Controller #0
             vendor: Intel Corporation
             physical id: 1e
             bus info: pci@0000:00:1e.0
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm bus_master cap_list
             configuration: driver=intel-lpss latency=0
             resources: irq:20 memory:df14c000-df14cfff
        *-generic:2
             description: SD Host controller
             product: Sunrise Point-LP Secure Digital IO Controller
             vendor: Intel Corporation
             physical id: 1e.6
             bus info: pci@0000:00:1e.6
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm bus_master cap_list
             configuration: driver=sdhci-pci latency=0
             resources: irq:23 memory:df14b000-df14bfff
        *-isa
             description: ISA bridge
             product: Sunrise Point-LP LPC Controller
             vendor: Intel Corporation
             physical id: 1f
             bus info: pci@0000:00:1f.0
             version: 21
             width: 32 bits
             clock: 33MHz
             capabilities: isa bus_master
             configuration: latency=0
        *-memory
             description: Memory controller
             product: Sunrise Point-LP PMC
             vendor: Intel Corporation
             physical id: 1f.2
             bus info: pci@0000:00:1f.2
             version: 21
             width: 32 bits
             clock: 33MHz (30.3ns)
             capabilities: bus_master
             configuration: driver=intel_pmc_core latency=0
             resources: irq:0 memory:df144000-df147fff
        *-multimedia
             description: Audio device
             product: Sunrise Point-LP HD Audio
             vendor: Intel Corporation
             physical id: 1f.3
             bus info: pci@0000:00:1f.3
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi bus_master cap_list
             configuration: driver=snd_hda_intel latency=32
             resources: irq:280 memory:df140000-df143fff memory:df120000-df12ffff
        *-serial
             description: SMBus
             product: Sunrise Point-LP SMBus
             vendor: Intel Corporation
             physical id: 1f.4
             bus info: pci@0000:00:1f.4
             version: 21
             width: 64 bits
             clock: 33MHz
             configuration: driver=i801_smbus latency=0
             resources: irq:16 memory:df14a000-df14a0ff ioport:f040(size=32)
        *-network
             description: Ethernet interface
             product: Ethernet Connection I219-V
             vendor: Intel Corporation
             physical id: 1f.6
             bus info: pci@0000:00:1f.6
             logical name: eno1
             version: 21
             serial: b8:ae:ed:7c:3b:f0
             capacity: 1Gbit/s
             width: 32 bits
             clock: 33MHz
             capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
             configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=3.2.6-k firmware=0.13-4 latency=0 link=no multicast=yes port=twisted pair
             resources: irq:277 memory:df100000-df11ffff
  *-scsi
       physical id: 1
       bus info: scsi@3
       logical name: scsi3
       capabilities: scsi-host
       configuration: driver=usb-storage
  *-network:0
       description: Ethernet interface
       physical id: 2
       logical name: docker0
       serial: 02:42:09:af:9a:91
       capabilities: ethernet physical
       configuration: broadcast=yes driver=bridge driverversion=2.3 firmware=N/A ip=172.17.0.1 link=no multicast=yes
  *-network:1
       description: Ethernet interface
       physical id: 3
       logical name: br-c49048a1344a
       serial: 02:42:11:8f:9b:ac
       capabilities: ethernet physical
       configuration: broadcast=yes driver=bridge driverversion=2.3 firmware=N/A ip=172.18.0.1 link=no multicast=yes

Results of fdisk -l

Disk /dev/sda: 232.9 GiB, 250059350016 bytes, 488397168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa78b9688

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1            2048  97658879  97656832  46.6G 83 Linux
/dev/sda2        97658880 105471999   7813120   3.7G 82 Linux swap / Solaris
/dev/sda3       105472000 488397167 382925168 182.6G 83 Linux

18.3.3 Dell XPS 9360 Arch, GPT/UEFI

Results of lshw

arch
    description: Laptop
    product: XPS 13 9360 (075B)
    vendor: Dell Inc.
    serial: 253Z9G2
    width: 4294967295 bits
    capabilities: smbios-3.0 dmi-3.0 smp vsyscall32
    configuration: boot=normal chassis=laptop family=XPS sku=075B uuid=44454C4C-3500-1033-805A-B2C04F394732
  *-core
       description: Motherboard
       product: 0839Y6
       vendor: Dell Inc.
       physical id: 0
       version: A00
       serial: /253Z9G2/CN129636AG0201/
     *-firmware
          description: BIOS
          vendor: Dell Inc.
          physical id: 0
          version: 1.0.7
          date: 09/13/2016
          size: 64KiB
          capacity: 15MiB
          capabilities: pci pnp upgrade shadowing cdboot bootselect edd int13floppynec int13floppy1200 int13floppy720 int13floppy2880 int5printscreen int9keyboard int14serial int17printer acpi usb smartbattery biosbootspecification netboot uefi
     *-memory
          description: System Memory
          physical id: 35
          slot: System board or motherboard
          size: 16GiB
        *-bank:0
             description: Row of chips LPDDR3 Synchronous 1867 MHz (0.5 ns)
             product: H9CCNNNCLTMLAR-NUD
             vendor: SK Hynix
             physical id: 0
             serial: 00000000
             slot: System Board Memory
             size: 8GiB
             width: 64 bits
             clock: 1867MHz (0.5ns)
        *-bank:1
             description: Row of chips LPDDR3 Synchronous 1867 MHz (0.5 ns)
             product: H9CCNNNCLTMLAR-NUD
             vendor: SK Hynix
             physical id: 1
             serial: 00000000
             slot: System Board Memory
             size: 8GiB
             width: 64 bits
             clock: 1867MHz (0.5ns)
     *-cache:0
          description: L1 cache
          physical id: 39
          slot: L1 Cache
          size: 128KiB
          capacity: 128KiB
          capabilities: synchronous internal write-back unified
          configuration: level=1
     *-cache:1
          description: L2 cache
          physical id: 3a
          slot: L2 Cache
          size: 512KiB
          capacity: 512KiB
          capabilities: synchronous internal write-back unified
          configuration: level=2
     *-cache:2
          description: L3 cache
          physical id: 3b
          slot: L3 Cache
          size: 4MiB
          capacity: 4MiB
          capabilities: synchronous internal write-back unified
          configuration: level=3
     *-cpu
          description: CPU
          product: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
          vendor: Intel Corp.
          physical id: 3c
          bus info: cpu@0
          version: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
          serial: To Be Filled By O.E.M.
          slot: U3E1
          size: 3500MHz
          width: 64 bits
          clock: 100MHz
          capabilities: x86-64 fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp cpufreq
          configuration: cores=2 enabledcores=2 threads=4
     *-pci
          description: Host bridge
          product: Intel Corporation
          vendor: Intel Corporation
          physical id: 100
          bus info: pci@0000:00:00.0
          version: 02
          width: 32 bits
          clock: 33MHz
        *-display
             description: VGA compatible controller
             product: Intel Corporation
             vendor: Intel Corporation
             physical id: 2
             bus info: pci@0000:00:02.0
             version: 02
             width: 64 bits
             clock: 33MHz
             capabilities: pciexpress msi pm vga_controller bus_master cap_list rom
             configuration: driver=i915 latency=0
             resources: irq:282 memory:db000000-dbffffff memory:90000000-9fffffff ioport:f000(size=64) memory:c0000-dffff
        *-generic:0
             description: Signal processing controller
             product: Skylake Processor Thermal Subsystem
             vendor: Intel Corporation
             physical id: 4
             bus info: pci@0000:00:04.0
             version: 02
             width: 64 bits
             clock: 33MHz
             capabilities: msi pm cap_list
             configuration: driver=proc_thermal latency=0
             resources: irq:16 memory:dc420000-dc427fff
        *-usb
             description: USB controller
             product: Sunrise Point-LP USB 3.0 xHCI Controller
             vendor: Intel Corporation
             physical id: 14
             bus info: pci@0000:00:14.0
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi xhci bus_master cap_list
             configuration: driver=xhci_hcd latency=0
             resources: irq:276 memory:dc410000-dc41ffff
           *-usbhost:0
                product: xHCI Host Controller
                vendor: Linux 4.9.11-1-ARCH xhci-hcd
                physical id: 0
                bus info: usb@1
                logical name: usb1
                version: 4.09
                capabilities: usb-2.00
                configuration: driver=hub slots=12 speed=480Mbit/s
              *-usb
                   description: Bluetooth wireless interface
                   vendor: Qualcomm Atheros Communications
                   physical id: 3
                   bus info: usb@1:3
                   version: 0.01
                   capabilities: bluetooth usb-2.01
                   configuration: driver=btusb maxpower=100mA speed=12Mbit/s
           *-usbhost:1
                product: xHCI Host Controller
                vendor: Linux 4.9.11-1-ARCH xhci-hcd
                physical id: 1
                bus info: usb@2
                logical name: usb2
                version: 4.09
                capabilities: usb-3.00
                configuration: driver=hub slots=6 speed=5000Mbit/s
        *-generic:1
             description: Signal processing controller
             product: Sunrise Point-LP Thermal subsystem
             vendor: Intel Corporation
             physical id: 14.2
             bus info: pci@0000:00:14.2
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi cap_list
             configuration: driver=intel_pch_thermal latency=0
             resources: irq:18 memory:dc434000-dc434fff
        *-generic:2
             description: Signal processing controller
             product: Sunrise Point-LP Serial IO I2C Controller #0
             vendor: Intel Corporation
             physical id: 15
             bus info: pci@0000:00:15.0
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm bus_master cap_list
             configuration: driver=intel-lpss latency=0
             resources: irq:16 memory:dc433000-dc433fff
        *-generic:3
             description: Signal processing controller
             product: Sunrise Point-LP Serial IO I2C Controller #1
             vendor: Intel Corporation
             physical id: 15.1
             bus info: pci@0000:00:15.1
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm bus_master cap_list
             configuration: driver=intel-lpss latency=0
             resources: irq:17 memory:dc432000-dc432fff
        *-communication
             description: Communication controller
             product: Sunrise Point-LP CSME HECI #1
             vendor: Intel Corporation
             physical id: 16
             bus info: pci@0000:00:16.0
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi bus_master cap_list
             configuration: driver=mei_me latency=0
             resources: irq:280 memory:dc431000-dc431fff
        *-pci:0
             description: PCI bridge
             product: Intel Corporation
             vendor: Intel Corporation
             physical id: 1c
             bus info: pci@0000:00:1c.0
             version: f1
             width: 32 bits
             clock: 33MHz
             capabilities: pci pciexpress msi pm normal_decode bus_master cap_list
             configuration: driver=pcieport
             resources: irq:16 ioport:2000(size=4096) memory:c4000000-da0fffff ioport:a0000000(size=570425344)
        *-pci:1
             description: PCI bridge
             product: Sunrise Point-LP PCI Express Root Port #5
             vendor: Intel Corporation
             physical id: 1c.4
             bus info: pci@0000:00:1c.4
             version: f1
             width: 32 bits
             clock: 33MHz
             capabilities: pci pciexpress msi pm normal_decode bus_master cap_list
             configuration: driver=pcieport
             resources: irq:16 memory:dc000000-dc1fffff
           *-network
                description: Wireless interface
                product: QCA6174 802.11ac Wireless Network Adapter
                vendor: Qualcomm Atheros
                physical id: 0
                bus info: pci@0000:3a:00.0
                logical name: wlp58s0
                version: 32
                serial: 9c:b6:d0:17:68:55
                width: 64 bits
                clock: 33MHz
                capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
                configuration: broadcast=yes driver=ath10k_pci driverversion=4.9.11-1-ARCH firmware=WLAN.RM.2.0-00180-QCARMSWPZ-1 ip=192.168.1.10 latency=0 link=yes multicast=yes wireless=IEEE 802.11
                resources: irq:281 memory:dc000000-dc1fffff
        *-pci:2
             description: PCI bridge
             product: Sunrise Point-LP PCI Express Root Port #6
             vendor: Intel Corporation
             physical id: 1c.5
             bus info: pci@0000:00:1c.5
             version: f1
             width: 32 bits
             clock: 33MHz
             capabilities: pci pciexpress msi pm normal_decode bus_master cap_list
             configuration: driver=pcieport
             resources: irq:17 memory:dc300000-dc3fffff
           *-generic
                description: Unassigned class
                product: RTS525A PCI Express Card Reader
                vendor: Realtek Semiconductor Co., Ltd.
                physical id: 0
                bus info: pci@0000:3b:00.0
                version: 01
                width: 32 bits
                clock: 33MHz
                capabilities: pm msi pciexpress bus_master cap_list
                configuration: driver=rtsx_pci latency=0
                resources: irq:274 memory:dc300000-dc300fff
        *-pci:3
             description: PCI bridge
             product: Sunrise Point-LP PCI Express Root Port #9
             vendor: Intel Corporation
             physical id: 1d
             bus info: pci@0000:00:1d.0
             version: f1
             width: 32 bits
             clock: 33MHz
             capabilities: pci pciexpress msi pm normal_decode bus_master cap_list
             configuration: driver=pcieport
             resources: irq:16 memory:dc200000-dc2fffff
           *-storage
                description: Non-Volatile memory controller
                product: Toshiba America Info Systems
                vendor: Toshiba America Info Systems
                physical id: 0
                bus info: pci@0000:3c:00.0
                version: 01
                width: 64 bits
                clock: 33MHz
                capabilities: storage pm msi pciexpress msix nvm_express bus_master cap_list
                configuration: driver=nvme latency=0
                resources: irq:16 memory:dc200000-dc203fff
        *-isa
             description: ISA bridge
             product: Intel Corporation
             vendor: Intel Corporation
             physical id: 1f
             bus info: pci@0000:00:1f.0
             version: 21
             width: 32 bits
             clock: 33MHz
             capabilities: isa bus_master
             configuration: latency=0
        *-memory UNCLAIMED
             description: Memory controller
             product: Sunrise Point-LP PMC
             vendor: Intel Corporation
             physical id: 1f.2
             bus info: pci@0000:00:1f.2
             version: 21
             width: 32 bits
             clock: 33MHz (30.3ns)
             configuration: latency=0
             resources: memory:dc42c000-dc42ffff
        *-multimedia
             description: Audio device
             product: Intel Corporation
             vendor: Intel Corporation
             physical id: 1f.3
             bus info: pci@0000:00:1f.3
             version: 21
             width: 64 bits
             clock: 33MHz
             capabilities: pm msi bus_master cap_list
             configuration: driver=snd_hda_intel latency=32
             resources: irq:283 memory:dc428000-dc42bfff memory:dc400000-dc40ffff
        *-serial
             description: SMBus
             product: Sunrise Point-LP SMBus
             vendor: Intel Corporation
             physical id: 1f.4
             bus info: pci@0000:00:1f.4
             version: 21
             width: 64 bits
             clock: 33MHz
             configuration: driver=i801_smbus latency=0
             resources: irq:16 memory:dc430000-dc4300ff ioport:f040(size=32)
  *-battery
       product: DELL TP1GT61
       vendor: SMP
       physical id: 1
       version: 10/12/2016
       serial: 04E6
       slot: Sys. Battery Bay
       capacity: 59990mWh
       configuration: voltage=7.6V
  *-network
       description: Ethernet interface
       physical id: 2
       logical name: docker0
       serial: 02:42:dc:c5:14:28
       capabilities: ethernet physical
       configuration: broadcast=yes driver=bridge driverversion=2.3 firmware=N/A ip=172.17.0.1 link=no multicast=yes

Results of fdisk -l

Disk /dev/nvme0n1: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 4030120E-0E61-42FF-B84F-39B078DE42A0

Device             Start        End   Sectors   Size Type
/dev/nvme0n1p1      2048    1026047   1024000   500M EFI System
/dev/nvme0n1p2   1026048   34580479  33554432    16G Linux swap
/dev/nvme0n1p3  34580480  139438079 104857600    50G Linux filesystem
/dev/nvme0n1p4 139438080 1000215182 860777103 410.5G Linux home

Results of cat /etc/fstab

#
# /etc/fstab: static file system information
#
# <file system> <dir>   <type>  <options>       <dump>  <pass>
# /dev/nvme0n1p3
UUID=5a8e21d0-e7a2-4541-88c1-0dd8b6a06f1d       /               ext4            rw,relatime,data=ordered        0 1

# /dev/nvme0n1p4
UUID=e93c7469-b458-40f6-8aa3-7d5e4f363f5d       /home           ext4            rw,relatime,data=ordered        0 2

# /dev/nvme0n1p1
UUID=E234-BF95          /boot           vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro    0 2

# /dev/nvme0n1p2
UUID=d00ebe21-1a90-4cc6-b309-cf7793ffacfe       none            swap            defaults        0 0

# Intenso 2TB
# UUID=a3c930e1-c549-4755-9afd-609396225988       /media/backup   ext4            defaults,nofail,x-systemd.device-timeout=1      0       2
# nas:/backup-dell-arch                             /media/backup   nfs4          ,rsize=8192,wsize=8192,timeo=14,intr        0       0
nas:/backup-dell-arch   /media/backup  nfs          noauto,x-systemd.automount,x-systemd.device-timeout=10,timeo=14,x-systemd.idle-timeout=1min 0 0

18.3.4 Intel NUC Gentoo, GPT/UEFI !FIRST ATTEMPT!

THIS IS THE FIRST ATTEMPT

18.3.4.1 Preparing the environment

When booting screen appers

boot: gentoo

If you wanna change keyboard layout do it. But default is US.

passwd root
ifconfig
net-setup wlp1s0  # Brings up a cursor wizard
ping -c 3 scanme.nmap.org

Configure and start ssh, fipple with the /etc/ssh/sshd_config file to get ssh working.

/etc/init.d/sshd start
#service sshd start

C-a ? to get help.

18.3.4.2 Preparing the disks
gdisk /dev/sda

The new partitioning scheme looks like this.

Disk /dev/sda: 488397168 sectors, 232.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): EFA262F6-5A57-42B2-BBE1-3C2F6C45234D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 488397134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   EF00  EFI System
   2         1026048        17803263   8.0 GiB     8200  Linux swap
   3        17803264       122660863   50.0 GiB    8300  Linux filesystem
   4       122660864       488397134   174.4 GiB   8302  Linux /home

Create file system for EFI partition, /dev/sda1

mkfs.fat -F 32 /dev/sda1

Create swap

mkswap /dev/sda2
swapon /dev/sda2

Create ext4 file systems on the over ones.

mkfs.ext4 /dev/sda3
mkfs.ext4 /dev/sda4

Verify the paritions with

parted /dev/sda -l
fdisk /dev/sda

dump

livecd ~ # mkswap /dev/sda2
Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
no label, UUID=143ad2e0-cf3d-4d3e-be2f-2a5155cd28ca
livecd ~ # swapon /dev/sda2
livecd ~ # free -h
              total        used        free      shared  buff/cache   available
Mem:            15G         64M         15G         64M        288M         15G
Swap:          8.0G          0B        8.0G
livecd ~ # mkfs.ext4 /dev/sda3
mke2fs 1.43.3 (04-Sep-2016)
Discarding device blocks: done
Creating filesystem with 13107200 4k blocks and 3276800 inodes
Filesystem UUID: 4ff96d18-4463-41bb-9fe0-77b9c16f2fc1
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done

livecd ~ # mkfs.ext4 /dev/sda4
mke2fs 1.43.3 (04-Sep-2016)
Discarding device blocks: done
Creating filesystem with 45717033 4k blocks and 11436032 inodes
Filesystem UUID: 75731e7a-9e43-4b99-a0e3-d23d4cb19eb9
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

livecd ~ # fdisk /dev/sda -l
Disk /dev/sda: 232.9 GiB, 250059350016 bytes, 488397168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: EB2437FC-B1B0-45EF-80F1-98C0F933C496

Device         Start       End   Sectors   Size Type
/dev/sda1       2048   1026047   1024000   500M EFI System
/dev/sda2    1026048  17803263  16777216     8G Linux swap
/dev/sda3   17803264 122660863 104857600    50G Linux filesystem
/dev/sda4  122660864 488397134 365736271 174.4G Linux home
livecd ~ #

Mount the /root parition

mount /dev/sda3 /mnt/gentoo
18.3.4.3 Installing the Gentoo installation files

If date is not correct. Set it with

ntpd -q -g

Go into the mounted dir

cd /mnt/gentoo

Download the stage file

curl -O http://mirror.mdfnet.se/gentoo/releases/amd64/autobuilds/20170403/systemd/stage3-amd64-systemd-20170403.tar.bz2
tar xvjpf stage3-*.tar.bz2 --xattrs --numeric-owner

Edit /mnt/gentoo/etc/portage/make.conf

Append this to the file: It’s a big o, not a 0.

VIDEO_CARDS="intel i965"
CFLAGS="-march=native -O2 -pipe"
MAKEOPTS="-j3"
CXXFLAGS="${CFLAGS}"
18.3.4.4 Installing the Gentoo base system

Select mirrors

mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

Create folder for portage files

mkdir /mnt/gentoo/etc/portage/repos.conf/

Copy gentoo.conf to the new directory

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

Copy DNS info to the new system

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

Mount the needed file systems

mount -t proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev

Enter the new environment.

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

Mount the boot partition

mount /dev/sda1 /boot

Mount /home

mount /dev/sda4 /home

Update portage libs

emerge-webrsync
emerge --sync

Update portage itself

emerge --ask --verbose --oneshot portage

TODO: Learn more about eselect , man news.eselect

List available profiles

eselect profile list

Select default/linux/amd64/13.0/systemd

eselect profile set default/linux/amd64/13.0/systemd

Update the @world set. !I needed to run this twice to work!

emerge --ask --update --deep --newuse @world

Look at the USE flags set

emerge --info | grep ^USE

TODO: Learn what the USE variables are

less /usr/portage/profiles/use.desc

Install Emacs. This may be an older version, i will update this later.

emerge --ask app-editors/emacs

Configure locale

emacs /etc/locale.gen

Add this ones.

en_US.UTF-8 UTF-8
sv_SE.UTF-8 UTF-8
sv_SE ISO-8859-1

Generate locale’s

locale-gen

Verify

locale -a

Set system wide

eselect locale list

Set enUS.utf8

eselect locale set en_US.utf8

Edit the file

emacs /etc/env.d/02locale

Make sure this is there.

LANG="en_US.utf8"
LC_COLLATE="C"

Reload environment

env-update && source /etc/profile && export PS1="(chroot) $PS1"

Download the kernel

emerge --ask sys-kernel/gentoo-sources

Create Machine ID

systemd-machine-id-setup

Check that the kernel is there

ls -l /usr/src/linux

/etc/mtab

ln -sf /proc/self/mounts /etc/mtab

Remove uneeded kernel tool.

emerge --ask --unmerge sys-kernel/genkernel

Install dracut

emerge --ask sys-kernel/dracut

Install genkernel-next

emerge --ask sys-kernel/genkernel-next

Edit /etc/genkernel.conf

emacs /etc/genkernel.conf

Change

# Use udev instead of mdev as the default device manager for the initramfs.
# If systemd and perhaps lvm is used, then this _must_ be turned on.
UDEV="yes"
  1. fstab

    Geet UUIDs from the /boot partition

    blkid
    

    Example

    UUID=22ED-14BE                             /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro      0  2
    UUID=f54c8ffa-cbf8-496e-a473-277b67253f9b  none  swap defaults                                                                                                  0  0
    UUID=22a12142-d9c2-4900-b715-9540cc38b509  /     ext4 rw,relatime,data=ordered                                                                                  0  1
    UUID=8cfae628-d041-4149-845a-1cc8b43d000a  /home ext4 rw,relatime,data=ordered                                                                                  0  2
    
  2. Generate kernal?

    Install additional firmware.

    emerge --ask sys-kernel/linux-firmware
    

    Compile kernel

    genkernel --install all
    
18.3.4.5 Configure the system

Get the UUID from the disks

blkid

Update /etc/fstab

emacs /etc/fstab

Example

UUID=8c523ff3-efe2-4be3-9642-42856a512387       /               ext4            rw,relatime,data=ordered                                                                                0 1
UUID=3F31-27AA                                  /boot           vfat            rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro    0 2
UUID=a3e4ed90-b053-4ee7-845b-489d58029225       /home           ext4            rw,relatime,data=ordered                                                                                0 2
UUID=96cc4b6c-bdd1-42e0-96cd-6c6ceb50f31f       none            swap            defaults                                                                                                0 0

Create a machine ID for journaling to work, manual

systemd-machine-id-setup

Set hostname

echo nils-gentoo > /etc/hostname

Set password for root

passwd
18.3.4.6 Installing system tools

Install euses

emerge --ask app-portage/euses

Update USE flags

emacs /etc/portage/make.conf

Append to USE variable.

emacs dbus networkmanager policykit

According to Polkit, source

Update /etc/genkernel.conf

emacs /etc/genkernel.conf

Append the following, source

CONFIG_FUTEX="yes"

Update @world

emerge --ask --changed-use --deep @world

Install dhcp

emerge --ask net-misc/dhcp

Install NetworkManager and wpasupplicant

emerge --ask net-misc/networkmanager net-wireless/wpa_supplicant
18.3.4.7 Configuring the bootloader

Install efibootmgr

emerge --ask sys-boot/efibootmgr
genkernel --install initramfs

This is how it looks on my Arch install ! HOW TO GET THE initramfs WORKING?!

.:
total 31760
drwxr-xr-x  4 root root     4096 Jan  1  1970 .
drwxr-xr-x 18 root root     4096 Feb 23 10:11 ..
drwxr-xr-x  4 root root     4096 Nov  1 19:36 EFI
-rwxr-xr-x  1 root root 21865248 Feb 23 09:05 initramfs-linux-fallback.img
-rwxr-xr-x  1 root root  5769899 Feb 23 09:05 initramfs-linux.img
drwxr-xr-x  3 root root     4096 Nov  1 21:13 loader
-rwxr-xr-x  1 root root  4863776 Feb 19 14:49 vmlinuz-linux

./EFI:
total 16
drwxr-xr-x 4 root root 4096 Nov  1 19:36 .
drwxr-xr-x 4 root root 4096 Jan  1  1970 ..
drwxr-xr-x 2 root root 4096 Nov  1 19:36 BOOT
drwxr-xr-x 2 root root 4096 Nov  1 19:36 systemd

./EFI/BOOT:
total 88
drwxr-xr-x 2 root root  4096 Nov  1 19:36 .
drwxr-xr-x 4 root root  4096 Nov  1 19:36 ..
-rwxr-xr-x 1 root root 80171 Oct  7 19:38 BOOTX64.EFI

./EFI/systemd:
total 88
drwxr-xr-x 2 root root  4096 Nov  1 19:36 .
drwxr-xr-x 4 root root  4096 Nov  1 19:36 ..
-rwxr-xr-x 1 root root 80171 Oct  7 19:38 systemd-bootx64.efi

./loader:
total 16
drwxr-xr-x 3 root root 4096 Nov  1 21:13 .
drwxr-xr-x 4 root root 4096 Jan  1  1970 ..
drwxr-xr-x 2 root root 4096 Nov  1 21:12 entries
-rwxr-xr-x 1 root root   23 Nov  1 19:36 loader.conf

./loader/entries:
total 12
drwxr-xr-x 2 root root 4096 Nov  1 21:12 .
drwxr-xr-x 3 root root 4096 Nov  1 21:13 ..
-rwxr-xr-x 1 root root  172 Nov  1 19:38 arch.conf
18.3.4.8 Dumps

Look into bootctl https://www.freedesktop.org/software/systemd/man/bootctl.html#


https://dracut.wiki.kernel.org/index.php/Main_Page http://caesar.acc.umu.se/pub/debian-meetings/2010/fosdem10/high/Dracut_a_generic_modular_initramfs_generation_tool.ogv


ln -s /usr/share/zoneinfo/Europe/Stockholm /etc/localtime

Set hostname

echo gentoo > /etc/hostname

Install esearch

emerge --ask app-portage/esearch

Update some db

eupdatedb

<2017-03-05 Sun 18:31> https://wiki.gentoo.org/wiki/Dracut Generates initramfs.

Install dracut

emerge --ask sys-kernel/dracut

Rebuild the kernel agan?

emerge --ask sys-kernel/genkernel-next

Create kernel

genkernel --install all

Installing firmware

emerge --ask sys-kernel/linux-firmware

18.3.5 Intel NUC Gentoo, GPT/UEFI !SECOND ATTEMPT!

18.3.5.1 Setup the installation environment

When booting screen appers, boot into the correct environment

boot: gentoo

Now you can change keyboard layout. But default is US.

passwd root
ifconfig
net-setup wlp1s0  # Brings up a cursor wizard
ping -c 3 scanme.nmap.org

Start SSH to be able to login remotly

/etc/init.d/sshd start
18.3.5.2 Preparing the disks
gdisk /dev/sda

The new partitioning scheme looks like this.

Disk /dev/sda: 488397168 sectors, 232.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): EFA262F6-5A57-42B2-BBE1-3C2F6C45234D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 488397134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   EF00  EFI System
   2         1026048        17803263   8.0 GiB     8200  Linux swap
   3        17803264       122660863   50.0 GiB    8300  Linux filesystem
   4       122660864       488397134   174.4 GiB   8302  Linux /home

Results for fdisk -l

Disk /dev/sda: 232.9 GiB, 250059350016 bytes, 488397168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: EB2437FC-B1B0-45EF-80F1-98C0F933C496

Device         Start       End   Sectors   Size Type
/dev/sda1       2048   1026047   1024000   500M EFI System
/dev/sda2    1026048  17803263  16777216     8G Linux swap
/dev/sda3   17803264 122660863 104857600    50G Linux filesystem
/dev/sda4  122660864 488397134 365736271 174.4G Linux home

Create file system for EFI partition, /dev/sda1

mkfs.fat -F 32 /dev/sda1

Create swap

mkswap /dev/sda2
swapon /dev/sda2

Create ext4 file systems on the over ones.

mkfs.ext4 /dev/sda3
mkfs.ext4 /dev/sda4

Verify the paritions with

parted /dev/sda -l
fdisk /dev/sda -l

Mount the /root parition

mount /dev/sda3 /mnt/gentoo
18.3.5.3 Installing the Gentoo installation files

If date is not correct. Set it with

ntpd -q -g

Go into the mounted dir

cd /mnt/gentoo

Download the stage file

curl -O http://mirror.mdfnet.se/gentoo/releases/amd64/autobuilds/20170403/systemd/stage3-amd64-systemd-20170403.tar.bz2

Unpacking the stage tarball

tar xvjpf stage3-*.tar.bz2 --xattrs --numeric-owner

Edit /mnt/gentoo/etc/portage/make.conf

Append this to the file: It’s a big o, not a 0.

VIDEO_CARDS="intel i965"
CFLAGS="-march=native -O2 -pipe"
MAKEOPTS="-j3"
18.3.5.4 Installing the Gentoo base system

Select mirrors

mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

Create portage config folder

mkdir /mnt/gentoo/etc/portage/repos.conf

Copy config file to new folder

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

Copy DNS info

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

Mounting the necessary filesystems

mount -t proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev

Entering the new environment

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

Mounting the boot partition

mkdir /boot
mount /dev/sda2 /boot
  1. Configuring Portage

    Installing a ebuild repository snapshot from the web

    emerge-webrsync
    

    Updating the Gentoo ebuild repository

    emerge --sync
    

    Check that the right profile is set.

    eselect profile list
    

    Update world

    emerge --ask --update --deep --newuse @world
    
  2. Configuring machine id
    systemd-machine-id-setup
    
  3. Configuring hostname
    hostnamectl set-hostname nils-gentoo
    
  4. Configuring timezone
    
    

19 SSH Script

This script will iterate over all of the host in ~/.ssh/config.

for i in $(cat ~/.ssh/config | awk -F: 'match($1,/^Host/){print $1}' | awk -F" " '{print $2}')
do
    ssh -q -oBatchMode=yes $i exit
    if [ $? -eq 0 ]
    then
        echo "$i worked"
        # generate a new key
        # add the new pub key to the server
        # remove old stuff
    else
        echo "$i failed"
    fi
done

MYFILE=/tmp/myservers-$(mktemp).txt

cat blabla >> $MYFILE

while read line; do ssh $line echo “hallo” done < $MYFILE

### display date date

### check for superuser privileges if $(id -un) != root ; then echo “error: need superuser privileges. are you root?” exit fi

### trap

function cleanuptemp { ### umount tc container printf “\nSignal received… Unmounting truecrypt container…\n” sudo -u andersch /media/uberbacku-tc

### umount sshfs sleep 1 printf “\nSignal received… Unmounting sshfs…\n” umount /media/uberbacku

rm -rf $MYTEMPFOLDER/*

exit 1 } trap cleanuptemp SIGHUP SIGINT SIGPIPE SIGTERM

cleanuptemp()

20 Docker

docker ps
docker ps -a

docker attach

docker pull python:3.6

20.0.1 run

-d Run container in background and print container ID
-i Interactive
-t Get a TTY

21 Regular Expressions

21.1 email

'[a-z0-9\.]*@[a-z0-9\.]*\.[a-z][a-z][a-z]+'

Example:

Hey, this may be
some kind of somemail@gmail.com
and i would like to send this to
reciever@somemail.se
egrep '[a-z0-9\.]*@[a-z0-9\.]*\.[a-z][a-z]+' /tmp/re_email.txt --color

21.2 IP address

'[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'
Hey, this may be
some kind 192.168.255.255 of somemail@gmail.com
and i would like 127.0.0.1 to send this to
reciever@somemail.se

Find IP address and print only the match and color it. If -o is left out, it will print the line where it found it.

egrep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' /tmp/re_ip.txt --color -o

21.3 Card nr’s

'[[:digit:]]\{4\}-[[:digit:]]\{4\}-[[:digit:]]\{4\}-[[:digit:]]\{4\}'
Hey, this may be
some kind 4444 5555 6666 7777 192.168.255.255 of somemail@gmail.com
and i would like 127.0.0.1 to send this to
0000-1111-2222-3333
reciever@somemail.se

Example 1

grep '[[:digit:]]\{4\}-[[:digit:]]\{4\}-[[:digit:]]\{4\}-[[:digit:]]\{4\}' /tmp/re_bank1.txt --color -o

Example 2

grep '[[:digit:]]\{4\}.\?[[:digit:]]\{4\}.\?[[:digit:]]\{4\}.\?[[:digit:]]\{4\}' /tmp/re_bank1.txt -o --color

22 WiFi

Show WiFi signal data.

watch -n 1 cat /proc/net/wireless

23 Theory

23.1 udev

23.2 paging

23.3 dbus

23.4 initramfs

Is an initial ram file system based on tmpfs. It contains the tools and scripts needed to mount the file systems before the init binary on the real root file system is called. These tools can be decryption abstraction layers (for encrypted file systems), logical volume managers, software raid, bluetooth driver based file system loaders, etc,

The content of the initramfs is made by creating a cpio archive. cpio is an old (but proven) file archiver solution (and its resulting archive files are called cpio files). cpio is definitely comparable to the tar archiver. The choice of cpio here was because it was easier to implement (code-wise) and supported (back then) device files which tar could not.

The content of the initramfs is made by creating a cpio archive. cpio is an old (but proven) file archiver solution (and its resulting archive files are called cpio files). cpio is definitely comparable to the tar archiver. The choice of cpio here was because it was easier to implement (code-wise) and supported (back then) device files which tar could not. source.

24 Dumps

grep -i '[0-9A-F]\{2\}\(:[0-9A-F]\{2\}\)\{5\}' dump_klockan_11_14-01.csv | awk -F" " '{ print $1 }' | sort | uniq | sed 's/,$//'
grep -i '[0-9A-F]\{2\}\(:[0-9A-F]\{2\}\)\{5\}' dump_klockan_11_14-01.csv | awk -F" " '{ print $1 }' | sort | uniq | wc -l
pacman -Ql python | grep '/usr/bin' | awk ' {print } '
pacman -Ql openssh | grep '/etc' | awk ' {print } ' | sort | uniq


FILES=$(pacman -Ql $(pacman -Qo $(whereis ssh) 2> /dev/null) 2> /dev/null | grep '/bin' | sort | uniq | awk ' {print $2} ')

for f in $FILES; do
        if [ -f $f ]; then
                echo $f
        fi
done

Here are a commands dump that need to be sorted out later on.

openssl s_client -connect google.se:443

Author: John Herrlin

Created: 2017-04-18 Tue 18:06

Emacs 25.1.1 (Org mode 8.2.10)

Validate