21
October
2022
15:12

Short Tips

21 October 2022 15:12

A collection of short tips.

1) If, after an incorrect shutdown of the computer, Linux does not start, the cursor is blinking on a black background: boot from the USB flash drive in Live mode, launch the Terminal and check the hard drive partitions:

lsblk
sudo fsck /dev/sda5
sudo fsck /dev/sda6

where sda5 and sda6 are the "/" and "/home" partitions, respectively.

New (03/2024):fixing boot using boot-repair.
You need to boot from the LiveCD (after turning on the PC, press F9 - in the "Please select boot device" menu, select the DVD drive "UEFI" or regular - depending on the disk partitioning style)) and load the graphic mode. In the terminal, run the commands to install and launch boot-repair utilities. Connect the Internet and follow these steps:
sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt update
sudo apt install -y boot-repair
sudo boot-repair

Click the "Recommended recovery method (Fixes the most common problems)" button.

2) Creating a hard disk image while ignoring errors (for example, to restore photos):

sudo dd if=/dev/sdb of=ndd.img conv=noerror,sync

An improved way to rescue data from a badly damaged hard disk partition /dev/sdc1 to another disk mounted in the "/media/user/foto" directory in the petrov.img file:

sudo ddrescue -f /dev/sdc1 /media/user/foto/petrov.img mapfile

Recovering photos from a disk image file: scan the rescued partition (recovery result in the petrov.img file) with a deep search using the program https://recuva.ru/ for Windows.

3) To remove the annoying video that is launched every time on the site, install the FireFox extension "Block Site" (https://add0n.com/block-site.html) and add the domain this video is playing from to your "Existing Rules" list. An example of such a rule:*://vp.rambler.ru/*.

You can also use "stubs" in the /etc/hosts file. For example, deadlines:
127.0.0.1 dsp-rambler.ru
127.0.0.1 zoomdecorate.rambler.ru
In the FireFox browser, in the “Privacy and Security” settings, enable “Strict” protection.

4) List all systemd manager services, as well as a list of services that start at every boot (Source:linuxhandbook.com)

systemctl list-units --type=service
systemctl list-unit-files --type=service --state=enabled

5) Try to start the service and look at the error in the log:

systemctl start ‹service_name›
systemctl status ‹service_name›
journalctl -xe

6) Shutdown Linux PC from Command Line

sudo shutdown -P now

7) If commands do not work from the command line host и nslookup(error "bash: nslookup: command not found"), you need to install the "dnsutils" package.

sudo apt-get install dnsutils

8) The reverse command to add-apt-repository:

How to remove a PPA repository from the operating system:

sudo apt-get update
sudo apt-get install ppa-purge
sudo ppa-purge ppa:something/ppa

9) Fastest Linux kernel for older processors -5.10.0-051000-generic
(Version 6.0 brought bugfixes, but the execution speed of programs dropped slightly. The older version 5.6 is also slower than 5.10).
Installing kernels 5.10, or 5.11.17 or 5.12.0 with one command -on GitHub
Taken from GitHub, installing kernel 5.10:
mkdir -p /tmp/ && cd /tmp/ && \
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.10/amd64/linux-headers-5.10.0-051000_5.10.0-051000.202012132330_all.deb && \
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.10/amd64/linux-headers-5.10.0-051000-generic_5.10.0-051000.202012132330_amd64.deb && \
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.10/amd64/linux-image-unsigned-5.10.0-051000-generic_5.10.0-051000.202012132330_amd64.deb && \
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.10/amd64/linux-modules-5.10.0-051000-generic_5.10.0-051000.202012132330_amd64.deb && \
sudo dpkg -i *.deb

Note: on Ubuntu 22.04 (and Linux Mint 21 "Vanessa") the linux-headers-5.10.0-051000-generic package will be installed with an error because the package will be broken, due to an unmet library dependency libssl1.1. I solved the problem as follows: after selecting the additional boot option 5.10 in the menu, booting with the 5.10 kernel:

  • fixed the packages with the command sudo apt-get install -f(the faulty package linux-headers-5.10 was removed)
  • downloaded libssl1.1.deb for its architecture (AMD64)
  • installed by double clicking libssl1.1_1.1.1n-0+deb10u3_amd64.deb
  • downloaded linux-headers-5.10.0-051000-generic...amd64.deb
  • installed by double clicking linux-headers-5.10.0-051000-generic
  • пI rebooted the PC and booted into the same 5.10 kernel. Now sudo apt-get install -f gives no errors, and linux-headers-5.10.0-051000-generic is installed.

10) If an error is visible in the dmesg log r8169 0000:03:00.0: Unable to load firmware rtl_nic/rtl8168g-2.fw (-22), решение проблемы: sudo apt-get update && sudo apt-get reinstall firmware-realtek

