Section 27.1. Objective 1: Operating the Linux Filesystem


27.1. Objective 1: Operating the Linux Filesystem

If you've been through the Level 1 program already (or simply are already familiar with the first parts of this book), you should understand the basics behind operating your Linux filesystem pretty well. The first of the following subsections reviews some utilities covered in Level 1 Topic 104.

Part of life is planning for, setting up, and living with things for some period of time, while being ready (when requirements change) to cope and alter the setup to fit the new situation without destroying what you already have. Working as a senior Linux administrator, you will likely be responsible for a number of production servers or at the very least some company's very important production server. For that reason, you don't have much room for trial and error; you need to know how things should be and what needs to be changed without fiddling around for days. The Level 2 Exams will expect you to be able to create filesystems on production servers, add swap partitions as needed, protect filesystem data integrity, and deal with changing demands.

27.1.1. Level 1 Review

You've covered the bases on mount and umount as well as the /etc/fstab file in Chapter 6, but if you're a little rusty, here's a recap.


Syntax

 mount [options] device mount [options] directorymount [options] device directory 


Description

Used to mount filesystems onto the filesystem hierarchy. The first and second forms consult /etc/fstab and mount the filesystem located on device or attached to directory, respectively. The third form ignores /etc/fstab and mounts the filesystem on device at mount point directory.


Command-line options


-a

Mount all of the partitions specified in /etc/fstab, except those with the noauto option.


-h

Display help on the mount command.


-omount_options

Specify mount options on the command line. The following list applies to any filesystem:


async

All I/O to the filesystem should be done asynchronously.


atime

Update inode access time for each access. This is the default.


auto

Can be mounted with the -a option.


defaults

Use default options: rw, suid, dev, exec, auto, nouser, and async.


noatime

Do not update inode access times on this filesystem. This option might be useful, for instance, for faster access on the news spool to speed up news servers.


noauto

Can be mounted only explicitly (i.e., the -a option will not cause the filesystem to be mounted).


noexec

Do not allow execution of any binaries on the mounted filesystem. This option might be useful for a server that has file systems containing binaries for architectures other than its own.


nosuid

Do not allow set-user-identifier or set-group-identifier bits to take effect. Increases security.


remount

Attempt to remount an already-mounted file system. This is commonly used to change the mount flags for a file system, especially to make a read-only file system writable. It does not change device or mount point.


ro

Mount the file system read-only.


sync

All I/O to the file system should be done synchronously. All changes are physically written to the device at the time you issue the command. Recommended for removable devices.


user

Allow an ordinary user to mount the file system. The name of the mounting user is written to the mtab file so that she can unmount the file system again. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user, exec, dev, suid).


users

Allow every user to mount and unmount the file system. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line users, exec, dev, suid).


-r

Mount the filesystem read-only.


-tfstype

Specify that the filesystem to be mounted is of type fstype. This option is typically used interactively, when no entry for the mount exists in /etc/fstab.


-v

Set verbose mode.


-w

Mount the filesystem in read/write mode.


Syntax

 umount [options] deviceumount [options] directory 


Description

Unmount the filesystem on device or mounted on directory.


-a

Unmounts all of the filesystems described in /etc/mtab.


-t fstype

Unmounts only filesystems of type fstype.


The /etc/fstab is a plain text file and consists of lines with six fields:

  • Device

  • Mount point

  • Filesystem type

  • Mount options

  • Dump frequency

  • Pass number for fsck

Example 27-1 shows some of the items that are typically mounted.

Example 27-1. Sample /etc/fstab file

 /dev/sda1      /                ext2    defaults        1 1 /dev/sda5      /boot            ext2    defaults        1 2 /dev/sda9      /home            ext2    defaults        1 2 /dev/sda6      /root            ext2    defaults        1 2 /dev/sda10     /tmp             ext2    defaults        1 2 /dev/sda8      /usr             ext2    defaults        1 2 /dev/sda7      /var             ext2    defaults        1 2 /dev/sda11     swap             swap    defaults        0 0 /dev/fd0       /mnt/floppy      ext2    noauto,users    0 0 /dev/hdc       /mnt/cdrom       iso9660 noauto,ro,users 0 0 /dev/hdd       /mnt/zip         vfat    noauto,users    0 0 fs1:/share     /fs1             nfs     defaults        0 0 

27.1.2. Additional Filesystem Management Files

