๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป๊ฐœ๋ฐœ

Linux CLI ํ™˜๊ฒฝ์—์„œ ๋ฐฐํ„ฐ๋ฆฌ ์ˆ˜๋ช… ์—ฐ์žฅ ๋ฐฉ๋ฒ•

by ๋ˆˆ๋ˆ„ :) 2024. 11. 25.

Linux CLI ํ™˜๊ฒฝ์—์„œ ๋…ธํŠธ๋ถ์˜ ๋ฐฐํ„ฐ๋ฆฌ ๋ณดํ˜ธ ๋ชจ๋“œ๋ฅผ ์ง์ ‘ ํ™œ์„ฑํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋…ธํŠธ๋ถ ์ œ์กฐ์‚ฌ๊ฐ€ ์ œ๊ณตํ•˜๋Š” ํ•˜๋“œ์›จ์–ด ์„ค์ •์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ผ๋ฐ˜์ ์œผ๋กœ ๋ฐฐํ„ฐ๋ฆฌ ๋ณดํ˜ธ ๋ชจ๋“œ๋Š” ํŠน์ • ์ œ์กฐ์‚ฌ์˜ BIOS ์„ค์ •์ด๋‚˜ ์ „์šฉ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ํ†ตํ•ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿฌ๋‚˜ ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ์ด Linux์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณต๋˜์ง€ ์•Š์„ ๊ฒฝ์šฐ,

์•„๋ž˜์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ๋น„์Šทํ•œ ํšจ๊ณผ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

 

 


 

1. ๋ฐฐํ„ฐ๋ฆฌ ์ถฉ์ „ ์ž„๊ณ„๊ฐ’ ์„ค์ •

์ผ๋ถ€ ๋…ธํŠธ๋ถ์€ Linux์—์„œ ACPI(Advanced Configuration and Power Interface) ์ปค๋„ ๋ชจ๋“ˆ์„ ํ†ตํ•ด **์ถฉ์ „ ์ž„๊ณ„๊ฐ’(Charge Threshold)**์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฐฐํ„ฐ๋ฆฌ๊ฐ€ 80% ์ด์ƒ ์ถฉ์ „๋˜์ง€ ์•Š๋„๋ก ์„ค์ • ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ ์šฉ ๊ฐ€๋Šฅ ๋ชจ๋ธ:

  • Lenovo ThinkPad
  • ์ผ๋ถ€ Dell ๋ฐ ASUS ๋…ธํŠธ๋ถ
  • ๊ธฐํƒ€ ACPI ์ง€์› ๋ชจ๋ธ

์„ค์ • ๋ฐฉ๋ฒ•:

  1. ACPI ๋ชจ๋“ˆ ํ™•์ธcharge_control_end_threshold ๋˜๋Š” ์œ ์‚ฌํ•œ ํŒŒ์ผ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  2.  
  3.  
    ์ฝ”๋“œ ๋ณต์‚ฌ
    ls /sys/class/power_supply/BAT0/
  4. bash
  5. ์ถฉ์ „ ์ž„๊ณ„๊ฐ’ ์„ค์ •์œ„ ๋ช…๋ น์€ ๋ฐฐํ„ฐ๋ฆฌ๊ฐ€ 80% ์ด์ƒ ์ถฉ์ „๋˜์ง€ ์•Š๋„๋ก ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.
  6. bash
    ์ฝ”๋“œ ๋ณต์‚ฌ
    echo 80 | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
  7. ์˜๊ตฌ ์„ค์ • rc.local์ด๋‚˜ udev ๊ทœ์น™์„ ํ†ตํ•ด ๋ถ€ํŒ… ์‹œ ์ž๋™์œผ๋กœ ์„ค์ •๋˜๋„๋ก ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  8. bash
    ์ฝ”๋“œ ๋ณต์‚ฌ
    echo 'echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold' | sudo tee -a /etc/rc.local

 


 

2. ์ถฉ์ „๊ธฐ ์ž๋™ ์ œ์–ด ์Šคํฌ๋ฆฝํŠธ