11) Rebuild the intiramfs in the current kernel or refresh the initramfs of all kernels in the system. (Regeneration initial file system in RAM (RAMdisk) - initramfs files named initrd.img-*):
sudo update-initramfs -c -k $(uname -r)
sudo update-initramfs -c -k all

12) If the sudo apt-get update update is stuck at the stage of setting package parameters, you can interrupt the process with Ctrl+C and continue the update with the command:

sudo dpkg --configure -a

"Broken" packages are fixed with the command

sudo apt-get install -f

13) Bulk renaming of files by mask from the Linux command line:

 sudo apt-get install mmv

 mmv '*.png' 'img#1.png'

Result: file 1.png will be renamed to img1.png, 2.png to img2.png, etc.
(Source)

14) Enable more aggressive swapping from RAM to SWAP to free up RAM.
I think the swapiness parameter should be increased from 60 to 100 when enabled compressing RAM using ZSwap.

View swapiness parameter:

cat /proc/sys/vm/swappiness 

Set new value (from 0 to 100):

sudoedit /etc/sysctl.conf

On older PCs with little RAM but a fast SSD, add the line to the end of the "/etc/sysctl.conf" file
vm.swappiness = 100
and on powerful PCs with RAM of 16 GB and above, you can reduce the use of the page file to zero.
vm.swappiness = 0
and reboot the OS. Check:free -m
The default swapiness value is 60.

Note. Swapiness = 0 or 1 is recommended for database servers with large amounts of RAM

The following commands, which disable the SWAP enable and disable commands, move memory pages from the page file back to RAM (for high-end workstations and servers):

sudo swapoff --all
sudo swapon --all

15) Display hard disk usage statistics: size of first-level directories.

sudo du --max-depth=1 -h /

or

sudo tree -hF /

Calculate the size of your home folder:

sudo tree -hf /home

16) Checking audio playback over the Internet

mpv https://hls-01-radiorecord.hostingradio.ru/record-eurodance/112/playlist.m3u8

17) Save the /dev/sdc3 partition of the faulty HDD drive (with bad blocks) to file file.img on an external USB drive,
mounted in /media folder...

while true; do sudo ddrescue -r 0 -a 10 /dev/sdc3 /media/vladimir/NTFS/file.img log.logfile; done

18) (Windows) Combating WMI memory leak, wmiapsrv,exe process: add a task to the Scheduler, run as Administrator with the highest rights, daily, commands:

taskkill /im wmiapsrv,exe /f

19) To reduce Linux boot time, you can disable searching and scanning of BTRFS file systems by removing the package btrfs-progs:

sudo apt remove btrfs-progs

20) When you launch the Chrome browser, the “Unlock your login keychain” window appears.

Authentication required

Your login keychain was not unlocked when you signed in to the computer.

Password: |

Cancel Unblock"

To solve the problem with the keychain, delete in the user folder

rm ~/.local/share/keyrings/login.keyring

The next time you launch Chrome, the system will ask you for a password for the new keychain. Do not enter - click “Continue” - Keep passwords unencrypted? - “Continue”.

21) Find out the motherboard model from the command line:

sudo dmidecode -t 2

22) Increase the sound quality in Linux as much as possible, for listening to music on good headphones (Hi-Fi):

sudo nano /etc/pulse/daemon.conf


resample-method = soxr-vhq

resample-method = speex-float-10

default-sample-format = float32le
default-sample-rate = 44100
alternate-sample-rate = 48000

Local file ~/.pulse/daemon.conf you need to remove it if it exists. Restarting the service pulseaudio:

pulseaudio -k && pulseaudio --start    

The last, most minor improvement is in the alsa configuration file:

sudo nano /usr/share/alsa/alsa.conf

defaults.pcm.dmix.rate 44100

The idea is to avoid changing the sample rate both when playing back and when mixing sources. Checking audio parameters in real time:

cat /proc/asound/card0/pcm0p/sub0/hw_params

Should be: rate: 44100 (44100/1).

23) Search the "/var" folder for changed files today

find /var -type f -mtime -1

The same thing, but with suppressed "Access Denied" error messages:

find /var 2>/dev/null -type f -mtime -1

The same, excluding the /var/log and /var/spool folders

find /var 2>/dev/null -type f -mtime -1 | grep -vP "/var/log|/var/spool" 

24) Search for packages installed in the OS by mask (for example, containing the word golang)

 apt list --installed | grep golang

25) Checking the “flash drive” with the FAT32 file system:

sudo dosfsck -w -a -v /dev/sdX

where sdX is the disk name, replace it with /dev/sdd, etc. (output by lsblk command)
-w – write changes immediately,
-a – apply "treatment" automatically,
-v – display additional information.

26) Checking a flash drive with the NTFS file system

sudo apt-get install ntfs-3g

sudo ntfsck /dev/sdX

