Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux+ Certification Bible.pdf
Скачиваний:
46
Добавлен:
15.03.2015
Размер:
3.78 Mб
Скачать

Chapter 12 Linux Disk and System Management

385

The daily management activities of a Linux system administrator include many different tasks. From managing and configuring disk drives, to managing net-

works, to scheduling maintenance jobs, many parts of the system must be attended to on a routine basis.

For each of these system management activities, the administrator can use many tools and commands to ease the administration and configuration of various parts of the system.

This chapter deals with such system administration items as disk and file system management, by using the fdisk, mkfs, and fsck commands; system job scheduling, by using at and cron; network management, by using the ifconfig command; finding and analyzing core dumps; and finally, upgrading packages and installing patches.

Disk and File System Management

5.1 Create and manage local storage devices and file systems (e.g., fsck, fdisk, mkfs)

The most common tool for managing your disks and file systems is the fdisk utility. This utility allows you to partition your drives and assign file systems to them.

To use fdisk on your hard drives, specify which hard drive you are using with the following conventions:

The first ATA/IDE hard drive is called hda; the second is called hdb, etc.

The first SCSI drive is called sda; the second is called sdb, etc.

With these hard drives, each partition is also numbered, so the first partition of the first IDE drive is hda1.

To start fdisk on the first ATA/IDE drive, use the following command:

fdisk /dev/hda

To view a list of commands that you can use from the fdisk prompt, type ? (question mark). A display output similar to the following appears:

Command action

a toggle a bootable flag

bedit bsd disklabel

c toggle the dos compatiblity flag

ddelete a partition

l list known partition types

mprint this menu

n add a new partition

386 Part V Maintaining the Linux System

p print the partition table

qquit without saving changes

t change a partition’s system id u change display/entry units

v verify the partition table

wwrite table to disk and exit

xextra functionality (experts only)

In addition, in expert mode (see the “x” command in the preceding example), you can use these advanced commands, but I recommend that you don’t use these commands unless you know what you are doing. For most users, the following basic commands will suffice:

Command action

b move beginning of data in a partition

cchange number of cylinders

d print the raw data in the partition table e list extended partitions

h change number of heads

mprint this menu

p print the partition table q quit without saving changes

rreturn to main menu

s change number of sectors v verify the partition table

wwrite table to disk and exit

I recommend that you begin with the “p” command to print a list of your current partition table. The following is a sample partition table from a Linux system:

Device

Boot

Start

End

Blocks

ID

System

/dev/hda1

*

1 949

1912152

 

83

Linux

/dev/hda2

950

1015

133056

5

Extended

/dev/hda5

950

1015

133024

82

Linux Swap

In the preceding example, you can see that /dev/hda1 is the boot drive and that it contains the main Linux system. The system ID is the type of Linux file system, which, in this case, is the ext2 filesystem — the default for Linux.

The Linux swap file is ID 82, and is installed on the /dev/hda5 partition. The following is a list of other file system numbers:

0

Empty

9

AIX bootable

75

PC/IX

b7

BSDI fs

1

DOS 12-bit FAT

a

OS/2 Boot Manag 80

Old MINIX

b8

BSDI swap

2

XENIX root

40

Venix 80286

81

Linux/MINIX

c7

Syrinx

3

XENIX usr

51

Novell?

82

Linux swap

db

CP/M

4

DOS 16-bit <32M 52

Microport

83

Linux native

e1

DOS access

5

Extended

63

GNU HURD

93

Amoeba

e3

DOS R/O

6

DOS 16-bit >=32 64

Novell Netware

94

Amoeba BBT

f2

DOS Sec

7

OS/2 HPFS

65

Novell Netware

a5

BSD/386

ff

BBT

8AIX

Chapter 12 Linux Disk and System Management

387

The most important ID numbers to remember are the Linux specific designations, such as 82 for the Linux Swap file, and 83 for a typical Linux partition.

As the preceding examples demonstrate, you can see and format partitions for all types of systems. If you have a dual-boot system with Microsoft Windows, use the DOS fat file system.

You can use the fdisk tool to add and delete partitions. You must set the size of the partition by number of blocks. You must also set the file system with the file system ID number. After you finish, hit the “w” command to write the partition table to disk, and then exit the utility.

After you have set up your partitions, you won’t be able to use them until you actually format the partitions with a valid file system. For Linux, the default file system is the ext2 system. If you have added another hard drive to your system, such as /dev/hdb, you will want to create another partition for Linux to use on that drive.

Using the fdisk tool, add a partition called /dev/hdb1. If you want, use all the available blocks to allocate the entire drive to one partition. After you finish using fdisk, format the partition with the ext2 file system.

For this, you need to use the mkfs command:

mkfs -t ext2 /dev/hdb2

This command tells the mkfs command to invoke the mke2fs utility to format the partition with the ext2 file system.

To mount the file system for use, use the mount command to mount your new partition:

mount /dev/hdb1 /home2

The file system used by Linux is the ext2 file system.

Repairing Partitions

File systems can be very complex, and with a great amount of disk activity and read and writes, the occasional error is bound to happen. The utility that you use to repair these problems and inconsistencies is fsck, which is short for “File System Check.” (This is similar in function to the Windows SCANDISK utility)

The fsck utility scans all disks and partitions, and if possible, repairs them when necessary. This utility runs automatically at boot time if the system has shut down

Соседние файлы в предмете Операционные системы