๋ฐฐํ„ฐ๋ฆฌ ๋ณดํ˜ธ ๋ชจ๋“œ๊ฐ€ ํ•˜๋“œ์›จ์–ด์ ์œผ๋กœ ์ง€์›๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ, ์ถฉ์ „๊ธฐ๋ฅผ ์ˆ˜๋™์œผ๋กœ ์ œ์–ดํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์ž‘๋™ ์›๋ฆฌ:

  • ํ˜„์žฌ ๋ฐฐํ„ฐ๋ฆฌ ์ถฉ์ „ ์ƒํƒœ๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ํ™•์ธํ•˜์—ฌ, ์ถฉ์ „๋Ÿ‰์ด ์ผ์ • ์ˆ˜์ค€์— ๋„๋‹ฌํ•˜๋ฉด ์ถฉ์ „๊ธฐ๋ฅผ ๊บผ๋ƒ…๋‹ˆ๋‹ค.
  • ๋ฐฐํ„ฐ๋ฆฌ ์ถฉ์ „์ด 20% ์ดํ•˜๋กœ ๋–จ์–ด์ง€๋ฉด ๋‹ค์‹œ ์ถฉ์ „๊ธฐ๋ฅผ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

์Šคํฌ๋ฆฝํŠธ ์ž‘์„ฑ:

#!/bin/bash 
# ์ถฉ์ „ ์ž„๊ณ„๊ฐ’
MAX_CHARGE=80 MIN_CHARGE=20 
# ๋ฐฐํ„ฐ๋ฆฌ ์ƒํƒœ ํŒŒ์ผ(ACPI ์ •๋ณด ๊ฒฝ๋กœ)
BATTERY_CAPACITY_PATH="/sys/class/power_supply/BAT0/capacity" BATTERY_STATUS_PATH="/sys/class/power_supply/BAT0/status" while true; do 
# ํ˜„์žฌ ๋ฐฐํ„ฐ๋ฆฌ ์šฉ๋Ÿ‰ ์ฝ๊ธฐ
CURRENT_CAPACITY=$(cat "$BATTERY_CAPACITY_PATH") CURRENT_STATUS=$(cat "$BATTERY_STATUS_PATH") if [[ "$CURRENT_STATUS" == "Charging" && "$CURRENT_CAPACITY" -ge $MAX_CHARGE ]]; then echo "์ถฉ์ „๊ธฐ ๋ถ„๋ฆฌ ๊ถŒ์žฅ: ๋ฐฐํ„ฐ๋ฆฌ๊ฐ€ $MAX_CHARGE% ์ด์ƒ์ž…๋‹ˆ๋‹ค." elif [[ "$CURRENT_STATUS" == "Discharging" && "$CURRENT_CAPACITY" -le $MIN_CHARGE ]]; then echo "์ถฉ์ „๊ธฐ ์—ฐ๊ฒฐ ๊ถŒ์žฅ: ๋ฐฐํ„ฐ๋ฆฌ๊ฐ€ $MIN_CHARGE% ์ดํ•˜์ž…๋‹ˆ๋‹ค." fi 
# 5๋ถ„ ์ฃผ๊ธฐ๋กœ ํ™•์ธ
sleep 300 done

 

์‹คํ–‰ ๋ฐฉ๋ฒ•:

  1. ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ €์žฅํ•˜๊ณ  ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ:
    bash
    ์ฝ”๋“œ ๋ณต์‚ฌ
    chmod +x battery_manager.sh ./battery_manager.sh
  2. ์„œ๋ฒ„์—์„œ ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์‹คํ–‰:
    bash
    ์ฝ”๋“œ ๋ณต์‚ฌ
    nohup ./battery_manager.sh &
     

 

3. BIOS ์—…๋ฐ์ดํŠธ ๋ฐ ์ œ์กฐ์‚ฌ ํˆด ํ™•์ธ

๋ฐฐํ„ฐ๋ฆฌ ๋ณดํ˜ธ ๋ชจ๋“œ๋Š” BIOS๋‚˜ ํŽŒ์›จ์–ด ์—…๋ฐ์ดํŠธ๋ฅผ ํ†ตํ•ด ํ™œ์„ฑํ™”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์„ ํ™•์ธํ•˜์„ธ์š”:

  • ์ œ์กฐ์‚ฌ ๊ณต์‹ ์ง€์› ํŽ˜์ด์ง€์—์„œ ์ตœ์‹  BIOS/ํŽŒ์›จ์–ด๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”.
  • ์ผ๋ถ€ ์ œ์กฐ์‚ฌ๋Š” Linux์šฉ ์ „์šฉ ์œ ํ‹ธ๋ฆฌํ‹ฐ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. (์˜ˆ: tlp ๋˜๋Š” thinkpad_acpi ๋“ฑ)

 


 

