2014年4月1日火曜日

How to use zram

Optimizing Swap with ZRAM on Raspbian

Optimizing Swap with ZRAM on Raspbian

By default, Raspbian uses a swap file on the SD card for easy setup. While swap helps when system memory is low, using the SD card for swap can shorten its lifespan due to frequent writes and cause slower performance.

ZRAM is a solution to these issues. It’s a kernel feature that creates a compressed swap partition in RAM, improving both performance and longevity of the SD card.

Disable Default Swap Setting

sudo apt-get install chkconfig
sudo chkconfig dphys-swapfile off

Enable Swap on ZRAM

Load the ZRAM module:

sudo modprobe zram

Set a 128MB ZRAM swap space:

echo $((128*1024*1024)) | sudo tee /sys/zram0/disksize

Create the swap space on ZRAM:

sudo mkswap /dev/zram0

Enable the swap:

sudo swapon -p 10 /dev/zram0

With ZRAM enabled, your Raspberry Pi will benefit from faster swap performance and reduced SD card wear.

Enjoy optimizing your Raspberry Pi! 🚀

How to move rootfs to external usb storage

Move RootFS to External USB Storage (Bookworm)

Move RootFS to External USB Storage (Bookworm)

This guide explains how to move the root filesystem (rootfs) of a Raspberry Pi running Bookworm to an external USB storage device.

1. Prepare Your External USB Storage

sudo fdisk /dev/sdX
# Create a new partition (type Linux) and format it
sudo mkfs.ext4 /dev/sdX1

Replace /dev/sdX with the actual device name of your USB storage.

2. Mount the USB Storage

sudo mkdir /mnt/usb
sudo mount /dev/sdX1 /mnt/usb

3. Copy RootFS to USB

sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt/usb

4. Modify Boot Configuration

sudo nano /boot/cmdline.txt

Change the root= parameter to point to your USB device, e.g., root=/dev/sdX1.

5. Reboot the Raspberry Pi

sudo sync
sudo reboot

Your Raspberry Pi should now boot from the external USB storage. 🚀

2014年3月27日木曜日

CPU frequency scaling

Optimizing CPU Frequency on Raspbian

Optimizing CPU Frequency on Raspbian

Raspbian allows you to optimize CPU frequency settings to balance performance and power consumption. Adjusting CPU frequency can be useful for performance tuning or extending battery life in portable projects.

Check Current CPU Frequency

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

List Available Governors

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

Set CPU Governor to 'performance'

sudo cpufreq-set -g performance

Set Maximum CPU Frequency

sudo cpufreq-set -u 1500000

Verify Changes

cpufreq-info

Adjusting CPU frequency helps in managing your Raspberry Pi’s thermal and power efficiency. Experiment with different settings to find the optimal balance for your use case.

Happy tuning your Raspberry Pi! 🚀