The Linux File System
◾
409
Options to alter the output of df are shown below:
• -a—output all file systems, including “dummy” file systems
• -B size—output number of blocks in size increments, for instance, -B 1K would out-
put file system capacity and availability in 1K block sizes while -B 8K would use 8K
block sizes
• -h—use human-readable format for sizes using units in K, M, G, T, and so on
• -i—output inodes
rather than disk blocks
The df command can be used on individual file systems, as in
df /home
. The
parameter(s) can also be individual files, in which case df outputs the usage information
for the file’s file system. For instance,
df /home/foxr/somefile
would output the
same information as
df /home
.
Finally, the /etc/mtab file contains the up-to-date mount information. That is, while
fstab is a static description of the file space’s partitions, mtab shows you what is currently
mounted, including file systems that are mounted remotely. If you have not mounted or
unmounted
any partitions, then you should have the same partitions listed in both mtab
and fstab. However, mtab is interactive; that is, it is modified as partitions are mounted and
unmounted. If you have unmounted some partitions and want to reestablish the mounting
as you expect to see it upon a fresh boot of the OS, you can issue the mount all command,
which is
mount –a
. We explore mounting later.
10.4.3 Creating Partitions
When do you create your initial partitions? You do so when you first install your operating
system, as we saw in Chapter 8. How do you decide upon the partitions for your system?
What size do we reserve for our partitions and what types should these partitions be (what
types of file systems?) Where will we make the mount points for the partitions? These are
decisions that we will make based on the type and usage of our computer.
Is it a standalone workstation for a single user? If so, fine-grained
partitions are not
really needed and most of the space can be reserved for /home. Is the workstation one that
multiple users might be using at a time? This may lead you to a greater degree of partition-
ing such as having a separate /usr partition for software. Is the computer a server that will
handle dozens, hundreds, or even millions of requests a day? If so, then /var will store a
greater amount of information and so might require extra space.
Fortunately, these partitioning decisions are fairly uniform in that we do not have to
consider too many other questions. This simplifies the partitioning process and lets us
have confidence in our decisions. Below is a description of the different partitions that you
might choose and why.
/—every Linux installation requires a root partition for the Linux OS. This will include
the directories /bin, /usr/bin, /sbin, and /usr/sbin unless we specify
a finer-grained distri-
bution. In addition, / will store the root account’s home directory (/root).
410
◾
Linux with Operating System Concepts
If we do not separately create a /boot partition, then /boot (the OS kernel and boot
loader programs) will be stored under the root partition as well.
/home—we separate the user space from the root partition for security purposes. The
/home partition should be the partition in which all user directories and files are stored.
While / is not expected to grow, /home will grow as you add users to the system and those
users create files. The /home directory is a potential target for placing disk quotas whereas
/ would not need this.
/var—this top-level directory houses many of the system data files. The term “var” indi-
cates “variable” in that these files will change over time. Not only does this require that the
partition be rw (readable, writable) but also that we will need to ensure room for these files
to grow over time.
Among the files that you would find here are mail directories (one for each user account),
log files, which are generated by various software
and operating system events, print spooler
files, and possibly even server files such as the web space for a website. Unlike /home, there
would be little point to placing disk quotas on this file space because the files will primarily
be owned by various software (or root).
swap—The swap space is essential so that the Linux operating system can expect to run
efficiently no matter how many processes are launched. Processes are copied into memory
to be executed. However, when memory becomes full, unused portions of those processes
are held in swap space. This includes both executable code and data space. The items moved
between swap space and memory are known as pages and the pages are only loaded into
memory on demand (as needed). So memory is in reality only
storing portions of what is
running while their entire backing content is stored in swap space.
The swap space for Linux should be at least the size of the computer’s RAM. This is dif-
ferent from Windows systems where swap space is often recommended to be at least twice
the size of the main memory. If you examine the swap partition entry in /etc/fstab (see
Figure 10.5), you will see that this file system does not have a mount point like the other
partitions. You will also see that the swap partition does not even appear when you use the
df command (see Figure 10.6).
Linux comes with
swapon
and
swapoff
instructions to mount and unmount the
swap space. Normally, you would never unmount the swap space. But if you wanted to
switch swap spaces, for instance, if your original swap partition was deemed too small
and you have created a new swap
partition on another device, you can swapoff and then
swapon using the new device. When using these commands, the option -a will turn
all
swap space off or on.
Other partitions that you might make include /usr to store all executable user software,
/tmp, which is used by running software to store temporary files, /boot to store the boot
program itself, /opt and /usr/bin. The /opt directory is for third-party software and /usr/
bin allows you to separate the binary portions of the /usr directory from other files that
support application software (such as man pages, configuration files,
shared library files,
and source code).
You might expect files in /usr and /opt to be read-only, so you would mount them using
the ro option instead of the default rw. The /tmp directory is writable by anyone and
The Linux File System
◾
411
everyone so it might be mounted using a umask of 000 (recall the umask from Chapter 9
is used to establish default permissions by subtracting the umask from 777 for directories,
thus /tmp would have permissions of 777).
10.4.4 Altering Partitions
What happens if you decide, after OS installation, that you want to increase the number of
Do'stlaringiz bilan baham: