Linux
by Kamran Husain
IN THIS CHAPTER
- Determining What Tools You Have Installed
- The installpkg Utility
- Generating a New Kernel
- Setting the Default Video Mode
- Accessing DOS Files
- Configuring mtools
- Handling Multiple CD-ROMs
- Adding New File Systems
- Linux Loadable Modules
This chapter covers a variety of topics that basically could not fit in other
chapters, nor could they justify a chapter by themselves. We cover these topics briefly
and provide locations where you can get more information:
- Determining what tools you have installed
- The installpkg utility
- Generating a new kernel
- Setting the default video mode
- Accessing DOS files
- Configuring mtools
- Handling multiple CD-ROMs
- How to address some problems accessing the disc
- Making a file system
The version of Linux on the CD-ROM at the back of this book has the pkgtool
utility for you to use. (See Figure 5.1 for this tool's main screen, which includes
a list of some of its features.) You see the screen in Figure 5.1 when you install
Linux. If you have a color monitor, you will see this in color.
FIGURE
5.1. The main screen for pkgtool.
pkgtool can be used to install packages from CD-ROM or mounted floppy
disks, or in any mounted directory. You can then view what types of packages are
available for your system and remove or add them as necessary.
To view the contents of a package, move the blue highlighted bar down to the View
selection and press Enter. You can also type V to go directly to this selection.
After you press Enter, you will see another screen, as shown in Figure 5.2.
FIGURE
5.2. The View package
screen.
Let's look at the contents of the bison package by using the arrow keys
to scroll down to bison and then pressing Enter. You are presented with
the screen as shown in Figure 5.3. You can scroll up and down in this screen to get
the complete listing by using vi movement commands (j or k)
or the arrow keys on your keyboard.
FIGURE
5.3. The bison View
screen.
Now you can decide if you want this package by reading its description. If you
feel that you would never use a parser generator, then by all means wipe this package
off your disk. (Think twice if you intend to take a compiler class any time in the
future.) To delete this package, you have to go back to the main menu. Press Enter
to select EXIT. You will return to the view selection screen. Select the Cancel button
with the arrow key and press Enter. Then to remove a package, select the Remove option
from the pkgtool main menu.
Depending on the speed of your computer, you will most certainly have to wait
while you view a message telling you about how many BogoMIPS this is going to take.
You can toggle the selection of any packages by using the spacebar. Press Enter when
you are done or select the Cancel button if you want to bail out now.
The installpkg utility creates *.tgz packages for distributing
Linux files. This program has four modes of operation:
- installpkg package_name. By itself, it will install the *.tgz
package you specified in the system. For example, installpkg flex.tgz will
install flex on your system for you.
- installpkg -warn package_name. This will not do the installation process,
but simply tells you what it's about to do.
- installpkg -r package_name. This recursively installs the files in the
root directory from your current directory.
- installpkg -m package_name. This will make a package for you given all
the files in the directory you happen to execute this is in.
Information about all of the installed packages on your system is stored in /var/adm/packages.
Any related script files are stored in /var/adm/scripts.
The removepkg utility is used to remove packages that are listed in the
/var/adm/packages directory. There is a -warn option that tells
you what files will be removed but are not actually removed yet. Do not use the removepkg
utility unless you are absolutely sure that the files in this package are not used
elsewhere.
You will have to install a new kernel if:
- After installation, the Linux kernel does not have the features that the boot
disk kernel had. For example, when you used the boot disk, you could access your
CD-ROM, but the kernel on the hard disk does not recognize it!
- You want to add more features to the kernel. See Chapter 56, "Working with
the Kernel."
- The kernel Linux installed for you is very big and you want a leaner, meaner
kernel that uses less memory.
To compile a custom kernel for your hardware, follow these steps:
- 1. If you haven't installed the C compiler and kernel source, do that
by running installpkg (discussed above).
2. Use the bootkernel disk you created at the time you installed Linux.
At the LILO prompt, enter mount root=/dev/hda1. Ignore any error messages
as the system starts up.
3. Change to root.
4. Go to /usr/src/linux.
5. Run the command make config.
6. Choose your drivers and so on.
7. These four commands will build and install the new kernel to work with LILO:
# make dep
# make clean
# make zlilo
# rdev -R /newkernel
-
CAUTION: Before performing
these steps, be sure to read Chapter 56 in its entirety. Compiling a kernel (without
proper precautions) that does not match your system configuration can yield your
Linux installation unmountable.
You don't have to recompile the kernel to set the default video mode. Just use
rdev with the -v switch to set the video mode in the kernel (either
on your hard drive or on your boot floppy). For example, to change the kernel in
/vmlinuz to prompt for the video mode on bootup, type the following:
rdev -v /vmlinuz -3
To change the kernel on your boot floppy, type
rdev -v /dev/fd0 {video-mode}
These are the valid video-mode options for the kernel: -3 Prompt the user for
a response every time
-2 Extended VGA
-1 Normal VGA
The rdev program resides in /sbin. rdev is very handy
and also is used to set the root and swap partitions, ramdisk size, and more in a
compiled kernel. It means&tm;Ñu don't have to recompb|e the kernel to make
these changes. Use rdev -? for a list of options.
You can always mount the DOS directories and disks to get to DOS files. There
is a set of tools called mtools that expedites this procedure. Look at the
man pages for a complete description of this handy toolset. The following commands
are available for Linux:
mattrib |
Changes MS-DOS file attribute flags. |
mbadblocks |
Marks bad blocks on an MS-DOS diskette. |
mcd |
Changes MS-DOS directory. |
mcopy |
Copies MS-DOS files to/from UNIX. |
mdel |
Deletes an MS-DOS file. |
mdir |
Displays an MS-DOS directory. |
mformat |
Adds an MS-DOS file system to a low-level formatted diskette. |
mlabel |
Makes an MS-DOS volume label. |
mmd |
Makes an MS-DOS subdirectory. |
mmount |
Mounts an MS-DOS FAT-formatted floppy. |
mmove |
Moves or renames an MS-DOS file. |
mrd |
Removes an MS-DOS subdirectory. |
mren |
Renames an existing MS-DOS file. |
mtest |
Tests and displays configuration information. |
mtools |
A public domain collection of programs that enable UNIX systems to read, write, and
manipulate files on an MS-DOS file system (typically a disk). Each program attempts
to emulate the MS-DOS equivalent command. |
mtype |
Displays the contents of an MS-DOS file. |
An entry in the file /etc/mtools contains the following fields: drive,
device, fat, cylinders, heads, sectors,
and offset. Two examples of entries from /etc/mtools are
A /dev/fd0 12 80 2 15
C /dev/hda1 16 0 0 0
which define the DOS disk in drive A as accessible through the device /dev/fd0,
having a 12-bit FAT, 80 cylinders, 2 heads, and 15 sectors per track; DOS disk in
drive C is accessible through the device /dev/hda1, has a 16-bit FAT, and
its geometry is simply that of the hard disk where it lives. The last three numbers
can be zero if you want; this enables mtools to try to figure out the disk's
geometry itself, and perhaps to fail. A 12-bit FAT is common for floppies but might
occur in small hard-disk partitions. A 16-bit FAT is common for hard disks.
This is an extract of my /etc/mtools file:
A /dev/fd0 12 0 0 0 # 3.5 1.4 Meg (autodetect)
B /dev/fd1 12 0 0 0 # 5.25 1.2 Meg (autodetect)
C /dev/hda1 16 0 0 0 # 1st partition of my Disk
There are two detailed README files in the mtools.n2 distribution.
These files treat compiling and using mtools. There is a file README.mtools
that treats only using mtools, which is a part of the MCC interim version
of Linux.
-
TIP: If you want to get
to the MS-DOS files the hard way, you can use mount -t msdos /dev/hda1 /msdos
to mount the partition /dev/hda1 as an MS-DOS file system on the directory
/msdos. The directory /msdos, however, must exist before this command
can be executed. The caveat to using this approach, however, is that the mount point
is not persistent when the system is rebooted. Therein lies the advantage to using
mtools--the mount points will remain even after system reboots.
Use the following shell script to mount the CD-ROM drive:
#
# This should be run while logged in as root
echo "Execute: mount -t iso9660 /dev/cdrom /cdrom"
#
mount -t iso9660 /dev/cdrom /cdrom
-
CAUTION: Don't pull the
CD-ROM out if it's already mounted; use umount /cdrom before swapping disks.
Although this may not seem to be the appropriate place in the book for the topic
of creating file systems to expand your files system space, it is. After you have
worked with Linux for a while, you will want extra space for all the files you accumulate.
If you are not familiar with the way files work in Linux, you might want to familiarize
yourself with Chapter 8, "File System."
In most cases, you will want to expand the /usr partition to allow for
more programs. Most programs wind up under the /usr partition by default
and it's easy to run out of room. A key point to keep in mind is that you do not
have to have your entire file structure on the same drive or under the /
(root) directory. The major restriction is that /:, /sbin,
/bin, /lib, /dev, and /conf have to exist on
the root drive for Linux to boot. Any other file systems, including /usr,
can be mounted afterward.
Let's start with the example of adding a new physical drive to your system. You
can just as easily extend this example to that of creating new partitions on your
existing drive and creating a file system on them.
My example here deals with the hard drive on an IDE controller, so my first drive
is addressed as/dev/hda and the second as /dev/hdb. If you have
a SCSI controller, you will have /dev/sda and/dev/sdb for the first
and second drives, respectively.
You have to do the next operation as root, so read the instructions here
carefully and be careful when deleting files. The usual check and balance system
of confirming permissions on deleting important files does not apply to the superuser.
Create a new partition on your new disk as we did in Chapter 3, "Installing
Linux." You can run fdisk /dev/hdb to run fdisk directly on
the second partition. As a summary, you will use the n command to create
a new partition, specify the size in +Megabytes, and assign a type 83 for
Linux native type of partition. After you have created the new partition, it's a
good idea to reboot. Most of the documentation I have read on Linux says that it's
not necessary, but I am of the old school of thought about being safe and not sorry.
On your return from the reboot, you will create the extended file system with
the mke2fs command. The extended file system is the preferred file system
because it allows for clean boots without having to worry about a file system check
every time you reboot. The syntax for this command to create a file system is
mke2fs -c partition size-in-blocks
Therefore, to create your new file system with 480,000 blocks, you would use this
command:
# mke2fs -c /dev/hdb1 4800000
where the /dev/hdb1 is the first partition on drive B, the -c
flag checks the newly created blocks for errors, and the size is 480,000 blocks.
Be prepared for an onslaught of messages about inodes, blocks, and so forth. This
process may take a while, so be patient.
Now you can mount this new file system with the mount command. First,
create an empty directory in your root directory, let's call it /data.
# cd /
# mkdir data
# mount -t ext2 /dev/hdb1 /data
The mount command shown above will mount the file system in the second
drive as /data. The -t option specifies what type of file system
exists on the new partition. You can now copy files into this new /data
partition. Now you can use this partition for extra space.
The problem is that this mount is valid only for the duration while your machine
is running. If you want this to be mounted automatically at boot time, you should
edit the /etc/fstab file and add the following line:
/dev/hdb1 /data ext2 defaults 1 1
The line will cause init, the boot process for Linux, to mount the /dev/hdb1
partition on to the/data directory as an extended file system using the
default mount parameters.
The Linux kernel (since version 1.2.0) also supports loadable modules. Using loadable
modules enables you to build a minimal kernel and add or remove mo
Contact
[email protected] with questions or comments.
Copyright 1998
EarthWeb Inc., All rights reserved.
PLEASE READ THE ACCEPTABLE USAGE STATEMENT.
Copyright 1998 Macmillan Computer Publishing. All rights reserved.