Notes for Week 3

  1. If you have not yet created a non-root user, do so at this time using the commands

    Logout as root and log back in as that user, and do most of your work as that user. When you need to work as root, execute the command su (which will prompt you for the root password) to temporarily become root. When you have finished the work which required root privilege, use the exit command to return to being a non-root user.

    There are some nice screen savers that will run under non-root users. Unfortunately, in the past, some of the 3D ones could lock your system up tightly enough to force you to power down. The safest thing is to select the "Blank Screen Only" mode in xscreensaver-command -prefs.

    A systems administrator NEVER walks away from her/his console without first locking the screen.

    You can do this with xscreensaver-command -lock.

    Note that in order to use the 3-D screensavers, you must be a member of the video group. We will learn how to do this in week 6.
  2. Examine the file /usr/doc/linux-3.13/devices.txt. It contains a list of all of the hardware device filenames which can appear in /dev. This is not the same as all of the devices supported by Linux. That list is much larger (since many types of devices can accessed by the same device file, and some devices, such as many network devices, do not have /dev entries), and is constantly changing.

    To find out if a device is supported, you have to know which version of the kernel you are running, and what capabilities were built into it. Suppose you wanted to see if your kernel supports the Realtek 8169 Gigabit Ethernet adaptor. You would first examine the

    Kconfigs files in the linux source tree (here collected into one file for your convenience)
    for your Linux distribution to identify the "config" parameter associated with that device. Loading the file (either into your browser, emacs or less), and searching for
    Realtek 8169
    tells you that the configuration parameter is called "R8169". Then examine the configuration file for your kernel:
    /boot/config-3.13.3 was used for our kernel
    (either by loading the file and searching for R8169, or by using the "grep" command:
    grep /boot/config-3.13.3 -e R8169
    grep is like the Windows FIND command after it has been bitten by a radioactive spider.

    grep is your friend. For example, you can use it as a sort of dynamic glossary. Suppose you save a copy of each page of these notes in the directory "notes". To find which pages contain references to "passwd", you would simply

    grep -ile 'passwd' notes/*.html
    which results in the following output:
    notes/week1.html
    notes/week3.html
    notes/week6.html
    notes/weekd.html
    notes/weeke.html
    This tells you that the passwd command (or something related to it) is discussed in the notes for weeks 1, 3, 6, 13 and 14.
    The "i" option tells grep to be "case-insensitive" when searching for the string "passwd"; this allows for matching of the string at, for instance, the beginning of a sentence. The "l" option tells grep to simply "list" the names of the files in which the string occurs, and the "e" option specifies that the next string is the "expression" you which to search for. The asterisk is a "wild-card", which matches any string; here, as often, it is used to specify any filename ending in ".html". We used the asterisk in step 5 of week 2 to copy everything in / to the hard drive.
    Either way, you find the line "CONFIG_R8169=m", which tells you that support for that device has been built into your kernel as a module which can be loaded and unloaded dynamically as needed. If the result had been "CONFIG_R8169=y", the driver was built into the kernel as it is loaded at boot time, and is always in memory, and if the result had been "CONFIG_R8169=n", there would be no support for this device in your kernel.
    Note that newer devices which use the same chip set as an older device will often work with the older device driver.
    Linux support for newer devices, particularly video cards, often lags behind Windows support. When a manufacturer designs a new device, they write a Windows device driver for it and provide both the hardware and software to Microsoft so that it can be integrated into the operating system. When someone in the Linux community wants support for a new device, they have to buy one of the devices for themselves, either write a new driver or modify an existing one to work with it, and then give it to the open source community for testing and integration.
  3. Section 4 of the man pages contains descriptions of many of the device files. Of particular interest are:

    Suppose you wanted to find out quickly what the major and minor device numbers were for SCSI drives sdb1 and sdb2. Here are several ways to do this:

    The first two provide a "long" list of the devices files, which show the numbers preceding the creation date, as well as the device type (block) in the first letter of the output. The "[12]" is a way of allowing either character to match in the filename (and can be used with grep), and the "{1,2}" is similar but can be expanded to include whole strings in the place of the numerals.

    These two methods only work if the device file exists. More about this when we discuss udevd next week.
    The last way illustrates both a way to see the 10 lines surrounding any grep match (the "Context"), and that sometimes you get much more information than you expected!
  4. File management under Linux is handled by the Virtual File System. Since Linux supports many different types of filesystems (Ext2, FAT, VFAT, ISO-9660, HPFS, NFS, NCP, NTFS, etc.), each filesystem type has its own driver and the VFS serves as a common interface between them and the file access routines that handle opening, reading, writing, closing, etc., of files and directories. So, for instance, an ls command will produce compatible results no matter which filesystem is being referenced. The VFS maintains a common inode and directory cache for all of the filesystems, and the filesystem drivers use the same disk cache and drivers. All currently accessible files and directories have path names relative to the same directory tree root, called "/".

    Examine /boot/config-3.13.3 and Kconfigs to see which filesystem types are supported by this version of Linux.

    In general, Windows only supports three types of filesystems: FAT, NTFS, and ISO-9660.

  5. Some useful file and filesystem commands:

  6. A flash drive can be mounted using the command mount /media/usbstg. If you use a second flash drive simultaneously, in our lab the additional device address will be sdd1. For sdd1, you will have to mount it explicitly with mount -t vfat /dev/sdd1 /mnt (only root can do this, since the mount points are not listed in /etc/fstab).
    Remember to unmount the drive before removing it physically from the interface; like floppies, there is no guarantee that the filesystem on the drive is in a consistent state if you remove it while it is still mounted.
  7. The installation we performed last week left us with two ext2 filesystems: one for the root filesystem, which is mounted read-only, and one for /var, which is writable. Occasionally we will need to make modifications to the root filesystem. For instance, you may wish to create a directory /media/flash as a mount point for a flash drive. To modify the root filesystem, you can re-mount it writable using the command mount -wo remount /. After making the desired modifications, you can then re-mount it read-only using the command mount -ro remount /.
  8. An entire filesystem can be copied to disk using the dd command. For example, dd if=/dev/sdc1 of=flash.image will copy the entire first flash drive partition to the file flash.image. This disk image can then be mounted using the loopback interface, and treated like any other filesystem: mount -o loop flash.image /mnt.
    You may have to modprobe loop to load the loopback module if it has not already been loaded.
    We did this in step 5 last week.

    Window's DISKCOPY command is a very limited form of dd.


  9. EXERCISES for Week 3:

    1. Are there any "hidden" files in the root directory? In /etc? In /dev?
    2. Search all the files in your home directory (but not the subdirectories!) for the string xscreensaver. Display the contents of every file containing that string.
    3. Make a bin directory in your home directory. Copy the files you just found into it. Change to your new bin directory and rename the files there to remove any periods from the names. Delete those files.
    4. What are the device type, major and minor numbers for the device holding /var while running from the DVD?
    5. What are the device type, major and minor numbers for the first loopback device?


©2015, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.

Please send comments or suggestions to the author.