450 likes | 602 Views
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.
E N D
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 • Hardware probing tool run at system boot time to determine what hardware has been added or removed from the system. • kudzu is normally configured to run at startup • It will check you system for hardware then compare the results with /etc/sysconfig/hwconf • If changes are detected kudzu will prompt you to change your system configuration
Kudzu • Devices kudzu will detect and configure are: • Network devices • SCSI devices • Audio devices • Input/Output devices (keyboards, mice) • CD-ROMs • Scanners
Kudzu • Normally run at boot up you can run kudzu anytime • kudzu does not normally detect digital camera, usb dirves and/or webcams • these are normally detected by the hald daemon
Modules • What is a loadable kernel module • When to use modules • Intel 80386 memory management • How module gets loaded in proper location • Internals of module • Linking and unlinking module
Kernel module description • To add a new code to a Linux kernel, it is necessary to add some source files to kernel source tree and recompile the kernel. • 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 loadable kernel module • Typical modules: • device drivers • file system drivers • system calls
When kernel code must be a module • Some higher level component of Linux kernel can be compiled as modules • Some Linux kernel code must be linked statically then component is included in the kernel or it is not compiled at all • Basic Rules of Thumb: • Install kernels are bloated • A working kernel should be built with anything that is necessary to get the system booted up • Everything else can be built as a modules
Advantages of modules • There is no necessity to rebuild the kernel, when a new kernel option is added • Modules help find system problems (if system problem caused a module just don't load it) • Modules save memory • Modules are much faster to maintain and debug • Modules once loaded are inasmuch fast as kernel
Module Implementation • Modules are stored in the file system as ELF (Executable and Linkable Format) object files • The kernel makes sure that the rest of the kernel can reach the module's global symbols • Module must know the addresses of symbols (variables and functions) in the kernel and in other modules The • kernel keeps track of the use of modules, so that no modules is unloaded while another module or kernel is using it
Module Implementation • The kernel considers only modules that have been loaded into RAM by the insmod program and allocates memory area containing: • The module object • A null terminated string that represents module's name • The code that implements the functions of the module
Programs for linking and unlinking • insmod • Reads from the name of the module to be linked • Locates the file containing the module's object code • Computes the size of the memory area needed to store the module code, its name, andthe module object • lsmod • reads /proc/modules • rmmod • Invokes the query_module( ) system call • Invokes the delete_module( ) system call • Use the QM_REFS subcommand several times, to retrieve dependency information on the linked modules • modprobe • takes care of possible complications due to module dependencies, uses depmod program and /etc/modules.conf file
Device drivers • There are two major ways for a kernel module to talk to processes: • To use the proc file system (/proc directory) • Through device files (/dev directory) • Device driver sits between some hardware and the kernel I/O subsystem. Its purpose is to give the kernel a consistent interface to the type of hardware it "drives".
Modules How To • The Linux Documentation Project (tldp) http://tldp.org/HOWTO/Module-HOWTO/ • Module Programming Guide http://www.linuxhq.com/guides/LKMPG/mpg.html
Module Lab • Using lsmod list the modules running • Using insmod insert a module • Using modprobe insert a module • Using rmmod remove a module • Note: I’ll show you where the modules are and what they are called
File System Administration • Disk devices are represented by device files that reside in the /devdirectory • Device file – a file used by Linux commands that represent a specific device on the system • Character devices • Transfer data to and from the system one character or data bit at a time • Block devices • Storage devices that transfer to and from the system in chunks of many bits by caching the information in RAM • Can transfer information must faster than character devices
The /dev Directory List 1st floppy & 1st SCSI tape device in the /dev directory $ ls –l /dev/fd0 /dev/st0 brw-rw---- 1 root floppy 2, 0 Aug 30 2001 /dev/fd0 crw-rw---- 1 root disk 9, 0 Apr 4 2001 /dev/st0 Major number floppy 2,scsi tape9 • Used by the kernel to identify what device driver to call to interact properly with a given category of hardware Minor number 0on both • Used by the kernel to identify which specific device, within a given category, to use a driver to communicate with • The b indicates block devices • The cindicates character devices
The /dev Directory Table 6-1 (continued): Common device files
Filesystems • Filesystem • The organization imposed on a physical storage medium that is used to manage the storage and retrieval of data • Formatting • The process where a filesystem is placed on a disk drive • Create the ext2 format file system on floppy device 0 $ mkfs –t ext2 /dev/fd0 or $ mkfs /dev/fd0(ext2 is default filesystem for mkfs) • To list devices currently used on the system. $ cat /proc/devices
Working with Floppy Disks • Floppy disks must be prepared before they are used in Linux • Each disk device must be formatted with a filesystem prior to being used to store files Table 6-3: Commands used to create filesystems
Filesystem Types Table 6-2: Common Linux filesystems
Mounting Mounting • Process used to associate a device with a directory in the logical directory tree such that users may store data on that device Mount point • Directory in a file structure to which something is mounted Mount floppy to default mount point (directory) $ mount /dev/fd0 Mount floppy to specified mount point (directory) $ mount /dev/fd0 /flopper
Mounting • When the Linux filesystem is first turned on, a filesystem present on the hard drive is mounted to the / directory • Root filesystem • Filesystem that contains the most files that make up the operating system • Should have enough free space to prevent errors and slow performance
Working with CD-ROMs • Linux systems have an ATAPI compliant IDE CD-ROM drive that attaches to the mainboard via an IDE ribbon cable • These CD-ROMs act as a normal IDE hard disk, and must be configured on of the four configurations below: • Primary master (/dev/hda) • Primary slave (/dev/hdb) • Secondary master (/dev/hdc) • Secondary slave (/dev/hdd)
Working 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)
Working with Hard Disks • SCSI hard disks are well-suited to UNIX/Linux servers that require a great deal of storage space for programs and user files • Different device files associated with SCSI hard disks: • First SCSI hard disk drive (/dev/sda) • Second SCSI hard disk drive (/dev/sdb) • Third SCSI hard disk drive (/dev/sdc)
Working with Hard Disks • Different device files associated with SCSI hard disks (continued): • Fourth SCSI hard disk drive (/dev/sdd) • Fifth SCSI hard disk drive (/dev/sde) • Sixth SCSI hard disk drive (/dev/sdf) • And so on
Hard Disk Partitioning • Recall that hard disks have the largest storage capacity of any device used to store information on a regular basis • This poses some problems, because as the size of a disk increases, organization becomes more difficult and the chance of error increases • Partition • A physical division of a hard disk drive
Hard Disk Partitioning • It is good practice to use more than just two partitions on Linux system as this division can be useful to: • Segregate different types of data • Allow for the use of more than one type of filesystem on one hard disk drive • Reduce the chance the filesystem corruption will render a system unusable • Speed up access to stored data by keeping filesystems as small as possible
Hard Disk Partitioning • Tracks • Area on a hard disk that form a concentric circle of sectors • Sector • Smallest unit of data storage on a hard disk • Block • Unit of data commonly used by filesystem commands
Hard Disk Partitioning • Cylinder • Series of tracks on a hard disk that are written to simultaneously by the magnetic heads in a hard disk drive
Working with Hard Disk Partitions • Disk Druid is an easy-to-use partitioning tool used with Red Hat Linux, specifically designed for installation only • To create partitions after installations, you use the fdisk command • To use the fdisk command, you simply specify the hard disk partition as an argument
Disk Usage • There may be several filesystems mounted to the directory tree • The more filesystems that are used, the less likely it is that a corrupted filesystem may interfere with normal system operations • Conversely, using more filesystems typically results in less hard disk space per filesystem and may result in system errors if certain filesystems fill up with data • The easiest method for monitoring free space by mounted filesystem is to use the df (disk free space) command
Checking Filesystems for Errors • Filesystem corruption • Errors in a filesystem structure that prevent the retrieval of stored data • Syncing • Process of writing data to the hard disk drive that was stored in RAM • Bad blocks • Those areas of a storage medium used by filesystem commands
Summary • Disk devices are represented by device files that reside in the /dev directory • Each disk drive must contain a filesystem, which is then mounted to the Linux directory tree for usage using the mount command • Hard disks must be partitioned into distinct sections before filesystems are created on those partitions
Summary • There are many different filesystems available to Linux • It is important to monitor disk usage using the df, du, and dumpe2fs commands to avoid running out of storage space • If hard disk space is limited, you can use hard disk quotas to limit the space that each user has on filesystems