Server Management (Unmanaged)

Comprehensive Guide to Linux File System Management

By the Domain India teamPublished 8 min read
Knowledge base article
Contents (9 sections)

Most Linux server emergencies start with the disk: a full filesystem stops databases and mail, a filesystem error after a crash stops the server booting, and wrong permissions break websites or open them to attack. This guide covers the commands you need to watch disk space, find what is using it, check and repair filesystems, add a new disk, and set ownership and permissions correctly.

Key takeaways

Use df -hT and df -i to see space and inodes, and du or ncdu to find what is filling the disk. Check a filesystem only when it is unmounted: e2fsck for ext4, xfs_repair for XFS, with a dry run first. Mount new disks by UUID in /etc/fstab and test with findmnt --verify before you reboot. For websites, directories are usually 755 and files 644; never use 777.

Where these commands run

Everything here is for a VPS or server where you have root access. On shared hosting you can't partition disks or run filesystem checks; section 8 covers what you can do there instead.

1. See how much space is left

bash
df -hT        # size, used, free and type of every mounted filesystem
df -i         # inodes: the number of files a filesystem can still hold
findmnt       # what is mounted where, as a tree

A filesystem can report "No space left on device" while df -h still shows free space. That means it has run out of inodes, usually because of millions of tiny files such as PHP sessions, cache fragments or mail in a queue. df -i shows it straight away.

2. Find what is using the space

bash
sudo du -xh --max-depth=1 / | sort -h            # biggest top-level folders, this filesystem only
sudo du -xh --max-depth=1 /var | sort -h         # then drill down
sudo find / -xdev -type f -size +500M -exec ls -lh {} \;   # single large files

