exFAT corrupt mount fix

After mounting a SD card kernel complained

May 16 09:37:51 plex kernel: exFAT-fs (sdc1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

Had to install exfatprogs and just run sudo fsck.exfat -v -y /dev/sdc1 and after mounting the error is gone and the copy process has better performance.

Source: https://askubuntu.com/a/1264032/168459

EXT4 error loading journal after power cut

Feb 28 09:15:15 nuc kernel: JBD2: journal reset failed
Feb 28 09:15:15 nuc kernel: EXT4-fs (sdc1): error loading journal

The above was in journalctl when mount command failed.

So tried fsck

$ sudo fsck /dev/sdc1
fsck from util-linux 2.39.3
e2fsck 1.47.0 (5-Feb-2023)
/dev/sdc1: recovering journal
/dev/sdc1 has gone 66 days without being checked, check forced.
Pass 1: Checking inodes, blocks, and sizes
Inode 118489333 extent tree (at level 2) could be narrower.  Optimize<y>? yes

Inode 118489579 extent tree (at level 1) could be narrower.  Optimize<y>? yes
Inode 118489629 extent tree (at level 2) could be narrower.  Optimize<y>? yes
Inode 118489674 extent tree (at level 1) could be narrower.  Optimize<y>? yes
Inode 236848701 extent tree (at level 1) could be shorter.  Optimize<y>? yes
Pass 1E: Optimizing extent trees
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (203470928, counted=202796926).
Fix<y>? yes
/dev/sdc1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdc1: 1818337/244187136 files (0.2% non-contiguous), 773948802/976745728 blocks

After fsck I tried mount and ls which took some time, but fortunately it worked

Solving bad sector

Couple of days ago I spotted the following issue in journalctl

smartd[319]: Device: /dev/sdb [SAT], 2 Currently unreadable (pending) sectors

sudo smartctl -a /dev/sdb said

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Elements / My Passport (USB, AF)
Device Model:     WDC WD50NDZW-11A8JS0
Serial Number:    WD-WX52D8163UPC
LU WWN Device Id: 5 0014ee 2bf4619ea
Firmware Version: 01.01A01
User Capacity:    5,000,947,523,584 bytes [5.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Form Factor:      2.5 inches
TRIM Command:     Available, deterministic
Device is:        In smartctl database 7.3/5319
ATA Version is:   ACS-3 T13/2161-D revision 5
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Sat Mar 11 18:29:46 2023 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       2
  3 Spin_Up_Time            0x0027   253   253   021    Pre-fail  Always       -       4658
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       947
  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x002e   200   200   000    Old_age   Always       -       0
  9 Power_On_Hours          0x0032   086   086   000    Old_age   Always       -       10459
 10 Spin_Retry_Count        0x0032   100   100   000    Old_age   Always       -       0
 11 Calibration_Retry_Count 0x0032   100   100   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       218
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       211
193 Load_Cycle_Count        0x0032   116   116   000    Old_age   Always       -       253807
194 Temperature_Celsius     0x0022   105   101   000    Old_age   Always       -       47

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed: read failure       90%     10424         733750280
# 2  Extended offline    Completed: read failure       90%     10401         73375028

So I had to learn about this issue, because I encountered first time bad sectors on my HDD. After some reading I ended up with fsck -vcck from wiki.archlinux.org/title/Badblocks#During_filesystem_check

$ sudo fsck -vcck /dev/sdb1
fsck from util-linux 2.38.1
e2fsck 1.47.0 (5-Feb-2023)
Checking for bad blocks (non-destructive read-write test)
Testing with random pattern: 99.74% done, 34:36:43 elapsed. (0/0/0 errors)

Hope the above fsck will solve that smartd error

UPDATE

After bunch of optimizes

Inode 69271555 extent tree (at level 1) could be narrower.  Optimize<y>? yes
Inode 69271558 extent tree (at level 2) could be narrower.  Optimize<y>? yes
Inode 69271562 extent tree (at level 1) could be narrower.  Optimize<y>? yes
Inode 69271563 extent tree (at level 2) could be narrower.  Optimize<y>? yes
Pass 1E: Optimizing extent trees
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/sdb1: ***** FILE SYSTEM WAS MODIFIED *****

       75042 inodes used (0.05%, out of 152616960)
         796 non-contiguous files (1.1%)
          50 non-contiguous directories (0.1%)
             # of inodes with ind/dind/tind blocks: 0/0/0
             Extent depth histogram: 70463/682/30
   293501388 blocks used (24.04%, out of 1220933888)
           0 bad blocks
         159 large files

       61214 regular files
        8493 directories
           0 character device files
           0 block device files
           0 fifos
           0 links
        5322 symbolic links (3855 fast symbolic links)
           4 sockets
------------
       75033 files

And finally SMART says Completed without error after extended self-test

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     10490         -
# 2  Extended offline    Completed: read failure       90%     10424         733750280
# 3  Extended offline    Completed: read failure       90%     10401         733750280
2 of 2 failed self-tests are outdated by newer successful extended offline self-test # 1

Transmission daemon wait for mount

After reboot I had to manually start transmission due ConditionPathIsDirectory=/media/usb-4tb/torrent

Finally found the solution at https://unix.stackexchange.com/a/247547/39470

With systemctl list-units --type=mount just list your mounts and add the unit name to After=

My /etc/systemd/system/transmission.service looks the following now

[Unit]
Description=Transmission BitTorrent Daemon
After=network.target systemd-networkd-wait-online.service media-usb\x2d4tb.mount
ConditionPathIsDirectory=/media/usb-4tb/torrent

StartLimitIntervalSec=500
StartLimitBurst=3 # Only 3 retries of restart

[Service]
User=transmission
Type=notify
ExecStart=/usr/bin/transmission-daemon -f --log-error
ExecReload=/bin/kill -s HUP $MAINPID
NoNewPrivileges=true
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Set Brave browser as default in Linux

You might test/check if it isn’t already with

$ xdg-mime query default x-scheme-handler/http
google-chrome.desktop
$ xdg-settings get default-web-browser
brave-browser.desktop
$ echo $BROWSER
/usr/bin/brave

To set xdg-mime

$ xdg-mime default brave-browser.desktop x-scheme-handler/http
$ xdg-mime default brave-browser.desktop x-scheme-handler/https

Setting BROWSER env via .bashrc or .zshrc just append export BROWSER=/usr/bin/brave

Mosaic/grid view of RTSP streams with ffmpeg

Finally found a solution for grid/mosaic playback of RTSP streams.


#!/bin/bash
ffmpeg -rtsp_transport tcp \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/102 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/202 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/302 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/402 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/502 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/602 \
-filter_complex "
nullsrc=size=1920×1080 [base];
[0:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [upperleft];
[1:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [upperright];
[2:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [middleleft];
[3:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [middleright];
[4:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [lowerleft];
[5:v] setpts=PTS-STARTPTS, scale=w=960:h=360 [lowerright];
[base][upperleft] overlay=x=0:y=0 [tmp1];
[tmp1][upperright] overlay=x=960:y=0 [tmp2];
[tmp2][middleleft] overlay=x=0:y=360 [tmp3];
[tmp3][middleright] overlay=x=960:y=360 [tmp4];
[tmp4][lowerleft] overlay=x=0:y=720 [tmp5];
[tmp5][lowerright] overlay=x=960:y=720
" \
-c:v rawvideo -f nut – | mpv –


#!/bin/bash
# 8 channel input, 4 rows and 2 columns layout
ffmpeg -rtsp_transport tcp \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/102 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/202 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/302 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/402 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/502 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/602 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/702 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/802 \
-filter_complex "
nullsrc=size=1920×1080 [base];
[0:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [upperleft];
[1:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [upperright];
[2:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [middleleft];
[3:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [middleright];
[4:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [lowerleft];
[5:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [lowerright];
[6:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [centerleft];
[7:v] setpts=PTS-STARTPTS, scale=w=960:h=270 [centerright];
[base][upperleft] overlay=x=0:y=0 [tmp1];
[tmp1][upperright] overlay=x=960:y=0 [tmp2];
[tmp2][middleleft] overlay=x=0:y=270 [tmp3];
[tmp3][middleright] overlay=x=960:y=270 [tmp4];
[tmp4][lowerleft] overlay=x=0:y=540 [tmp5];
[tmp5][lowerright] overlay=x=960:y=540 [tmp6];
[tmp6][centerleft] overlay=x=0:y=810 [tmp7];
[tmp7][centerright] overlay=x=960:y=810
" \
-c:v rawvideo -f nut – | mpv –


ffmpeg -rtsp_transport tcp \
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/101 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/201 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/301 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/401 \
-filter_complex "
nullsrc=size=1920×1080 [base];
[0:v] setpts=PTS-STARTPTS, scale=960×540 [upperleft];
[1:v] setpts=PTS-STARTPTS, scale=960×540 [upperright];
[2:v] setpts=PTS-STARTPTS, scale=960×540 [lowerleft];
[3:v] setpts=PTS-STARTPTS, scale=960×540 [lowerright];
[base][upperleft] overlay=shortest=1 [tmp1];
[tmp1][upperright] overlay=shortest=1:x=960 [tmp2];
[tmp2][lowerleft] overlay=shortest=1:y=540 [tmp3];
[tmp3][lowerright] overlay=shortest=1:x=960:y=540
" \
-c:v libx264 -preset superfast -crf 18 -f matroska – | ffplay –


ffmpeg -rtsp_transport tcp \
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/102 \ # use substream with lower resolution
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/202 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/302 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3:6911/Streaming/Channels/402 \
-filter_complex "
nullsrc=size=1920×1080 [base];
[0:v] setpts=PTS-STARTPTS, scale=960×540 [upperleft];
[1:v] setpts=PTS-STARTPTS, scale=960×540 [upperright];
[2:v] setpts=PTS-STARTPTS, scale=960×540 [lowerleft];
[3:v] setpts=PTS-STARTPTS, scale=960×540 [lowerright];
[base][upperleft] overlay=shortest=1 [tmp1];
[tmp1][upperright] overlay=shortest=1:x=960 [tmp2];
[tmp2][lowerleft] overlay=shortest=1:y=540 [tmp3];
[tmp3][lowerright] overlay=shortest=1:x=960:y=540
" \
-c:v libx265 \ # check output and see what format the camera use, see `ffmpeg -encoders | grep V`
-preset superfast -crf 18 -f matroska – | ffplay –

Source: https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos

Remotely connecting to existing X server via VNC server

My goal was to connect to a remote desktop. Had to tweak systemd to autologin with specific user.

sudo vim /etc/systemd/system/getty@tty1.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin mike --noclear %I $TERM

I’m a zsh user so had to add the following into ~/.zprofile

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
    exec startx
fi

So after these changes after rebooting the PC the X server started and I could connect to it.

Just had to start

x0vncserver -display :0 -rfbauth .vnc/passwd

Sat Mar 28 16:18:32 2020
 Geometry:    Desktop geometry is set to 3840x1200+0+0
 XDesktop:    Using evdev codemap
 XDesktop:    
 XDesktop:    XTest extension present - version 2.2
 XDesktop:    RANDR extension not present
 XDesktop:    Will not be able to handle session resize
 Main:        Listening on port 5900

The desktop has no public IP so I had to port forward

ssh vnc-server -L 9900:localhost:5900

Now I was able to connect with vncviewer

vncviewer localhost:9900
TigerVNC Viewer 64-bit v1.10.1
Built on: 2019-12-27 09:17
Copyright (C) 1999-2019 TigerVNC Team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.

Sat Mar 28 16:20:09 2020
 DecodeManager: Detected 8 CPU core(s)
 DecodeManager: Creating 4 decoder thread(s)
 CConn:       Connected to host localhost port 9900
 CConnection: Server supports RFB protocol version 3.8
 CConnection: Using RFB protocol version 3.8
 CConnection: Choosing security type VeNCrypt(19)
 CVeNCrypt:   Choosing security type TLSVnc (258)

Switch from netctl to NetworkManager on Arch Linux

On my notebook I finally decided to try NetworkManager with its applet

After installing. I had to check status of some networking services and disable them.

systemctl status dhcpcd.service
sudo systemctl stop netctl.service
sudo systemctl stop netctl-ifplugd@eth0.service
sudo systemctl status netctl-ifplugd@eth0.service
sudo systemctl stop netctl-auto@wlan0.service

And then wait for the magic after starting NetworkManager
sudo systemctl start NetworkManager.service

network manager applet

I should have searched for a how to video on YouTube and could save some debugging time with journalctl -f 🙂 After setup I found https://www.youtube.com/watch?v=MAi9DurTRQc

Google Play Music desktop player MPRIS media keys for Linux

I finally nailed it 😀
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.google-play-music-desktop-player /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.google-play-music-desktop-player /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next

Also added to my Awesome window manager config
https://github.com/mikaelz/dotfiles/blob/f7e8246a06b9e91b5656419708c9c122f1aa4685/.config/awesome/rc.lua#L372-L375

Monitor progress of cp, mv, gzip, mysql and CLI commands

To monitor progress of an ongoing copy or mysql dump import you might try progress CLI tool. Track progress of commands like cp, mv, dd, tar, cat, rsync, grep, fgrep, egrep, cut, sort, md5sum, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, adb, gzip, gunzip, bzip2, bunzip2, xz, unxz, lzma, unlzma, 7z, 7za, zcat, bzcat, lzcat, split, gpg, etc.