Advanced Unix

45
1 Advanced Unix Advanced Unix Kudzu, Modules and File Kudzu, Modules and File Systems Systems

description

Advanced Unix. Kudzu, Modules and File Systems. System Administration. Some additional duties of a system administrator are: Hardware Configuration File System Management System Monitoring For hardware configuration a common Linux tool is Kudzu http://rhlinux.redhat.com/kudzu/. Kudzu. - PowerPoint PPT Presentation

Transcript of Advanced Unix

Page 1: Advanced Unix

11

Advanced UnixAdvanced Unix

Kudzu, Modules and File Kudzu, Modules and File SystemsSystems

Page 2: Advanced Unix

22

System AdministrationSystem Administration

Some additional duties of a system Some additional duties of a system administrator are:administrator are:• Hardware ConfigurationHardware Configuration• File System ManagementFile System Management• System MonitoringSystem Monitoring

For hardware configuration a common For hardware configuration a common Linux tool is Linux tool is KudzuKudzu• http://rhlinux.redhat.com/kudzu/http://rhlinux.redhat.com/kudzu/

Page 3: Advanced Unix

33

KudzuKudzu

Hardware probing tool run at system boot Hardware probing tool run at system boot time to determine what hardware has time to determine what hardware has been added or removed from the system.been added or removed from the system.

kudzukudzu is normally configured to run at is normally configured to run at startupstartup

It will check you system for hardware then It will check you system for hardware then compare the results with compare the results with /etc/sysconfig/hwconf/etc/sysconfig/hwconf

If changes are detected If changes are detected kudzukudzu will prompt will prompt you to change your system configurationyou to change your system configuration

Page 4: Advanced Unix

44

KudzuKudzu

Devices Devices kudzukudzu will detect and will detect and configure are:configure are:• Network devicesNetwork devices• SCSI devicesSCSI devices• Audio devicesAudio devices• Input/Output devices (keyboards, mice)Input/Output devices (keyboards, mice)• CD-ROMsCD-ROMs• ScannersScanners

Page 5: Advanced Unix

55

KudzuKudzu

Normally run at boot up you can run Normally run at boot up you can run kudzukudzu anytime anytime

kudzukudzu does not normally detect does not normally detect digital camera, usb dirves and/or digital camera, usb dirves and/or webcamswebcams• these are normally detected by the hald these are normally detected by the hald

daemondaemon

Page 6: Advanced Unix

ModulesModules WWhat is a loadable kernel modulehat is a loadable kernel module

WWhen to use moduleshen to use modules

Intel 80386 memory managementIntel 80386 memory management

How module gets loaded in proper locationHow module gets loaded in proper location

Internals of moduleInternals of module

LLinking and unlinking moduleinking and unlinking module

Page 7: Advanced Unix

Kernel module descriptionKernel module description

To add a new code to a Linux kernel, it is necessary to add To add a new code to a Linux kernel, it is necessary to add

some source files to kernel source tree and recompile the some source files to kernel source tree and recompile the

kernel. kernel.

But you can also add code to the Linux kernel while it is But you can also add code to the Linux kernel while it is

running. A chunk of code added in such way is called a running. A chunk of code added in such way is called a

loadable kernel moduleloadable kernel module

Typical modules:Typical modules:

• device driversdevice drivers

• file system driversfile system drivers

• system callssystem calls

Page 8: Advanced Unix

When kernel code must be a When kernel code must be a modulemodule

Some higher level component of Linux kernel Some higher level component of Linux kernel can be compiled as modulescan be compiled as modules

Some Linux kernel code must be linked Some Linux kernel code must be linked

statically then component is included in the statically then component is included in the

kernel or it is not compiled at allkernel or it is not compiled at all

Basic Rules of Thumb:Basic Rules of Thumb:

• Install kernels are bloatedInstall kernels are bloated

• A working kernel should be built with anything that is A working kernel should be built with anything that is

necessary to get the system booted upnecessary to get the system booted up

• Everything else can be built as a modulesEverything else can be built as a modules

Page 9: Advanced Unix

Advantages of modulesAdvantages of modules

