2024-07-26
How To Clone And Resize Encrypted Linux Installation

copy encrypted linux install to new disk

perform a bit-by-bit clone to new disk

1
2
sudo dd if=<source_disk_device> of=<target_disk_device> bs=4M status=progress

remember to detach the old disk and enlarge the system partition on new disk


in kde partiton manager, you can resize both the encrypted partition and the root partition as well as the swap partition (install tools prompted by name)

follow the guide here to do it manually:

https://wiki.archlinux.org/title/Resizing_LVM-on-LUKS

Read More

2024-07-24
How To Remove X11 And Qt Dependencies For A Headless Ubuntu System

Make desktop ubuntu headless

1
2
3
4
sudo apt-get purge libx11.* libqt.*
sudo apt-get autoremove -y
sudo apt-get clean

Read More

2024-06-19
Run Gui Programs Under Cron, Monitor Root Filesystem Disk Usage And Send Alarm

the ultimate solution:

copy all current user environment variables to crontab.


to run notify-send you have to set DBUS_SESSION_BUS_ADDRESS


to run other gui programs you set DISPLAY and XAUTHORITY


wall works for tmux and ssh sessions but not gnome-terminal.

in kde everything works fine. install konsole instead.


script for monitoring disk usage:

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
used_percentage=$(df / | awk 'NR==2 {sub(/%/, "", $5); print $5}')
alarm_message="Root filesystem has less than 10% free space."
# Compare the percentage with the number 90
if [ "$used_percentage" -lt 90 ]; then
echo "Disk is ok."
else
wall $alarm_message
notify-send $alarm_message
fi

Read More

2024-05-12
Viewing Cpu Usage History With Sysstat And The Sar Command

View history CPU usage statistics

First install sysstat package, then run sar -u

Read More

2023-09-26
Maintaining Stability With Mount --Bind: Detaching And Reattaching Linux Disks

linux disk detach and reattach, how to maintain stability

use mount --bind

Read More

2022-12-15
Reset Usb

