Monitoring and Managing Your Raspberry Pi’s File System Space
In this article, we will explore how to check the storage space of your Raspberry Pi running Raspbian OS. We’ll learn about different types of file systems and how to identify them, as well as how to …
Updated September 18, 2023
In this article, we will explore how to check the storage space of your Raspberry Pi running Raspbian OS. We’ll learn about different types of file systems and how to identify them, as well as how to monitor and manage free space on your SD card.
Raspberry Pi is a small, low-cost computer used for various projects and applications that require high-performance computing. To ensure optimal performance and stability, it’s essential to keep an eye on the storage space available on your Raspberry Pi. In this article, we will explore how to check the storage space of your Raspberry Pi running Raspbian OS (the official operating system for Raspberry Pi).
There are two types of file systems on a Raspberry Pi: root and boot. The root file system is where most of the operating system files are stored, including system binaries, libraries, and user data. The boot file system contains the kernel and device tree, which are essential for starting up the Raspberry Pi and loading the root file system.
- Checking File System Types: To identify the type of file systems on your Raspberry Pi, open a terminal window and run the following command:
df -Th
This will display information about each mounted file system, including its type (ext4 for root and vfat for boot), size, used space, available space, and mount point. For example:
Filesystem Type Size Used Avail Use% Mounted on
/dev/root ext4 15G 8.7G 6.0G 59% /
devtmpfs devtmpfs 234M 0 234M 0% /dev
tmpfs tmpfs 47M 8.0K 47M 1% /run
/dev/mmcblk0p1 vfat 253M 6.1M 241M 3% /boot
In this example, /dev/root
is the root file system with ext4 type and /dev/mmcblk0p1
is the boot file system with vfat type.
- Monitoring Storage Space:
To monitor storage space on your Raspberry Pi, you can use the
df
command along with the-h
option for a human-readable output and the-x
option to exclude temporary filesystems like tmpfs and devtmpfs:
df -hx
This will display information about each mounted file system, including total space, used space, available space, and percentage of used space:
Filesystem Size Used Avail Use% Mounted on
/dev/root 15G 2.4G 12G 17% /
/dev/mmcblk0p1 253M 6.1M 241M 3% /boot
You can also monitor the storage space for a specific file system by specifying its mount point:
df -hx /media/pi/USBDRIVE
Replace /media/pi/USBDRIVE
with the actual mount point of your USB drive or other storage device.
- Managing Storage Space: If you find that your Raspberry Pi has low storage space, there are several ways to free up some space:
- Remove unnecessary files: Use the
du
command to identify large files and folders that can be safely deleted. For example, rundu -sh ~/*
to list the size of all files and folders in your home directory. - Cleanup apt cache: The package manager on Raspbian OS stores downloaded packages in
/var/cache/apt/archives
. You can free up space by runningsudo apt clean
. - Remove old kernel images: If you have multiple kernel images installed, you can remove the older ones using the
sudo rpi-update
command. - Enable swap: If your Raspberry Pi frequently runs out of memory, enabling swap space on an external storage device like a USB drive can help prevent crashes. To enable swap, follow these steps:
- Create a swap file using
dd
:sudo dd if=/dev/zero of=/path/to/swapfile bs=1M count=512
(replace/path/to/swapfile
with the desired location and size) - Make it a swap partition:
sudo mkswap /path/to/swapfile
- Enable the swap file:
sudo swapon /path/to/swapfile
- To make the change permanent, add the following line to
/etc/fstab
:/path/to/swapfile none swap sw 0 0
- Reboot your Raspberry Pi for changes to take effect:
sudo reboot
- Create a swap file using
By regularly monitoring and managing storage space on your Raspberry Pi, you can ensure optimal performance and prevent system issues related to insufficient disk space. Remember that low storage space can lead to system instability and even data loss, so it’s essential to keep an eye on it and take action when necessary.