Notes for Week 3

  1. If you have not yet created a non-root user, do so at this time using the commands "useradd -m (name)", to create the account, and "passwd (name)" to give the account a password (where "(name)" denotes the login name). 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. The su command will place you in /root. When you have finished the work which required root privilege, use the "exit" command to return to being a non-root user.
  2. Examine the file /usr/src/linux-2.6.12.3/Documentation/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 devices are accessed by the same device file) and is constantly changing. To find out if a device is supported, refer to the Hardware HOWTO. Note that newer devices which use the same chip set as an older device will often work with the older device driver. To find out which devices are supported by your current kernel, examine the file /boot/config-2.6.12.3, which contains the kernel configuration parameters used to build your kernel. The meanings of these parameters can be found in the Kconfigs file.

    Section 4 of the man pages contains descriptions of many of the device files. Of particular interest are character devices with major device number 1 (memory device files), 4 (virtual console and serial port device files) and 14 (Open Sound System device files), and block devices with major number 2 (floppy device files), 3 (Primary IDE device files), 8 (SCSI device files), 11 (SCSI CD-ROM device files) and 22 (Secondary IDE device files).

  3. 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-2.6.12.3 and Kconfigs to see which filesystem types are supported by this version of linux.

  4. Use df to display space utilization on filesystems. To see specific information about the space taken up by files in specific directories, use (for example) "du -s /usr/*".

    Software hangs often arise from file locks or conflicts; "fuser -v file" displays information about processes which have a given file or directory open.

    hdparm can be used to interrogate and modify drive settings. In the lab, "hdparm -i /dev/hda" will display information about the DVD drive (the -i option does not currently support SATA drives). The command "hdparm -tT /dev/sda" will run timing tests on the SATA drive; these are an indicator of potential throughput. ANY OTHER USAGE OF HDPARM IS DANGEROUS; if there is something you want to try in the lab, check first with the instructor. If you damage the hard drive using hdparm without having first obtained permission from the instructor, you will be subject to the withdrawal / expulsion policy outlined in the syllabus under the section "Tests and Grades".

    The stat command can be used to view the details of a file's inode.

    The sync command forces synchronization of the mounted filesystems with the VFS and device cache. Periodically executing the sync command ensures that no data will be lost in the event of a power failure.

    The touch command updates a file's modification time to the current time without changing any other attributes of the file (if the file does not yet exist, touch will create an inode for it, but no space will be assigned for its contents). Hence "touch (file)" creates a sort of filesystem time stamp which can be used to flag important events in the life of a filesystem. For instance, if you "touch /root/.installed" immediately after installing your OS, "find / -newer /root/.installed" will find all files and directories modified since installation. Note that the time stamp file in this example has been given a name that begins with a period. This has been done simply to avoid seeing that file every time an ls command is executed (you can see such files with an "ls -a" command).

  5. To format a floppy, first "fdformat /dev/fd0H1440" to format the raw sectors; then use "mke2fs /dev/fd0" or "mkdosfs /dev/fd0" to create the filesystem on the diskette. Note that a filesystem does not have to be created for the diskette to be useful: a bootable floppy often has no filesystem, only the compressed kernel image starting at sector 0.
  6. The partition table of a zip disk typically contains a VFAT filesystem in primary partition number four. This is what windows expects, but you can repartition a zip disk using fdisk, and create whatever partition structure you wish.
  7. Flash drives can be mounted using the command "mount -t vfat /dev/sdb1 /mnt". Depending on the number of flash drives you use, the order in which you use them and the USB port to which you connect them, the device address may be sdc1, sdd1, etc.

    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 (CD-ROM and zip drives will not eject a disk until it has been unmounted).

  8. 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 /".
  9. An entire filesystem can be copied to disk using the dd command. For example, "dd if=/dev/fd0 of=floppy.image" will copy the entire floppy disk to the file floppy.image. This disk image can then be mounted using the loopback interface, and treated like any other filesystem: "mount -o loop floppy.image /mnt".


©2005, 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.