How to Quickly Create an Encrypted USB Drive on KDE Plasma

Need to create an encrypted USB drive? Are your running KDE Plasma?

Then great! Here are 6 simple steps on how to quickly and painlessly create an encrypted USB drive with KDE Partition Manager.

Let’s start

a. Start by inserting your USB drive

b. Now launch KDE Parition Manager and type your password

c. Select the USB drive and right click to delete the existing partition

⚠️ WARNING: remember, this will delete all your existing files)

d. Right click to create a new partition

e. Select your “File system” type, check “Encrypt with LUKS”, set the “Password” and “Label” and click on “Ok”

f. Click on apply and you are done. Go grab a coffee because you worked really hard you deserve it

Mounting the Drive

The mounting process should be as painless as setting up the USB drive.

a. Insert the USB drive and click on “Mount” under “Disk & Device” on your system tray

b. Type in your very secure password (mine is “password123”) and profit

Tip: You can set it to remember if you really trust your own machine

How to Install Waveshare 3.5" LCD on Ubuntu 20.04

Linux Hardware Raspberry Pi

Following the steps of an older post (Installing Kuman 3), I find myself trying to configure the same Waveshare 3.5” LCD touch screen on my Raspberry Pi 3B, but now with Ubuntu 20.04 64.bit.

As usual the LCDs from Waveshare are not that easy to configure. While researching online I could not find any working instructions on how to configure the screen with Ubuntu 20.04. I found a few Git repos (Wavesahre and LCD Wiki), but they all failed to get me with a working config.

After spending a lot of time I was able to get it to work using some of the files and instructions from Waveshare’s official Git Repo (as well as LCD Wiki).

If you want to save yourself sometime, just use my Ansible repo to get your RPI3B configured. Otherwise, the manual instructions are bellow.

GitHub: waveshare35-rpi3b-ubuntu-20.04-64

Instructions

a. Download Ubuntu 20.04 64-bit for RPI3 and setup your SD card

https://ubuntu.com/download/raspberry-pi

Make sure to check the downloaded file

b. Power the Pi on, login (SSH or HDMI), change the password and update

# apt-get update apt-get upgrade

c. Install Xubuntu and evdev

Note: you could just install X instead of Xubuntu and there’s a chance the instructions will work

# apt-get install xubuntu-desktop xserver-xorg-input-evdev

d. Backup the files we are going to modify

We are not modifying config.txt, but we are backing it up just in case

# cd /boot/firmware

# cp cmdline.txt cmdline.txt.orig
# cp usercfg.txt usercfg.txt.orig
# cp config.txt config.txt.orig

e. Add the following lines to /boot/firmware/usercfg.txt

dtparam=i2c_arm=on
dtparam=audio=on
dtparam=spi=on
enable_uart=1
dtoverlay=waveshare35a
hdmi_drive=2
disable_overscan=1

f. Make changes to /boot/firmware/cmdline.txt

  • Modify
    • console=ttyAMA0,115200
  • Add
    • fbcon=map:10
    • fbcon=font:ProFont6x11
net.ifnames=0 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc fbcon=map:10 fbcon=font:ProFont6x11

g. Create the directory /etc/X11/xorg.conf.d

# mkdir -p /etc/X11/xorg.conf.d

h. Create the file /etc/X11/xorg.conf.d/99-calibration.conf

Section "InputClass"
    Identifier "calibration"
    MatchProduct "ADS7846 Touchscreen"
    Option "Calibration" "3932 300 294 3801"
    Option "SwapAxes" "1"
    Option "EmulateThirdButton" "1"
    Option "EmulateThirdButtonTimeout" "750"
    Option "EmulateThirdButtonMoveThreshold" "30"
EndSection

i. Create the file /usr/share/X11/xorg.conf.d/99-fbturbo.conf

Section "Device"
    Identifier "Allwinner A10/A13 FBDEV"
    Driver "fbturbo"
    Option "fbdev" "/dev/fb2"

    Option "SwapbuffersWait" "true"
EndSection

j. Copy 10-evdev.conf to 45-evdev.conf

# cd /usr/share/X11/xorg.conf.d/
# cp 10-evdev.conf 45-evdev.conf

k. Clone https://github.com/waveshare/LCD-show.git

# mkdir /root/Git
# cd /roo/Git

# git clone https://github.com/waveshare/LCD-show.git

# cd LCD-show

l. Copy waveshare35a-overlay.dtb to /boot/firmware/overlays as both waveshare35a-overlay.dtb and waveshare35a-overlay.dtbo

