291 lines
7.3 KiB
Markdown
291 lines
7.3 KiB
Markdown
# Battery Life Optimizer
|
|
|
|
A comprehensive tool suite for optimizing Linux laptop battery life using TLP and PowerTOP.
|
|
|
|
## 🔋 Overview
|
|
|
|
This repository provides scripts, configurations, and tools to maximize your Linux laptop's battery life through advanced power management. The toolkit includes automated installation scripts, optimized configuration files, and monitoring tools.
|
|
|
|
## ✨ Features
|
|
|
|
- **Automated Installation**: One-command setup for TLP and PowerTOP
|
|
- **Optimized Configurations**: Pre-tuned settings for maximum battery life
|
|
- **Monitoring Tools**: Real-time battery and power consumption monitoring
|
|
- **Power Analysis**: Detailed PowerTOP reports and recommendations
|
|
- **Profile Management**: Easy switching between power profiles
|
|
- **Safety First**: Backup and rollback capabilities
|
|
|
|
## 🚀 Quick Start
|
|
|
|
### 1. Install TLP and PowerTOP
|
|
|
|
```bash
|
|
# Clone or download this repository
|
|
cd battery_life
|
|
|
|
# Run the installation script
|
|
./scripts/install.sh
|
|
```
|
|
|
|
### 2. Monitor Your Battery
|
|
|
|
```bash
|
|
# Show current battery status
|
|
./scripts/battery-monitor.sh
|
|
|
|
# Watch battery status in real-time
|
|
./scripts/battery-monitor.sh --watch
|
|
```
|
|
|
|
### 3. Analyze Power Consumption
|
|
|
|
```bash
|
|
# Generate a PowerTOP report
|
|
./scripts/powertop-analyze.sh
|
|
|
|
# Apply automatic optimizations
|
|
./scripts/powertop-analyze.sh --auto-tune
|
|
```
|
|
|
|
### 4. Manage TLP Settings
|
|
|
|
```bash
|
|
# Show TLP status
|
|
./scripts/tlp-manager.sh
|
|
|
|
# Get optimization recommendations
|
|
./scripts/tlp-manager.sh --recommendations
|
|
|
|
# Switch to power saving profile
|
|
./scripts/tlp-manager.sh --profile powersave
|
|
```
|
|
|
|
## 📁 Directory Structure
|
|
|
|
```
|
|
battery_life/
|
|
├── scripts/
|
|
│ ├── install.sh # Installation script
|
|
│ ├── uninstall.sh # Uninstallation script
|
|
│ ├── battery-monitor.sh # Battery status monitor
|
|
│ ├── powertop-analyze.sh # PowerTOP analysis tool
|
|
│ └── tlp-manager.sh # TLP configuration manager
|
|
├── config/
|
|
│ ├── tlp.conf # Optimized TLP configuration
|
|
│ └── powertop.service # PowerTOP systemd service
|
|
├── docs/
|
|
│ └── [Documentation files]
|
|
└── README.md
|
|
```
|
|
|
|
## 🛠️ Detailed Usage
|
|
|
|
### Installation Script
|
|
|
|
The installation script (`scripts/install.sh`) automatically:
|
|
- Installs TLP and PowerTOP packages
|
|
- Configures systemd services
|
|
- Applies optimized settings
|
|
- Creates backup of existing configurations
|
|
- Installs additional power management tools
|
|
|
|
**Features:**
|
|
- Automatic system detection
|
|
- ThinkPad-specific optimizations
|
|
- Safe installation with rollback options
|
|
- Comprehensive logging
|
|
|
|
### Battery Monitor
|
|
|
|
Real-time battery monitoring with detailed information:
|
|
|
|
```bash
|
|
# Single status check
|
|
./scripts/battery-monitor.sh
|
|
|
|
# Continuous monitoring (updates every 5 seconds)
|
|
./scripts/battery-monitor.sh --watch
|
|
```
|
|
|
|
**Information displayed:**
|
|
- Battery capacity and status
|
|
- Charging/discharging time estimates
|
|
- Power consumption
|
|
- AC adapter status
|
|
- System efficiency metrics
|
|
- Power saving tips
|
|
|
|
### PowerTOP Analysis
|
|
|
|
Generate detailed power consumption reports:
|
|
|
|
```bash
|
|
# Generate 60-second HTML report
|
|
./scripts/powertop-analyze.sh
|
|
|
|
# Custom duration and format
|
|
./scripts/powertop-analyze.sh --duration 120 --format html
|
|
|
|
# Apply automatic optimizations
|
|
./scripts/powertop-analyze.sh --auto-tune
|
|
|
|
# Show latest report in browser
|
|
./scripts/powertop-analyze.sh --show-report
|
|
```
|
|
|
|
**Report formats:**
|
|
- HTML: Interactive web-based reports
|
|
- CSV: Data for spreadsheet analysis
|
|
- TXT: Plain text for terminal viewing
|
|
|
|
### TLP Manager
|
|
|
|
Comprehensive TLP configuration management:
|
|
|
|
```bash
|
|
# Show current TLP status
|
|
./scripts/tlp-manager.sh --status
|
|
|
|
# Display configuration details
|
|
./scripts/tlp-manager.sh --config
|
|
|
|
# Get optimization recommendations
|
|
./scripts/tlp-manager.sh --recommendations
|
|
|
|
# Switch power profiles
|
|
./scripts/tlp-manager.sh --profile powersave|balanced|performance
|
|
|
|
# Force battery/AC mode
|
|
./scripts/tlp-manager.sh --toggle-mode
|
|
```
|
|
|
|
## ⚙️ Configuration Details
|
|
|
|
### TLP Configuration
|
|
|
|
The optimized TLP configuration (`config/tlp.conf`) includes:
|
|
|
|
- **CPU Management**: Aggressive power saving governors
|
|
- **Disk Settings**: Optimized APM levels and timeouts
|
|
- **Graphics**: Power-efficient GPU settings
|
|
- **USB**: Smart autosuspend with device blacklists
|
|
- **Audio**: Power saving for sound devices
|
|
- **Battery Thresholds**: Smart charging limits (ThinkPad)
|
|
- **Radio Devices**: Automatic wireless management
|
|
|
|
### Key Optimizations
|
|
|
|
1. **CPU Scaling**: Uses `powersave` governor on battery
|
|
2. **Frequency Limits**: Reduces max CPU frequency on battery
|
|
3. **Turbo Boost**: Disabled on battery to save power
|
|
4. **Disk Power Management**: Aggressive APM settings
|
|
5. **USB Autosuspend**: Enabled with smart device handling
|
|
6. **Wireless Management**: Auto-disable unused radios
|
|
7. **Battery Charging**: Smart thresholds to extend battery life
|
|
|
|
## 🔧 Customization
|
|
|
|
### Modifying TLP Settings
|
|
|
|
1. Edit the configuration file:
|
|
```bash
|
|
sudo nano /etc/tlp.conf
|
|
```
|
|
|
|
2. Or modify the template and reinstall:
|
|
```bash
|
|
nano config/tlp.conf
|
|
./scripts/install.sh # Will backup and apply new config
|
|
```
|
|
|
|
### Adding Custom Optimizations
|
|
|
|
Create additional scripts in the `scripts/` directory following the existing patterns. All scripts include:
|
|
- Error handling and safety checks
|
|
- Colored output for better readability
|
|
- Comprehensive logging
|
|
- Usage instructions
|
|
|
|
## 📊 Expected Results
|
|
|
|
Typical battery life improvements:
|
|
- **Light usage**: 20-40% improvement
|
|
- **Normal usage**: 15-30% improvement
|
|
- **Heavy usage**: 10-20% improvement
|
|
|
|
Results vary based on:
|
|
- Hardware configuration
|
|
- Usage patterns
|
|
- Existing system settings
|
|
- Battery age and health
|
|
|
|
## 🔍 Troubleshooting
|
|
|
|
### Common Issues
|
|
|
|
1. **TLP not starting**: Check service status with `systemctl status tlp`
|
|
2. **PowerTOP requires sudo**: This is normal for hardware access
|
|
3. **Settings not persisting**: Ensure TLP service is enabled
|
|
4. **Conflicts with other power managers**: Disable conflicting services
|
|
|
|
### Debug Information
|
|
|
|
```bash
|
|
# Check TLP status and configuration
|
|
sudo tlp-stat
|
|
|
|
# View TLP service logs
|
|
journalctl -u tlp.service
|
|
|
|
# Test PowerTOP without changes
|
|
sudo powertop --time=10
|
|
```
|
|
|
|
### Getting Help
|
|
|
|
1. Check the logs in `/var/log/` for error messages
|
|
2. Run `tlp-stat` to see current configuration
|
|
3. Use the troubleshooting commands in each script
|
|
4. Review the official documentation:
|
|
- [TLP Documentation](https://linrunner.de/tlp/)
|
|
- [PowerTOP Guide](https://01.org/powertop/)
|
|
|
|
## 🔄 Uninstallation
|
|
|
|
To remove all components:
|
|
|
|
```bash
|
|
./scripts/uninstall.sh
|
|
```
|
|
|
|
This will:
|
|
- Restore original configurations
|
|
- Remove installed packages (with confirmation)
|
|
- Clean up created services
|
|
- Preserve your data and reports
|
|
|
|
## 🤝 Contributing
|
|
|
|
Contributions are welcome! Please:
|
|
1. Test thoroughly on your system
|
|
2. Include error handling and logging
|
|
3. Follow the existing code style
|
|
4. Update documentation as needed
|
|
|
|
## ⚠️ Disclaimer
|
|
|
|
- Test in a safe environment first
|
|
- Some optimizations may reduce performance
|
|
- Hardware compatibility may vary
|
|
- Always backup important data
|
|
- Use at your own risk
|
|
|
|
## 📜 License
|
|
|
|
This project is provided as-is for educational and practical use. Feel free to modify and distribute according to your needs.
|
|
|
|
---
|
|
|
|
**Happy power saving!** 🔋✨
|
|
|
|
For questions or issues, please check the troubleshooting section or create an issue with detailed system information. |