Skip to main content

Command Palette

Search for a command to run...

How to Troubleshoot 'Can't write to disk'?

Updated
3 min read

Disk is Full

If the disk is full, the system won’t be able to write new data. Use the df -h command to check disk usage. If the usage is at 100%, identify large files or directories using du -sh /path/to/directory and delete unnecessary files. Alternatively, clear temporary files with rm -rf /tmp/* or use log rotation tools to manage log files.

# Displays the entire file system
df -h
----------------------------------------------------------
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                       32G     0   32G   0% /dev
tmpfs                          32G     0   32G   0% /dev/shm
tmpfs                          32G   23M   32G   1% /run
tmpfs                          32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/VolGroup-lv_root  501G   95G  387G  20% /
/dev/vda1                     976M  161M  749M  18% /boot
/dev/mapper/vg01-data          40G   49M   38G   1% /opt/cloud
/dev/mapper/vg01-log          2.0T   81M  1.9T   1% /opt/cloud/logs
/dev/mapper/VolGroup-lv_log   512G  2.8G  488G   1% /var/log
/dev/mapper/VolGroup-lv_tmp   502G   68M  482G   1% /tmp
tmpfs                         6.3G     0  6.3G   0% /run/user/0
overlay                       501G   95G  387G  20% /var/lib/docker/overlay2/5d992b165f3bed9e4bfd4acea63da07aa2d4e4b5b64b3ab300e4a50e014c2ead/merged
# Displays the specified file directory, if not specified, use current folder as default
du -h
----------------------------------------------------------
8.0K    ./.docker/scan
9.4M    ./.docker/desktop/log/host
9.4M    ./.docker/desktop/log
9.4M    ./.docker/desktop
4.0K    ./.docker/run
9.4M    ./.docker
4.0K    ./.cache
4.0K    ./.local/state/rancher-desktop
8.0K    ./.local/state
12K     ./.local
4.0K    ./snap/ubuntu-desktop-installer/1286
4.0K    ./snap/ubuntu-desktop-installer/1284
4.0K    ./snap/ubuntu-desktop-installer/common
16K     ./snap/ubuntu-desktop-installer
20K     ./snap
9.5M    .

Out of Inodes

Even if there’s free disk space, you may run out of inodes (metadata for files), preventing new file creation. Check inode usage with df -i. If inodes are exhausted, delete small files or unused files to free up inodes. Use find /path/to/directory -type f to locate files for cleanup.

df -i
----------------------------------------------------------
Filesystem                      Inodes  IUsed     IFree IUse% Mounted on
devtmpfs                       8206780    556   8206224    1% /dev
tmpfs                          8210274      1   8210273    1% /dev/shm
tmpfs                          8210274   2076   8208198    1% /run
tmpfs                          8210274     18   8210256    1% /sys/fs/cgroup
/dev/mapper/VolGroup-lv_root  33357824 511777  32846047    2% /
/dev/vda1                        65536    356     65180    1% /boot
/dev/mapper/vg01-data          2621440     12   2621428    1% /opt/cloud
/dev/mapper/vg01-log         131588096     11 131588085    1% /opt/cloud/logs
/dev/mapper/VolGroup-lv_log   34078720    527  34078193    1% /var/log
/dev/mapper/VolGroup-lv_tmp   33423360     15  33423345    1% /tmp
tmpfs                          8210274      5   8210269    1% /run/user/0
overlay                       33357824 511777  32846047    2% /var/lib/docker/overlay2/5d992b165f3bed9e4bfd4acea63da07aa2d4e4b5b64b3ab300e4a50e014c2ead/merged

Read-Only System

If the filesystem is mounted as read-only, you won’t be able to write to the disk. This can happen due to filesystem errors or hardware issues. Check the mount status with mount | grep ro. Remount the filesystem as read-write using mount -o remount,rw /path/to/mount. If the issue persists, check for errors with dmesg or journalctl.

File System is Corrupted

A corrupted filesystem can prevent writes. Boot into a live system and run fsck to check and repair the filesystem (e.g., fsck /dev/vda1). Always unmount the filesystem before running fsck. If the corruption is severe, you may need to restore data from backups and reformat the partition.

Key Commands for Troubleshooting

  • df -h: Check disk space usage.

  • df -i: Check inode usage.

  • du -sh /path/to/directory: Find large files or directories.

  • df shows disk usage for entire filesystems, while du calculates disk usage for specific files and directories.

  • mount | grep ro: Check if a filesystem is read-only.

  • mount -o remount,rw /path/to/mount: Remount as read-write.

  • fsck /dev/sdX1: Check and repair a filesystem.

  • dmesg: View kernel messages for errors.

  • journalctl: Examine system logs for issues.

4 views

More from this blog

Clarence's Blog

56 posts

I share insights on programming, web development, cloud computing, computer networks, and AI, alongside financial knowledge, reading notes, and reflections on business and entrepreneurship.