where sdX is the disk name, replace it with /dev/sdd, etc. (output by lsblk command)

27) Note on editing ~/.xinitrc:

The desktop name is displayed using the command
echo $XDG_CURRENT_DESKTOP

if LXQt- then in .xinitrc call exec startlxqt
if LXDE- then in .xinitrc call exec startlxde
if xfce4- then in .xinitrc call exec startxfwm4
etc.

28) In OSs like Ubuntu, programs are launched at the beginning of the session using the ~/.config/autorun folder with files *. desktop. Files for automatic launch (autorun) can be copied from a shared folder /usr/share/applications/ в профиль пользователя: ~/.config/autorun/.

For example:
cp /usr/share/applications/firefox.desktop ~/.config/autorun/

  • to launch Mozilla Firefox at the beginning of the user session.

29) Mounting the IMG disk image file, mounting, fixing the DOS file system

dd if=/dev/sdd of=disk.img conv=sync,noerror
sudo losetup /dev/loop10 disk.img
sudo mkdir /mnt/myimg
sudo mount /dev/loop10 /mnt/myimg
sudo dosfsck /mnt/myimg

Another way (does not work with all file systems):
First, disconnect the old connection
sudo umount /mnt/myimg
sudo losetup -d /dev/loop10
Find out offset xxxx from the beginning of the disk
fdisk -lu disk.img
sudo mount -o loop,offset=xxxx ~/img.img /mnt/myimg

sudo apt-get autoclean
sudo apt-get -f install
sudo apt-get update
sudo apt-get dist-upgrade
sudo dpkg --configure -a

30) Package repair

sudo apt-get autoclean
sudo apt-get -f install
sudo apt --fix-broken install
sudo apt-get update
sudo apt-get dist-upgrade
sudo dpkg --configure -a

31) Disassembling and assembling the DEB package, using the dpkg-deb utility, in order to correct the version in the dependencies
(Данный способ не рекомендуется к частому применению: лучше установить более новую версию программы, тогда она не будет требовать зависимости от старых библиотек).

mkdir tmp
cd tmp
wget http://....имя_пакета.deb
dpkg-deb -e package_name.deb
nano ./DEBIAN/control  #here I corrected the version number in the dependencies
dpkg-deb -b . имя_пакета.deb
dpkg -i имя_пакета.deb

32) If, after replacing the hardware (motherboard and processor), Linux does not start (the cursor blinks on the black screen), you need to select recovery mode in the Grub menu, enter as root and delete xorg.conf file, because it interferes with the detection of the video card. In most distributions, for example, in the popular Linux Mint, this file xorg.conf не нужен. (Генерация его происходит командой Xorg -configure- manually, not required)

rm /etc/X11/xorg.conf

33) To display the direct dependencies of a package (which installed packages this package depends on):

apt-cache depends --installed snap
  • snap depends on libc6

34) To display the reverse dependencies of a package (which installed packages depend on a given package):

apt-cache rdepends --installed snap
  • Many packages depend on snap, such as snapd-xdg-open, gnome-software-plugin-snap, ...

35) Display the UUID of disk drive partitions (in Windows and Linux):

Windows, display the UUID of hard drive volumes:

wmic volume get Driveletter, DeviceID

Linux, display UUID of hard drive volumes:

ls -l /dev/disk/by-uuid/

36) If you receive an error message "Unable to determine SOCKS version from socks" when running "pip3 install"

You need to clear the "all_proxy" environment variable.

export all_proxy="" 

37) Where is autoboot located in Linux LITE?

cd ~/.config/autostart
ls

The directory contains .desktop files. An example of a psensor.desktop file to run psensor processor temperature monitoring.

[Desktop Entry]  
Type=Application            
Version=1.0
Name=Psensor
GenericName=Psensor
Comment=Psensor is a graphical temperature monitor for Linux
Keywords=temperature;fan;monitoring;indicator;
Icon=psensor
TryExec=psensor
Exec=psensor
Categories=System;Monitor;
X-GNOME-Autostart-Delay=30
StartupNotify=true

38) How to stop and disable the AnyDesk service and icon?

After installing AnyDesk, there is no option not to start the service using AutoStart.
The icon appears on the system tray when anydesk.service is launched.

systemctl stop anydesk.service
systemctl disable anydesk.service
systemctl status anydesk.service

AnyDesk settings are located in the ~/.anydesk folder, in the cat system.conf file.

39) The guest network in the Keenetic router sometimes cannot access the Internet. The client cannot obtain an IP address from the DHCP server. The IP address of the guest network client could not be obtained. Solution:

You need to connect via Telnet to the router and execute two commands (first one, then the second):

interface Bridge1 up
system configuration save

40) Troubleshooting an error while loading the operating system "Failed to start casper-md5check.se.check":

sudo systemctl disable casper-md5check.service

Last change: 08/25/2025



Related publications