Sam Hooke

Freeing up disk space on Arch Linux

Visualising what is using up disk space §

To visualise what is taking up disk space I use qdirstat:

$ sudo pacman -S qdirstat
$ qdirstat

Launching it opens a GUI which can be used to see what is hogging disk space.

The pacman cache is taking up a significant chunk.

Clearing up the pacman cache §

To free up space from the pacman cache, use the paccache package. It used to be included by default, but is now included in the pacman-contrib package:

$ sudo pacman -S pacman-contrib

Using the -r option will by default delete all but the last 3 most recent versions of previously cached packages:

$ sudo paccache -r
==> finished: 104 packages removed (disk space saved: 555.24 MiB)

Use k to specify how many most recent versions to keep, for example to keep only the most recently cached version:

$ sudo paccache -rk1
==> finished: 612 packages removed (disk space saved: 2.45 GiB)

Further, use the u option to target only uninstalled packages in the cache. For example, to delete all cached copies of all uninstalled packages:

$ paccache -ruk0
==> finished: 58 packages removed (disk space saved: 89.48 MiB)

You could use -rk0 to delete all cached copies of all uninstalled and installed packages, but this is advised against in case you want to downgrade or re-install without downloading. However it may be helpful if all other attempts to free up disk space have not been sufficient.

Clearing up orphaned packages §

To delete orphaned packages:

$ pacman -Rns $(pacman -Qtdq)

Further commands for viewing disk usage §

To view which disks are present:

$ sudo fdisk -l
Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9F94F053-B3CD-4ADF-92A1-9272701DCB5B

Device        Start       End   Sectors  Size Type
/dev/sda1      2048   1050623   1048576  512M EFI System
/dev/sda2   1050624  42991615  41940992   20G Linux filesystem
/dev/sda3  42991616  51380223   8388608    4G Linux swap
/dev/sda4  51380224 250068991 198688768 94.8G Linux filesystem

Disk /dev/loop0: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop1: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/docker-8:2-658581-pool: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 65536 bytes / 65536 bytes

To view what file systems are currently mounted:

$ findmnt
TARGET                                SOURCE      FSTYPE      OPTIONS
/                                     /dev/sda2   ext4        rw,relatime,data=ordered
├─/proc                               proc        proc        rw,nosuid,nodev,noexec,relatime
│ └─/proc/sys/fs/binfmt_misc          systemd-1   autofs      rw,relatime,fd=27,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=12637
│   └─/proc/sys/fs/binfmt_misc        binfmt_misc binfmt_misc rw,relatime
├─/sys                                sys         sysfs       rw,nosuid,nodev,noexec,relatime
│ ├─/sys/firmware/efi/efivars         efivarfs    efivarfs    rw,nosuid,nodev,noexec,relatime
│ ├─/sys/kernel/security              securityfs  securityfs  rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/cgroup                    tmpfs       tmpfs       ro,nosuid,nodev,noexec,mode=755
│ │ ├─/sys/fs/cgroup/unified          cgroup2     cgroup2     rw,nosuid,nodev,noexec,relatime,nsdelegate
│ │ ├─/sys/fs/cgroup/systemd          cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,xattr,name=systemd
│ │ ├─/sys/fs/cgroup/blkio            cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,blkio
│ │ ├─/sys/fs/cgroup/pids             cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,pids
│ │ ├─/sys/fs/cgroup/cpu,cpuacct      cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,cpu,cpuacct
│ │ ├─/sys/fs/cgroup/net_cls,net_prio cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,net_cls,net_prio
│ │ ├─/sys/fs/cgroup/cpuset           cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,cpuset
│ │ ├─/sys/fs/cgroup/perf_event       cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,perf_event
│ │ ├─/sys/fs/cgroup/memory           cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,memory
│ │ ├─/sys/fs/cgroup/rdma             cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,rdma
│ │ ├─/sys/fs/cgroup/freezer          cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,freezer
│ │ ├─/sys/fs/cgroup/hugetlb          cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,hugetlb
│ │ └─/sys/fs/cgroup/devices          cgroup      cgroup      rw,nosuid,nodev,noexec,relatime,devices
│ ├─/sys/fs/pstore                    pstore      pstore      rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/bpf                       bpf         bpf         rw,nosuid,nodev,noexec,relatime,mode=700
│ ├─/sys/kernel/config                configfs    configfs    rw,relatime
│ └─/sys/kernel/debug                 debugfs     debugfs     rw,relatime
├─/dev                                dev         devtmpfs    rw,nosuid,relatime,size=4030284k,nr_inodes=1007571,mode=755
│ ├─/dev/shm                          tmpfs       tmpfs       rw,nosuid,nodev
│ ├─/dev/pts                          devpts      devpts      rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
│ ├─/dev/mqueue                       mqueue      mqueue      rw,relatime
│ └─/dev/hugepages                    hugetlbfs   hugetlbfs   rw,relatime,pagesize=2M
├─/run                                run         tmpfs       rw,nosuid,nodev,relatime,mode=755
│ └─/run/user/1000                    tmpfs       tmpfs       rw,nosuid,nodev,relatime,size=807204k,mode=700,uid=1000,gid=1000
├─/mnt/media                          systemd-1   autofs      rw,relatime,fd=29,pgrp=1,timeout=60,minproto=5,maxproto=5,direct,pipe_ino=12642
├─/tmp                                tmpfs       tmpfs       rw,nosuid,nodev
├─/home                               /dev/sda4   ext4        rw,relatime,data=ordered
└─/boot                               /dev/sda1   vfat        rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=

To view a (human readable) summary of disk usage:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
dev             3.9G     0  3.9G   0% /dev
run             3.9G  840K  3.9G   1% /run
/dev/sda2        20G   15G  3.6G  81% /
tmpfs           3.9G   80M  3.8G   3% /dev/shm
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           3.9G  8.0M  3.9G   1% /tmp
/dev/sda4        94G   12G   77G  14% /home
/dev/sda1       511M   41M  471M   8% /boot
tmpfs           789M  8.0K  789M   1% /run/user/1000