While /etc/fstab is the most important file when it comes to manipulating your filesystems, two additional files are important too: /etc/mtab and /proc/mounts. These two files contain the same information, and /etc/mtab could be dropped had it not been that Linux should work even if the /proc filesystem is not present. Some distributions and live CDs (which let you boot a Linux system from a CD instead of installing it on your hard disk) do drop mtab and symbolically link it to /proc/mounts.

The information these files contain is the list of filesystems mounted on the system. Sometimes, such as after a system crash, the mtab file won't be accurate, but the system initialization scripts assiduously rebuild it from scratch. The kernel maintains the mounts file, and it will be quite accurate, but perhaps not 100% helpful.

Examples 27-2 and 27-3 show the files' formats for a single system.

Example 27-2. /etc/mtab example

 /dev/hda2 / ext3 rw 0 0 none /proc proc rw 0 0 usbdevfs /proc/bus/usb usbdevfs rw 0 0 /dev/hda1 /boot ext3 rw 0 0 /dev/hdb1 /home ext3 rw 0 0 none /dev/shm tmpfs rw 0 0 none /dev/pts devpts rw,gid=5,mode=620 0 0 automount(pid1017) /misc autofs rw,fd=5,pgrp=1017,minproto=2,maxproto=3 0 0 automount(pid1019) /homes autofs rw,fd=5,pgrp=1019,minproto=2,maxproto=3 0 0 none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0 

Example 27-3. /proc/mounts example

 rootfs / rootfs rw 0 0 /dev/root / ext3 rw 0 0 /proc /proc proc rw 0 0 usbdevfs /proc/bus/usb usbdevfs rw 0 0 /dev/hda1 /boot ext3 rw 0 0 /dev/hdb1 /home ext3 rw 0 0 none /dev/shm tmpfs rw 0 0 none /dev/pts devpts rw 0 0 automount(pid1017) /misc autofs rw 0 0 automount(pid1019) /homes autofs rw 0 0 none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0 

If you compare these two examples, you'll see that the information for the root filesystem in mounts is generic and that there are two / filesystems mounted. mtab, in contrast, specifies the device. With regard to the oddities in the mounts file, if you recall the use of initrd scripts in Chapter 26, you should recognize that this is due to the use of initrd, which requires two root filesystems and assigns odd device names in the initrd environment.

27.1.3. Managing Swap

Setting up swap is usually done once in a machine's life, when Linux is installed. However, it may turn out that the applications you run require a lot more memory and a lot more swap to be able to run effectively, or at all. If so, you will need to have spare disk space, or new disks, and then add swap space as needed. After a new swap partition is created, issue mkswap to create a swap signature on it, which enables it for swap use. After that you should update /etc/fstab appropriately, and if you don't wish to reboot, issue swapon to activate the partition. If for some reason you need to stop using a swap partition, swapoff can do it for you.

Unix has used advanced caching techniques to speed up filesystem operations for a long time. To ensure that the files on disk were updated, a process called update ran the sync command every 30 seconds. This would flush all cached writes to disk at once. Flushing everything every 30 seconds is quite crude, so at some time in the history of Linux this process was moved into the kernel and refined. The Linux program known as update got a new alias, bdflush. The 2.4 kernel carried out flushing through a pair of threads. bdflush looked for dirty buffers to write to disk. kupdated worked like the old update process, but flushed individual buffers instead of flushing all of them. In the 2.6 kernel, the functions are combined once again in a set of pdflush threads.

Data buffers are flushed 30 seconds after the kernel is done with them, and meta data buffers are flushed after 5 seconds. Some filesystems that have very strong data consistency requirements make sure their data is flushed according to a stricter schedule.

The sync command is still there, but you will very seldom need it. It will still flush all buffers at once, and on a active system with a lot of memory it can take a while to complete. If your disks are set up right, the system will be far from frozen, so only the sync command will hang.

Since it takes up to 30 seconds to flush things, it is always a good idea to either wait 30 seconds after all activity has ceased before you reboot a system or to call sync. You will still see old Unix hands do a repeated sync; sync; sync; reboot just to make sure everything is on disk before the reboot commences.


Syntax

 mkswap [-c] [-vn] [-f] device [ size ] 


Description

Create a Linux swap area on a device, such as a hard drive, or in a file. The device is usually a disk partition but can also be a file. You can also specify size, but it's not recommended. When size is omitted, mkswap simply uses the entire partition or file specified.


Frequently Used Options


-c

Check the device for bad blocks before creating the swap area. This is in fact an infrequently used option; it's a waste of time to run it. Modern disks remap bad sectors, whereas old disks just got read errors on bad sectors.