# cp waveshare35a-overlay.dtb /boot/firmware/overlays/waveshare35a-overlay.dtb
# cp waveshare35a-overlay.dtb /boot/firmware/overlays/waveshare35a-overlay.dtbo

m. Reboot and enjoy

How to Show Progress for dd

Bash Linux Hardware Storage

If you have reached this page I expect that you already know what dd is. But you if you don’t, dd is a command-line utility that is used to convert and copy files. It’s commonly found on various (Linux) distro help pages that show new users how to setup USB (or Micro SD) drives to install or run (like Raspberry Pi) the OS.

One of the main problems is that when running the dd utility, it does not provide any information on the current status of the copy process. This can make users anxious not knowing if it’s done or not.

The Solutions

1. Running dd with the status option

This requires you to be running dd version 8.24 and above. If you are running a modern Linux distro you are most likely covered.

You can check your version with dd --version:

➤ dd --version
dd (coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Rubin, David MacKenzie, and Stuart Kemp.

We will also need to use oflag=sync to make sure that we are really syncing as data is being copied so we get a better sense of when it’s done. Otherwise dd goes blank at the end as it’s trying to sync.

Note: while using oflag=sync makes the copy slower, using a higher block size will help speed up the process (bs=4M instead of bs=1M)

The command:

Structure:

dd bs=4M if=/path/to/input of=/path/to/output status=progress oflag=sync

Example: here are backing up the contents of /dev/sdf to a file (ubuntu-server-20.04.1-updated.iso)

sudo dd bs=4M if=/dev/sdf of=ubuntu-server-20.04.1-updated.iso status=progress oflag=sync

The output:

1. Running dd with pv

In reality this should be option 1 as it gives a nicer output with a progress bar, ETA and other data. pv is a terminal-based tool for monitoring the progress of data through a pipeline. It can potentially be used with any pipe.

The command:

Structure:

pv -tpreb /path/to/input | sudo dd of=/path/to/output bs=4M oflag=sync

Options used:

  • -t - “Turn the timer on”
  • -p - “Turn the progress bar on”
  • -r - “Turn the rate counter on”
  • -e - “Turn the ETA timer on”
  • -b - “Turn the total byte counter on”

Example: Here we are copying the image file to /dev/sdf

pv -tpreb ubuntu-20.04.1-preinstalled-server-arm64+raspi.img | sudo dd of=/dev/sdf bs=4M oflag=sync

The output:


Putting all in a Bash alias for re-use

Add the function below to your ~/.bash_aliases and it will be available whenever you need. Call it with dd_iso [image] [device] and it will use pv if it’s already installed in your syste.

dd_iso ()
{
    usage="usage: dd_iso [image] [device]";
    if [[ $# -lt 2 ]]; then
        echo "$usage";
        return 0;
    else
        if [[ $# -eq 2 ]]; then
            iso="$1";
            device="$2";
        fi;
    fi;
    if [[ ${iso##*.} != iso && ${iso##*.} != img ]]; then
        echo "The first parameter should be an iso";
        return 1;
    else
        if [[ ! -b "$device" ]]; then
            echo "The second parameter needs to be a device";
            return 1;
        fi;
    fi;
    device_type="$(basename "$(readlink -f "/sys/class/block/${device##*/}/..")")";
    if [[ "$device_type" != "block" ]]; then
        echo "Do not specify a parition as the device";
        return 1;
    fi;
    sudo dd bs=4M if="$iso" of="$device" status=progress oflag=sync
}

Quick Guide to SUID, SGID and Sticky Bit

Linux

This is a quick guide on how to configure and use SGID, SUID and the sticky bit on Linux. I will not get into a lot of details, but I will add comments and notes that might help you understand or overcome a few common issues.

SUID - Set-user Identification

When a command or script with SUID bit set is run, its effective UID becomes that of the owner of the file, rather than of the user who is running it.

-rws-----

Note: SUID does not work on scripts that start with a shebang (#!)

# chmod u+s [file]
-rwsr--r--. 1 root root 0 Mar 16 21:48 test

# chmod 4744 [file]
-rwsr--r--. 1 root root 0 Mar 16 21:48 test

Note: A capital ’S’ (-rwSr–r–) indicates that the execute bit is not set

SGID - Set-group identification

SGID permission is similar to the SUID permission. The main difference is that when a script or command with SGID set is run, it runs as if it were a member of the same group in which the file is a member.

-rwxr-sr--

Setting SGID

# chmod g+s [file]
-rwxr-sr--. 1 root root 0 Mar 16 21:48 test

# chmod 2754 [file]
-rwxr-sr--. 1 root root 0 Mar 16 21:48 test

Note: A capital ’S’ (-rwxr-Sr–) indicates that the execute bit is not set

Sticky bit

Anyone can write, but only the owner can delete the files (just like /tmp).

drwxrwxrwt

Sticky bit is usually set on directories. Setting the sticky bit on a folder does nothing (on Linux).

Setting sticky bit

# chmod o+t [dir]
-rwxr-r-t. 1 root root 0 Mar 16 21:48 test

# chmod 1755 [dir]
-rwxr-xr-t. 1 root root 0 Mar 16 21:48 test

Notes:

  • A capital ’T’ indicates that the execute bit is not set
  • You should give write permission to make sure that the target users can write to the folder

Additional Special Permissions

A . can represent special permissions (SELinux related).

-rw-rw-rw-.  

A + indicates ACLs are applied.

-rw-rw-rw-+

Cheat Table

Mode Octal Symbolic
SUID 4755 u+s
SGID 2775 g+s
Sticky Bit 1777 o+t

Note: Octal mode is not an absolute translation to symbolic mode as symbolic changes only the specified permission set (user, group OR others), while octal overwrites all permission sets (user, group AND others)

TLP and CPUFreq on ThinkPad P1 Gen 2 (KDE Arch)

Linux Hardware ThinkPad

On this tutorial I will show you how to install and configure TLP and Intel P-state and CPUFreq Manager on your ThinkPad P1 Gen 2 (with KDE Arch).

If you don’t know, TLP allows you to configure specific rules to help optimize the battery life on your laptop, while Intel P-state and CPUFreq Manager gives you a pretty interface via a tray icon that allows you to control CPU/GPU frequencies and a few power profiles.

TLP

Using TLP’s threshold functionality we can change the charge thresholds for the battery. On ThinkPads the charging process is controlled by the embedded controller (EC) firmware (instead of software running on the operating system). Lenovo’s default settings start charging when the battery drops below 96%, and stops at 100%. This is good for “performance” but it deteriorates the battery causing a shorter lifespan. By changing the battery charge thresholds with TLP we can extend the lifespan of the battery.

Note: Lithium-ion batteries do not suffer from memory effect like NiCd and NiMH batteries. See the quote below (https://batteryuniversity.com) for an explanation

A lithium-ion battery provides 300-500 discharge/charge cycles. The battery prefers a partial rather than a full discharge. Frequent full discharges should be avoided when possible. Instead, charge the battery more often or use a larger battery. There is no concern of memory when applying unscheduled charges.

Installation

This part is very simple. Install the following packages and then reboot:

=> Main

  • tlp
  • acpi_call
  • smartmontools

=> AUR

  • tlpui-git

Configuration

a. Run tlpui and go to the ‘ThinkPad Battery’ tab on the left

b. Set the following parameters/options

START_CHARGE_THRESH_BAT0

Value = 50/60

This is the threshold of when the battery will start charging. If you set it to 50 the battery will only start charging when it’s below 50%.

STOP_CHARGE_THRESH_BAT0

Value = 70/80

This is the value of when the battery will stop charging. If you set it to 80 the battery will stop charging when close to %80.

RESTORE_THRESHOLDS_ON_BAT

Value = enabled

When you bypass the charge thresholds with a TLP command you would usually need to reboot your machine to reset the thresholds. When RESTORE_THRESHOLDS_ON_BAT is enabled the configured thresholds will be restored when the power is unplugged.

This is useful if you need to fully charge your battery for a meeting, or to work in a place where you know you won’t have a power outlet.

NATACPI_ENABLE

Value = enabled

TPACPI_ENABLE

Value = enabled

TPSMAPI_ENABLE

Value = disabled

tp_smapi doesn’t support newer models, so we need to disable this.

c. Go back to the ‘General’ tab and enable TLP_ENABLE

d. Click on ‘save’ and reboot

Additional TLP Commands

Get a full report from TLP

sudo tlp-stat

Get a report with battery information only

sudo tlp-stat -b

Temporarily bypass the current config and use specified threshold

sudo tlp setcharge [start threshold] [stop threshold]

Bypass thresholds and fully charge battery

sudo tlp fullcharge

Bypass the start threshold and charge up to the stop threshold

sudo tlp chargeonce

Intel P-state and CPUFreq Manager

a. Install plasma5-applets-plasma-pstate (AUR)

b. Add the widget to your panel

c. Done! You should now be able to use the widget for basic control


Reference:

code with