There is no necessity to rebuild the kernel, when a There is no necessity to rebuild the kernel, when a new kernel option is addednew kernel option is added

Modules help find system problems (if system Modules help find system problems (if system

problem caused a module just don't load it)problem caused a module just don't load it)

Modules save memoryModules save memory

Modules are much faster to maintain and debugModules are much faster to maintain and debug

Modules once loaded are inasmuch fast as kernelModules once loaded are inasmuch fast as kernel

Page 10: Advanced Unix

Module ImplementationModule Implementation

Modules are stored in the file system as ELF Modules are stored in the file system as ELF ((EExecutable and xecutable and LLinkable inkable FFormat) ormat) object filesobject files

The kernel makes sure that the rest of the kernel The kernel makes sure that the rest of the kernel

can reach the module's global symbolscan reach the module's global symbols

Module must know the addresses of symbols Module must know the addresses of symbols

(variables and functions) in the kernel and in other (variables and functions) in the kernel and in other

modules The modules The

kernel keeps track of the use of modules, so that no kernel keeps track of the use of modules, so that no

modules is unloaded while another module or modules is unloaded while another module or

kernel is using itkernel is using it

Page 11: Advanced Unix

Module ImplementationModule Implementation

The kernel considers only modules that have been The kernel considers only modules that have been

loaded into RAM by the loaded into RAM by the insmodinsmod program and program and

allocates memory area containing:allocates memory area containing:

• The module objectThe module object

• A null terminated string that represents module's nameA null terminated string that represents module's name

• The code that implements the functions of the moduleThe code that implements the functions of the module

Page 12: Advanced Unix

1212

Linking and Unlinking ModulesLinking and Unlinking Modules

Page 13: Advanced Unix

1313

Programs for linking and unlinkingPrograms for linking and unlinking insmodinsmod

• Reads from the name of the module to be linkedReads from the name of the module to be linked• Locates the file containing the module's object codeLocates the file containing the module's object code• Computes the size of the memory area needed to store Computes the size of the memory area needed to store

the module code, its name, andthe module code, its name, and the module objectthe module object lsmodlsmod

• reads /proc/modulesreads /proc/modules rmmodrmmod

• Invokes the query_module( ) system callInvokes the query_module( ) system call• Invokes the delete_module( ) system callInvokes the delete_module( ) system call

Use the QM_REFS subcommand several times, to retrieve Use the QM_REFS subcommand several times, to retrieve dependency information on the linked modulesdependency information on the linked modules

modprobemodprobe• takes care of possible complications due to moduletakes care of possible complications due to module

ddependencies, uses depmod program and ependencies, uses depmod program and /etc/modules.conf/etc/modules.conf file file

Page 14: Advanced Unix

1414

Device driversDevice drivers

There are two major ways for a kernel There are two major ways for a kernel module to talk to processes:module to talk to processes:

To use the proc file system To use the proc file system (/proc(/proc directory) directory) Through device files Through device files (/dev(/dev directory) directory)

DDevice driver sits between some hardware and evice driver sits between some hardware and the kernel I/O subsystem. Its purpose is to give the kernel I/O subsystem. Its purpose is to give the kernel a consistent interface to the type of the kernel a consistent interface to the type of hardware it "drives". hardware it "drives".

Page 15: Advanced Unix

1515

Modules How ToModules How To

The Linux Documentation Project (tldp)The Linux Documentation Project (tldp)http://tldp.org/HOWTO/Module-HOWTO/http://tldp.org/HOWTO/Module-HOWTO/

Module Programming GuideModule Programming Guidehttp://www.linuxhq.com/guides/LKMPG/mpg.htmlhttp://www.linuxhq.com/guides/LKMPG/mpg.html

Page 16: Advanced Unix

1616

Module LabModule Lab

Using lsmod list the modules runningUsing lsmod list the modules running Using insmod insert a moduleUsing insmod insert a module Using modprobe insert a moduleUsing modprobe insert a module Using rmmod remove a moduleUsing rmmod remove a module Note: I’ll show you where the Note: I’ll show you where the

modules are and what they are modules are and what they are calledcalled

Page 17: Advanced Unix

1717

Disk devices are represented by device files that Disk devices are represented by device files that reside in the reside in the /dev/dev directorydirectory

Device file – a file used by Linux commands that Device file – a file used by Linux commands that represent a specific device on the systemrepresent a specific device on the system

Character devicesCharacter devices• Transfer data to and from the system one character or data Transfer data to and from the system one character or data

bit at a timebit at a time Block devices Block devices

• Storage devices that transfer to and from the system in Storage devices that transfer to and from the system in chunks of many bits by caching the information in RAMchunks of many bits by caching the information in RAM

• Can transfer information must faster than character devicesCan transfer information must faster than character devices

File System AdministrationFile System Administration

Page 18: Advanced Unix

1818

The /dev DirectoryThe /dev DirectoryList 1List 1stst floppy & 1 floppy & 1stst SCSI tape device in the SCSI tape device in the /dev/dev directory directory

$ $ ls –l /dev/fd0 /dev/st0ls –l /dev/fd0 /dev/st0

brw-rw---- 1 root floppy 2, 0 Aug 30 2001 /dev/fd0brw-rw---- 1 root floppy 2, 0 Aug 30 2001 /dev/fd0crw-rw---- 1 root disk 9, 0 Apr 4 2001 /dev/st0crw-rw---- 1 root disk 9, 0 Apr 4 2001 /dev/st0

Major number floppy Major number floppy 22,, scsi tapescsi tape 99 Used by the kernel to identify what Used by the kernel to identify what device driverdevice driver to call to to call to

interact properly with a given category of hardwareinteract properly with a given category of hardwareMinor number Minor number 00 on bothon both Used by the kernel to identify which Used by the kernel to identify which specific devicespecific device, within a , within a

given category, to use a driver to communicate withgiven category, to use a driver to communicate with The The bb indicates block devices indicates block devices The The cc indicates character devicesindicates character devices

Page 19: Advanced Unix

1919

The /dev DirectoryThe /dev Directory

Table 6-1 (continued): Common device files

Page 20: Advanced Unix

2020

FilesystemsFilesystems FilesystemFilesystem

• The organization imposed on a physical storage medium The organization imposed on a physical storage medium that is used to manage the storage and retrieval of datathat is used to manage the storage and retrieval of data

FormattingFormatting• The process where a filesystem is placed on a disk driveThe process where a filesystem is placed on a disk drive

Create the ext2 format file system on floppy Create the ext2 format file system on floppy device 0device 0

$ $ mkfs –t ext2 /dev/fd0mkfs –t ext2 /dev/fd0

or or

$ $ mkfs /dev/fd0mkfs /dev/fd0 (ext2 is default filesystem for mkfs)(ext2 is default filesystem for mkfs)

To list devices currently used on the system.To list devices currently used on the system.

$ $ cat /proc/devicescat /proc/devices

Page 21: Advanced Unix

2121

Working with Floppy DisksWorking with Floppy Disks

Table 6-3: Commands used to create filesystems

Floppy disks must be prepared before they are used Floppy disks must be prepared before they are used in Linuxin Linux

Each disk device must be formatted with a Each disk device must be formatted with a filesystem prior to being used to store filesfilesystem prior to being used to store files

Page 22: Advanced Unix

2222

Filesystem TypesFilesystem Types

Table 6-2: Common Linux filesystems

Page 23: Advanced Unix

2323

Filesystem TypesFilesystem Types

Page 24: Advanced Unix

2424

MountingMountingMountingMounting Process used to associate a device with a directory Process used to associate a device with a directory

in the logical directory tree such that users may in the logical directory tree such that users may store data on that devicestore data on that device

Mount pointMount point Directory in a file structure to which something is Directory in a file structure to which something is

mountedmounted

Mount floppy to default mount point (directory)Mount floppy to default mount point (directory)$ $ mount /dev/fd0mount /dev/fd0

Mount floppy to specified mount point (directory)Mount floppy to specified mount point (directory)$ $ mount /dev/fd0 /floppermount /dev/fd0 /flopper

Page 25: Advanced Unix

2525

Working with Floppy DisksWorking with Floppy Disks

Page 26: Advanced Unix

2626

MountingMounting

Page 27: Advanced Unix

2727

MountingMounting

Page 28: Advanced Unix

2828

MountingMounting

When the Linux filesystem is first When the Linux filesystem is first turned on, a filesystem present on turned on, a filesystem present on the hard drive is mounted to the the hard drive is mounted to the // directorydirectory

Root filesystemRoot filesystem• Filesystem that contains the most files Filesystem that contains the most files

that make up the operating systemthat make up the operating system• Should have enough free space to Should have enough free space to

prevent errors and slow performanceprevent errors and slow performance

Page 29: Advanced Unix

2929

Working with CD-ROMsWorking with CD-ROMs Linux systems have an ATAPI compliant Linux systems have an ATAPI compliant

IDE CD-ROM drive that attaches to the IDE CD-ROM drive that attaches to the mainboard via an IDE ribbon cablemainboard via an IDE ribbon cable• These CD-ROMs act as a normal IDE hard These CD-ROMs act as a normal IDE hard

disk, and must be configured on of the four disk, and must be configured on of the four configurations below:configurations below:

Primary master (/dev/hda)Primary master (/dev/hda) Primary slave (/dev/hdb)Primary slave (/dev/hdb) Secondary master (/dev/hdc)Secondary master (/dev/hdc) Secondary slave (/dev/hdd)Secondary slave (/dev/hdd)

Page 30: Advanced Unix

3030

Working with Hard DisksWorking with Hard Disks

IDE hard disk drives attach to the mainboard with an IDE cable and must be configured on one of four configurations, each of which has a different device file:• Primary master (/dev/hda)• Primary slave (/dev/hdb)• Secondary master (/dev/hdc)• Secondary slave (/dev/hdd)

Page 31: Advanced Unix

3131

Working with Hard DisksWorking with Hard Disks

SCSI hard disks are well-suited to SCSI hard disks are well-suited to UNIX/Linux servers that require a UNIX/Linux servers that require a great deal of storage space for great deal of storage space for programs and user filesprograms and user files

Different device files associated with Different device files associated with SCSI hard disks:SCSI hard disks:• First SCSI hard disk drive (/dev/sda)First SCSI hard disk drive (/dev/sda)• Second SCSI hard disk drive (/dev/sdb)Second SCSI hard disk drive (/dev/sdb)• Third SCSI hard disk drive (/dev/sdc)Third SCSI hard disk drive (/dev/sdc)

Page 32: Advanced Unix

3232

Working with Hard DisksWorking with Hard Disks

Different device files associated with Different device files associated with SCSI hard disks (continued):SCSI hard disks (continued):• Fourth SCSI hard disk drive (/dev/sdd)Fourth SCSI hard disk drive (/dev/sdd)• Fifth SCSI hard disk drive (/dev/sde)Fifth SCSI hard disk drive (/dev/sde)• Sixth SCSI hard disk drive (/dev/sdf)Sixth SCSI hard disk drive (/dev/sdf)• And so onAnd so on

Page 33: Advanced Unix

3333

Hard Disk PartitioningHard Disk Partitioning

Recall that hard disks have the largest Recall that hard disks have the largest storage capacity of any device used to storage capacity of any device used to store information on a regular basisstore information on a regular basis• This poses some problems, because as the This poses some problems, because as the

size of a disk increases, organization size of a disk increases, organization becomes more difficult and the chance of becomes more difficult and the chance of error increaseserror increases

PartitionPartition• A physical division of a hard disk driveA physical division of a hard disk drive

Page 34: Advanced Unix

3434

Hard Disk PartitioningHard Disk Partitioning

It is good practice to use more than just It is good practice to use more than just two partitions on Linux system as this two partitions on Linux system as this division can be useful to:division can be useful to:• Segregate different types of dataSegregate different types of data• Allow for the use of more than one type of Allow for the use of more than one type of

filesystem on one hard disk drivefilesystem on one hard disk drive• Reduce the chance the filesystem Reduce the chance the filesystem

corruption will render a system unusablecorruption will render a system unusable• Speed up access to stored data by keeping Speed up access to stored data by keeping

filesystems as small as possiblefilesystems as small as possible

Page 35: Advanced Unix

3535

Hard Disk PartitioningHard Disk Partitioning

TracksTracks• Area on a hard disk that form a Area on a hard disk that form a

concentric circle of sectorsconcentric circle of sectors SectorSector

• Smallest unit of data storage on a hard Smallest unit of data storage on a hard diskdisk

BlockBlock• Unit of data commonly used by Unit of data commonly used by

filesystem commandsfilesystem commands

Page 36: Advanced Unix

3636

Hard Disk PartitioningHard Disk Partitioning

CylinderCylinder• Series of tracks Series of tracks

on a hard disk on a hard disk that are written that are written to to simultaneously simultaneously by the magnetic by the magnetic heads in a hard heads in a hard disk drivedisk drive

Page 37: Advanced Unix

3737

Hard Disk PartitioningHard Disk Partitioning

Page 38: Advanced Unix

3838

Hard Disk PartitioningHard Disk Partitioning

Page 39: Advanced Unix

3939

Hard Disk PartitioningHard Disk Partitioning

Page 40: Advanced Unix

4040

Working with Hard Disk Working with Hard Disk PartitionsPartitions

Disk Druid is an easy-to-use Disk Druid is an easy-to-use partitioning tool used with Red Hat partitioning tool used with Red Hat Linux, specifically designed for Linux, specifically designed for installation onlyinstallation only

To create partitions after installations, To create partitions after installations, you use the fdisk commandyou use the fdisk command

To use the fdisk command, you simply To use the fdisk command, you simply specify the hard disk partition as an specify the hard disk partition as an argumentargument

Page 41: Advanced Unix

4141

Disk UsageDisk Usage

There may be several filesystems mounted to There may be several filesystems mounted to the directory treethe directory tree

The more filesystems that are used, the less The more filesystems that are used, the less likely it is that a corrupted filesystem may likely it is that a corrupted filesystem may interfere with normal system operationsinterfere with normal system operations

Conversely, using more filesystems typically Conversely, using more filesystems typically results in less hard disk space per filesystem results in less hard disk space per filesystem and may result in system errors if certain and may result in system errors if certain filesystems fill up with datafilesystems fill up with data

The easiest method for monitoring free space The easiest method for monitoring free space by mounted filesystem is to use the df (disk by mounted filesystem is to use the df (disk free space) commandfree space) command

Page 42: Advanced Unix

4242

Checking Filesystems for ErrorsChecking Filesystems for Errors

Filesystem corruptionFilesystem corruption• Errors in a filesystem structure that Errors in a filesystem structure that

prevent the retrieval of stored dataprevent the retrieval of stored data SyncingSyncing

• Process of writing data to the hard disk Process of writing data to the hard disk drive that was stored in RAMdrive that was stored in RAM

Bad blocksBad blocks• Those areas of a storage medium used Those areas of a storage medium used

by filesystem commandsby filesystem commands

Page 43: Advanced Unix

4343

Checking Filesystems for ErrorsChecking Filesystems for Errors

Page 44: Advanced Unix

4444

SummarySummary

Disk devices are represented by device Disk devices are represented by device files that reside in the files that reside in the /dev/dev directory directory

Each disk drive must contain a filesystem, Each disk drive must contain a filesystem, which is then mounted to the Linux which is then mounted to the Linux directory tree for usage using the mount directory tree for usage using the mount commandcommand

Hard disks must be partitioned into Hard disks must be partitioned into distinct sections before filesystems are distinct sections before filesystems are created on those partitionscreated on those partitions

Page 45: Advanced Unix

4545

SummarySummary

There are many different filesystems There are many different filesystems available to Linuxavailable to Linux

It is important to monitor disk usage using It is important to monitor disk usage using the the dfdf, , dudu, and , and dumpe2fsdumpe2fs commands to commands to avoid running out of storage spaceavoid running out of storage space

If hard disk space is limited, you can use If hard disk space is limited, you can use hard disk quotas to limit the space that hard disk quotas to limit the space that each user has on filesystemseach user has on filesystems