Building Tablet PC Applications (Pro-Developer)

As you ve seen in Figure 7.5 , there are many ways to format a filesystem for different operating systems. In addition, there are several ways to format a partition for Linux. The latest versions of Linux include journaling features, which promote quick recovery from drive crashes. Each of these procedures set up different types of labels for your partitions.

Basic Linux Formats

As you ve learned, you can format a filesystem in several different ways. While the current default for Red Hat Linux is the third extended filesystem, ext3, a number of other Linux filesystems are available that you may want to use. Table 7.3 lists the major Linux filesystem formats.

Table 7.3: Major Linux Filesystem Formats

Format

Description

ext2

The second extended filesystem, which was the standard for Red Hat Linux through 2001. If you have older systems with ext2 partitions, they are easy to convert to ext3.

ext3

The third extended filesystem, which is the current default for Red Hat Linux. Includes a journal, which records all pending changes, such as data to be written to disk.

reiserfs

The Reiser filesystem, which is based on different designs from the Linux extended filesystems.

xfs

The Silicon Graphics filesystem, which supports extremely large hard drives .

Linux is moving toward journaling filesystems. A journal records all pending changes, such as data to be written to disk. If a drive crashes, Linux can check the journal for pending changes. No disk check is required, which can save considerable time.

Several other Linux type filesystems are available, including ext, bfs, minix, xia, and jfs. None of these filesystems are commonly used on the Linux operating system today.

Formatting a Partition

Linux configures the mkfs command as a front end to format Linux partitions. If a partition has been previously formatted, all you need is that command, and Linux will reformat the partition to the same filesystem. Otherwise, you ll need to specify the type of filesystem to be built by including the -t switch. You can also check for bad blocks before formatting with the -c switch.

The commands are fairly straightforward. For example, the following commands format the /dev/sdb1 partition to the noted filesystems:

# mkfs -t ext2 /dev/sdb1 # mkfs -t ext3 /dev/sdb1 # mkfs -t vfat /dev/sdb1 # mkfs -t reiserfs /dev/sdb1

Another way to create an ext3 filesystem is with the following command (the -j creates a journal);

# mkfs -j /dev/sdb1

Alternatively, if you re formatting a partition for Linux swap space, use the mkswap command. For example, if you want to set up /dev/sdb5 as a swap partition, the command is straightforward:

# mkswap /dev/sdb5

Tuning

It s easy to convert an older partition formatted to the ext2 filesystem to ext3. In fact, the ext3 filesystem is virtually identical to ext2. The only difference is that ext3 partitions include a journal.

Therefore, if you create a journal for an ext2 filesystem, it automatically becomes an ext3 filesystem. All you need is the tune2fs -j command. For example, the following command converts the /dev/hda1 partition from ext2 to ext3:

# tune2fs -j /dev/hda1

Disk Management

Two very similar disk management commands are available in Linux: du and df . The directory usage ( du ) command lists the amount of space used by each file in and below your current directory. The disk free ( df ) space command lists the amount of space available on each hard drive volume. Figure 7.6 shows the output you get if you run the du command in a Linux user s home directory.

Figure 7.6: Output from du

The number you see on the left is the size of the file, in kilobytes, which is the default from both the df and du commands. The applicable file is shown on the right. For example, you may see the following:

1941 ./.gimp/tmp

The first dot ( . ) means that you start in your current directory. The slash ( / ) navigates to a subdirectory, in this case .gimp . In other words, this line means there are 1941 kilobytes of disk space dedicated to the .gimp/tmp subdirectory.

The df command shows how full each filesystem is on your computer. As you can see in Figure 7.7, the df -m command assesses each filesystem and displays the results in megabytes. It includes any other filesystems, such as your floppy or CD-ROM drives that are currently mounted.

Figure 7.7: Output from df -m

The -m switch gives you results in megabytes, and the -k switch gives you results in kilobytes.

Extended Partition Data

Linux includes a substantial amount of data with each partition, which you can access with commands such as e2label and dumpe2fs . When you install Red Hat Linux, Linux partitions that you create during the installation process are automatically given appropriate label data. For example, I can get the following from this command:

# e2label /dev/sda1 /boot

As you will see later in this chapter, labels can be important. The default /etc/fstab uses disk labels. You can also find disk labels in the GRUB configuration file. But when you configure a new partition with fdisk and format it with mkfs , neither command adds a label. So if you want to mount the /home/mj directory on the /dev/sdb1 partition, you should also label it with the following command:

# e2label /dev/sdb1 /home/mj

Alternatively, you can get more information about a partition with the dumpe2fs command. Look at Figure 7.8, which illustrates a partition with the /home/mj label.

Figure 7.8: Find filesystem data with dumpe2fs

