Skip to content

3 ‐ Linux fixes

SimonHeggie edited this page Feb 21, 2025 · 7 revisions

This page is a fix and troubleshooting guide that covers the issues I encounter allow with my fixes.

Lenovo Legion Pro 7 16IRX8H

This is my professional laptop.

There are just a few things I had to adjust to get things working perfectly.

Fixing built in sound (Intel HDA ALC287)

Click to expand

Run the Following Script

Copy and paste the following script into the terminal:

View Fix Script
#!/bin/bash

echo "Applying all audio fixes to force built-in audio as default and ensure proper initialization..."

## Backup existing configurations
BACKUP_DIR="/etc/audio_fixes_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"

backup_file() {
    if [ -f "$1" ]; then
        sudo cp "$1" "$BACKUP_DIR/"
        echo "[BACKUP] Saved $1 to $BACKUP_DIR/"
    fi
}

# Modify Kernel Parameters to Force Sound Initialization
echo "Modifying GRUB boot parameters..."
GRUB_FILE="/etc/default/grub"
backup_file "$GRUB_FILE"

sudo sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="snd_hda_intel.dmic_detect=0 snd_hda_intel.power_save=0 snd_hda_intel.probe_mask=1 /' "$GRUB_FILE"
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

# Disable ALSA Power Saving
echo "Disabling ALSA power saving..."
MODPROBE_FILE="/etc/modprobe.d/alsa-base.conf"
backup_file "$MODPROBE_FILE"

echo "options snd_hda_intel power_save=0" | sudo tee "$MODPROBE_FILE"

# Force PipeWire to Prioritize Built-in Audio
echo "Setting PipeWire to always prioritize built-in audio..."
mkdir -p ~/.config/pipewire/media-session.d/

PIPEWIRE_CONFIG="~/.config/pipewire/media-session.d/alsa-monitor.conf"
backup_file "$PIPEWIRE_CONFIG"

cat <<EOF > "$PIPEWIRE_CONFIG"
{
    "rules": [
        {
            "matches": [
                {
                    "node.name": "alsa_output.pci-0000_00_1f.3.analog-stereo"
                }
            ],
            "actions": {
                "node.pause-on-idle": false,
                "priority.driver": 2000,
                "priority.session": 2000
            }
        },
        {
            "matches": [
                {
                    "node.name": "alsa_output.pci-0000_01_00.1.pro-output-3"
                }
            ],
            "actions": {
                "priority.driver": 100,
                "priority.session": 100
            }
        }
    ]
}
EOF

# Delay Audio Service Start to Ensure Hardware is Ready
echo "Creating a systemd service to delay audio initialization..."
SYSTEMD_SERVICE="/etc/systemd/system/restart-audio.service"
backup_file "$SYSTEMD_SERVICE"

cat <<EOF | sudo tee "$SYSTEMD_SERVICE"
[Unit]
Description=Restart PipeWire & ALSA after boot
After=multi-user.target

[Service]
ExecStart=/bin/bash -c 'sleep 5; systemctl --user restart pipewire pipewire-pulse; sudo alsactl init'
Type=oneshot
RemainAfterExit=true

[Install]
WantedBy=default.target
EOF

sudo systemctl enable restart-audio.service

# Restart audio services
echo "Restarting audio services..."
systemctl --user restart pipewire pipewire-pulse
sudo alsactl init

echo "All fixes applied. Reboot your system to test."

Verification Tests

Once applied, test the following:

Cold Boot with HDMI Plugged In:

  • Sound should work immediately.
  • "Pop" sound should be heard at boot.
  • Check default device using:
View Command
pactl get-default-sink

Pausing and Unpausing Audio:

  • Ensure the built-in sound card does not drop when idle.

Plugging and Unplugging HDMI Multiple Times:

  • Built-in speakers should stay the default.

System Updates & Kernel Changes:

  • After updating, verify that GRUB settings persist using:
View Command
cat /etc/default/grub
  • If a new kernel causes issues, re-run the script.

How to Undo These Changes

If something goes wrong, you can revert all changes using the following script:

View Rollback Script
#!/bin/bash

echo "Rolling back audio fixes..."

# Remove ALSA configuration
if [ -f "/etc/asound.conf" ]; then
    sudo rm /etc/asound.conf
    echo "Removed ALSA configuration."
fi

# Remove PipeWire configuration
if [ -f "~/.config/pipewire/media-session.d/alsa-monitor.conf" ]; then
    rm ~/.config/pipewire/media-session.d/alsa-monitor.conf
    echo "Removed PipeWire configuration."
fi

# Remove systemd service
if [ -f "/etc/systemd/system/restart-audio.service" ]; then
    sudo rm "/etc/systemd/system/restart-audio.service"
    sudo systemctl disable restart-audio.service
    echo "Removed delayed audio service."
fi

# Restore GRUB settings
sudo sed -i 's/snd_hda_intel.dmic_detect=0 snd_hda_intel.power_save=0 snd_hda_intel.probe_mask=1 //' /etc/default/grub
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

# Restart audio services
systemctl --user restart pipewire pipewire-pulse
sudo alsactl init

echo "Rollback complete. Reboot your system to test."

Final Notes

  • This solution is tested on Lenovo Legion running Nobara 40 but may work on other Fedora-based distros.
  • If the issue returns after a kernel update, re-run the script.
  • This should help others with similar hardware and issues. Let me know if anything needs adjustment.