the same for /sys/bus/usb/drivers/*.


in case kali failed to detect presence of hard disks, shall you pop up a dialog for us to decide whether to reset to usb or not.

reset-usb.sh

1
2
3
4
#!/bin/bash
reset-ahci-controllers.sh
reset-xhci-controllers.sh

reset-ahci-controllers.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
# this freaking works.
# Script to reset all local xHCI (USB) controllers
# Based on: http://billauer.co.il/blog/2013/02/usb-reset-ehci-uhci-linux/
if [[ ${EUID} != 0 ]]; then
echo This must be run as root!
exit 1
fi
for xhci in /sys/bus/pci/drivers/ahci; do
if ! cd ${xhci}; then
echo "Weird error. Failed to change directory to ${xhci}."
exit 1
fi
echo "Resetting devices from ${xhci}..."
for i in ????:??:??.?; do
echo -n "${i}" > unbind
echo -n "${i}" > bind
done
done

reset-xhci-controllers.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
# this freaking works.
# Script to reset all local xHCI (USB) controllers
# Based on: http://billauer.co.il/blog/2013/02/usb-reset-ehci-uhci-linux/
if [[ ${EUID} != 0 ]]; then
echo This must be run as root!
exit 1
fi
for xhci in /sys/bus/pci/drivers/?hci_hcd; do
if ! cd ${xhci}; then
echo "Weird error. Failed to change directory to ${xhci}."
exit 1
fi
echo "Resetting devices from ${xhci}..."
for i in ????:??:??.?; do
echo -n "${i}" > unbind
echo -n "${i}" > bind
done
done

Read More

2022-08-11
Linux Fan Not Spinning, Gpu Fan Not Spinning

everytime the fucking machine restarts, it fails devastatingly.

the word: Giving the fans some time to reach full speed...

the script:

1
2
3
4
5
6
7
#!/usr/bin/expect
spawn pwmconfig
#expect "Giving the fans some time to reach full speed..."
expect "If you do not want to do this hit control-C now!!!"
send "\03"
expect eof

hope this shit works?

1
2
3
echo 255 | sudo tee /sys/class/hwmon/hwmon6/pwm3
echo 255 | sudo tee /sys/class/hwmon/hwmon6/pwm1

i have install something other than that. like i8kctl, some thermal controllers by intel (thermald)? but still gpu fan not spinning till now.

1
2
3
4
apt install -y lm-sensors fancontrol
sensors-detect
pwmconfig

already have cpu frequency under control by running temp_throttle.sh

notes: found controllers dell_smm-isa-0000

1
2
3
4
Found the following PWM controls:
hwmon6/pwm1 current value: 255
hwmon6/pwm3 current value: 255

Read More

2022-08-09
Systemd On Linux, Maintainence Details

view full logs

1
2
journalctl -u <serviceName>.service

create, install, restart, reload

1
2
3
4
5
6
cd /etc/systemd/system
create <serviceName>.service
systemctl enable <serviceName>.service
systemctl daemon-reload
systemctl start <serviceName>.service

sample systemd service config files

maybe we should add some autorestart configs at it?

frpc_service.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=frpc service, expose ssh, webdav and code-server ports
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
User=root
ExecStart=/root/frp_client_linux/frp_0.36.2_linux_amd64/frpc -c frpc.ini
WorkingDirectory=/root/frp_client_linux/frp_0.36.2_linux_amd64
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target

pyjom_webdav_rclone_service.service

1
2
3
4
5
6
7
8
9
[Unit]
Description=rclone webdav served on pyjom, after the disk is mounted
[Service]
User=root
ExecStart=/usr/bin/python3 mount_help_and_serve_pyjom.py
WorkingDirectory=/root/Desktop/works/restore_sessions
[Install]
WantedBy=multi-user.target

tempthrottle.service

1
2
3
4
5
6
7
8
9
[Unit]
Description=temperature control, cpu temperature under 60 celsius
[Service]
User=root
ExecStart=/usr/bin/python3 tempthrottle_daemon.py
WorkingDirectory=/root/Desktop/works/restore_sessions
[Install]
WantedBy=multi-user.target

clash_fastgithub.service

1
2
3
4
5
6
7
8
9
10
[Unit]
Description=Clash Fastgithub Proxy
After=network.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/clash -d /etc/clash
[Install]
WantedBy=multi-user.target

tujia_scraper_qq_bot.service

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=two crucial services: tujia scraper, qq bot
Wants=network.target
After=syslog.target network-online.target
[Service]
Environment="DISPLAY=:1"
Environment="XAUTHORITY=/root/.Xauthority"
User=root
ExecStart=/usr/bin/python3 main_daemon.py
WorkingDirectory=/root/Desktop/works/restore_sessions
[Install]
WantedBy=graphical.target

sync_git_repos_syncdog.service

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=syncdog (server), to sync things to the cloud (github)
Wants=sshd.service
Wants=network.target
[Service]
User=root
ExecStart=/usr/bin/python3 syncdog_test.py
WorkingDirectory=/root/Desktop/works/sync_git_repos
[Install]
WantedBy=multi-user.target

Read More

2022-07-27
Linux Restore Window Sessions

to relaunch app in given workspace

tools:

wmctrl

devilspie

launch_on_workspace

references:

https://unix.stackexchange.com/questions/27050/how-to-start-an-application-on-a-different-workspace

https://askubuntu.com/questions/89946/open-application-in-specific-workspace

npm install -g linux-window-session-manager

restore session manually

dconf-editor

org.gnome.gnome-session

auto-save-session -> on

Read More

2022-07-25
Cpu Overheating (Temperature Too High)

linux

cpufrequtils

throttling cpu frequencies by temperature incrementally

the desired temperature is 60.

usually when one throttles the CPU temperature, the GPU cannot be overheated.

it is turning my core i7 into a pentium 3! but not entirely cumbersome.

Read More