battery improvements and pc start
This commit is contained in:
@@ -8,12 +8,26 @@ https://community.frame.work/t/fingerprint-scanner-compatibility-with-linux-ubun
|
||||
|
||||
## Revert Kernel (if needed)
|
||||
|
||||
With koji
|
||||
|
||||
```bash
|
||||
sudo dnf install koji
|
||||
mkdir /tmp/kernel-download
|
||||
cd /tmp/kernel-download
|
||||
koji search build kernel-6.0.12*
|
||||
koji download-build --arch=x86_64 kernel-6.0.12-300.fc37
|
||||
sudo dnf install ./*.rpm
|
||||
```
|
||||
|
||||
```bash
|
||||
# Find the kernels you have installed
|
||||
sudo rpm -qa kernel
|
||||
|
||||
# List available kernels
|
||||
sudo ls /boot | grep vmlinuz
|
||||
|
||||
# Revert to a previous kernel
|
||||
grubby --set-default /boot/vmlinuz-5.14.10-300.fc35.x86_64
|
||||
sudo grubby --set-default /boot/vmlinuz-5.14.10-300.fc35.x86_64
|
||||
```
|
||||
|
||||
## Make DNF Fast
|
||||
@@ -133,7 +147,7 @@ ansible-playbook --ask-become-pass ansible/framework_fedora.yml
|
||||
|
||||
```bash
|
||||
# Create an encrypted drive
|
||||
sudo cryptsetup luksFormat
|
||||
sudo cryptsetup luksFormat /dev/sdb1
|
||||
|
||||
# LUKS Disk Encryption can use up to 8 key slots to store passwords. We can use these keys to auto mount LUKS device.
|
||||
# cryptsetup luksDump /dev/sda
|
||||
@@ -170,6 +184,24 @@ sudo cryptsetup luksOpen /dev/disk/by-uuid/1d7ce570-e695-47a0-9dda-5f14b5b20e21
|
||||
sudo cryptsetup luksClose backup0
|
||||
```
|
||||
|
||||
### Backup Disks
|
||||
|
||||
Backup disks will respect the following naming convention:
|
||||
|
||||
brand_size_purpose_year_month
|
||||
|
||||
So for a backup drive you would create:
|
||||
|
||||
`wd_4tb_backup_2023_01`
|
||||
|
||||
Or for an archive drive:
|
||||
|
||||
`samsung_1tb_archive_2023_01`
|
||||
|
||||
#### Disk Health
|
||||
|
||||
`smartctl -a /dev/sda`
|
||||
|
||||
### Create BTRBK Config
|
||||
|
||||
`sudo vim /etc/btrbk/btrbk.conf`
|
||||
@@ -388,3 +420,213 @@ sudo systemctl stop packagekit
|
||||
dconf write /org/gnome/software/allow-updates false
|
||||
dconf write /org/gnome/software/download-updates false
|
||||
```
|
||||
|
||||
## Battery Life
|
||||
|
||||
```bash
|
||||
grubby --args="nvme.noacpi=1" --update-kernel=ALL
|
||||
```
|
||||
|
||||
Enable automatic power profile switching on AC/Battery
|
||||
|
||||
1. `sudo mkdir /lib/udev/power-profiles`
|
||||
1. `sudo vim /lib/udev/power-profiles/power-saver`
|
||||
|
||||
```bash
|
||||
powerprofilesctl set power-saver
|
||||
```
|
||||
|
||||
1. `sudo chmod +x /lib/udev/power-profiles/power-saver`
|
||||
1. `sudo vim /lib/udev/power-profiles/performance`
|
||||
|
||||
```bash
|
||||
powerprofilesctl set performance
|
||||
```
|
||||
|
||||
1. `sudo chmod +x /lib/udev/power-profiles/performance`
|
||||
|
||||
sudo vim /etc/udev/rules.d/10-power.rules
|
||||
|
||||
```bash
|
||||
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/bin/bash /lib/udev/power-profiles/power-saver"
|
||||
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/bin/bash /lib/udev/power-profiles/performance"
|
||||
```
|
||||
|
||||
~~Calibrate with powertop~~
|
||||
|
||||
Powertop causes connection issues with USB while the computer is plugged in. Do not
|
||||
recommend.
|
||||
|
||||
```bash
|
||||
sudo dnf install powertop
|
||||
# This will take a while
|
||||
sudo powertop --calibrate
|
||||
sudo powertop
|
||||
```
|
||||
|
||||
~~Install and enable tlp~~
|
||||
|
||||
TLP seems to limit maximum performance. I'm leaving it here for posterity.
|
||||
Stick with powertop and power profiles daemon.
|
||||
|
||||
```bash
|
||||
sudo systemctl stop power-profiles-daemon.service
|
||||
sudo systemctl disable power-profiles-daemon.service
|
||||
sudo systemctl mask power-profiles-daemon.service
|
||||
|
||||
sudo dnf install tlp
|
||||
sudo systemctl mask systemd-rfkill.service
|
||||
sudo systemctl mask systemd-rfkill.socket
|
||||
sudo systemctl enable tlp.service --now
|
||||
sudo systemctl status tlp.service
|
||||
```
|
||||
|
||||
### Simple Battery Monitoring App
|
||||
|
||||
alarm charge_full_design device power subsystem voltage_min_design
|
||||
capacity charge_now hwmon2 present technology voltage_now
|
||||
capacity_level current_now manufacturer serial_number type
|
||||
charge_full cycle_count model_name status uevent
|
||||
|
||||
```bash
|
||||
sudo mkdir /etc/battery_monitor
|
||||
sudo vim /etc/battery_monitor/battery_monitor.sh
|
||||
```
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
CSV_LOCATION="/home/ducoterra/data"
|
||||
CSV_NAME="battery_monitor.csv"
|
||||
BATTERY_DATA_LOCATION="/sys/class/power_supply/BAT1"
|
||||
if [ ! -f $CSV_LOCATION/$CSV_NAME ];
|
||||
then
|
||||
mkdir -p $CSV_LOCATION;
|
||||
echo "time,percent,charge_now,charge_full,voltage_now,current_now,cycle_count,status" > $CSV_LOCATION/$CSV_NAME
|
||||
chown -R ducoterra:ducoterra $CSV_LOCATION
|
||||
fi
|
||||
time=$(date --iso-8601=seconds)
|
||||
percent=$(cat $BATTERY_DATA_LOCATION/capacity)
|
||||
charge_now=$(cat $BATTERY_DATA_LOCATION/charge_now)
|
||||
charge_full=$(cat $BATTERY_DATA_LOCATION/charge_full)
|
||||
voltage_now=$(cat $BATTERY_DATA_LOCATION/voltage_now)
|
||||
current_now=$(cat $BATTERY_DATA_LOCATION/current_now)
|
||||
cycle_count=$(cat $BATTERY_DATA_LOCATION/cycle_count)
|
||||
status=$(cat $BATTERY_DATA_LOCATION/status)
|
||||
|
||||
echo "$time,$percent,$charge_now,$charge_full,$voltage_now,$current_now,$cycle_count,$status" >> $CSV_LOCATION/$CSV_NAME
|
||||
```
|
||||
|
||||
`sudo vim /etc/systemd/system/battery_monitor.service`
|
||||
|
||||
```conf
|
||||
[Unit]
|
||||
Description=Records the current battery level
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash /etc/battery_monitor/battery_monitor.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
`sudo vim /etc/systemd/system/battery_monitor.timer`
|
||||
|
||||
```conf
|
||||
[Unit]
|
||||
Description=Run battery_monitor every 15 seconds
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*:*:0,15,30,45
|
||||
AccuracySec=10sec
|
||||
Persistent=true
|
||||
Unit=battery_monitor.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
`sudo systemctl start battery_monitor.timer`
|
||||
|
||||
## Turn Off Fingerprint When Laptop Lid Closed
|
||||
|
||||
To disable fingerprint authentication when the laptop lid is closed, and re-enable when it is reopened, we will use acpid to bind to the button/lid.* event to a custom script that will stop and mask the fprintd service on lid close, and unmask and start the fprintd service on lid open.
|
||||
|
||||
We also check that the HDMI cable is connected by testing the contents of /sys/class/drm/card0-HDMI-A-1/status.
|
||||
|
||||
Follow the steps below:
|
||||
|
||||
1. Create a .locks file in your home dir: `mkdir ~/.locks`
|
||||
1. Create file /etc/acpi/laptop-lid.sh with the following contents:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
lock=/home/ducoterra/.locks/fprint-disabled.lock
|
||||
|
||||
if grep -Fq closed /proc/acpi/button/lid/LID0/state # &&
|
||||
# This is used to detect if a display is connected.
|
||||
# For USB C displayport use:
|
||||
# grep -Fxq connected /sys/class/drm/card1-DP-2/status
|
||||
# For hdmi use:
|
||||
# grep -Fxq connected /sys/class/drm/card0-HDMI-A-1/status
|
||||
then
|
||||
touch "$lock"
|
||||
systemctl stop fprintd
|
||||
systemctl mask fprintd
|
||||
elif [ -f "$lock" ]
|
||||
then
|
||||
systemctl unmask fprintd
|
||||
systemctl start fprintd
|
||||
rm -f "$lock"
|
||||
fi
|
||||
```
|
||||
|
||||
2. Make the file executable with
|
||||
|
||||
`chmod +x /etc/acpi/laptop-lid.sh`
|
||||
|
||||
3. Create file /etc/acpi/events/laptop-lid with the following contents:
|
||||
|
||||
```bash
|
||||
event=button/lid.*
|
||||
action=/etc/acpi/laptop-lid.sh
|
||||
```
|
||||
|
||||
4. Restart the acpid service with:
|
||||
|
||||
`sudo service acpid restart`
|
||||
|
||||
Now the fingerprint will be used only when the lid is open.
|
||||
|
||||
In order to restore the correct state of the fprintd service if you disconnect/reconnect while the laptop is off, you may call the above script from a systemd init file. The steps to do this are the following:
|
||||
|
||||
1. Create a file named /etc/systemd/system/laptop-lid.service with the following contents:
|
||||
|
||||
```bash
|
||||
[Unit]
|
||||
Description=Laptop Lid
|
||||
After=suspend.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/etc/acpi/laptop-lid.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=suspend.target
|
||||
```
|
||||
|
||||
2. Reload the systemd config files with
|
||||
|
||||
`sudo systemctl daemon-reload`
|
||||
|
||||
3. Start the service with
|
||||
|
||||
`sudo systemctl start laptop-lid.service`
|
||||
|
||||
4. Enable the service so that it starts automatically on boot
|
||||
|
||||
`sudo systemctl enable laptop-lid.service`
|
||||
|
||||
Now the status should be correct even after connecting/disconnecting when the computer is off.
|
||||
|
||||
Reference in New Issue
Block a user