Month: October 2021

VIM Basic

VIM Basic

This is not a full guide, but those new functions to me.

Movement

Scrolling

^E - down (End)
^Y - up (Hard to remember and use)

Jumping

H - High (Top)
M - Middle
L - Low (Bottom)

Object

w - words
s - sentences
p - paragraphs
t - tags (in XML/HTML file)

Selection

a -- all (whole + border)
i - in (whole)
t - 'til (find but no border)
f - find
F - find backword

Command

d y v
c i a o

Basic Example

diw
caw
yi)
va"

Macro

Register

q{key}
...
q

Play

@{key}

Register

View

:reg

Paste with number

"<n>p

Plugins

vundle - plugin manager
nerdtree - file drawer
ctrlp - fuzzy file finder
fugitive - git tool
syntastic - systax checker / linter

References

nicknisi / vim-workshop

Systemd services for user in Linux

Systemd services for user in Linux

The traditional way of starting up program after user login, is using user profile. The systemd provides a new way for such tasks.

Usage

The systemd regular services are running as root privileges, unless User value in Service session. They are triggerred as background jobs, no matter user login or not. The systemd user services are running for user and run as that user id, and they are triggered after that user login.

Definition

To define services run as a normal user, they can be defined in user's home directory in ~/.config/systemd/user folder, they will be picked up by systemd as a user service.

Managing

To manage these services, folowing commands can be used.

Check all systemd services for user

systemctl status --user

Enable and start up

systemctl --user enable myuser.service
systemctl --user start myuser.service

Reload all systemd configuration. It is required after service definition files modified.

systemctl --user daemon-reload

For all users

The /etc/systemd/user/ folder is to define services for all users. The default available user services definition files are in /usr/lib/systemd/user/ folder, they can be used to enable systemd user service. For example,

# ls /usr/lib/systemd/user/syncthing.service
syncthing.service
# systemctl --user status syncthing
Unit syncthing.service could not be found.
# systemctl status syncthing
* syncthing.service - Syncthing - Open Source Continuous File Synchronization
...

Other systemd user definition file locations can be defined by administrator

$XDG_RUNTIME_DIR/systemd/user/
~/.local/share/systemd/user/

Common usage

The most common usage of systemd user servers, are X window related processes, they need to be run after user login, running as background services for user, such as reminder, window manager, etc., but not the background services for system.

References

systemd user services and systemctl --user
What does "systemctl daemon-reload" do?

ESXi with UEFI iSCSI boot on Raspberry Pi

ESXi with UEFI iSCSI boot on Raspberry Pi

Steps

Setup iSCSI disk

  • Create iSCSI Target and LUN in Synology
  • Download RPi4 UEFI Firmware, and unzip it to a SD card which formatted as FAT32 partition
  • Boot from the SD card, and perform following tasks using UEFI menu
    • Disable 3G memory limit
      Device Manager => Raspberry Pi Configuration => Advanced Configuration => Limit RAM to 3 GB)
    • Create device which mapped to iSCSI target
      Device Manager => iSCSI Configuration => Add an Attempt

After Attempt 1 created, Reset (restart) Raspberry Pi. Now, in Boot Manager, should see UEFI SYNOLOGY iSCSI Storage.

Setup boot order

  • Change Boot order and let it before other network boot, otherwise, there will be too much waiting time.

Prepare ESXi installation disk

  • Download and flush VMware-VMvisor-Installer-7.0.0-xxxx.aarch64.iso to USB device

Install ESXi

  • Reset (Reboot) again, and in UEFI menu select boot from USB device
  • Then perform ESXi installation, and select iSCSI disk as target

After installation completed, take out ESXi installation USB, then another reset is required,

Configure ESXi

  • Boot into iSCSI
  • Change ESXi name, etc.

Troubleshooting

Unable to see iSCSI disk in Boot Manager

Most likely is the iSCSI configuration wrong.

  • Check iSCSI Target Name
  • Check iSCSI Target IP
  • Check iSCSI LUN ID (This issue costed me a few hours)
  • Check User/Password

Synchronous Exception

After installation complete, suddenly cannot boot into any destination, and just show error Synchronous Exception.

End up, I have to recopy UEFI image into micro SD card, redo iSCSI configuration. Luckily the iSCSI has no issue, which contains installed ESXi image.

References