4. TLP(Thermal Power Management) ์‚ฌ์šฉ

TLP๋Š” Linux์—์„œ ์ „๋ ฅ ๊ด€๋ฆฌ๋ฅผ ์ตœ์ ํ™”ํ•˜๋Š” ๋„๊ตฌ๋กœ, ๋ฐฐํ„ฐ๋ฆฌ ๋ณดํ˜ธ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์„ค์น˜ ๋ฐ ์„ค์ •:

  1. TLP ์„ค์น˜ (Ubuntu ์˜ˆ์‹œ):
  2.  
    ์ฝ”๋“œ ๋ณต์‚ฌ
    sudo apt install tlp
  3. bash
  4. ๋ฐฐํ„ฐ๋ฆฌ ๋ณดํ˜ธ ์„ค์ •: /etc/tlp.conf ํŒŒ์ผ์„ ์—ด๊ณ , ๋‹ค์Œ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ ๋˜๋Š” ์ˆ˜์ •:
  5. bash
    ์ฝ”๋“œ ๋ณต์‚ฌ
    START_CHARGE_THRESH_BAT0=20 STOP_CHARGE_THRESH_BAT0=80
  6. TLP ์žฌ์‹œ์ž‘:
  7. bash
    ์ฝ”๋“œ ๋ณต์‚ฌ
    sudo systemctl restart tlp

์ƒํƒœ ํ™•์ธ:

TLP๊ฐ€ ์ ์šฉ ์ค‘์ธ์ง€ ํ™•์ธ:

bash
์ฝ”๋“œ ๋ณต์‚ฌ
sudo tlp-stat -b

 


 

5. ๋ฌผ๋ฆฌ์  ํ•ด๊ฒฐ์ฑ…

  • ๋ฐฐํ„ฐ๋ฆฌ ๋ถ„๋ฆฌ: ๋ฐฐํ„ฐ๋ฆฌ๊ฐ€ ์ฐฉํƒˆ์‹์ด๋ผ๋ฉด ์™„์ „ํžˆ ๋ถ„๋ฆฌํ•˜๊ณ , ์–ด๋Œ‘ํ„ฐ๋งŒ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • ํƒ€์ด๋จธ ํ”Œ๋Ÿฌ๊ทธ: ์ผ์ • ์‹œ๊ฐ„ ์ดํ›„ ์ „์›์„ ์ฐจ๋‹จํ•˜๋Š” ํƒ€์ด๋จธ ํ”Œ๋Ÿฌ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฌผ๋ฆฌ์ ์œผ๋กœ ์ถฉ์ „์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

 


 

์š”์•ฝ

  1. ACPI๋ฅผ ํ™œ์šฉํ•œ ์ถฉ์ „ ์ž„๊ณ„๊ฐ’ ์„ค์ •: ๊ฐ€์žฅ ํšจ๊ณผ์ ์ด๊ณ  ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•.
  2. TLP ์‚ฌ์šฉ: ์‹œ์Šคํ…œ ์ „๋ฐ˜์˜ ์ „๋ ฅ ๊ด€๋ฆฌ ์ตœ์ ํ™”.
  3. ์ถฉ์ „๊ธฐ ์ œ์–ด ์Šคํฌ๋ฆฝํŠธ: ํ•˜๋“œ์›จ์–ด ์ œ์•ฝ์„ ๊ทน๋ณตํ•˜๊ธฐ ์œ„ํ•œ ๋Œ€์•ˆ.
  4. BIOS ์—…๋ฐ์ดํŠธ ํ™•์ธ: ํ•˜๋“œ์›จ์–ด ์ œ์กฐ์‚ฌ๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์†”๋ฃจ์…˜ ํ™œ์šฉ.

์ด ์ค‘ ACPI ๋ชจ๋“ˆ์ด ์ง€์›๋œ๋‹ค๋ฉด ๊ฐ€์žฅ ์ง๊ด€์ ์ด๊ณ  ํ™•์‹คํ•œ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.