-f

Force execution of the mkswap command with its options regardless of errors and warnings. Also infrequently used, unless you know that an error in /etc/mtab is confusing mkswap.


-vn

Specifies the version of swap style. -v0 creates the old swap style, whereas -v1 creates the new one. If no -v argument is supplied, mkswap uses the new style unless you're running a pre-2.2 kernel. If you need to run a pre-2.2 kernel, you must specify -v0.


Syntax

 swapon [options] 


Description

The swapon command enables devices and files to be used for swap. swapon is required after creating a swap partition with mkswap.


Frequently used options


--a

Enable all devices marked as swap in /etc/fstab. Using -e with -a skips defined swap devices that do not exist.


h

Display help for swapon.


-s

Display a swap usage summary.


Syntax

 swapoff options 


Description

Disable swap devices.


Frequently used options


-a

Disable all devices marked as swap in /etc/fstab. Using -e with -a skips defined swap devices that do not exist.

27.1.4. Linux Partitioning Scheme

Chapter 6 presented a lot of important directories. In this chapter, we'll rehash that information with a view toward when some of these different directories should be made separate filesystems.


/ (root)

Everything needed to boot a Linux system must reside on this filesystem: /dev, /bin, /sbin, /etc, and /lib. You can certainly have many other things in this partition, but they are optional. The root filesystem can run anything from 100 MB and up; 700 MB is quite large if the other large filesystems are separated. The one imperative is to keep this filesystem from being 100% full. If it is filled, the machine will quite probably fail to boot if you try to reboot it. Separating out the logs (mostly in /var) to a separate partition is one of the smartest things you can do to prevent this problem.


/boot

Quite a few PC BIOS can't boot anything that resides beyond the 1024th cylinder of your boot disk, which allows 64 MB of data. The /boot partition needs to house only some kernels, so 64 MB should be plenty. Realistic usage is in the order of 1020 MB. Due to the kernel's small space needs, it can equally well be stored in the root partition, as long as the kernel is entirely within the 1024th cylinder of the boot disk.


/usr

The main bulk of the software in a Linux distribution goes here. A pretty full installation seems to be around 4 GB these days, but there have been dramatic increases in the past. If you plan for the system to exist for a long time without being reinstalled and repartitioned, you should make this partition at least 8 GB. If you are going to build your kernels yourself, you may want to make the partition even larger. The kernel source usually resides in /usr/src, and a full, compiled, 2.4 kernel tree is about 250 MB, so the megabytes can add up pretty quickly if you patch the kernels, keep backups, and keep a couple of versions around.


/home

Users are very inconsiderate. They won't understand if you yell at them because they filled your root filesystem so that the machine won't boot. Keeping the user home directories in a separate partition is a big favor to yourself and them. But remember that a .mozilla directory alone can be 200 MB because Mozilla caches web objects and mail.


/var

This is where the logs live and where download commands such as apt-get cache packages. On an active system, the logs can be pretty big. Make this partition at least 2 GB; anything up to 8 GB or even beyond can be useful. For example, the complete set of Fedora Core 1 RPMs is about 1.8 GB, and if you want to yum update a heavily loaded system, you need enough space to store all the packages. /var/tmp is often used to offload things such as the contents of CDs to install software or data waiting to be burned to CDs.


/opt

This is the standard location for installing applications, the kind that run your business or whatever. Look at the installation requirements for each application; 8 GB goes a long way.


/usr/local

This is the standard location to install OS add-ons that are not managed by the OS package system. Separating them out can keep them from crowding out the OS from /usr. But because a Linux distribution these days contains almost anything you can think of, there is not much call for /usr/local, and a few hundred megabytes are usually enough.


/tmp

Some kinds of work require a lot of temporary space; /tmp is the default place to store it. Some software will take direction from the TMP or TEMP environment variables to store temporary files somewhere else. If you want to ensure that excessive use of /tmp does not affect any other parts of your system, you can put it on a separate partition. A few hundred megabytes usually suffice. If you have a lot of memory or the speed of temporary file operations is of importance, consider mounting /tmp as tmpfs, which makes it memory-resident instead of confined to a slow disk. The complete fstab line to do this is:

 swap            /tmp            tmpfs   rw,mode=1777            0 2 



LPI Linux Certification in a Nutshell
LPI Linux Certification in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596005288
EAN: 2147483647
Year: 2004
Pages: 257

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net