Boot ESXi-Arm Fling on a Raspberry Pi 4 Using ISCSI
Raspberry Pi 4 UEFI Firmware Images
ESXi on Arm 10/22 更新
Raspberry Pi 4 Model B 8GBにESXi for ARM 7.0.0をインストール
Synchronous Exception at 0x00000000371013D8 #97

Add bluetooth device from ubuntu console

Add bluetooth device from ubuntu console

I used following steps to add bluetooth keyboard.

Steps

  • Run bluetoothctl, then get following prompt
[bluetooth]# 
  • Run following commands to initialize bluetooth
power on
agent on
default-agent
scan on
  • Find the bluetooth device mac address

  • Run following command to connect to it

trust XX:XX:XX:XX:XX:XX
pair XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX
  • Then disable scan and quit
scan off
exit

References

How to connect bluetooth headset via command line on ubuntu 12.04

Change user name in ubuntu

Change user name in ubuntu

To change default user name ubuntu created in Raspberry Pi image, without adding a temporary user or enable root id, can be done using background job.

Commands

Change user name and home directory

usermod -l newUsername -d /home/newUsername oldUsername

Change group name

groupmod -n <newgroup> <oldgroup>

Job

The actual execution should be triggered as background job. I used screen command as below

  1. Login as ubuntu (default id)
  2. Run sudo -i to root
  3. Run screen to launch screen session
  4. Run following command, and press Ctrl-A d detach screen session immediately, without command executed.
newname=<new_user_name>
sleep 30; ps -ef | grep ^ubuntu | awk '{print $2}' | xargs kill -9 ; usermod -l $newname -d /home/$newname ubuntu; groupmod -n $newname ubuntu; mv /home/ubuntu /home/$newname
  1. Quit from console or ssh session
  2. After 30 seconds, login to the system using newname if succeeded. Othewise, use ubuntu login again.
  3. Then sudo to root and run screen -r to check if error or quit screen session.

References

How do I change my username?

Tmux vs Screen

Tmux vs Screen

The unix command screen and tmux have similar goal, but tmux is more complex than screen.

Quick Tips

In order to start using tmux without worrying about forgetting keys, remember follows one after another.

  • Help using key Ctrl+b ?
  • Detach using key Ctrl+b d
  • Resume using command tmux a
  • Create window using command Ctrl+b c
  • Navigate windows using key Ctrl+b w, then arrow keys
  • Rename window using key Ctrl+b ,
  • Status bar has window name and <id>
  • Switch window using key Ctrl+b <id>

Commands

screen tmux
Startup screen tmux
Starting Named Session screen -S session_name tmux new -s session_name
List running session screen -ls tmux ls
Reattach screen -r
Reattach by id screen -r <id> tmux attach-session -t <id>

Keys

screen tmux
Help Ctrl+a ? Ctrl+b ?
Create a new shell (without window) Ctrl+a c
Switch to next shell Ctrl+a space
Switch to previous shell Ctrl+a backspace
Create a new window (with shell) Ctrl+b c
List all shells Ctrl+a "
Choose window from a list Ctrl+b w
Switch to N'th shell Ctrl+a <n>
Switch to N'th window Ctrl+b <n>
Rename the current window Ctrl+a A Ctrl+b ,
Split current region horizontally into two regions Ctrl+a S Ctrl+b %
Split current region vertically into two regions Ctrl+a | Ctrl+b "
Switch the input focus to the next region Ctrl+a tab Ctrl+b o
Toggle between the current and previous windows Ctrl+a Ctrl+a Ctrl+b ;
Close all regions but the current one Ctrl+a Q
Close the current region Ctrl+a X Ctrl+b x
Detach from session Ctrl+a d Ctrl+b d
Sent Ctrl+a to region Ctrl+a a

Customize

screen

Customization can be done in /etc/screenrc and ~/.screenrc. Sample of contents is shown below.

# Turn off the welcome message
startup_message off

# Disable visual bell
vbell off

# Set scrollback buffer to 10000
defscrollback 10000

# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'

tmux

Customization can be done in ~/.tmux.conf. Sample of contents is shown below.

# Improve colors
set -g default-terminal 'screen-256color'

# Set scrollback buffer to 10000
set -g history-limit 10000

# Customize the status line
set -g status-fg  green
set -g status-bg  black

References

How To Use Linux Screen
Getting started with Tmux
How to split the terminal into more than one "view"?

BerryBoot on Raspberry Pi

BerryBoot on Raspberry Pi