ncdu (install it from your distribution's packages) does the same interactively and lets you delete as you go. The usual suspects on a web server:

LocationWhat fills itSafe fix
/var/logOld or runaway logsFix the noisy service, then sudo journalctl --vacuum-size=500M and logrotate
/var/lib/mysqlDatabases, binary logsPurge old binary logs from MySQL; never delete data files by hand
/var/lib/dockerOld images and containersdocker system prune after checking what it will remove
/home or /var/wwwBackups left in the web rootMove them off the server
/tmpAbandoned uploads and sessionsRemove files older than a few days

If df still shows the disk full after you deleted a big file, a running process is holding it open. sudo lsof +L1 lists deleted-but-open files; restart that service to free the space.

3. List disks and partitions

bash
lsblk -f      # disks, partitions, filesystem type, label, UUID and mount point
sudo blkid    # UUIDs and types, for /etc/fstab

On a KVM VPS the disk is usually vda (partitions vda1, vda2); on other systems it may be sda or nvme0n1. Read the output carefully before you run anything that writes to a device.

4. Check and repair a filesystem

Never check a mounted filesystem

Running a repair on a mounted filesystem can destroy data. Unmount it first. The root filesystem can only be checked at boot or from a rescue system. Take a backup of anything you can still read before you repair.

ext4. Do a read-only check first, then repair:

bash
sudo umount /data
sudo e2fsck -fn /dev/vdb1     # -n: report only, change nothing
sudo e2fsck -fy /dev/vdb1     # -y: fix, answering yes to every question

XFS (the default on AlmaLinux and Rocky Linux) uses its own tool; fsck does nothing on XFS:

bash
sudo umount /data
sudo xfs_repair -n /dev/vdb1  # dry run
sudo xfs_repair /dev/vdb1     # repair

If xfs_repair refuses because of a dirty log, mount and unmount the filesystem once to replay the log. xfs_repair -L throws the log away and can lose recent changes: use it only as a last resort.

The root filesystem. On systemd distributions, add fsck.mode=force to the kernel command line for one boot, or check from a rescue system. Most distributions also check the root filesystem automatically at boot after an unclean shutdown.

5. Add a new disk or partition

  1. Create a partition table and partition.
    sudo parted /dev/vdb --script mklabel gpt mkpart data 0% 100% (or use fdisk interactively).
  2. Make the filesystem.
    sudo mkfs.ext4 /dev/vdb1 or sudo mkfs.xfs /dev/vdb1.
  3. Mount it.
    sudo mkdir -p /data && sudo mount /dev/vdb1 /data
  4. Add it to /etc/fstab by UUID.
    Get the UUID with blkid, then add a line like UUID=your-uuid /data ext4 defaults,nofail 0 2. nofail lets the server boot even if this disk is missing.
  5. Test before rebooting.
    sudo findmnt --verify and sudo mount -a. An fstab mistake can stop the server booting.

On a VPS, extra space usually comes from moving to a bigger plan, which grows the existing disk. You then grow the partition and filesystem instead of creating a new one; Cloning and resizing your VPS shows how with growpart, resize2fs and xfs_growfs.

6. Ownership and permissions

Every file has an owner, a group, and permissions for the owner (u), the group (g) and everyone else (o).

NumberMeaningTypical use
755Owner all; group and others read and enterDirectories, scripts
644Owner read and write; others readWeb files, images, HTML, PHP
600Owner only, read and writeConfig files with passwords, SSH keys
700Owner only, everythingPrivate scripts and folders, ~/.ssh
bash
sudo chown -R www-data:www-data /var/www/example   # owner:group (nginx/apache user varies by distribution)
chmod 640 wp-config.php                             # numeric
chmod u+x deploy.sh                                 # symbolic: add execute for the owner
find /var/www/example -type d -exec chmod 755 {} +  # directories
find /var/www/example -type f -exec chmod 644 {} +  # files

Avoid chmod -R 755 on a whole site: it makes every file executable. Use the two find commands instead. And never use 777; it lets any process on the server change your files, which is how many hacked sites get infected.

7. Keep the disk healthy

  • Set up log rotation for every application log you create.
  • Alert yourself when a filesystem passes about 80% full, before it becomes an outage.
  • Keep backups off the server, not in the web root or on the same disk.
  • After a crash or forced restart, read journalctl -b -p err for filesystem errors.

8. On shared hosting

On shared hosting (cPanel, DirectAdmin, Webuzo) the server's disks are managed for you. You can still:

9. Where Domain India fits

A Domain India VPS gives you the root access these commands need, on KVM with NVMe storage. It is self-managed, so disk health and backups are yours to look after, and support helps with anything outside the server, such as a forced restart. Live price, excluding 18% GST:

VPS Starter
₹552.65/mo + GST
  • 1 vCPU
  • 2 GB DDR4 RAM
  • 64 GB NVMe SSD Storage
  • 2 TB Monthly Bandwidth
See plan details
How do I check disk space on a Linux server?

Run df -hT to see the size, used space, free space and type of each mounted filesystem, and df -i to see inode usage. Use du or ncdu to find which folders are using the space.

Why does Linux say no space left when df shows free space?

The filesystem has run out of inodes, the entries that record each file. Run df -i to confirm, then find and remove the folder holding millions of small files, such as old sessions or cache files.

Can I run fsck on a mounted filesystem?

No. Checking or repairing a mounted filesystem can destroy data. Unmount it first, or check the root filesystem at boot or from a rescue system.

How do I check an XFS filesystem?

Unmount it, run xfs_repair -n for a read-only check, then xfs_repair to fix it. The fsck command does not repair XFS.

What permissions should website files have?

Usually 755 for directories and 644 for files, with 600 or 640 for configuration files that hold passwords. Never use 777.

Can I run these commands on shared hosting?

Partitioning and filesystem checks need root access, so they only work on a VPS or your own server. On shared hosting you can check disk usage in the control panel and change permissions in the File Manager or over jailed SSH, which support enables on request.

Ready to manage your own server? Read the Linux shell commands guide, compare VPS plans, or open a ticket if a disk problem on your server needs our help.

Get a server of your own

KVM VPS plans with full root access, NVMe storage and a choice of Linux operating system.

See VPS plans

Ready when you are

Get VPS from ₹552.65/mo + GST

See plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app