linux installation and administration – lesson 5 tutor: george papamarkos topic: devices in linux

17
Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Upload: rolf-holland

Post on 26-Dec-2015

220 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Linux Installation and Administration – Lesson 5

Tutor: George PapamarkosTopic: Devices in Linux

Page 2: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Lesson Outline

• Managing Filesystems– Mounting Disks

• Managing Devices – Device Files– Loading Device Drivers– Loading Modules Automatically

Page 3: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Managing Devices – Device Files

• Device Files allow user programs access hw devices on the system through Linux kernel

• Device Drives in Linux/Unix are part of the monolithic kernel

• Devices are located under the /dev dir– E.g. /dev/ttyS0 for the 1st serial port– /dev/hda2 for the 2nd partition of the

1st IDE HDD drive

Page 4: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Managing Devices – Device Files

• Some device files do not correspond to actual devices– E.g. /dev/null acts as a byte sink.Write on

this device succeeds always but what is written is ignored

• Devices are divided to:– Block Devices: Data are read and written in

“blocks”• E.g. the IDE hard drives

– Character Devices: Data are read and written sequentially

• E.g. serial port

Page 5: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Managing Devices – Device Files

• In ls –l command in /dev dir, the size of the files has been replaced by two numbers separated by a comma.– brw-rw---- 1 root disk 3, 0 November 2 2004 /dev/hda– The 1st value is called major number and the second is

called minor number– Major Num: Specifies a particular driver within the

kernel– Minor Num: Specifies a particular devices handled by

the driver– E.g. All USB devices are handled by the same driver

with one major num although for each of them there is a minor num

Page 6: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Working with Device Files

• Create a device file:mknod -m permissions name type major minorwhere:• name is the full pathname of the device to create, such as

/dev/rft0• type is either c for a character device or b for a block device• major is the major number of the device• minor is the minor number of the device• -m permissions is an optional argument that sets the permission

bits of the new device file to permissions– E.g. mknod /dev/test b 42 0

• Remove a device file:rm /dev/test

• You can of course create links between devices using ln command

Page 7: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Loading Device Drivers

• Drivers are cooperating with kernel and they are:– Compiled within the kernel, or– Loaded like external modules to the

kernel (like .dll files in Windows) at runtime

• A module is simply a single object file containing all the code for the driver.– E.g. usbcore.o the module for usb

devices

Page 8: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Loading Device Drivers

• The modules are stored (in most of the systems) in /lib/modules/kernel-version where different dirs per module category exist

Page 9: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Load a Module• Command: insmod <module_name>

– insmod usbcore.o

• The module may fail to load due to dependencies from other modules

• You have to find by your own and resolve this• To avoid this, create a module database with the

command: depmod –a, to store all the info about the module

• After that you can replace insmod with modprobe command, which checks the create database and resolves the module dependencies automatically

Page 10: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Working with modules

• List the already loaded drivers with:–lsmod

• Remove a loaded driver with:–Rmmod <module_name>–E.g. rmmod usbcore

Page 11: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Mounting Filesystems on Devices

• Filesystem is the way the data are organised and stored (in physical level) on disks

• Common Filesystems in Linux1. Ext2/ext32. ReiserFS3. Swap4. NFS 5. Vfat6. /proc filesystem

Page 12: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Mounting filesystems• In order to access any filesystem under Linux, you

must mount it on a certain directory.• The mount command is used to do this and usually

must be executed as root.• The format of this command is: mount -t type device mount-point

where type is the type name of the filesystem, device is the physical device where the filesystem resides (the device file in /dev), and mount-point is the directory on which to mount the filesystem.

• You have to create the directory before issuing mount.

Page 13: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Mounting Filesystems

• E.g. – mount -t vfat /dev/hda2 /mnt/windows

To mount the windows hda2 FAT32 partition

• There are many options to the mount command, which can be specified with the -o switch.

• One common option to mount is -o ro, which mounts the filesystem as read-only. E.g. CDROMs

mount -t iso9660 -r /dev/cdrom /mnt/cdrom

Page 14: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

Unmounting Filesystems

• The inverse of mounting a filesystem is, naturally, unmounting it.

• Unmounting a filesystem has two effects:– synchronizes the system's buffers with the

actual contents of the filesystem on disk– it makes the filesystem no longer available

from its mount point.

• Unmounting is done with the umount command– umount <mount_dir>, e.g. umount mnt/windows

Page 15: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

/etc/fstab

• You can find out what devices are mounted, and where, using the mount command with no arguments

• The system automatically mounts several filesystems when the system boots.

• This is handled by the file /etc/fstab– Each line in this file is of the format:device mount-point type optionse.g. /dev/hda2 /mnt/windows vfat defaults

Page 16: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

/etc/fstab

• The option defaults should be used for most filesystems; it enables a number of other options, such as rw (read-write access), async (buffer I/O to the filesystem in memory asynchronously), and so forth.

• Another potentially useful option is umask, which lets you set the default mask for the permission bits, something that is especially useful with some foreign filesystems.

Page 17: Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux

/etc/fstab

• At boot time mount –a command is called that mounts everything listed in /etc/fstab

• A filesystem does not need to be listed in /etc/fstab in order to be mounted, but it does need to be listed there in order to be mounted "automatically" by mount -a