Raspberry Pi 2/3/4 requires SD card to be used for booting, which saves OS filesystems. There are some issues with SD card with OS boot.

  • Limited size
  • Hard to backup

I was thinking a solution to move root filesystem to iSCSI, but grub is not used in OS of Raspberry Pi. As the design of BerryBoot, it can install various OSes on iSCSI disk with multi-boot environment. So started testing it with Ubuntu OS.

Hardware

Although, BerryBoot declares supporting Raspberry Pi 1/2/3/4, I tried Pi 3B+, but very slow and hanging. End up used Pi 4 (8GB).

Boot up error

After installation completed, got following error. It is caused iSCSI LUN import requires time, at time of error reported, LUN had not detected by iSCSI driver.

iSCSI target does not have any partitions

The solution give is changing iscsi.sh file in boot partition (the SD card), adding loop for delay.

IP address and VNC

The BerryBoot interface used same IP as ubuntu OS, but it doesn't configure DNS. So after bootup, the ubuntu OS has no DNS setting, then manual update of file /etc/systemd/resolv.conf is required.

In order to remotely control BerryBoot, add following command to enable VNC. Then when booting error or like to select another OS, VNC viewer can be used to connect to BerryBoot.

Wired network headless installation

  • Append following at end of line in cmdline.txt (same line append)
... vncinstall ipv4=192.168.88.88/255.255.255.0/192.168.88.1

Wireless headless installation

  • Append following at end of line in cmdline.txt (same line append)
vncinstall ipv4=192.168.88.88/255.255.255.0/192.168.88.1/wlan0
  • Create a file called wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
ap_scan=1

network={
    ssid="ssid-of-accesspoint"
    psk="wpa-password"
}

Update error

The most important task is update, which includes package update and kernel update

Package update

It is quite smooth during update, but complaining /boot doesn't exist. I checked the OS structure, there is a /boot folder, with one kernel, and a filesystem /media/user_id/boot, which saves SD contents.

Kernel update

Kernel update was totally failed with following error

Can't find /boot/vmlinuz- (see /tmp/flash-kernel-no-kernel-error.log)

The solution given by other is removing two packages

sudo apt remove u-boot-rpi:arm64
sudo apt remove flash-kernel

Note: According to internet, BerryBoot uses its own kernel, meaning it can not be updated using package update command.

do-release-update

This is a very strange action I took. The OS I installed via BerryBoot is Ubuntu 20.10 Desktop, but the OS still can perform do-release-update to same version. The even more strange thing is, after I upgrade, it still appear as can perform do-release-update, then I spent another upgrade, another few hours upgrade, then it can fininally upgraded.

I think the package was not at the correct release stage, but don't know why got 980+ packages to upgrade after first run. Felt like perform exactly the same action once more.

The output of uname after patched ubuntu screen as below

  • BerryBoot ubuntu
root@camel:~# uname -a
Linux camel 5.10.43v64 #1 SMP PREEMPT Tue Jun 15 00:52:48 CEST 2021 aarch64 aarch64 aarch64 GNU/Linux
root@camel:~# 
  • Normal ubuntu
root@ubuntupi:/usr/lib# uname -a
Linux ubuntupi 5.13.0-1009-raspi #10-Ubuntu SMP PREEMPT Mon Oct 25 13:58:43 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
root@ubuntupi:/usr/lib# 

Filesystem structure

The BerryBoot ubuntu has different filesystem structure, the root filesystem is mapped to none, and no entry in /etc/fstab, I think the reason behind, is root filesystem is mounted via kernel, which is the iSCSI disk, and cannot be changed.

Output of df

root@camel:~# df
Filesystem     1K-blocks    Used Available Use% Mounted on
none            16646144 6422360   8396520  44% /
tmpfs            3957172       0   3957172   0% /dev/shm
tmpfs            1582872    1404   1581468   1% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs            3957172       0   3957172   0% /run/qemu
tmpfs             791432      72    791360   1% /run/user/126
tmpfs             791432      64    791368   1% /run/user/1000
root@camel:~# 

Output of mount

root@camel:~# mount | grep -w /
none on / type overlay (rw,relatime,lowerdir=/mnt/shared:/squashfs,upperdir=/mnt/data/Ubuntu_20.10_Desktop.img192,workdir=/mnt/data/Ubuntu_20.10_Desktop.img192.work,redirect_dir=on)
root@camel:~# 

