Chapter 4: Linux Advanced Commands
4.8 Disk and storage commands
Friends, if the No space left on device error hits during the Amul-style dairy's Diwali order rush, the orders stop. So make it a habit to look at df -h and du -sh every day.
मित्रांनो, No space left on device हा एरर Amul-स्टाइल डेअरीच्या दिवाळी ऑर्डर्सच्या गर्दीत आला तर ऑर्डर्स थांबतात. म्हणून df -h आणि du -sh रोज बघायची सवय ठेवा.
दोस्तों, No space left on device वाला एरर Amul-स्टाइल डेयरी की दिवाली ऑर्डर्स की भीड़ में आया तो ऑर्डर्स रुक जाते हैं. इसलिए df -h और du -sh रोज़ देखने की आदत रखो.
# Read-only Linux inventory on this host
df -hT . # filesystem capacity and type for the current directory
df -i . # inode counts for that filesystem, when reported
findmnt --target . --output TARGET,SOURCE,FSTYPE
lsblk --output NAME,TYPE,SIZE,FSTYPE,UUID,MOUNTPOINTS
# Size of a particular directory you have permission to inspect
du -sh .
free -h # memory, a separate resource/etc/fstab format. This is a fictional row for reading practice. Its UUID is a placeholder.
# <device> <mount point> <type> <options> <dump> <fsck>
UUID=00000000-0000-0000-0000-000000000123 /data ext4 defaults,nofail 0 2
Ravindra Bagale's Tip
For an authorized fstab change, keep a copy of the original. Confirm the source filesystem, its identifier, and the target. Verify the candidate with findmnt --verify --tab-file and use an approved test of the intended mount before relying on it.
Ravindra Bagale's Tip – मराठी
fstab बदलण्याची परवानगी असेल तर मूळ फाइलची प्रत ठेवा. Source filesystem, त्याचा identifier आणि target तपासा. findmnt --verify --tab-file ने candidate तपासा आणि फक्त अपेक्षित mount साठी मंजूर चाचणी वापरा.
Ravindra Bagale's Tip – हिंदी
fstab बदलने की अनुमति हो तो मूल फ़ाइल की एक प्रति रखें। Source filesystem, उसका identifier और target जाँचें। findmnt --verify --tab-file से candidate जाँचें और इच्छित mount के लिए स्वीकृत परीक्षण करें।
Lab
खाली दिलेल्या workshop lab मध्ये df ने scratch directory चा filesystem तपासा. मग du ने दोन directories ची जागा मोजा आणि sparse file चे logical bytes आणि allocation वेगवेगळे नोंदवा.
Locate the place that cannot accept a new file
The Mauli workshop saves each inspected batch's worksheet on a Linux server. An operator tries to upload a new file and receives a message that there is no space left on the device. Another person sees plenty of space beside a different drive in a terminal and concludes that the message must be wrong. They may both be looking at real evidence. The upload writes to one particular path. That path can be on a different filesystem from the one with free space. Identify the exact output path and the account doing the writing before estimating what the machine can store.
A block device gives the operating system access to numbered blocks of storage. An attached EBS volume on an EC2 Linux instance is one example. A physical or virtual drive can hold a partition table dividing it into portions. A partition is a defined range within the device and can itself be used as a block device. A filesystem is an arrangement of file content, directory names, and metadata that makes the storage usable as paths. A filesystem can be on a partition, on an entire device, or on another storage layer. Device size, partition size, and filesystem size answer different questions, even when the values happen to agree.
A mount attaches the view of a filesystem to a location within the site's directory tree. That location is called the mount point. A path such as /data/worksheets/today.txt can refer to the filesystem mounted at /data. If that mounted filesystem is missing, the same path might instead refer to a directory on the parent's filesystem, provided the directory exists there. For the workshop this difference is critical. An application meant to write to a data volume can fill the root disk if the planned data mount was absent and a writable path was already present. Seeing a directory exists is insufficient evidence of a mounted data volume.
In the exercise you will distinguish three views. The first is the mounted filesystem's space accounting for an output path. The second is the amount a collection of ordinary files and folders appears to use. The third is the device and filesystem layout behind those paths. df helps with the first, du with the second, and findmnt and lsblk with the third. Read the observation each tool gives you before deciding whether its value contradicts another command. Many apparent contradictions come from comparing different layers.
Use Bash and a Linux lab with standard utilities and Python 3 for a later file lifetime example. The commands operate on newly generated files under one private temporary directory. They do not format or write any block device, mount or unmount anything, install software, or resize an AWS volume. The portable file operations can also be practiced on other Unix-like systems. The explicit Linux-only inventory commands require the util-linux tools and the filesystem layout on that Linux host.
Read space available to the actual destination
Start with a scratch directory and two subdirectories named after kinds of workshop files. The first capacity query is for the scratch directory on your machine, so it gives a real observation even though the exercise data is synthetic. The -h display abbreviates sizes in units suitable for reading. The -k display expresses counts in units of 1024 bytes on the GNU and usual Unix implementations used here. For comparing a pair of measurements, use a consistent unit and a clearly known path.
disk_lab=$(mktemp -d) || exit 1
printf 'Lab directory: %s\n' "$disk_lab"
mkdir "$disk_lab/worksheets" "$disk_lab/logs"
df -h "$disk_lab"
df -k "$disk_lab"
Filesystem Size Used Avail Use% Mounted on
/dev/example 8.0G 7.5G 500M 94% /
The example is a human-readable illustration. Your report contains real device or filesystem names, sizes, and a mount point. A filesystem might be named after a mapped device, a service export, a memory-backed filesystem, or another source. With a path argument, df asks for information about the mounted filesystem serving that path. If you use a bare command with no path, many other mounts can appear in the display. That broad view can orient you, while the path-specific view directly tests the intended destination.
Read available space as a budget for ordinary use. Depending on the filesystem and its settings, some space can be reserved for privileged operations or used internally for bookkeeping. Used plus available need not exactly match the total in a rounded display. A near-full number tells you little about which folder is growing. It also reflects the time you ran the command, and other processes may continue writing. If you plan a large transfer, leave room for changes during the transfer and any temporary copies it needs instead of relying on the last displayed megabyte.
Imagine df -h / gives 500 MiB available and df -h /data gives 80 GiB available. An upload path actually under the mounted data filesystem can use its own availability. An application that first creates a 900 MiB temporary copy under /tmp on the root filesystem can fail before it moves the final file. Trace every path the application writes, including temporary storage, spool files, logs, and final outputs. A local test using a tiny file under one location may succeed without reproducing the actual space requirement.
On Linux with GNU df, df -hT "$disk_lab" includes filesystem type. Use it when the type affects a decision, for example differentiating ext4 and XFS before reading a resize procedure. A memory-backed filesystem can also appear as a mounted filesystem. The memory information reported by free -h is another layer. Available process memory and free space on a block-backed filesystem are different resources. Treat a memory pressure message and a filesystem allocation error as separate observations, even on a machine where both resources are important.
An error reporting no space can occur even when some data blocks are available. A filesystem such as ext4 can run out of inodes, which are structures holding each file's metadata and references to its content. Many tiny files can consume many such slots while using little data space. On a filesystem that exposes inode totals, df -i "$disk_lab" shows inode usage. Find the columns for total, used, and free inodes and interpret them only for the filesystem containing the failed write. A single directory can be the source of many files but df -i still reports a filesystem-level total. Other filesystem designs may not have a fixed inode count to report in the same way.
When comparing a space budget with a measured file, convert to the same unit before making the decision. On GNU df, -h uses powers of 1024 and -H uses powers of 1000, with rounded output. A MiB is 1048576 bytes, while a decimal MB is 1000000 bytes. The training write of 1048576 bytes is one MiB. An application limit described only as MB can be ambiguous if you are comparing it with tools that use another convention. Keep exact byte counts when a difference of a few percent matters, and give the units beside the numbers in the report.
For a concrete estimate, 51200 KiB available is 52428800 bytes, or 50 MiB. Suppose the writer needs a 30 MiB staged file and a second 30 MiB complete copy on that same filesystem before it removes the first. The peak can reach 60 MiB of fresh data, plus bookkeeping, although the finished file alone fits. If both names actually refer to one file after an in-filesystem rename, that particular peak estimate would differ. Trace the writer's real behavior before quoting a budget. The capacity command measures availability at a moment, while the write sequence determines the peak demand.
Measure the directories you actually own
The workshop wants to know whether inspection forms or log history are taking more room in an existing directory. Create a tiny representative tree to practice. A short worksheet supplies the training content. An ordinary file of one million forty-eight thousand five hundred seventy-six zero bytes stands for a larger log. The log name is under the newly generated scratch directory. Use the complete output path as shown, because dd writes directly to the destination given by of=. Here the destination is just a new regular file. The input /dev/zero is a harmless source of zero bytes, and the byte count bounds the write to one MiB.
printf '%s\n' 'Station A checked' 'Station B checked' > "$disk_lab/worksheets/today.txt"
dd if=/dev/zero of="$disk_lab/logs/inspection.bin" bs=4096 count=256 \
2> "$disk_lab/log-write.txt"
cat "$disk_lab/log-write.txt"
du -sk "$disk_lab/worksheets" "$disk_lab/logs" | sort -n
wc -c < "$disk_lab/logs/inspection.bin"
The logical file length should be 1048576 bytes, calculated as 4096 times 256. The dd report exposes whether it wrote the planned blocks, and the final byte count checks the actual result. The usage numbers from du vary with the filesystem. On a typical filesystem with ordinary allocated blocks, the log directory appears larger. If an implementation compresses or otherwise represents the zeros differently, an estimated allocation can be lower. In either case read the size measurement that answers your question, and enable a content check when you need to know byte length.
du walks the paths given and estimates their file space use. With -s it prints a summary for each argument, and with -k its displayed units are KiB. Sorting the two numeric lines gives a comparison without relying on abbreviated human-readable units. A directory's total can include its own bookkeeping and the allocated space of descendants. It can be affected by changes during the walk or paths your account cannot read. Diagnostics belong with the observation. Hiding those messages with a discard redirect does not make an incomplete walk accurate.
GNU du has a --max-depth=1 option for a directory with more subdirectories. Use it on a specific tree you have authorized to examine. It prints totals for the directory and immediate children that it traverses, even though each child's total can include deeper descendants. It does not count just files at that depth. The outer total contains the child data, so adding the outer total to every child would double-count. The command below also applies -x, which constrains the traversal by filesystem. That can be helpful for an application tree with nested mounts and a question about usage on one filesystem.
du -x -k --max-depth=1 "$disk_lab" | sort -n
On a GNU Linux environment you should see lines for both named subdirectories and the entire scratch tree. If you are using a different du implementation, read its local help for depth syntax. Do not start with a complete recursive walk of a production server when the failed output supplies a narrower starting point. A broad scan can include separate network mounts, virtual filesystems, unrelated users' files, or heavy activity. Compare the specific path's filesystem first, then inspect the approved directories on that filesystem.
A directory traversal typically sees names that still exist when it visits them. Extra filesystem use may come from areas outside your search, filesystem metadata, snapshots, retained blocks, or files whose last name was removed while a process kept them open. That is one reason the sum of a few sorted directory results can be lower than overall filesystem use. A complete reconciliation can require filesystem-specific tools. The next two experiments focus on differences you can see on an ordinary small fixture without filling any disk.
Compare length, allocation, and distinct file identities
A file's apparent size describes its logical length. Many applications see bytes from offset zero through that length. Allocated space describes how much storage the filesystem associates with storing the file, under that filesystem's implementation. A sparse file contains holes, which are regions that can read as zeros without having a stored block for each position. Create one small example by extending a newly named regular file to the same nominal size as the dense simulation. Avoid applying this command to existing data. Shrinking an existing file with truncate can discard its tail.
truncate -s 1048576 "$disk_lab/worksheets/sparse.bin"
printf 'logical bytes of sparse file: '
wc -c < "$disk_lab/worksheets/sparse.bin"
du -k "$disk_lab/worksheets/sparse.bin" "$disk_lab/logs/inspection.bin"
The sparse file should read as 1048576 bytes. On a local filesystem supporting sparse files, its allocation display will often be zero or much lower than the ordinary written file's. The exact numbers depend on filesystem storage and rounding. If both appear to use the same amount, report that outcome and the filesystem type. A size difference is useful evidence about this environment's representation, not a required property of every filesystem. On GNU systems you can also use du --apparent-size to ask for logical size and du -b for apparent byte size. In this exercise wc -c supplies a simple independent length observation.
A hard link is another directory name for the same underlying file identity. If a second name is made for the already written log, there need not be a second copy of its content blocks. Both names refer to the same inode on the same filesystem. The next block uses ln without the symbolic option to make that second name. The ls -li display shows the inode numbers for comparison within this one filesystem. It also includes the count of hard links in its long display. These numbers are expected to match at the start of each of the two output lines, while the paths differ.
ln "$disk_lab/logs/inspection.bin" "$disk_lab/logs/inspection-alias.bin"
ls -li "$disk_lab/logs/inspection.bin" "$disk_lab/logs/inspection-alias.bin"
du -sk "$disk_lab/logs"
The directory still has one shared log object and an additional name for it. GNU du normally avoids counting a multiply linked inode more than once within a given traversal. Separate commands run on each name can each report its size, so adding them outside the tool could overstate allocation. Creating a separate copy through an ordinary data-copying command has different semantics from adding a hard link. Filesystems can also support copies that share data initially while allowing independent later edits, which is another reason to read the filesystem's own accounting when the exact available space matters.
When a service deletes one of several hard-linked names, another name can keep the underlying file available. The disk usage conclusion depends on the identity and lifetime of that file, rather than just the pathname you removed. This lesson's cleanup removes both known names. You can compare the link count with the number of intentional references instead of using a directory-wide deletion to make a space number change.
Observe why removing a name can leave a file open
A service that writes a log usually opens the file and keeps a handle while it continues writing. An open file descriptor refers to that file independently of looking up the path a second time. Suppose you remove the log's last name while the service still has it open. The file is absent from a directory listing, so a new directory walk cannot find its data. The open handle keeps the object alive, which can explain why filesystem space does not return as soon as you expect.
Make the difference visible with Python 3 and just one small text file. The script writes the known text, reopens the file for reading, and removes its name while the handle is open. In the example, unlink means remove a directory name. The code constructs the filename under the established scratch directory and affects only that synthetic fixture. No live log or process is involved. The file is so small that the overall filesystem's free-space measurement may not visibly change, so the lesson checks identity, names, and readable content directly.
python3 - "$disk_lab" <<'PYTHON'
import os
from pathlib import Path
import sys
path = Path(sys.argv[1]) / "temporary-open-log.txt"
path.write_text("workshop report ready\n", encoding="utf-8")
with path.open("rb") as handle:
print(f"Before: path exists={path.exists()}, links={os.fstat(handle.fileno()).st_nlink}")
path.unlink()
print(f"After unlink: path exists={path.exists()}, links={os.fstat(handle.fileno()).st_nlink}")
print("The open handle reads:", handle.read().decode("utf-8").strip())
print(f"After close: path exists={path.exists()}")
PYTHON
Before: path exists=True, links=1
After unlink: path exists=False, links=0
The open handle reads: workshop report ready
After close: path exists=False
os.fstat reads metadata through the open descriptor and can still find the file's link count. path.exists() instead checks whether the name resolves in the directory. The exact lines show both observations at the same moment. After the link count goes to zero and the last handle closes, the filesystem can reclaim the file's storage in the normal case. A snapshot, shared extent, or other resource retained by the filesystem can still affect how much space ultimately becomes available. Keep the explanation focused on what a pathname walk can and cannot see.
When this pattern occurs in a production log, read the deployed application's supported log rotation instructions. A rotation mechanism can move or replace a log and signal the service to reopen its files where that behavior is supported. Interfering with an open process or forcefully stopping it just to change a space measurement can cause a separate outage. On a Linux host you manage, the installed lsof tool can list matching open files with links below one using +L1. Access varies by account, and a narrow process or service scope is preferable. The lab's small subprocess already gives direct evidence without requiring privileged visibility into other processes.
Trace the filesystem from path to device
Use Linux's findmnt to ask about the mount serving a particular path. --target accepts a path within the mount and shows the filesystem covering it. --mountpoint is a different operation that filters for the actual mounting location. This distinction lets you verify a planned mount, not just that a directory has some backing filesystem. In the next read-only block, the specific lab path and system root both already exist.
findmnt --target "$disk_lab" --output TARGET,SOURCE,FSTYPE,OPTIONS
findmnt --mountpoint / --output TARGET,SOURCE,FSTYPE
lsblk --output NAME,TYPE,SIZE,FSTYPE,UUID,MOUNTPOINTS
The first output includes the mount containing the lab. If the scratch location is on the root filesystem, its target can be slash, even though the input path begins in a temporary directory. If it is on a separate temporary mount, the result can instead show that target and its own source. The second output asks specifically for the root mount. The final command lists block devices and their selected properties. Some util-linux versions use a single MOUNTPOINT column instead of the multi-value version; check local column support if needed. Read the requested output fields together and use actual values from your environment.
NAME TYPE SIZE FSTYPE UUID MOUNTPOINTS
nvme0n1 disk 16G
└─nvme0n1p1 part 8G xfs example-root /
nvme1n1 disk 80G ext4 example-data /data
This simplified teaching display shows an 8 GiB partition on a 16 GiB device, and another device whose ext4 filesystem is used directly. The shown identifiers are fictional labels for the example. An actual filesystem UUID is a specific identifier reported by the filesystem and tools. On the first device the root mount corresponds to the partition row, rather than the whole parent device row. Existing readings may include partitions reserved for boot or other purposes. Seeing a parent size larger than one child does not by itself tell you that the area can safely be assigned to that child. Examine the actual disk layout before any planned storage operation.
Several Linux devices can contribute to one filesystem if a logical storage layer groups them. Conversely, a filesystem can be mounted in several paths. Network filesystems can appear in findmnt and df without a corresponding locally attached block device. Containers can have an overlay, which presents a combined filesystem view with particular rules about where modifications are stored. Use the source fields to identify the type, and do not invent a direct disk mapping where the environment does not offer one. On a production machine you can trace from the actual application path to the appropriate storage documentation.
For a concrete comparison, suppose the planned /data directory returns target slash from findmnt --target /data. That is evidence it belongs to the root filesystem in this view. If a separate mount was expected, an exact findmnt --mountpoint /data query should also be used. No match indicates it is not a mount point in that context. If the data volume later gets mounted, existing files behind the mount under the parent can be hidden by the new view while still using root space. Investigate with an approved recovery procedure. Do not start unmounting paths used by running services to inspect them.
Read a mount plan separately from the live mount table
The /etc/fstab file is a description used by multiple Linux utilities and startup components. Each entry names a filesystem source, a target path, a type, options, and numeric fields for historical dump and filesystem check behavior. This plan is separate from the current records in the live mount table. A mounted filesystem might have been attached manually or by software that did not use fstab. An entry in fstab may specify a filesystem that has not been mounted. Compare the plan and current state if an application expects a particular mount.
The following scratch file has one fictional entry and will never be installed or mounted. Its UUID is a placeholder shaped like a filesystem identifier. It uses an ext4 example so the non-root check order field makes sense as a reading exercise. The command tells findmnt to read the alternate table as a plan rather than process it as a request to mount the target. You can inspect the text itself on any machine, while the parsing command is specific to a Linux environment with the relevant util-linux support.
cat > "$disk_lab/mount-plan.txt" <<'FSTAB'
# Training only. This UUID is fictional and must not be installed.
UUID=00000000-0000-0000-0000-000000000123 /data ext4 defaults,nofail 0 2
FSTAB
findmnt --fstab --tab-file "$disk_lab/mount-plan.txt" \
--output SOURCE,TARGET,FSTYPE,OPTIONS
SOURCE TARGET FSTYPE OPTIONS
UUID=00000000-0000-0000-0000-000000000123 /data ext4 defaults,nofail
Display spacing can vary. Read the first field as a request to locate the matching filesystem identifier, the second as where it should appear, and the third as the intended type. The options field is a comma-separated list. nofail changes the handling of absence or mount failure in supported startup and mount flows. It does not create the data filesystem or stop an application from accidentally being started against an ordinary fallback directory. For required application storage, the service must either be ordered behind an appropriate mount dependency or check the effective storage before writing. Pick that policy based on the importance of the data and the actual system configuration.
Device path names may change across boots or attachments. A filesystem UUID can identify a volume more reliably when the values are unique in the environment. It is different from a partition identifier and from an AWS EBS volume ID. A volume restored or cloned from another source can retain filesystem identifiers depending on how it was produced. Confirm that the intended source is present and unique rather than using the first output line that looks plausible. In this lab the fictional UUID is used solely for reading fields and has no relationship to an actual volume.
For an authorized configuration change, first preserve the known-good configuration and confirm the volume and target. Tools such as findmnt --verify --tab-file can check a prepared table for certain syntax and usability issues. Use that on a real candidate with the expected paths and identifiers, rather than asking the fictional exercise row to pass such a check. A validator does not prove the entire boot or application sequence. Apply an approved narrow change and verify that mount explicitly without testing unrelated mounts. In systemd environments the manager may also need to reread generator input after installation of the fstab change. This exercise only reads a scratch description.
Understand why extra device capacity may not appear in df
Consider the illustrated device with a nominal size of 16 GiB and an 8 GiB root partition. The inspection work may use a filesystem of roughly 8 GiB, and df can correctly report that figure even though lsblk correctly reports a larger device. The filesystem has its own structure and addressable area. Extending an EBS volume at the AWS layer changes the available block device size after the modification takes effect. It does not by itself extend a partition, logical volume, or filesystem inside the instance.
Make a simple drawing with three layers. The outer layer is the EBS volume visible as the Linux block device. The middle layer is the partition in the example, and the inner layer is the mounted filesystem. After the cloud change, only the outer layer has grown unless the operating system separately performed more steps. A filesystem directly on an unpartitioned device would skip the partition step. A layout using Logical Volume Manager may need a check of physical and logical volumes before extending the filesystem. Draw the observed hierarchy from the actual device inventory rather than assuming every machine has exactly three layers.
A recovery plan for a real resize starts with a known snapshot and the correct volume identification. Consult AWS's procedure for the filesystem and layout you have, including the volume modification state and whether a partition is present. Verify the current mount and its type before choosing any filesystem operation. Tooling for growing XFS differs from tooling for growing ext4. Never format a device just because it appears in the block list. Formatting writes a new filesystem and is a different operation from adding capacity to existing data. This standard lesson gives the read-only evidence needed to prepare such a decision, rather than issuing a volume change.
After a reviewed resize, check each boundary again. The device size should reflect the AWS volume change. The partition or logical volume, where present, should reflect the plan for intermediate storage. The mounted filesystem's capacity should reflect its own extension, and a read or application check should confirm expected data remains accessible. If the second or third observation disagrees with the first, inspect that layer before repeating the cloud operation. When there is a mismatch, identify precisely which size stayed unchanged and when each command ran.
Build a storage diagnosis without removing evidence
When an upload cannot be written, first capture the exact error, time, and destination. A process can create an upload staging file, write a second final file, and add a log entry. Each path may fail for a different reason. If the file itself does not yet exist, query the nearest existing parent directory along the intended destination with df and findmnt. Verify whether the path is in the filesystem you expected. If it is meant to be a separate mount, check the exact mount point as well. In a container or service namespace, run the relevant read-only check in the context where the service opens the files.
Next compare available blocks and, on filesystems that report them, available inodes. If the block budget is small, inspect authorized directories belonging to that filesystem. Record the numeric sizes, time of measurement, and any permissions messages from the traversal. If a narrow scan reports much less than filesystem usage, decide whether relevant directories were omitted, whether mounts or snapshots affect the accounting, or whether a process still holds files that disappeared from the scanned tree. Do not use a low usage estimate from one subtree to dismiss a full filesystem observation.
If the failure involves a specific account, the writer might face a quota or a permission restriction even while a system-wide display looks healthy. A quota is an administrator-set resource limit that can apply to a user, group, or project on supporting filesystems. It can constrain blocks, file counts, or both. The actual system call error and tool messages distinguish exhausted space, exceeded quota, a read-only filesystem, and other access problems. In a team investigation, ask whether the measurement used the same account and mount context as the application. Comparing one user's small successful file on a different mount is weak evidence about the original upload.
Use a paper case to practice interpreting evidence. In the first case the application's temporary folder is on root, where df -h shows 200 MiB available. Its final destination is on a mounted data filesystem with 50 GiB available. A 400 MiB upload fails while staging. The root budget is relevant even though the final destination could hold it. In the second case root has 30 GiB available but df -i shows zero free inodes. The app attempts to create another tiny file. Reducing the next file's byte length might not help when the system needs a free metadata entry before writing any data.
In a third case an application log was removed by name, then the visible directory shrank sharply, but the filesystem available space did not increase as expected. The operator can find out whether the service still holds the file open and whether filesystem-specific snapshots retain the storage. Those checks come before deleting a different file. A defined log retention policy determines what can be rotated, archived, or removed after approval. A small controlled lab teaches the distinction without creating pressure on a host that other people use.
Any repair needs its own proof. A retention change should produce the expected storage trend, and the application should continue writing to an approved log path. A mount repair should show the expected source and target from the same context as the writer. An expanded disk should be visible at the correct filesystem layer. Keep before and after measurements from the same commands so the comparison stays meaningful. A person reading the report should be able to tell what changed, what was verified, and which observations are still missing.
Complete a compact filesystem evidence sheet
For the first task, record the filesystem serving the scratch directory and turn the headlined size from df -h into a statement about the correct path. Include the type and mount point on Linux. Record the logical lengths of both the sparse and written file. Then compare the allocated numbers, even if your filesystem made them similar. A good explanation says that logical file size and allocation measure different properties and names the observed values. Do not write down a theoretical allocation as if it were measured.
For the second task, verify that the log and its hard-linked alias share an inode on the same filesystem. Predict what should happen if one name goes away, and explain why the other link still allows reading the data. Then relate that prediction to the Python open-but-unlinked test, where there is no name left but a descriptor stays open until the program closes it. These cases exercise two different kinds of references to a file. You can practice naming both conditions that have to end for normal reclamation: directory links and open references.
For the third task, draw the device and filesystem hierarchy shown in the fictional lsblk display. Underline the row describing the mounted root. Identify which layer would be larger after the cloud-side resize and which measurement might stay unchanged. Compare that example to the actual Linux lab path if those commands are available. State when a tool returned insufficient visibility or no matching source. If there are no block devices visible from a container, the proper conclusion is about that view, not that the machine has no storage.
Clean up after looking at the generated scratch directory and confirming that it belongs to this lesson. Any optional extra files should be removed only after identifying their names. The cleanup uses known file paths and then removes empty directories. It does not touch fstab, mounted filesystems, volume configuration, or system logs. Overall usage can continue to vary independently because the host is also doing other work.
if [ -n "${disk_lab:-}" ] && [ -d "$disk_lab" ]; then
printf 'Cleaning lesson files in %s\n' "$disk_lab"
rm -f -- "$disk_lab/worksheets/today.txt" "$disk_lab/worksheets/sparse.bin" \
"$disk_lab/logs/inspection.bin" "$disk_lab/logs/inspection-alias.bin" \
"$disk_lab/log-write.txt" "$disk_lab/mount-plan.txt" "$disk_lab/temporary-open-log.txt"
rmdir -- "$disk_lab/worksheets" "$disk_lab/logs" "$disk_lab"
fi
unset disk_lab
Check your storage reasoning
Interview question. A device shows 16 GiB, but the filesystem serving the app shows about 8 GiB. Which command is wrong?
Both can be right. The device inventory reports the parent block device, and the capacity query refers to the mounted filesystem. The app can be using an 8 GiB partition and filesystem inside that 16 GiB device. Trace the application path to its mount and source, then identify the layer that must be verified or extended.
Interview question. How can du shrink while df barely changes after a log pathname is removed?
The du walk measures names and objects it reaches. A process can keep the file open after the last name is removed, so the file can remain allocated. Check open references and the service's supported log rotation workflow. Filesystem metadata, shared data and snapshots can also explain comparisons that do not reconcile.
Quiz. The staging folder has 200 MiB free and the target volume has 50 GiB free. Why can a 400 MiB upload fail?
The temporary write occurs first and needs space on the staging folder's own filesystem. If the application writes the whole input there, 200 MiB does not cover 400 MiB. Check all participating output paths, including any temporary copies. Free space on a different mounted volume cannot increase this path's available budget by itself.
Quiz. ls names a data directory and fstab contains a row for it. Which test tells you whether the data volume is mounted there now?
Use an exact findmnt --mountpoint query for that directory in the service's view. Then compare the source to the intended filesystem identifier. The existence of the directory and the static declaration are observations about a path and plan, while the mount-table query describes current state.
Quiz. A sparse file has the same logical byte length as a written file. Should du show equal allocation?
It need not. Logical length includes holes that can read as zero bytes without individually allocated blocks, while du ordinarily estimates actual allocations. The filesystem's implementation determines the numbers you see. Compare both kinds of size explicitly.
Revision cards
Start at the application's path
Find the backed filesystem for the exact destination. Check the staging and final paths if the operation writes in more than one location.
Device, filesystem, and files
Use lsblk for device relationships, findmnt for mounted paths, df for filesystem capacity, and du for the visible files in a chosen tree.
Names, handles, and allocation
Removing a pathname and releasing storage are different observations. A second link, an open descriptor, or filesystem-level retention can keep the associated data.
Primary references
- GNU coreutils df manual for mount capacity and inode counts
- GNU coreutils du manual for allocation, depth, and hard links
- Util-linux block device and filesystem inventory
- Util-linux findmnt and mount table inspection
- Linux fstab format and mount fields
- GNU coreutils truncate and sparse file extensions
- Linux filesystem name and descriptor lifetime
- Amazon EBS guidance for extending filesystems after volume changes