How to Configure Linux Filesystems

0
84
How to Configure Linux Filesystems

Dit bericht verscheen eerder bij FOSSlife

Also, you can pass a file name as an argument, and df will report on the filesystem that contains the specified file – which could be handy if you don’t remember where a particular filesystem is mounted. Finally, a few options exist to make df more useful: ‑i reports inode usage instead of block usage of the filesystem(s); ‑l limits the report to local filesystems only; ‑‑type=<filesystem_type> and ‑‑exclude‑type=<filesystem_type> allow you to limit or exclude output to a particular filesystem type.

On discovering a nearly full filesystem, you can further explore space usage with du. Executing du </some/directory> returns a list of the disk space occupied by each subdirectory beneath </some/directory>, expressed in kilobytes. Adding the ‑a option tells du to report the space used by the files in addition to the directories.

Both commands are recursive. If you do not provide a directory as an argument to du, it reports on the current directory. The ‑c option produces a grand total in addition to individual usage statistics. Other helpful options are ‑L, which could help track down an errant large file, following all symbolic links; ‑x, which limits the scope of the search to the current filesystem only; and ‑‑max‑depth=N, which allows you to limit the number of recursive subdirectories into which you descend. This option is very helpful when dealing with a large file library.

Several utilities exist to help you get better performance out of your filesystems. The tune2fs program lets you control many parameters of ext2, ext3, and ext4 filesystems. You can set the number of mounts between automatic filesystem integrity checks with tune2fs ‑c N, set the maximum time interval between checks with tune2fs ‑i N[d|m|w] (where d, m, and w are days, months, and weeks, respectively), or add an ext3 or ext4 journal to a filesystem that does not have one with tune2fs ‑j. Additionally, you can adjust RAID parameters, journal settings, and reserved block behavior, as well as change parameters manually, such as the time last checked and number of mounts, which are usually reported automatically.

Other utilities are associated with specific filesystems. Btrfs has a separate utility for resizing filesystems (btrfs filesystem resize). The btrfs‑convert tool can migrate data from existing ext2/​3/​4 volumes to the Btrfs filesystem.

XFS also provides a defragmentation tool called xfs_fsr that can defragment a mounted XFS filesystem, and Btrfs supports defragmentation of metadata or entire filesystems. The

btrfs filesystem defragment ‑r ‑v /

command defragments the entire filesystem verbosely. No such utilities exist for ext3, but ext4 has e4defrag.

Troubleshooting

If you suspect trouble on a filesystem, you can run

fsck /a/<device>

to check and make repairs. If you run fsck with no target device specified, it will run checks sequentially on all of the filesystems in /etc/fstab.

The filesystem-specific error-checking programs – e2fsck for ext2, ext3 and ext4, btrfsck for Btrfs, and fsck.vfat for VFAT – support many of the same options, but again, the syntax may vary, so it is critical to read the man page for the filesystem checker before attempting any repairs.

When corrupted, VFAT filesystems suffer from bad clusters, bad directory pointers, and even bad file names. The fsck.vfat tool can find and correct many of these problems. Like the others, it can be called in non-interactive mode for use in scripts, and it can mark bad clusters automatically to prevent their reuse in the future. The ‑V flag tells fsck.vfat to run a second check after it has tried to correct any errors.

XFS has separate error-checking and repair utilities: xfs_check and xfs_repair (see the man pages for more on command-line options).

For ext2/​3/​4 problems, the debugfs tool lets you examine a filesystem and correct errors interactively. It can step through and work within a filesystem with commands similar to those of a typical Linux shell, such as cd, open, close, pwd, mkdir, and even chroot.
 

This article originally appeared in the Linux Shell Handbook and is republished here with permission.

Dit bericht verscheen eerder bij FOSSlife

Vorig artikelArtifical intelligence puts Microsoft Azure in top gear
Volgend artikelSpeech-to-text REST API v3.0 will be retired by 31 March 2026.