The normal ubuntu installed has same structure of other distributions, using /etc/fstab for root filesystem as well. So the normal operations can be taken on root filesystem

Output of df

root@ubuntupi:/usr/lib# df
Filesystem     1K-blocks     Used Available Use% Mounted on
tmpfs             794548    12732    781816   2% /run
/dev/mmcblk0p2  30358480 24453720   4573672  85% /
tmpfs            3972736        0   3972736   0% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs            3972736        0   3972736   0% /run/qemu
tmpfs            3972736     8364   3964372   1% /var/log
tmpfs            3972736        8   3972728   1% /tmp
tmpfs            3972736        0   3972736   0% /var/tmp
/dev/mmcblk0p1    258095    97201    160894  38% /boot/firmware
tmpfs             794544       92    794452   1% /run/user/126
tmpfs             794544       84    794460   1% /run/user/1000
root@ubuntupi:/usr/lib# 

Output of mount

root@ubuntupi:/usr/lib# mount | grep -w /
/dev/mmcblk0p2 on / type ext4 (rw,noatime,nobarrier)
root@ubuntupi:/usr/lib# 

Pros

Following advantages over normal ubuntu

  • Root filesystem type can be selected during installation. (Normal ubuntu on Raspberry Pi can not)
  • The iSCSI module is loaded by default.
    Note: Recent update of my normal ubuntu caused iSCSI module missing issue.
  • OS multiboot

Cons

Duo to BerryBoot has different filesystem structure and kernel, some diffculties would be facing later.

  • Specific Kernel
    • No kernel upgrade can cause package incompatible, for example, docker was mentioned by others
    • Auto rebuild kernel is almost impossible
  • Filesystem
    • Unable to verify root filesystem, scrubbing wasn't allowed during my testing
    • Unable to know root filesystem type even mounted
    • Cannot increase root filesystem size easily

Conclusion

The way BerryBoot manage the system is highly customized, which might not be adapted anywhere else. The customization also leads system compatibility issues later, and migration, backup, restore, etc., cannot be implemented in common way. So there could be no future-proof for this implemenation.

Compare local boot partition solution, which only holds root partition on iSCSI, the advantage of BerryBoot is iSCSI dependency issue reduced and multiboot OS capability. But the root on iSCSI uses bootload, which reduced OS compatibility issue.

My decision is still use normal bootload way for future systems to achieve maintennance free system.

References

Headless installation
Problems with update/upgrade Ubuntu 20.10 on Raspberry pi 4 with SSD
Raspberry Pi iSCSI Root on Ubuntu 20.04
How to Dual Boot a Raspberry Pi Using BerryBoot
BerryBoot v2.0 - bootloader / universal operating system installer
Storing your files on a Synology NAS (using iSCSI)

Verify package using debsums

Verify package using debsums

Verify every installed package

debsums

Verify every installed package (including configuration files).

debsums -a

Verify installed packages and report errors only

debsums -s

Verify every installed package and report changed files only

debsums -c

Verify every installed package (including configuration files) and report changed files only.

debsums -ca

Verify every installed package and report changed configuration files only.

sudo debsums -ce

Verify specific package

debsums -a bash

Create mismatch list

dpkg-query -S $(sudo debsums -c 2>&1 | sed -e "s/.*file \(.*\) (.*/\1/g") | cut -d: -f1 | sort -u

To reinstall them

apt-get install --reinstall <package name>

References

How to verify installed packages

Hot swapable Keychron keyboard issues

Hot swapable Keychron keyboard issues

Just got Keychron keyboard, with hot swap, which can easily switch between two Mac machines easily. Some issues struggle me for a while.

No eject button

The major difference between normal Mac keyboard and Keychron keyboard is reject button, so need to use another combination of keys for sleep instead, which uses power button. But my old iMac power button has issue as well.

Then when I put iMac to sleep, then try to switch to Mac Mini, the keyboard wakes iMac up. To overcome this issue, I tried to use mouse, but I can not move the mouse as well, it also wakes iMac up.

After search internet, people give a solution, that is using mouse to sleep, then lift it up, after that make it upside down. Then I did the same thing, except switch it off, because my mouse got light.

Switch between MacOS and Windows or Linux

Because of the switching between MacOS and Windows or Linux via a physical button, it isn't that easy, and the manual mentions do not do it often, otherwise, can cause issue.

References

Shortcut key to make my macbook sleep?