You can even check the last time this partition was mounted with the Last Mount Time variable from the dumpe2fs output; in this case n/a means that no directory has been mounted on this platform.

Mounting Directories

Before you can read or write to a Linux partition, you need to mount it. Without any help, you need to specify the partition, the directory being mounted, and the format associated with the partition. A typical syntax of the mount command is as follows :

# mount -t format partition directory

The format is the way the partition is configured, such as ext2, ext3, or vfat. The partition is the hard drive device being mounted, such as /dev/sda1 or /dev/hda1 . And the directory , also known as the mount point, is the part of the Linux directory structure allocated to that partition, such as /boot , /home , or /var .

In other words, you could mount the /home/mj directory on the /dev/sdb1 partition that has been formatted to the ext3 filesystem with the following command:

# mount -t ext3 /dev/sdb1 /home/mj

This is more complicated than is normally required. With the list of formats in the /etc/ filesystems configuration file, the mount command can look through this file and find a format that matches the /dev/sdb1 partition. So all you need is the following command:

# mount /dev/sdb1 /home/mj

You can make this even simpler. If you add the following line to your /etc/fstab configuration file, you need to specify only the partition or the directory:

/dev/sdb1 /home/mj ext3 defaults 1 2

In this case, either of the following commands would work:

# mount /dev/sdb1 # mount /home/mj

Sometimes it s important to unmount a directory. For example, Linux locks the CD drive on many computers until you unmount the relevant directory with a command such as:

# umount /mnt/cdrom

Note that this command is spelled umount , not unmount .

Troubleshooting

The failure of a filesystem can be more troubling than problems booting Linux. As you ll see in Chapter 11 , there are established methods for getting around boot problems. However, filesystem problems are more difficult to diagnose. They can be a sign of corrupted files, misaligned blocks, troubled configuration files, or even bad hardware.

Filesystem problems normally require troubleshooting during the boot process. Linux may have trouble mounting a specific partition, or a check of the filesystem integrity fails in some way. In either case, you may see a message that the fsck operation failed and that you need to type in the root password to gain access to Linux. An example of this situation is shown in Figure 7.9.

Figure 7.9: Linux s response to a filesystem problem

The fsck command is an important tool. It is used by Linux periodically to automatically check most of the partitions on your system. If you don t have a filesystem integrity problem, you may just need to adjust a parameter and remount a filesystem, such as the root ( / ) directory.

fsck

The fsck command is used to check and repair Linux filesystems. As with mkfs , it is a front end to commands that are dedicated to relevant filesystems, such as fsck.ext2 , fsck.ext3 , and fsck.reiserfs . If the filesystem format is known, the fsck command is all you need. If the partition is formatted to ext3 , the fsck.ext3 command is called automatically. Several key switches for this command are shown in Table 7.4.

Table 7.4: fsck Command Switches

Switch

Explanation

-a

Automatically repairs target filesystems without prompts. Should be used only within /etc/rc.sysinit .

-b superblock

Use a different superblock. Optional superblocks can be found via the dumpe2fs command.

-A

Check all filesystems listed in /etc/fstab .

-R

When -A is used, skip the root ( / ) directory filesystem.

-y

When fsck suggests a solution, it sets a default answer of "yes."

Warning  

Do not run fsck on a mounted partition. It can lead to severe filesystem damage.

If you suspect a problem, you can run fsck on any unmounted partition. Generally, you should accept the default suggestions for repairing any filesystem problems. While some data may be lost, this process should make your partition bootable again. At that point, you should be able to reboot Linux cleanly.

Note  

Incidentally, the pronunciation of fsck varies; some may say ef es check, while others may talk about running the fisk command on a partition.

Automated Partition Checks

The fsck command is no longer run periodically by default. However, you can change this by using the tune2fs -c count /dev/ partition command. To find the mount count information for a specific partition, use the dumpe2fs command. The relevant output is shown in Figure 7.10.

Figure 7.10: Periodic partition check information

Mounting and Remounting

One of the options in the rescue modes discussed in Chapter 11 is to mount filesystems such as root ( / ) in read-only mode. Once you ve made the necessary changes, you can mount that filesystem in read-write mode. Alternatively, you may want to mount a filesystem with programs such as /usr in read-only mode.

Eventually, you may want to change the /etc/fstab configuration file and reboot Linux. However, you can test your changes first by remounting the directory with the desired options. For example, if you want to remount the root ( / ) directory in read-write mode, use the following command:

# mount -o remount,rw /

Or if you want to remount /usr in read-only mode, you could use the following command:

# mount -o remount,ro /usr

Remember, changes with this command apply only until you reboot Linux, unless you also revise the /etc/fstab file accordingly .

 

Категории