Sunteți pe pagina 1din 154

V2.0.0.

cover

 Front cover

Linux System
Administration I:
Implementation
(Course Code QLX03)

Student Exercises
ERC 3.1

IBM Certified Course Material


Student Exercises

Trademarks
IBM® is a registered trademark of International Business Machines Corporation.
The following are trademarks of International Business Machines Corporation in the United
States, or other countries, or both:
AIX® DB2® Domino™
Hummingbird® Lotus® OS/2®
PS/2® XT™
Windows and Windows NT are trademarks of Microsoft Corporation in the United States,
other countries, or both.
Intel and Pentium are trademarks of Intel Corporation in the United States, other countries,
or both.
UNIX is a registered trademark of The Open Group in the United States and other
countries.
Linux is a registered trademark of Linus Torvalds in the United States and other countries.
Other company, product and service names may be trademarks or service marks of others.

June 2004 Edition

The information contained in this document has not been submitted to any formal IBM test and is distributed on an “as is” basis without
any warranty either express or implied. The use of this information or the implementation of any of these techniques is a customer
responsibility and depends on the customer’s ability to evaluate and integrate them into the customer’s operational environment. While
each item may have been reviewed by IBM for accuracy in a specific situation, there is no guarantee that the same or similar results will
result elsewhere. Customers attempting to adapt these techniques to their own environments do so at their own risk.

© Copyright International Business Machines Corporation 2001, 2004. All rights reserved.
This document may not be reproduced in whole or in part without the prior written permission of IBM.
Note to U.S. Government Users — Documentation related to restricted rights — Use, duplication or disclosure is subject to restrictions
set forth in GSA ADP Schedule Contract with IBM Corp.
V2.0
Student Exercises

TOC Contents
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v

Exercises Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii

Exercise 1. Physical Planning and Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

Exercise 2. Advanced Linux Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1

Exercise 3. Startup and Shutdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1

Exercise 4. System Administration Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1

Exercise 5. Packaging Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1

Exercise 6. X Window System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1

Exercise 7. Kernel Compilation and Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1

Exercise 8. Character Devices, PCMCIA, and USB . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1

Exercise 9. Block Devices, RAID, and LVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-1

Exercise 10. Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1

Exercise 11. Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1

Exercise 12. Linux on IBM eServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-1

Exercise 13. Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-1

Exercise 14. Backup and Restore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-1

Exercise 15. User Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1

Exercise 16. User-Level Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-1

Exercise 17. Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-1

Exercise 18. Printers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-1

Exercise 19. Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-1

Appendix A. Hardware Configuration Sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1

© Copyright IBM Corp. 2001, 2004 Contents iii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

iv Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

TMK Trademarks
The reader should recognize that the following terms, which appear in the content of this
training document, are official trademarks of IBM or other companies:
IBM® is a registered trademark of International Business Machines Corporation.
The following are trademarks of International Business Machines Corporation in the United
States, or other countries, or both:
AIX® DB2® Domino™
Hummingbird® Lotus® OS/2®
PS/2® XT™
Windows and Windows NT are trademarks of Microsoft Corporation in the United States,
other countries, or both.
Intel and Pentium are trademarks of Intel Corporation in the United States, other countries,
or both.
UNIX is a registered trademark of The Open Group in the United States and other
countries.
Linux is a registered trademark of Linus Torvalds in the United States and other countries.
Other company, product and service names may be trademarks or service marks of others.

© Copyright IBM Corp. 2001, 2004 Trademarks v


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

vi Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

pref Exercises Description


In exercise 1 you will install your own Red Hat Linux system, on which
you will perform exercises 2 through 15. Exercises 2 through 15 are
designed so that you will practice various system administration tasks.
These exercises will teach you how to install and configure Linux. The
exercises are largely independent of each other, except for exercise 2
(installing Linux). Exercise 3 and up all depend on the successful
completion of exercise 1.
Each exercise in this course is divided into sections as described
below. Select the section that best fits your method of performing labs.
You may elect to use a combination of these sections as appropriate.
Exercise Instructions — This section contains what it is you are to
accomplish. There are no definitive details on how to perform the
tasks. You are given the opportunity to work through the exercise
given what you learned in the unit presentation, utilizing the unit
Student Notebook, your past experience and maybe a little intuition.
Exercise Instructions With Hints — This section is an exact
duplicate of the Exercise Instructions section except that in addition,
specific details and/or hints are provided to help step you through the
exercise. A combination of using the Instructions section along with
Instructions With Hints section can make for a rewarding combination
providing you with no hints when you don't want them and hints when
you need them. Exercise instructions - This section contains what it is
you are accomplish.

© Copyright IBM Corp. 2001, 2004 Exercises Description vii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

viii Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 1. Physical Planning and Maintenance

What This Exercise Is About


This (optional) exercise will let perform some activities related to the
physical planning and maintenance of your system.

What You Should Be Able to Do


After completing this exercise you should have experience with
performing calculations for electrical power and air conditioning.

© Copyright IBM Corp. 2001, 2004 Exercise 1. Physical Planning and Maintenance 1-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Performing power and air conditioning calculations
__ 1. Go around the room and check the power rating of all electrical equipment in the
room. Calculate the total amount of power required. How many different electrical
circuits would you need at least to support all equipment in the room running at full
power? Don’t forget to add some extra capacity for future upgrades, the janitors
vacuum cleaner and so forth.
__ 2. Now calculate how many tons of air conditioning you need to cool the classroom.
Don’t forget to add additional cooling capacity for all people in the room. (Do not
perform calculations for windows and such; this is beyond the scope of this class.)

Equipping a computer room


__ 3. Go around the classroom and make recommendations as if you were going to use
this classroom as your computer room. Consider all things that were covered in the
lecture.

END OF EXERCISE

1-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 2. Advanced Linux Installation

What This Exercise Is About


This exercise will let you install Linux via the network.

What You Should Be Able to Do


After completing this exercise you should have experience with
installing Linux via the network.

Required Materials
To complete this exercise, you will need the following:
• A set of network install diskettes for your distribution
• The IP address and NFS export name of the install server
Your instructor will provide you with this.

© Copyright IBM Corp. 2001, 2004 Exercise 2. Advanced Linux Installation 2-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions (Fedore Core 2)


Installing Fedora Core 2 via the network
__ 1. Insert the Fedora Core 2 boot.iso CD in the CD drive of your computer.
__ 2. Turn on the computer.
__ 3. The system will boot from CD, and you will see a screen giving you different
installation options. We will use standard installation, so press Enter.
__ 4. Choose the language for the installation process and click OK.
__ 5. Choose your keyboard model, and click OK.
__ 6. Select NFS image as install media. Click OK.
__ 7. Depending on the classroom network setup, you might be able to use Dynamic IP, or
need to use Static IP addressing. Your instructor will tell you which choice to make,
and what IP addresses to use.
Click OK.
__ 8. Enter the IP address of the NFS server, and the directory that is exported and
contains Fedora Core 2.
__ 9. The install process will now contact the NFS server and will start the X-based
installer (Anaconda). This will take a minute or so.
__ 10. You will now see the Fedora Core Welcome Screen. Click Next.
__ 11. If a previous Linux installation was found on your system, you will now be prompted
to upgrade this. This is not what we want, so select Perform a new Fedora Core
installation and click Next.
__ 12. Choose the Custom installation type. Click Next.
__ 13. Choose to Manually Partition using Disk Druid. Click Next.
__ 14. The Disk Druid screen will now allow you to create your Linux partitions. First, delete
all existing partitions and create seven new partitions:
• A / (root) partition of 500 MB
• A /usr partition of 4000 MB
• A /boot partition of 100 MB
• A /home partition of 250 MB
• A /tmp partition of 250 MB
• A /var partition of 250 MB
• A swap partition of 256 MB
All partitions, except the swap partition, should be formatted as ext3.

2-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Do not make partitions larger than the size indicated, since we will need free,
unpartitioned space in other exercises.
Click Next. If you get a popup window that some values are less than what Fedora
suggests, ignore this.
__ 15. The next screen will allow you to set up your boot loader. Accept all defaults and
click Next.
__ 16. Check to see if the network parameters are correct. Then click Next.
__ 17. Do not configure any firewall rules, by selecting No firewall. Click Next.
__ 18. Do not select any additional language support. Click Next.
__ 19. Now select your Time Zone, then click Next.
__ 20. For convenience in the class, set the root password to ibmlnx. Click Next.
__ 21. Now you will have to choose which packages to install. Select the “Minimal”
installation profile (bottom of the list). (We will install additional package groups
later.)
Click Next.
__ 22. Note the location of the log file: /tmp/install.log and click Next.
__ 23. Fedora will now format the filesystems and install Fedora Core 2. This may take
anywhere from one to 15 minutes, depending on the number of packages to install,
the network bandwidth available and the speed of the computer.
While installing, you can see what is going on in detail by switching to the third
virtual terminal with Ctrl-Alt-F3. Switch back with Alt-F7. Also take a look at other
virtual screens (1 through 6).
__ 24. Your installation is now complete. Remove the diskette from the drive and click Exit
to reboot your system.

Fedora Kickstart installation


__ 25. After reboot, log in as root and take a look at the anaconda-ks.cfg file in your home
directory. Do you recognize the choices you made during the installation process?
__ 26. Modify the anaconda-ks.cfg file so that the following is added:
• The install process should be done via NFS, from the correct server and
directory.
• All partitions should be deleted, and partitions should be created according to
the scheme we just used.
• The following package groups need to be installed:
Printing Support
X Window System

© Copyright IBM Corp. 2001, 2004 Exercise 2. Advanced Linux Installation 2-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

GNOME Desktop
KDE (K Desktop Environment)
Legacy Software Development
Network Servers
Development Tools
Note that these package groups names need to be typed exactly like they
appear in the Fedora/base/comps.xml file on Fedora Core CD1 (which is
copied onto the install server)
• Two user accounts need to be created called tux1 and tux2, with full name
“Tux the Penguin (1)” and “Tux the Penguin (2)”, and their password identical
to their username.
The anaconda-ks.cfg file should now look like this:
install
nfs --server=10.0.0.1 --dir=/export/fedora2
lang en_US.UTF-8
langsupport --default en_US.UTF-8 en_US.UTF-8
keyboard us
xconfig --resolution 1024x768 --depth 24
network --device eth0 --bootproto dhcp
rootpw ibmlnx
firewall --disabled
selinux --disabled
authconfig --enableshadow --enablemd5
timezone Europe/Amsterdam
bootloader
clearpart --all
part /boot --fstype ext3 --size=100
part /usr --fstype ext3 --size=4000
part / --fstype ext3 --size=500
part /var --fstype ext3 --size=250
part /home --fstype ext3 --size=250
part /tmp --fstype ext3 --size=250
part swap --size=256

%packages
@ Printing Support
@ X Window System
@ GNOME Desktop
@ KDE (K Desktop Environment)
@ Legacy Software Development
@ Network Servers

2-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty @ Development Tools

%post
adduser -c “Tux the Penguin (1)” tux1
echo tux1 | passwd --stdin tux1
adduser -c “Tux the Penguin (2)” tux2
echo tux2 | passwd --stdin tux2
__ 27. Ask your instructor what to do with the kickstart file. There are two options:
i. Put the kickstart file on a blank floppy, which your instructor will provide.
» # mount /mnt/floppy
» # cp anaconda-ks.cfg /mnt/floppy/ks.cfg
» # umount /mnt/floppy
ii. Upload the file, under your own name, to the instructor server.
» # scp anaconda-ks.cfg 10.0.0.1:/export/kickstart/<yourname>.cfg
__ 28. Reboot your system. When the system boots from CD, make sure that you start a
kickstart install.
» # reboot
» When the boot prompt appears, start a kickstart install:
boot: linux ks=floppy
- OR -
boot: linux ks=nfs:10.0.0.1:/export/kickstart/<yourname>.cfg
» Wait for your system to start the installation. The instructor will probably start
the next lecture once all systems have successfully started their kickstart
installation.
__ 29. When the installation is finished, click Reboot.

Documenting your installation


__ 30. Fill in appendix A of this exercises guide, as far as you can.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 2. Advanced Linux Installation 2-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions (Red Hat Enterprise Linux 3 ES)


Installing Red Hat Enterprise Linux 3 ES via the network
__ 1. Insert the Red Hat Enterprise Linux 3 ES boot.iso CD in the CD drive of your
computer.
__ 2. Turn on the computer.
__ 3. The system will boot from CD, and you will see a screen giving you different
installation options. We will use standard installation, so press Enter.
__ 4. Choose the language for the installation process and click OK.
__ 5. Choose your keyboard model, and click OK.
__ 6. Select NFS image as install media. Click OK.
__ 7. Depending on the classroom network setup, you might be able to use Dynamic IP, or
need to use Static IP addressing. Your instructor will tell you which choice to make,
and what IP addresses to use.
Click OK.
__ 8. Enter the IP address of the NFS server, and the directory that is exported and
contains Red Hat Enterprise Linux.
__ 9. The install process will now contact the NFS server and will start the X-based
installer (Anaconda). This will take a minute or so.
__ 10. You will now see the Red Hat Linux Welcome Screen. Click Next.
__ 11. Select your mouse model. If you have a two-button mouse, make sure to emulate 3
buttons.
__ 12. If a previous Red Hat Linux was found on your system, you will now be prompted to
upgrade this. This is not what we want, so select “Perform a new Red Hat Enterprise
Linux installation” and click Next.
__ 13. Choose to Manually Partition using Disk Druid. Click Next.
__ 14. The Disk Druid screen will now allow you to create your Linux partitions. First, delete
all existing partitions and create seven new partitions:
• A / (root) partition of 500 MB
• A /usr partition of 4000 MB
• A /boot partition of 100 MB
• A /home partition of 250 MB
• A /tmp partition of 250 MB
• A /var partition of 250 MB
• A swap partition of 256 MB

2-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty All partitions, except the swap partition, should be formatted as ext3.
Do not make partitions larger than the size indicated, since we will need free,
unpartitioned space in other exercises.
Click Next. If you get a popup window that some values are less than what Red Hat
suggests, ignore this.
__ 15. The next screen will allow you to set up your boot loader. Accept all defaults and
click Next.
__ 16. Check to see if the network parameters are correct. Then click Next.
__ 17. Do not configure any firewall rules, by selecting No firewall. Click Next.
__ 18. Do not select any additional language support. Click Next.
__ 19. Now select your Time Zone, then click Next.
__ 20. For convenience in the class, set the root password to ibmlnx. Click Next.
__ 21. Select Customize the set of packages to be installed.
__ 22. Select the Minimal installation profile (bottom of the list). (We will install additional
package groups later.)
Click Next.
__ 23. Note the location of the log file: /tmp/install.log and click Next.
__ 24. Red Hat will now format the filesystems and install Red Hat Enterprise Linux. This
may take anywhere from one to 15 minutes, depending on the number of packages
to install, the bandwidth available and the speed of the computer.
While installing, you can see what is going on in detail by switching to the third
virtual terminal with Ctrl-Alt-F3. Switch back with Alt-F7. Also take a look at other
virtual screens (1 through 6).
__ 25. Your installation is now complete. Remove the diskette from the drive and click Exit
to reboot your system.

Red Hat Kickstart installation


__ 26. After reboot, log in as root and take a look at the anaconda-ks.cfg file in your home
directory. Do you recognize the choices you made during the installation process?
» Login: root
» Password: ibmlnx
» # less anaconda-ks.cfg
__ 27. Modify the anaconda-ks.cfg file so that the following is added:
• The install process should be done via NFS, from the correct server and
directory.

© Copyright IBM Corp. 2001, 2004 Exercise 2. Advanced Linux Installation 2-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

• All partitions should be deleted, and partitions should be created according to


the scheme we just used.
• The following package groups need to be installed:
Printing Support
X Window System
GNOME Desktop Environment
KDE Desktop Environment
Legacy Software Development
Network Servers
Development Tools
Note that these package groups names need to be typed exactly like they
appear in the Fedora/base/comps.xml file on Fedora Core CD1 (which is
copied onto the install server)
• Two user accounts need to be created called tux1 and tux2, with full name
“Tux the Penguin (1)” and “Tux the Penguin (2)”, and their password identical
to their username.
» # vi anaconda-ks.cfg
The anaconda-ks.cfg file should now look like this:
install
nfs --server=10.0.0.1 --dir=/export/rhel3es
lang en_US.UTF-8
langsupport --default en_US.UTF-8 en_US.UTF-8
keyboard us
mouse generic3ps/2 --device psaux
xconfig --resolution=1024x768 --depth=24
network --device eth0 --bootproto dhcp
rootpw ibmlnx
firewall --disabled
authconfig --enableshadow --enablemd5
timezone Europe/Amsterdam
bootloader
clearpart --all
part /boot --fstype ext3 --size=100
part /usr --fstype ext3 --size=4000
part / --fstype ext3 --size=500
part /var --fstype ext3 --size=250
part /home --fstype ext3 --size=250
part /tmp --fstype ext3 --size=250
part swap --size=256

2-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty
%packages
@ Printing Support
@ X Window System
@ GNOME Desktop Environment
@ KDE Desktop Environment
@ Legacy Software Development
@ Network Servers
@ Development Tools

%post
adduser -c “Tux the Penguin (1)” tux1
echo tux1 | passwd --stdin tux1
adduser -c “Tux the Penguin (2)” tux2
echo tux2 | passwd --stdin tux2
__ 28. Ask your instructor what to do with the kickstart file. There are two options:
i. Put the kickstart file on a blank floppy, which your instructor will provide.
» # mount /mnt/floppy
» # cp anaconda-ks.cfg /mnt/floppy/ks.cfg
» # umount /mnt/floppy
ii. Upload the file, under your own name, to the instructor server.
» # scp anaconda-ks.cfg 10.0.0.1:/export/kickstart/<yourname>.cfg
__ 29. Reboot your system. When the system boots from CD, make sure that you start a
kickstart install.
» # reboot
» When the boot prompt appears, start a kickstart install:
boot: linux ks=floppy
- OR -
boot: linux ks=nfs:10.0.0.1:/export/kickstart/<yourname>.cfg
» Wait for your system to start the installation. The instructor will probably start
the next lecture once all systems have successfully started their kickstart
installation.
__ 30. When the installation is finished, click Reboot.

Documenting your installation


__ 31. Fill in appendix A of this exercises guide, as far as you can.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 2. Advanced Linux Installation 2-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions (SuSE Professional 9.0)


Installing SuSE Professional 9.0 via the network
__ 1. Insert the SuSE Professional 9.0 CD 1in the CD drive of your computer.
__ 2. Turn on the computer.
__ 3. The system will boot from CD, and you will see a screen giving you different
installation options. Select Manual Installation and press Enter.
__ 4. Choose the language for the installation process and click OK.
__ 5. Choose your keyboard model, and click OK.
__ 6. Select Kernel modules (hardware drivers) and click OK.
__ 7. Select Load network card modules and click OK.
__ 8. Ask your instructor for the network card module that you need to select. Then click
OK. If your instructor tells you so, enter additional parameters.
__ 9. Click Back to get back to the main menu.
__ 10. Select Start installation / system.
__ 11. Select Start installation/update.
__ 12. Select Network as the course medium.
__ 13. Select NFS as the network protocol.
__ 14. Ask your instructor whether you can use automatic configuration via DHCP. If you
can’t, you will also receive an IP address, subnetmask, default gateway and name
server IP address.
__ 15. Enter the IP address of the NFS server.
__ 16. Enter the exported NFS directory name.
__ 17. The install process will now contact the NFS server and will start the X-based
installer. This will take a minute or so.
__ 18. Select your language and click Accept.
__ 19. If a previous SuSE installation has been detected, then you will get a pop-up screen
asking you whether you will want to install a new system, or upgrade the existing
system. Select New installation and click OK.

2-10 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 20. Review the installation settings, and make the following changes:
• Partitioning: Partition your system so that you will get the following
partitions:
- A / (root) partition of 500 MB
- A /usr partition of 4000 MB
- A /boot partition of 100 MB
- A /home partition of 250 MB
- A /tmp partition of 250 MB
- A /var partition of 250 MB
- A /opt partition of 1000 MB
- A swap partition of 256 MB
The easiest way to accomplish this is to click on the Partitioning header, then
select Create custom partition setup and then select Custom partitioning - for
experts. You can then delete all existing partitions and create new ones.
Make sure /boot is the first partition you create!
All partitions should be formatted as ReiserFS, except for the swap partition.
Do not make partitions larger than indicated, since we will need free,
unpartitioned space in the rest of this course.
When fully done, click Next.
• Software: Only install a Minimum Graphical System (without KDE).
When done, click Accept.
__ 21. Click Yes, install at the pop-up warning.
__ 22. SuSE will now format the filesystems and install SuSE Linux. This may take
anywhere from one to 15 minutes, depending on the number of packages to install,
the bandwidth available and the speed of the computer.
While installing, you can see what is going on in detail by switching to the third
virtual terminal with Ctrl-Alt-F3. Switch back with Alt-F7. Also take a look at other
virtual screens (1 through 6).
__ 23. SuSE will automatically reboot during the installation. This is normal and the
installation process will continue automatically. You don’t have to touch the keyboard
at all.
__ 24. Enter the password for the root user. For convenience in class, use ibmlnx.
__ 25. Check your network configuration and adjust if necessary.
__ 26. Skip the internet test. Click Next.
__ 27. Select Stand-Alone Machine and click Next.

© Copyright IBM Corp. 2001, 2004 Exercise 2. Advanced Linux Installation 2-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 28. Configure a user account for yourself, then click Next.


__ 29. Read the release notes, then click Next.
__ 30. Check the hardware configuration. Pay particular attention to getting a correct X
setup, since you will need X in the next few steps. When done, click Next.
__ 31. Click Finish.

SuSE AutoYaST installation


__ 32. Log in as root.
__ 33. Install autoyast2-version.noarch.rpm and autoyast2-installation-version.rpm through
yast2.
» # yast2
Go to software; Install and Remove Software.
Go to Search, and type autoyast.
Select all packages.
Click Accept.
Click Continue to confirm the automatic changes that are the result of
dependency checking.
Click Close.
__ 34. Start autoyast2
» # yast2 autoyast
__ 35. Go through all menus to create a configuration file that is more-or-less identical to
the system you are working on now.
Make sure that you use the partitioning scheme as suggested earlier. Note that the
size you specify is in bytes, so you need to specify 150M to get a 150-MB partition.
For software, use a Default system. In the detailed selection, select Filter; Selections
and select the following package categories:
• Graphical Base System
• GNOME system
• KDE Desktop Environment
• Help & Support Documentation
• Office Applications
• Network/Server
• C/C++ Compiler and Tools

2-12 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Make sure the root password is set to ibmlnx. (Note: this is hidden far within the
menu structure. Go to Security and Users; Edit and create users. Click Configure
and Set Filter to System Users. You can now click on Edit to modify the root
account.)
Add two user accounts, tux1 and tux2, with full names Tux the Penguin (1) and Tux
the Penguin (2), and passwords identical to their username.
Last, make sure that “confirm installation” (within System; General Options) is set to
No.
__ 36. Save the autoyast configuration file using your own surname as filename, and make
sure to add the extension xml. Then exit yast.
__ 37. Take a look at the autoyast configuration file. Do you recognize the configuration
choices you made?
» # less name.xml
__ 38. Ask your instructor what to do with the kickstart file. There are two options:
i. Put the autoyast file on a blank floppy, which your instructor will provide.
» # mount /media/floppy
» # cp <yourname>.xml /media/floppy/
» # umount /media/floppy
ii. Upload the file to the instructor server.
» # scp <yourname>.xml 10.0.0.1:/export/autoyast/
__ 39. Reboot your system. When the system boots from CD, make sure you start an
autoyast install.
» # reboot
» Insert the bootdisk floppy.
» When the system boots, select Installation. As boot options, specify
something along the lines of:
autoyast=nfs://10.0.0.1/export/autoyast/yourname.xml
install=nfs://10.0.0.1/export/suse90
(all this on one line!)
Note that if your system has multiple network adapters, you might also need
to add something along the lines of
insmod=eepro100 netdevice=eth0
to the boot options line.
» Wait for your system to start the installation. The instructor will probably start
the next lecture once all systems have successfully started their autoyast
installation.

© Copyright IBM Corp. 2001, 2004 Exercise 2. Advanced Linux Installation 2-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

If the installation fails with a complaint that certain filesystems are not large enough,
then you have most likely specified “250” instead of “250M” as the filesystem size.
It’s easiest to fix this error in the autoyast XML file directly, instead of going through
yast2 autoyast again.

Documenting your installation


__ 40. Fill in appendix A of this exercises guide, as far as you can.

END OF EXERCISE

2-14 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 3. Startup and Shutdown

What This Exercise Is About


This exercise will illustrate the startup and shutdown process of a
Linux system.

What You Should Be Able to Do


At the end of the lab, you should be able to:
• Choose between a graphical and a text-based login screen by
changing the run levels of a system
• Boot a Linux system in single-user mode
• Use run level editors

© Copyright IBM Corp. 2001, 2004 Exercise 3. Startup and Shutdown 3-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
The LILO boot loader
Do this exercise only if your distribution uses LILO.
__ 1. Log in as root.
__ 2. Open the /etc/lilo.conf file and view the contents. Add a line which tells lilo to display
the message file /boot/lilo.msg file before the boot:-prompt. If there are any other
message lines, remove them.
__ 3. Create the file /boot/lilo.msg and add some explanation about the different boot
options.
__ 4. Run lilo in test mode to verify whether /etc/lilo.conf is correct.
__ 5. If there were no errors, run lilo for real. If you are unsure, have your instructor take a
look at the /etc/lilo.conf file.
__ 6. Now reboot your system and watch the lilo prompt. Use the shutdown command to
perform the reboot.

The GRUB boot loader


Do this section only if your distribution uses GRUB
__ 7. Log in as root.
__ 8. Change the /boot/grub/grub.conf configuration file so that a password is required
when you try to alter the various boot options. Make sure the password is encrypted.
For convenience in class, use the password ibmlnx.
Note: When starting grub, it starts probing devices to guess BIOS drives. This may
take a long time - up to several minutes, depending on your hardware. Wait until this
is done before typing the md5crypt command within grub.
__ 9. Reboot your machine. Use the shutdown command to perform the reboot. Then try
to alter the GRUB boot sequence without and with supplying the password.

Retrieving kernel messages


The messages which are displayed by the kernel can be a helpful tool in problem
determination. That is why you might want to retrieve them, even after your system has
booted.
__ 10. Log in as root.
__ 11. View the kernel messages and the log file /var/log/messages.

Setting the default runlevel

3-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty The default runlevel can be altered to configure your system for your situation. In this
exercise, we will set the default to 5, so that you will get a graphical login prompt.
Note however that, depending on your hardware, kickstart or autoyast may not have
configured X correctly. So we need to test and, if needed, configure X first.
__ 12. Start X with the X command. (This only starts the XFree86 server.) If X comes up
correctly (black or grey background with an X-shaped mouse cursor, nothing more,
nothing less), stop the X server with Ctrl-Alt-Backspace and continue with the next
step. If X does not come up correctly, run system-config-display (Fedora),
redhat-config-xfree86 (Red Hat) or sax2 (SuSE) to configure X.
__ 13. Edit the file /etc/inittab so that the default runlevel will be 5.
__ 14. Reboot your system, this time using Ctrl-Alt-Delete.
__ 15. When LILO or GRUB appears, do nothing. After five to ten seconds, LILO or GRUB
should automatically boot your default operating system.
__ 16. When the graphical login prompt appears, switch to the first virtual terminal. Then
switch back to VT 7.
__ 17. Log in as root, then start a terminal screen.

Configuring Services
__ 18. Make a long list of files in the directories /etc/rc.d/rc3.d, /etc/rc.d/rc4.d, /etc/rc.d/rc5.d
and /etc/rc.d/init.d.
__ 19. Create a list of services with chkconfig, and check its output with the output from
the previous commands.
__ 20. Verify that the portmap service is enabled in your current runlevel. Disable this
service, then check the symbolic links in /etc/rc.d/rc5.d again.
__ 21. Check whether the portmap daemon is currently running. Then reboot the system.
__ 22. Log in and check whether the portmap daemon is running now.
__ 23. Enable the portmap service again, and start the service manually.

Using Single User Mode


Single User Mode is very convenient for system maintenance.
__ 24. Log out, reboot the system with Ctrl-Alt-Delete and boot in single user mode.
__ 25. Look at the list of running processes.
__ 26. Reboot the system.

Documenting your changes

© Copyright IBM Corp. 2001, 2004 Exercise 3. Startup and Shutdown 3-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 27. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

3-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


The LILO boot loader
Do this exercise only if your distribution uses LILO.
__ 1. Log in as root.
» Login: root
» Password: ibmlnx
__ 2. Open the /etc/lilo.conf file and view the contents. Add a line which tells lilo to display
the message file /boot/lilo.msg file before the boot:-prompt. If there are any other
message lines, remove them.
» # vi /etc/lilo.conf
» Add the line message=/boot/lilo.msg before the prompt line. Remove any
other message lines that you may see.
__ 3. Create the file /boot/lilo.msg and add some explanation about the different boot
options.
» # vi /boot/lilo.msg
» Add for instance the following text:
Enter linux for Linux or dos for Windows.
__ 4. Run lilo in test mode to verify whether /etc/lilo.conf is correct.
» # lilo -v -v -t
__ 5. If there were no errors, run lilo for real. If you are unsure, have your instructor take a
look at the /etc/lilo.conf file.
» # lilo -v
__ 6. Now reboot your system and watch the lilo prompt. Use the shutdown command to
perform the reboot.
» # shutdown -r now
» Wait for your system to shutdown, and watch the Lilo prompt as your system
reboots. You should see the text you entered in /boot/lilo.msg.
» Load linux again.

The GRUB boot loader


Do this section only if your distribution uses GRUB
__ 7. Log in as root.
» Login: root
» Password: ibmlnx

© Copyright IBM Corp. 2001, 2004 Exercise 3. Startup and Shutdown 3-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 8. Change the /boot/grub/grub.conf configuration file so that a password is required


when you try to alter the various boot options. Make sure the password is encrypted.
For convenience in class, use the password ibmlnx.
Note: When starting grub, it starts probing devices to guess BIOS drives. This may
take a long time - up to several minutes, depending on your hardware. Wait until this
is done before typing the md5crypt command within grub.
» # grub
grub> md5crypt
Password: ibmlnx
Encrypted: $1$JGuR//$kjOu7Q9kTZk01wFKWQqMb/
grub> quit
» # vi /boot/grub/menu.lst
Add the following line above the first “title” line:
password --md5 $1$JGuR//$kjOu7Q9kTZk01wFKWQqMb/
__ 9. Reboot your machine. Use the shutdown command to perform the reboot. Then try
to alter the GRUB boot sequence without and with supplying the password.
» # shutdown -r now
» Wait for your system to shutdown, and watch GRUB menu as it comes up.
Look at the screen carefully to determine which menu options are available.
Try to alter the Linux boot sequence, for instance by adding a kernel
parameter like mem=64M.
» Load linux again.

Retrieving kernel messages


The messages which are displayed by the kernel can be a helpful tool in problem
determination. That is why you might want to retrieve them, even after your system has
booted.
__ 10. Log in as root.
» Login: root
» Password: ibmlnx
__ 11. View the kernel messages and the log file /var/log/messages.
» # dmesg | less
» # less /var/log/messages

Setting the default runlevel


The default runlevel can be altered to configure your system for your situation. In this
exercise, we will set the default to 5, so that you will get a graphical login prompt.

3-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Note however that, depending on your hardware, kickstart or autoyast may not have
configured X correctly. So we need to test and, if needed, configure X first.
__ 12. Start X with the X command. (This only starts the XFree86 server.) If X comes up
correctly (black or grey background with an X-shaped mouse cursor, nothing more,
nothing less), stop the X server with Ctrl-Alt-Backspace and continue with the next
step. If X does not come up correctly, run system-config-display (Fedora),
redhat-config-xfree86 (Red Hat) or sax2 (SuSE) to configure X.
» #X
If X comes up correctly (you’ll see a black or grey screen with an X-shaped
mouse cursor), then exit X with Ctrl-Alt-Backspace. Otherwise, start
system-config-display (Fedora), redhat-config-xfree86 (Red Hat) or sax2
(SuSE). You need to do this in runlevel 3, so run init 3 first.
__ 13. Edit the file /etc/inittab so that the default runlevel will be 5.
» # vi /etc/inittab
» Change the line
id:3:initdefault:
» into
id:5:initdefault:
__ 14. Reboot your system, this time using Ctrl-Alt-Delete.
» <Ctrl-Alt-Delete>
__ 15. When LILO or GRUB appears, do nothing. After five to ten seconds, LILO or GRUB
should automatically boot your default operating system.
__ 16. When the graphical login prompt appears, switch to the first virtual terminal. Then
switch back to VT 7.
» <Ctrl-Alt-F1>
» You should see a text-based login prompt. (If you see a lot of X messages,
press Enter once. This is caused by the X server sending its output to tty1.)
» <Alt-F7>
» You should be back at the graphical login screen.
__ 17. Log in as root, then start a terminal screen.
» Login: root
» Password: ibmlnx
» When logged in, click the terminal icon.

Configuring Services
__ 18. Make a long list of files in the directories /etc/rc.d/rc3.d, /etc/rc.d/rc4.d, /etc/rc.d/rc5.d
and /etc/rc.d/init.d.
» # ls -l /etc/rc.d/rc3.d

© Copyright IBM Corp. 2001, 2004 Exercise 3. Startup and Shutdown 3-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» # ls -l /etc/rc.d/rc4.d
» # ls -l /etc/rc.d/rc5.d
__ 19. Create a list of services with chkconfig, and check its output with the output from
the previous commands.
» # chkconfig --list
__ 20. Verify that the portmap service is enabled in your current runlevel. Disable this
service, then check the symbolic links in /etc/rc.d/rc5.d again.
» # chkconfig --list portmap
» # chkconfig portmap off
» # chkconfig --list portmap
» # ls -l /etc/rc.d/rc5.d
__ 21. Check whether the portmap daemon is currently running. Then reboot the system.
» fedora/redhat# service portmap status
suse# rcportmap status
» # reboot
__ 22. Log in and check whether the portmap daemon is running now.
» Login: root
» Password: ibmlnx
» fedora/redhat# service portmap status
suse# rcportmap status
__ 23. Enable the portmap service again, and start the service manually.
» # chkconfig portmap on
» # chkconfig --list portmap
» fedora/redhat# service portmap start
suse# rcportmap start

Using Single User Mode


Single User Mode is very convenient for system maintenance.
__ 24. Log out, reboot the system with Ctrl-Alt-Delete and boot in single user mode.
» # exit
» <Ctrl-Alt-Delete>
» If your system uses LILO, type linux single at the LILO prompt.
» If your system uses GRUB, then press p and enter the password. Then,
press e to edit the operating system entry, and press e once again to edit the
kernel line. Then, add single at the end and press Enter. Then, press b to
boot Linux.
» On a Fedora/Red Hat system, you don’t have to log in: you will get a root
prompt immediately.

3-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » On a SuSE system, type the root password ibmlnx to get a root prompt.
__ 25. Look at the list of running processes.
» # ps ax
__ 26. Reboot the system.
» # reboot

Documenting your changes


__ 27. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 3. Startup and Shutdown 3-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

3-10 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 4. System Administration Tools

What This Exercise Is About


This exercise will give you some practical experience in using the
system administration tool on your distribution.

What You Should Be Able to Do


At the end of the lab, you should be able to use and configure the
system administration tool on the distribution used.

© Copyright IBM Corp. 2001, 2004 Exercise 4. System Administration Tools 4-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Working with the system administration tool
__ 1. Start the system administration tool that came with your distribution.
__ 2. Browse the menu structure of your system administration tool to get a feel for the
location of various configuration items.

Downloading and installing webmin (extra and optional)


If time and circumstances permit, then try to install webmin. Your instructor will tell you how
and where to get the install image. Follow the instructions from the lecture to install,
configure and run webmin.

Documenting your changes


__ 3. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

4-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


Working with the system administration tool
__ 1. Start the system administration tool that came with your distribution.
__ 2. Browse the menu structure of your system administration tool to get a feel for the
location of various configuration items.

Downloading and installing webmin (extra and optional)


If time and circumstances permit, then try to install webmin. Your instructor will tell you how
and where to get the install image. Follow the instructions from the lecture to install,
configure and run webmin.

Documenting your changes


__ 3. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 4. System Administration Tools 4-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

4-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 5. Packaging Tools

What This Exercise Is About


This exercise will give you some practical experience in using the
packaging tool on your distribution.

What You Should Be Able to Do


At the end of the lab, you should be able to:
• Install, upgrade and deinstall packages
• Query packages
• Verify the authenticity of packages
• Create simple packages

© Copyright IBM Corp. 2001, 2004 Exercise 5. Packaging Tools 5-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Retrieving information about installed packages
__ 1. Make a list of all packages that are installed on the system.
__ 2. Find out which package installed the /etc/inittab file.
__ 3. List the information of that package.
__ 4. List all files in that package.
__ 5. Verify whether all files in that package are still the same. Which file has changed and
in what respect? Why?

Installing packages
__ 6. Create a directory /mnt/install. Mount the installation directory from the installation
server on /mnt/install. List all the package files that are available on the install
server.
Note: If you can’t mount the installation directory from the installation server, then
check whether the portmap daemon is running, and check whether you do not have
any iptables rules that prevent NFS mounts.
__ 7. Add the public key from the distribution to your keyring.
__ 8. Verify that the package xsnow is not installed. Verify the package on the CD, and
install it. Then verify that it installed, and list the files in the package. You can also
execute xsnow, but note that KDE blocks the visual effects of xsnow.
Note: Distributions change, and xsnow might not be included on your CD. In that
case, use another entertaining X application, such as xearth, xjewel, xhangman or
xbill.
__ 9. Deinstall the xsnow package.

Using a package management frontend


__ 10. If necessary, start X. Then, start the preferred RPM frontend tool for your
distribution. Use this to install xsnow again.
Note: Red Hat does not include GnoRPM or kpackage, and its own frontend tool
(redhat-config-packages) can only install packages from package groups that are
predefined in RedHat/base/comps.xml on CD1. xsnow is not in any of these groups,
so there is no frontend tool on Red Hat that allows you to install xsnow. On Red Hat,
use redhat-config-packages to install a package that is in one of the predefined
groups.

Creating RPMs

5-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 11. Check with your instructor if the file hello-1.0.tar.gz is available somewhere on the
network and download it into /root. If it is available, then go to the next step. If it is
not available, you need to create it yourself. In that case, create a directory
/root/hello-1.0 and create the following files in it:
hello.c:
#include <stdio.h>
main()
{
printf("Hello, World!\n");
}
Makefile:
all: hello

hello: hello.c
gcc -o hello hello.c

install: hello
install -d $(DESTDIR)/usr/bin/hello
install -s -m 0755 -o root -g root hello $(DESTDIR)/usr/bin/hello

clean:
rm -f hello
Note: The lines containing commands are indented with a TAB, not with spaces!
README:
(c) Copyright IBM 2004
This program is licensed under the GPL.

This program prints the text "Hello, World!" on your screen. This is an
excellent way to start your day - some people even consider it better
than getting a random fortune cookie every morning!

To build, simply type make


To install, simply type make install
Then, go back to your /root directory and make a tar file of all these files, and gzip it
up.
__ 12. Copy the hello-1.1.tar.gz to /usr/src/redhat/SOURCES (Fedora/Red Hat) or
/usr/src/packages/SOURCES (SuSE)
__ 13. Create the hello.spec file as shown in the visual, in the correct directory.
__ 14. Start the RPM prep stage and watch the results.
__ 15. Start the RPM build stage and watch the results.

© Copyright IBM Corp. 2001, 2004 Exercise 5. Packaging Tools 5-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 16. Start the RPM install stage and watch the results.
__ 17. Create the binary RPM and watch the results.
__ 18. Create the source RPM and watch the results.

Documenting your changes


__ 19. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

5-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


Retrieving information about installed packages
__ 1. Make a list of all packages that are installed on the system.
» # rpm -q -a
__ 2. Find out which package installed the /etc/inittab file.
» # rpm -q -f /etc/inittab
__ 3. List the information of that package.
» # rpm -q -i -f /etc/inittab
__ 4. List all files in that package.
» # rpm -q -l -f /etc/inittab
__ 5. Verify whether all files in that package are still the same. Which file has changed and
in what respect? Why?
» # rpm -V -f /etc/inittab
If you did all the exercises up until now, you should see that /etc/inittab has
changed, both the MD5 checksum and modification time, but not the size.
That is because we changed the default runlevel.

Installing packages
__ 6. Create a directory /mnt/install. Mount the installation directory from the installation
server on /mnt/install. List all the package files that are available on the install
server.
Note: If you can’t mount the installation directory from the installation server, then
check whether the portmap daemon is running, and check whether you do not have
any iptables rules that prevent NFS mounts.
» # mkdir /mnt/install
» # mount server:directory /mnt/install
» # cd /mnt/install
» # find . -name "*.rpm" -print
__ 7. Add the public key from the distribution to your keyring.
» fedora/redhat# rpm --import RPM-GPG-KEY*
suse# gpg --import pubring.gpg
__ 8. Verify that the package xsnow is not installed. Verify the package on the CD, and
install it. Then verify that it installed, and list the files in the package. You can also
execute xsnow, but note that KDE blocks the visual effects of xsnow.

© Copyright IBM Corp. 2001, 2004 Exercise 5. Packaging Tools 5-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Note: Distributions change, and xsnow might not be included on your CD. In that
case, use another entertaining X application, such as xearth, xjewel, xhangman or
xbill.
» # xsnow
» # rpm -q xsnow
» # rpm -K xsnow-version.rpm
» # rpm -ivh xsnow-version.rpm
» # rpm -qil xsnow
» # xsnow
__ 9. Deinstall the xsnow package.
» # rpm -e xsnow

Using a package management frontend


__ 10. If necessary, start X. Then, start the preferred RPM frontend tool for your
distribution. Use this to install xsnow again.
Note: Red Hat does not include GnoRPM or kpackage, and its own frontend tool
(redhat-config-packages) can only install packages from package groups that are
predefined in RedHat/base/comps.xml on CD1. xsnow is not in any of these groups,
so there is no frontend tool on Red Hat that allows you to install xsnow. On Red Hat,
use redhat-config-packages to install a package that is in one of the predefined
groups.
» fedora# system-config-packages -t /mnt/install
redhat# redhat-config-packages -t /mnt/install
suse# yast2

Creating RPMs
__ 11. Check with your instructor if the file hello-1.0.tar.gz is available somewhere on the
network and download it into /root. If it is available, then go to the next step. If it is
not available, you need to create it yourself. In that case, create a directory
/root/hello-1.0 and create the following files in it:
hello.c:
#include <stdio.h>
main()
{
printf("Hello, World!\n");
}
Makefile:
all: hello

5-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty
hello: hello.c
gcc -o hello hello.c

install: hello
install -d $(DESTDIR)/usr/bin/hello
install -s -m 0755 -o root -g root hello $(DESTDIR)/usr/bin/hello

clean:
rm -f hello
Note: The lines containing commands are indented with a TAB, not with spaces!
README:
(c) Copyright IBM 2004
This program is licensed under the GPL.

This program prints the text "Hello, World!" on your screen. This is an
excellent way to start your day - some people even consider it better
than getting a random fortune cookie every morning!

To build, simply type make


To install, simply type make install
Then, go back to your /root directory and make a tar file of all these files, and gzip it
up.
» # cd /root
» # mkdir hello-1.1
» # cd hello-1.1
» # vi hello.c
» # vi Makefile
» # vi README
» # cd ..
» # tar -zcvf hello-1.1.tar.gz hello-1.1/
__ 12. Copy the hello-1.1.tar.gz to /usr/src/redhat/SOURCES (Fedora/Red Hat) or
/usr/src/packages/SOURCES (SuSE)
» fedora/redhat# cp hello-1.1.tar.gz /usr/src/redhat/SOURCES
suse# cp hello-1.1.tar.gz /usr/src/packages/SOURCES
__ 13. Create the hello.spec file as shown in the visual, in the correct directory.
» redhat# vi /usr/src/redhat/SPECS/hello.spec
suse# vi /usr/src/packages/SPECS/hello.spec
The file should look like this:
#

© Copyright IBM Corp. 2001, 2004 Exercise 5. Packaging Tools 5-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

# SPEC file for hello world program


#
Summary: Hello, World program
Name: hello
Version: 1.1
Release: 1
Copyright: GPL
Group: Applications/Useless
Source: hello-1.1.tar.gz
Distribution: Useless Linux 1.0
Vendor: IBM IT Education Services
Packager: John Doe <john@ls.ibm.com>
BuildRoot: /var/tmp/hello-1.1

%description
This program prints the text "Hello, World!" on your screen.
This is an excellent way to start your day - some people even
consider it better than getting a random fortune cookie every
morning!

%prep
%setup

%build
make

%install
make install DESTDIR=${RPM_BUILD_ROOT}

%files
%doc README
/usr/bin/hello
__ 14. Start the RPM prep stage and watch the results.
» fedora/redhat# rpmbuild -bp /usr/src/redhat/SPECS/hello.spec
suse# rpmbuild -bp /usr/src/packages/SPECS/hello.spec
» fedora/redhat# ls -lR /usr/src/redhat/BUILD
suse# ls -lR /usr/src/packages/BUILD
» # ls -lR /var/tmp/hello-1.1
__ 15. Start the RPM build stage and watch the results.
» fedora/redhat# rpmbuild -bp /usr/src/redhat/SPECS/hello.spec
suse# rpmbuild -bc /usr/src/packages/SPECS/hello.spec
» fedora/redhat# ls -lR /usr/src/redhat/BUILD
suse# ls -lR /usr/src/packages/BUILD

5-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » # ls -lR /var/tmp/hello-1.1


__ 16. Start the RPM install stage and watch the results.
» fedora/redhat# rpmbuild -bi /usr/src/redhat/SPECS/hello.spec
suse# rpmbuild -bi /usr/src/packages/SPECS/hello.spec
» fedora/redhat# ls -lR /usr/src/redhat/BUILD
suse# ls -lR /usr/src/packages/BUILD
» # ls -lR /var/tmp/hello-1.1
» # /var/tmp/hello-1.1/usr/bin/hello
__ 17. Create the binary RPM and watch the results.
» fedora/redhat# rpmbuild -bb /usr/src/redhat/SPECS/hello.spec
suse# rpmbuild -bb /usr/src/packages/SPECS/hello.spec
» fedora/redhat# ls -l /usr/src/redhat/RPMS/i386
suse# ls -l /usr/src/packages/RPMS/i386
» fedora/redhat# rpm -qilp /usr/src/redhat/RPMS/i386/hello-1.0-1.i386.rpm
suse# rpm -qilp /usr/src/packages/RPMS/i386/hello-1.0-1.i386.rpm
__ 18. Create the source RPM and watch the results.
» fedora/redhat# rpmbuild -bs /usr/src/redhat/SPECS/hello.spec
suse# rpmbuild -bs /usr/src/packages/SPECS/hello.spec
» fedora/redhat# ls -l /usr/src/redhat/SRPMS
suse# ls -l /usr/src/packages/SRPMS/hello-1.0-1.src.rpm
» fedora/redhat# rpm -qilp /usr/src/redhat/SRPMS/hello-1.0-1.src.rpm
suse# rpm -qilp /usr/src/packages/SRPMS/hello-1.0-1.src.rpm

Documenting your changes


__ 19. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 5. Packaging Tools 5-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

5-10 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 6. X Window System

What This Exercise Is About


This exercise will let you use the X Window System.

What You Should Be Able to Do


After completing this exercise you should have experience with:
• Configuring XFree86
• Starting and stopping X
• Window managers
• Running X applications over a network

© Copyright IBM Corp. 2001, 2004 Exercise 6. X Window System 6-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Configuring XFree86
Do this section only if your distribution uses XFree86 (RHEL 3, SuSE 9.0).
__ 1. If you are in a runlevel that automatically starts X, switch to a runlevel that does not
start X. If you started X manually, stop it.
__ 2. Make a backup copy of the XF86Config file.
__ 3. Try to configure your XF86Config file using redhat-config-xfree86 (Red Hat) or SaX
(SuSE). If redhat-config-xfree86 or SaX yields a sufficiently good XF86Config file
(test this with startx), then make a backup of this file called
XF86Config.redhat-config-xfree86 or XF86Config.sax2.
__ 4. Try to configure your XF86Config file using XFree86 -configure. If XFree86
-configure yields a sufficiently good XF86Config file (test this with startx), then make
a backup of this file called /etc/X11/XF86Config.XFree86.
__ 5. Select the XF86Config file that worked the best for you and rename it to
/etc/X11/XF86Config. Then, start X or switch to the runlevel that starts X for you.

Configuring Xorg
Do this section only if your distribution uses Xorg (Fedora Core 2).
__ 6. If you are in a runlevel that automatically starts X, switch to a runlevel that does not
start X. If you started X manually, stop it.
__ 7. Make a backup copy of the xorg.conf file.
__ 8. Try to configure your xorg.conf file using system-config-display (Fedora). If
system-config-display yields a sufficiently good xorg.conf file (test this with startx),
then make a backup of this file called xorg.conf.system-config-display.
__ 9. Try to configure your xorg.conf file using Xorg -configure. If Xorg -configure yields a
sufficiently good xorg.conf file (test this with startx), then make a backup of this file
called /etc/X11/xorg.conf.xorg.
__ 10. Select the xorg.conf file that worked the best for you and rename it to
/etc/X11/xorg.conf. Then, start X or switch to the runlevel that starts X for you.

Running Applications
For an application to run in an X environment, it needs to be ready for it. Most applications
that start with an “x” are. You can run them directly. Applications that are not X enabled, can
be run from an “xterm” window. An xterm window emulates an ordinary terminal in an X
environment.

6-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 11. In X, start an xterm from one of the window manager's menus. In Linux, the xterm is
sometimes also known as xterm, kterm or something else ending in -term. Try to run
some commands from this window.
__ 12. There are several ways of starting applications within X. One is from the window
manager's menus, which we already did. Another is from the command line from an
xterm window. Try that out: In the xterm window, run the command xterm &. You will
see a new xterm window appear.
__ 13. Another way of starting an application is from a real terminal window. Note that X
started in virtual terminal number 7, so we can still access number 1 through 6. Not
with Alt-F1 this time however, but with Ctrl-Alt-F1. Try that out. To switch back, use
Alt-F7.
__ 14. Switch to a virtual window where you have an ordinary command line prompt. If
necessary, log in as root.
__ 15. Run xterm. You will see an error message: Can't open display. What happened is
that the application wanted to contact the X-Server, but there was no information in
the environment about which X-Server to contact. This information is normally
stored in the $DISPLAY environment variable.
__ 16. Do an echo $DISPLAY in this window. Also do an echo $DISPLAY in an xterm
window.
__ 17. Switch back to the true terminal and set the display variable with: export
DISPLAY=127.0.0.1:0.0.. Now restart the xterm application. There should not be
any error messages.
__ 18. Switch to the X screen and note that you started an extra xterm window.

Running Applications Over a Network


Since applications use a TCP/IP connection to communicate to the X server, we can also
run applications from another server.
__ 19. GDM, the GNOME Display Manager, has a security feature that disallows X
sessions over the network. This feature is disabled by default, but on a Fedora Core
2 system, it is enabled. To disable this feature, modify the file
/etc/X11/gdm/gdm.conf: set the DisallowTCP directive to “false”. Then restart gdm
by switching to runlevel 3 and back to runlevel 5 again
__ 20. Walk over to the PC of a fellow student and ask him/her to open a terminal window
for you.
__ 21. Set the display variable to point to your own screen. The command for that will look
like this: export DISPLAY=1.2.3.4:0.0, where 1.2.3.4 is your own IP-address.
__ 22. Now try to start an xterm. You should get an error message: could not open display.
This is a safety feature of X: it does not automatically accept incoming connections.

© Copyright IBM Corp. 2001, 2004 Exercise 6. X Window System 6-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 23. Go back to your own system and enter the command xhost + This will enable
incoming connections.
__ 24. Go back to the system of your fellow student and retry the xterm command. This
time it should succeed.
__ 25. In your graphical screen you should see a new xterm. Try the hostname command
in this screen to verify that the xterm application is actually running on the other
system.
__ 26. Close the xterm and do an xhost -.
__ 27. Now try to open another xterm from your partners system, but this time use xauth
authentication.
Note: this only works if your systems hostname has been set properly and can be
resolved through DNS.

Running X-sessions over a network


You can not only run a single application over a network, but you can run your whole
X-session over a network as well. In this case it's not only the application that is running on
a remote system, but the window manager as well. In fact, the only program that needs to
be running locally is your X server.
Note: X sessions over a network are not well tested and various distributions have various
problems with it.
__ 28. Make all necessary changes to the configuration file of your favorite login manager
to enable remote logins. Then restart your login manager by switching to runlevel 3
and then to runlevel 5 again.
__ 29. Start a second X-server, this time telling X to get its login manager from your partner
system.
__ 30. Stop the second session and start it again, but do an indirect broadcast for a login
manager. You should get a chooser which allows you to login to any system running
a display manager on the network.
__ 31. If time permits, then perform step 22 and 23 again, but this time use Xnest to start
an X server within your current X environment. (Note: you might need to install
Xnest first.
__ 32. If time permits, run this section again, but with another display manager (xdm, kdm
or gdm). To select the display manager, do the following:
On a Fedora/Red Hat system, modify the file /etc/sysconfig/desktop so that the
DISPLAYMANAGER variable is set to “GNOME”, “KDE” or “XDM”.
On a SuSE system, modify the file /etc/sysconfig/displaymanager so that the
DISPLAYMANAGER variable is set to “gdm”, “kdm” or “xdm”. (Note: on a SuSE
system, gdm is not installed, even if you choose the GNOME package group.)

6-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty
Documenting your changes
__ 33. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 6. X Window System 6-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions With Hints


Configuring XFree86
Do this section only if your distribution uses XFree86 (RHEL 3, SuSE 9.0).
__ 1. If you are in a runlevel that automatically starts X, switch to a runlevel that does not
start X. If you started X manually, stop it.
» # init 3
__ 2. Make a backup copy of the XF86Config file.
» # cp /etc/X11/XF86Config /etc/X11/XF86Config.bak
__ 3. Try to configure your XF86Config file using redhat-config-xfree86 (Red Hat) or SaX
(SuSE). If redhat-config-xfree86 or SaX yields a sufficiently good XF86Config file
(test this with startx), then make a backup of this file called
XF86Config.redhat-config-xfree86 or XF86Config.sax2.
» redhat# redhat-config-xfree86
suse# sax2
» Answer all questions.
» # startx
__ 4. Try to configure your XF86Config file using XFree86 -configure. If XFree86
-configure yields a sufficiently good XF86Config file (test this with startx), then make
a backup of this file called /etc/X11/XF86Config.XFree86.
» # XFree86 -configure
» Answer all questions.
» # startx
__ 5. Select the XF86Config file that worked the best for you and rename it to
/etc/X11/XF86Config. Then, start X or switch to the runlevel that starts X for you.
» # cp /etc/X11/XF86Config.something /etc/X11/XF86Config
» # init 5

Configuring Xorg
Do this section only if your distribution uses Xorg (Fedora Core 2).
__ 6. If you are in a runlevel that automatically starts X, switch to a runlevel that does not
start X. If you started X manually, stop it.
» # init 3
__ 7. Make a backup copy of the xorg.conf file.
» # cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak

6-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 8. Try to configure your xorg.conf file using system-config-display (Fedora). If


system-config-display yields a sufficiently good xorg.conf file (test this with startx),
then make a backup of this file called xorg.conf.system-config-display.
» fedora# system-config-display
» Answer all questions.
» # startx
__ 9. Try to configure your xorg.conf file using Xorg -configure. If Xorg -configure yields a
sufficiently good xorg.conf file (test this with startx), then make a backup of this file
called /etc/X11/xorg.conf.xorg.
» # Xorg -configure
» Answer all questions.
» # startx
__ 10. Select the xorg.conf file that worked the best for you and rename it to
/etc/X11/xorg.conf. Then, start X or switch to the runlevel that starts X for you.
» # cp /etc/X11/xorg.conf.something /etc/X11/xorg.conf
» # init 5

Running Applications
For an application to run in an X environment, it needs to be ready for it. Most applications
that start with an “x” are. You can run them directly. Applications that are not X enabled, can
be run from an “xterm” window. An xterm window emulates an ordinary terminal in an X
environment.
__ 11. In X, start an xterm from one of the window manager's menus. In Linux, the xterm is
sometimes also known as xterm, kterm or something else ending in -term. Try to run
some commands from this window.
__ 12. There are several ways of starting applications within X. One is from the window
manager's menus, which we already did. Another is from the command line from an
xterm window. Try that out: In the xterm window, run the command xterm &. You will
see a new xterm window appear.
» # xterm &
__ 13. Another way of starting an application is from a real terminal window. Note that X
started in virtual terminal number 7, so we can still access number 1 through 6. Not
with Alt-F1 this time however, but with Ctrl-Alt-F1. Try that out. To switch back, use
Alt-F7.
» <Ctrl-Alt-F1>
» <Alt-F7>
__ 14. Switch to a virtual window where you have an ordinary command line prompt. If
necessary, log in as root.

© Copyright IBM Corp. 2001, 2004 Exercise 6. X Window System 6-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» <Ctrl-Alt-F1>
» Login: root
» Password: ibmlnx
__ 15. Run xterm. You will see an error message: Can't open display. What happened is
that the application wanted to contact the X-Server, but there was no information in
the environment about which X-Server to contact. This information is normally
stored in the $DISPLAY environment variable.
» # xterm
__ 16. Do an echo $DISPLAY in this window. Also do an echo $DISPLAY in an xterm
window.
» # echo $DISPLAY
» <Alt-F7>
» # echo $DISPLAY
__ 17. Switch back to the true terminal and set the display variable with: export
DISPLAY=127.0.0.1:0.0.. Now restart the xterm application. There should not be
any error messages.
» <Ctrl-Alt-F1>
» # export DISPLAY=:0.0
» # xterm &
__ 18. Switch to the X screen and note that you started an extra xterm window.
» <Alt-F7>

Running Applications Over a Network


Since applications use a TCP/IP connection to communicate to the X server, we can also
run applications from another server.
__ 19. GDM, the GNOME Display Manager, has a security feature that disallows X
sessions over the network. This feature is disabled by default, but on a Fedora Core
2 system, it is enabled. To disable this feature, modify the file
/etc/X11/gdm/gdm.conf: set the DisallowTCP directive to “false”. Then restart gdm
by switching to runlevel 3 and back to runlevel 5 again
» fedora# vi /etc/X11/gdm/gdm.conf
DisallowTCP=false
» fedora# init 3
» wait a few seconds
» fedora# init 5
__ 20. Walk over to the PC of a fellow student and ask him/her to open a terminal window
for you.

6-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 21. Set the display variable to point to your own screen. The command for that will look
like this: export DISPLAY=1.2.3.4:0.0, where 1.2.3.4 is your own IP-address.
» $ export DISPLAY=1.2.3.4:0.0
__ 22. Now try to start an xterm. You should get an error message: could not open display.
This is a safety feature of X: it does not automatically accept incoming connections.
» $ xterm &
__ 23. Go back to your own system and enter the command xhost + This will enable
incoming connections.
» # xhost +
__ 24. Go back to the system of your fellow student and retry the xterm command. This
time it should succeed.
» $ xterm &
__ 25. In your graphical screen you should see a new xterm. Try the hostname command
in this screen to verify that the xterm application is actually running on the other
system.
» # hostname
__ 26. Close the xterm and do an xhost -.
» # xhost -
__ 27. Now try to open another xterm from your partners system, but this time use xauth
authentication.
Note: this only works if your systems hostname has been set properly and can be
resolved through DNS.
» On your own system:
# xauth extract xauthfile hostname:0.0
» Transfer the xauthfile to the other machine, for instance using
# scp xauthfile root@otherhost:xauthfile
» On the other host:
$ xauth merge xauthfile
$ xterm -display hostname:0.0

Running X-sessions over a network


You can not only run a single application over a network, but you can run your whole
X-session over a network as well. In this case it's not only the application that is running on
a remote system, but the window manager as well. In fact, the only program that needs to
be running locally is your X server.
Note: X sessions over a network are not well tested and various distributions have various
problems with it.

© Copyright IBM Corp. 2001, 2004 Exercise 6. X Window System 6-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 28. Make all necessary changes to the configuration file of your favorite login manager
to enable remote logins. Then restart your login manager by switching to runlevel 3
and then to runlevel 5 again.
To determine the display manager you’re running:
» # ps ax | grep dm
For xdm:
» # init 3
» # cd /etc/X11/xdm
» # vi Xaccess
Uncomment the line which only has an '*' on it. (This is done already on
SuSE.)
» # vi xdm-config
Comment out (with a “!”) the last line that specifies
“DisplayManager.requestPort: 0”.
» # init 5
For kdm:
» # init 3
» fedora/redhat# cd /etc/kde/kdm
suse# cd /etc/opt/kde3/share/config/kdm
» # vi kdmrc
In the [Xdmcp] section, change Enable=false to Enable=true
» fedora/redhat# vi Xaccess
Uncomment the line which only has an ‘*’ on it.
» # init 5
For gdm:
» # init 3
» fedora/redhat# cd /etc/X11/gmd
suse# cd /etc/opt/gnome2/gdm
» # vi gdm.conf
In the [xdmcp] section, change Enable=false to Enable=true
» # init 5
__ 29. Start a second X-server, this time telling X to get its login manager from your partner
system.
» # X -query <hostname> :1
__ 30. Stop the second session and start it again, but do an indirect broadcast for a login
manager. You should get a chooser which allows you to login to any system running
a display manager on the network.
» # X -indirect <hostname> :1

6-10 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 31. If time permits, then perform step 22 and 23 again, but this time use Xnest to start
an X server within your current X environment. (Note: you might need to install
Xnest first.
» fedora# rpm -ivh /mnt/install/Fedora/RPMS/xorg-x11-Xnest-version. rpm
redhat# rpm -ivh /mnt/install/RedHat/RPMS/XFree86-Xnest-version.rpm
suse# rpm -ivh /mnt/install/suse/i586/XFree86-Xnest-version.rpm
» # Xnest -query <hostname> :1
» # Xnest -indirect <hostname> :1
__ 32. If time permits, run this section again, but with another display manager (xdm, kdm
or gdm). To select the display manager, do the following:
On a Fedora/Red Hat system, modify the file /etc/sysconfig/desktop so that the
DISPLAYMANAGER variable is set to “GNOME”, “KDE” or “XDM”.
On a SuSE system, modify the file /etc/sysconfig/displaymanager so that the
DISPLAYMANAGER variable is set to “gdm”, “kdm” or “xdm”. (Note: on a SuSE
system, gdm is not installed, even if you choose the GNOME package group.)
» fedora/redhat# vi /etc/sysconfig/desktop
Set the file to look like one of the three lines below:
DISPLAYMANAGER=”GNOME”
DISPLAYMANAGER=”KDE”
DISPLAYMANAGER=”XDM”
» suse# rpm -ivh /mnt/install/suse/i586/gdm2-version.rpm
» suse# vi /etc/sysconfig/displaymanager
Modify the DISPLAYMANAGER line so that it looks like one of the three lines
below:
DISPLAYMANAGER=”gdm”
DISPLAYMANAGER=”kdm”
DISPLAYMANAGER=”xdm”

Documenting your changes


__ 33. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 6. X Window System 6-11


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

6-12 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 7. Kernel Compilation and Configuration

What This Exercise Is About


This exercise will let you compile a Linux kernel.

What You Should Be Able to Do


After completing this exercise you should have experience with:
• Installing kernel sources
• Compiling the kernel
• Installing the kernel

© Copyright IBM Corp. 2001, 2004 Exercise 7. Kernel Compilation and Configuration 7-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Installing the kernel sources
__ 1. Install the kernel sources from the distribution media.

Configuring the kernel


__ 2. Change to the kernel source directory.
__ 3. Clean the kernel development tree of all distribution-dependent files.
__ 4. If your distribution also distributes the config file that they used to compile their
kernels, copy the config file which is most suitable for your situation to .config in the
current directory. After copying, run the make oldconfig command to make sure
that the .config file is correct.
__ 5. Configure the kernel: go through the configuration questions and use your best
judgement on what to enable. Select support for devices only if these are actually
present in your system.
Note: On a SuSE 8.2 system we have found that you need to disable filesystems;
ReiserFS extended attributes, or else the compile process will fail.
__ 6. View the kernel configuration file.

7-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 7. To avoid conflicts with the current kernel version, change the “EXTRAVERSION” on
the fourth line of /usr/src/linux/Makefile to “-LX03”.

Compiling the Kernel


__ 8. Create the dependency list, delete all old files, make the kernel image and make the
modules.

Installing the Kernel


__ 9. Copy the kernel image to the /boot directory. Make sure you add the version to the
name.
__ 10. Also copy the kernel map file and configuration file to the /boot directory. Again,
make sure you add the version to the name. Note that these files are not strictly
necessary but are very useful when you need to debug your kernel somehow.
__ 11. Install the kernel modules.
__ 12. Create an initial root disk (initrd).
__ 13. If your distribution uses LILO, then alter the file /boot/lilo.msg, and put some text in
it explaining which option will boot which operating system. Edit /etc/lilo.conf so that
the default operating system is the new /boot/bzImage-version-LX03, and the older
image (/boot/vmlinuz) is the second, with another label. Save /etc/lilo.conf and run
lilo.
__ 14. If your boot loader is GRUB, then edit the /boot/grub/menu.lst file and add an extra
stanza for your new kernel.
__ 15. Reboot your system. See if the new kernel boots and verify that it is indeed your new
kernel. Check the messages on your screen with Shift-PgUp or browse through
/var/log/messages. If there are any errors you might have done something wrong
during configuration. If there is time, try again. If there is no time left, reboot using
the older kernel.

Documenting your changes


__ 16. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 7. Kernel Compilation and Configuration 7-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions With Hints


Installing the kernel sources
__ 1. Install the kernel sources from the distribution media.
» fedora# cd /mnt/install/Fedora/RPMS
/redhat# cd /mnt/install/RedHat/RPMS
suse# cd /mnt/install/suse/i586
» # rpm -ivh kernel-source-version.rpm

Configuring the kernel


__ 2. Change to the kernel source directory.
» # cd /usr/src/linux
- OR -
# cd /usr/src/linux-version
__ 3. Clean the kernel development tree of all distribution-dependent files.
» # make mrproper
__ 4. If your distribution also distributes the config file that they used to compile their
kernels, copy the config file which is most suitable for your situation to .config in the
current directory. After copying, run the make oldconfig command to make sure
that the .config file is correct.
» fedora/redhat# cp configs/kernel-version-i686.config .config
suse# cp /boot/config-version .config
» # make oldconfig
__ 5. Configure the kernel: go through the configuration questions and use your best
judgement on what to enable. Select support for devices only if these are actually
present in your system.
Note: On a SuSE 8.2 system we have found that you need to disable Filesystems;
ReiserFS extended attributes, or else the compile process will fail.
» # make config
- OR -
# make menuconfig
- OR -
# make xconfig
__ 6. View the kernel configuration file.
» # less .config

7-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 7. To avoid conflicts with the current kernel version, change the “EXTRAVERSION” on
the fourth line of /usr/src/linux/Makefile to “-LX03”.
» # vi Makefile
Change the fourth line so that it reads:
EXTRAVERSION = -LX03

Compiling the Kernel


__ 8. Create the dependency list, delete all old files, make the kernel image and make the
modules.
» # make dep
» # make clean
» # make bzImage
» # make modules
make bzImage and make modules will take considerable time: up to two hours
on a moderate system. To make sure you don’t have to come back halfway
through the compilation, you can combine the arguments into one command:
» # make dep clean bzImage modules

Installing the Kernel


__ 9. Copy the kernel image to the /boot directory. Make sure you add the version to the
name.
» # cp arch/i386/boot/bzImage /boot/vmlinuz-version-LX03
__ 10. Also copy the kernel map file and configuration file to the /boot directory. Again,
make sure you add the version to the name. Note that these files are not strictly
necessary but are very useful when you need to debug your kernel somehow.
» # cp System.map /boot/System.map-version-LX03
» # cp .config /boot/config-version-LX03
__ 11. Install the kernel modules.
» # make modules_install
__ 12. Create an initial root disk (initrd).
» # cd /boot
» redhat# mkinitrd initrd-version-LX03.img version-LX03
suse# mk_initrd -k bzImage-version-LX03 -i initrd-version-LX03.img
__ 13. If your distribution uses LILO, then alter the file /boot/lilo.msg, and put some text in
it explaining which option will boot which operating system. Edit /etc/lilo.conf so that
the default operating system is the new /boot/bzImage-version-LX03, and the older

© Copyright IBM Corp. 2001, 2004 Exercise 7. Kernel Compilation and Configuration 7-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

image (/boot/vmlinuz) is the second, with another label. Save /etc/lilo.conf and run
lilo.
» # vi /boot/lilo.msg
Add for instance:
Press C for the current Linux kernel
or O for the older but stable kernel.
» # vi /etc/lilo.conf
Add the following stanza to the file, obviously modified for your situation:
image=/boot/bzImage-2.4.20-LX03
label=C
initrd=/boot/initrd-2.4.20-LX03.img
root=/dev/hda5
read-only
» # lilo -v
__ 14. If your boot loader is GRUB, then edit the /boot/grub/menu.lst file and add an extra
stanza for your new kernel.
» # vi /boot/grub/menu.lst
» Add the following stanza:
title New Kernel
root (hd0,0)
kernel /bzImage-2.4.20-LX03 ro root=/dev/hda5
initrd /initrd-2.4.20-LX03.img
Note that your kernel version number, /boot and root filesystem may be
different!
__ 15. Reboot your system. See if the new kernel boots and verify that it is indeed your new
kernel. Check the messages on your screen with Shift-PgUp or browse through
/var/log/messages. If there are any errors you might have done something wrong
during configuration. If there is time, try again. If there is no time left, reboot using
the older kernel.
» # shutdown -r now
» After reboot:
# uname -a
# cat /proc/version
# tail -200 /var/log/messages | less

Documenting your changes


__ 16. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

7-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 8. Character Devices, PCMCIA, and USB

Notice
The unit Character Devices does not include any exercises because
the hardware required to do any exercises will most likely not be
available in most classrooms. This page is here to keep unit numbers
and exercise numbers synchronized.

© Copyright IBM Corp. 2001, 2004 Exercise 8. Character Devices, PCMCIA, and USB 8-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

8-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 9. Block Devices, RAID, and LVM

What This Exercise Is About


This exercise will let you work with block devices, RAID and LVM.

What You Should Be Able to Do


After completing this exercise you should have experience with:
• RAM disks
• Software RAID
• Logical Volume Management

© Copyright IBM Corp. 2001, 2004 Exercise 9. Block Devices, RAID, and LVM 9-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Notice
In this unit we are going to create and use various block devices. Block devices as such are
not really useful though, until you create a filesystem in there. For this, we are going to use
the mke2fs command to create a filesystem, and the mount command to mount them.
These commands will be covered in-depth in the next unit.

Working with RAM disks


Note: There is a bug in Fedora Core 2 (and most likely related to the 2.6 kernel itself) which
prevents RAM disks from working properly if you put an ext2 filesystem on them. This bug
has been reported to Fedora (bugzilla bug number 124904) but no resolution was available
at this time of writing.
__ 1. Verify the size of the RAM disks that the kernel uses
__ 2. Format the ramdisk with mke2fs
__ 3. Create a directory /mnt/ramdisk and mount the RAM disk on that mountpoint.
__ 4. Run the df command to see how much space is available on this RAM disk.
__ 5. Copy some files onto this ramdisk and verify that they are indeed there.
__ 6. Unmount the ramdisk and mount it again. Is the file still there?
__ 7. Reboot your system and then try to mount the RAM disk again. Does this work?

Working with partitions


If you installed your system correctly, then you should have at least 450 MB in
unpartitioned space left. We're going to create three partitions in here, 150 MB each, which
are going to be used in the subsequent exercises.
__ 8. Start the fdisk program and create four additional partitions. The partition size
should be 150 MB each. Save the partition table to disk.
Write down the partition numbers you created, because you’ll be using these in the
rest of this exercise.
__ 9. Pay particular attention to the output of the fdisk command. Depending on
circumstances, it might mention “The kernel still uses the old table. The new table
will be used at the next reboot.” In this case, reboot your system.
__ 10. Format the first of the four partitions with the mke2fs command. Create a
mountpoint /mnt/partition and mount this partition on this mountpoint.
__ 11. Run the df command to see how much space is available on these partitions.
__ 12. Copy some files onto these partitions and verify that they are indeed there.

9-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 13. Reboot your system and then try to mount the partition again. Does this work?
__ 14. Unmount the partition you just mounted.

Working with RAID


__ 15. With fdisk, change the partition types of the four partitions to 0xfd (Linux RAID
autodetect). If necessary, reboot your system afterwards.
__ 16. If your distribution uses mdadm to implement the mdmonitor service, then disable
this service for now: The mdmonitor service warns you (via the syslog daemon) of
a failing RAID array component, but also prevents you from stopping RAID volumes
manually.
__ 17. Create the /etc/raidtab file so that the four partitions form a raid-linear volume.
Initialize the raid array and create a filesystem on it. Create a mountpoint /mnt/raid
and mount the filesystem on it. Then run the df command to find out how much
space this partition has and view the status of the RAID array. Then unmount the
partition and stop the raid volume.
__ 18. Modify the /etc/raidtab file so that the four partitions now form a raid-0 volume.
Initialize the raid array and create a filesystem on it. Mount the filesystem on
/mnt/raid again. Then run the df command to find out how much space this partition
has and check the status of the array again. Then unmount the partition and stop the
raid volume.
__ 19. Modify the /etc/raidtab file so that the first three partitions form a raid-1 volume, and
the last partition is a spare disk. Initialize the raid array and create a filesystem on it.
Mount the filesystem on /mnt/raid again. Then run the df command to find out how
much space this partition has and check the status of the raid array. Set one (or two)
disks in the raid array to faulty, and watch the raid array recover itself using the
spare disk. Then unmount the partition and stop the raid volume.
__ 20. Now modify the /etc/raidtab file so that the three partitions form a raid-5 volume.
Initialize the raid array and create a filesystem on it. Mount the filesystem on
/mnt/raid again. Then run the df command to find out how much space this partition
has. Set one disk in the raid array to faulty, and watch the raid array recover itself
using the spare disk. Then unmount the partition and stop the raid volume.
__ 21. Remove the /etc/raidtab file.

Working with LVM


__ 22. With fdisk, change the partition types of the three partitions to 0x8e (Linux LVM). If
necessary, reboot your system afterwards.
__ 23. Initialize each of the three partitions that you used earlier as Physical Volumes. If
you get an error message /etc/lvmtab does not exist, then run the vgscan command
to create it.

© Copyright IBM Corp. 2001, 2004 Exercise 9. Block Devices, RAID, and LVM 9-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 24. Create a volume group vg00, consisting of only the first two LVM partitions. Use a
PE size of 4 MB.
__ 25. Create a logical volume lv00 of 50 MB in the volume group vg00.
__ 26. Format the logical volume with the mke2fs command. Create a mount point
/mnt/lv00 and mount the logical volume. Then run the df command to see how much
space is available.
__ 27. Use the various LVM commands to retrieve information about the physical volumes,
the volume group and the logical volumes.
__ 28. Take a look at the files that were created in /etc/lvmconf. Can you read these files?
__ 29. Add the third and fourth LVM partitions to the volume group vg00, and migrate all
data onto these physical volumes. Then reduce the volume group so that the
volume group only contains the third and fourth partition. Do you need to unmount
the /dev/vg00/lv00 logical volume first?
__ 30. Add the first two LVM partitions back to your volume group, and create three more
logical volumes in this volume group, called lv01 through lv03. Each logical volume
needs to be 50 MB as well. We will need these in the next exercise.

Loopback Devices (optional)


__ 31. Create an empty, 32 MB file /var/tmp/filesystem and format this file as an ext2
filesystem.
__ 32. Create a mountpoint /mnt/loop and mount the filesystem on this mountpoint. Check
the size of the filesystem and copy the /etc/passwd file onto it. Then unmount the
filesystem again.
__ 33. Use the strings and grep tools to check whether you can read information
(particularly, some content of the passwd file) from the /var/tmp/filesystem file
without mounting it.
__ 34. If you have a 2.6 kernel with encryption enabled (Fedora Core 2), then create a
filesystem in /var/tmp/filesystem again, but this time make sure the filesystem is
encrypted. You will have to use losetup for this. Check again if you can read the file
with strings and grep.
__ 35. Mount the encrypted /var/tmp/filesystem again, but this time without using losetup.
Check if you can read the passwd file, then unmount the filesystem again.

Documenting your changes


__ 36. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

9-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


Notice
In this unit we are going to create and use various block devices. Block devices as such are
not really useful though, until you create a filesystem in there. For this, we are going to use
the mke2fs command to create a filesystem, and the mount command to mount them.
These commands will be covered in-depth in the next unit.

Working with RAM disks


Note: There is a bug in Fedora Core 2 (and most likely related to the 2.6 kernel itself) which
prevents RAM disks from working properly if you put an ext2 filesystem on them. This bug
has been reported to Fedora (bugzilla bug number 124904) but no resolution was available
at this time of writing.
__ 1. Verify the size of the RAM disks that the kernel uses
» # dmesg | grep RAM
__ 2. Format the ramdisk with mke2fs
» # mke2fs /dev/ram0
__ 3. Create a directory /mnt/ramdisk and mount the RAM disk on that mountpoint.
» # mkdir /mnt/ramdisk
» # mount /dev/ram0 /mnt/ramdisk
__ 4. Run the df command to see how much space is available on this RAM disk.
» # df
__ 5. Copy some files onto this ramdisk and verify that they are indeed there.
» # cp /etc/passwd /mnt/ramdisk/passwd
» # cat /mnt/ramdisk/passwd
__ 6. Unmount the ramdisk and mount it again. Is the file still there?
» # umount /mnt/ramdisk
» # mount /dev/ram0 /mnt/ramdisk
» # cat /mnt/ramdisk/passwd
__ 7. Reboot your system and then try to mount the RAM disk again. Does this work?
» # reboot
» After the reboot:
» # mount /dev/ram0 /mnt/ramdisk

Working with partitions

© Copyright IBM Corp. 2001, 2004 Exercise 9. Block Devices, RAID, and LVM 9-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

If you installed your system correctly, then you should have at least 450 MB in unpartitioned
space left. We're going to create three partitions in here, 150 MB each, which are going to
be used in the subsequent exercises.
__ 8. Start the fdisk program and create four additional partitions. The partition size
should be 150 MB each. Save the partition table to disk.
Write down the partition numbers you created, because you’ll be using these in the
rest of this exercise.
» # fdisk /dev/hda
» Command (m for help): p
» Command (m for help): n
» First cylinder (mmm-nnn, default mmm): mmm
» Last cylinder or +size or +sizeM or +sizeK (mmm-nnn, default nnn): +150M
» Command (m for help): n
» First cylinder (mmm-nnn, default mmm): mmm
» Last cylinder or +size or +sizeM or +sizeK (mmm-nnn, default nnn): +150M
» Command (m for help): n
» First cylinder (mmm-nnn, default mmm): mmm
» Last cylinder or +size or +sizeM or +sizeK (mmm-nnn, default nnn): +150M
» Command (m for help): n
» First cylinder (mmm-nnn, default mmm): mmm
» Last cylinder or +size or +sizeM or +sizeK (mmm-nnn, default nnn): +150M
» Command (m for help): p
» Command (m for help): w
Note: From this point on, the hints will assume that the partitions you created
are, respectively, /dev/hda9, /dev/hda10 and /dev/hda11. Make sure you
don’t accidently overwrite other partitions if your newly created partitions are
numbered differently.
__ 9. Pay particular attention to the output of the fdisk command. Depending on
circumstances, it might mention The kernel still uses the old table. The new table will
be used at the next reboot. In this case, reboot your system.
» # reboot
__ 10. Format the first of the four partitions with the mke2fs command. Create a
mountpoint /mnt/partition and mount this partition on this mountpoint.
» # mke2fs /dev/hda9
» # mkdir /mnt/partition
» # mount /dev/hda9 /mnt/partition
__ 11. Run the df command to see how much space is available on these partitions.
» # df
__ 12. Copy some files onto these partitions and verify that they are indeed there.
» # cp /etc/passwd /mnt/partition/passwd

9-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » # cat /mnt/partition/passwd


__ 13. Reboot your system and then try to mount the partition again. Does this work?
» # reboot
» After the reboot:
» # mount /dev/hda9 /mnt/partition
» # ls /mnt/partition
__ 14. Unmount the partition you just mounted.
» # umount /mnt/partition

Working with RAID


__ 15. With fdisk, change the partition types of the four partitions to 0xfd (Linux RAID
autodetect). If necessary, reboot your system afterwards.
» # fdisk /dev/hda
» Command (m for help): t
» Partition number (1-11): 9
» Hex code (type L to list codes): fd
» Command (m for help): t
» Partition number (1-11): 10
» Hex code (type L to list codes): fd
» Command (m for help): t
» Partition number (1-11): 11
» Hex code (type L to list codes): fd
» Command (m for help): t
» Partition number (1-11): 12
» Hex code (type L to list codes): fd
» Command (m for help): w
» # reboot
__ 16. If your distribution uses mdadm to implement the mdmonitor service, then disable
this service for now: The mdmonitor service warns you (via the syslog daemon) of
a failing RAID array component, but also prevents you from stopping RAID volumes
manually.
» fedora/redhat# service mdmonitor stop
__ 17. Create the /etc/raidtab file so that the four partitions form a raid-linear volume.
Initialize the raid array and create a filesystem on it. Create a mountpoint /mnt/raid
and mount the filesystem on it. Then run the df command to find out how much
space this partition has and view the status of the RAID array. Then unmount the
partition and stop the raid volume.
» # vi /etc/raidtab
» Edit the file so that it looks like this:
raiddev /dev/md0

© Copyright IBM Corp. 2001, 2004 Exercise 9. Block Devices, RAID, and LVM 9-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

raid-level linear
nr-raid-disks 4
nr-spare-disks 0
persistent-superblock 1
chunk-size 4

device /dev/hda9
raid-disk 0
device /dev/hda10
raid-disk 1
device /dev/hda11
raid-disk 2
device /dev/hda12
raid-disk 3
Save the file
» # mkraid /dev/md0
» # mkraid -f /dev/md0
» (Read the warning carefully)
» # mkraid --really-force /dev/md0
» # mke2fs /dev/md0
» # mkdir /mnt/raid
» # mount /dev/md0 /mnt/raid
» # df
Write down how much space the /mnt/raid filesystem has.
» # cat /proc/mdstat
» # umount /mnt/raid
» # raidstop /dev/md0
__ 18. Modify the /etc/raidtab file so that the four partitions now form a raid-0 volume.
Initialize the raid array and create a filesystem on it. Mount the filesystem on
/mnt/raid again. Then run the df command to find out how much space this partition
has and check the status of the array again. Then unmount the partition and stop the
raid volume.
» # vi /etc/raidtab
» Edit the file so that it now looks like this:
raiddev /dev/md0
raid-level 0
nr-raid-disks 4
nr-spare-disks 0
persistent-superblock 1
chunk-size 4

device /dev/hda9
raid-disk 0

9-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty device /dev/hda10


raid-disk 1
device /dev/hda11
raid-disk 2
device /dev/hda12
raid-disk 3
Save the file
» # mkraid /dev/md0
» # mkraid -f /dev/md0
» (Read the warning carefully)
» # mkraid --really-force /dev/md0
» # mke2fs /dev/md0
» # mount /dev/md0 /mnt/raid
» # df
Write down how much space the /mnt/raid filesystem has.
» # cat /proc/mdstat
» # umount /mnt/raid
» # raidstop /dev/md0
__ 19. Modify the /etc/raidtab file so that the first three partitions form a raid-1 volume, and
the last partition is a spare disk. Initialize the raid array and create a filesystem on it.
Mount the filesystem on /mnt/raid again. Then run the df command to find out how
much space this partition has and check the status of the raid array. Set one (or two)
disks in the raid array to faulty, and watch the raid array recover itself using the
spare disk. Then unmount the partition and stop the raid volume.
» # vi /etc/raidtab
» Modify the file so that it looks like this:
raiddev /dev/md0
raid-level 1
nr-raid-disks 3
nr-spare-disks 1
persistent-superblock 1
chunk-size 4

device /dev/hda9
raid-disk 0
device /dev/hda10
raid-disk 1
device /dev/hda11
raid-disk 2
device /dev/hda12
spare-disk 0
Save the file

© Copyright IBM Corp. 2001, 2004 Exercise 9. Block Devices, RAID, and LVM 9-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» # mkraid /dev/md0
» # mkraid -f /dev/md0
» # mkraid --really-force /dev/md0
» # mke2fs /dev/md0
» # mount /dev/md0 /mnt/raid
» # df
Write down how much space the /mnt/raid filesystem has.
» # cat /proc/mdstat
Repeat this command until the volume is synchronized.
» # raidsetfaulty /dev/md0 /dev/hda9
» # raidsetfaulty /dev/md0 /dev/hda10
» # cat /proc/mdstat
Repeat this command until the volume is synchronized.
» # raidsetfaulty /dev/md0 /dev/hda11
» # cat /proc/mdstat
» # raidhotremove /dev/md0 /dev/hda9
» # raidhotremove /dev/md0 /dev/hda10
» # raidhotremove /dev/md0 /dev/hda11
» # raidhotadd /dev/md0 /dev/hda9
» # raidhotadd /dev/md0 /dev/hda10
» # raidhotadd /dev/md0 /dev/hda11
» # cat /proc/mdstat
Repeat this command until the volume is synchronized again. Can you
determine which of the partitions is the primary, which are backups and which
is spare?
» # umount /mnt/raid
» # raidstop /dev/md0
__ 20. Now modify the /etc/raidtab file so that the three partitions form a raid-5 volume.
Initialize the raid array and create a filesystem on it. Mount the filesystem on
/mnt/raid again. Then run the df command to find out how much space this partition
has. Set one disk in the raid array to faulty, and watch the raid array recover itself
using the spare disk. Then unmount the partition and stop the raid volume.
» # vi /etc/raidtab
» Modify the file so that it looks like this:
raiddev /dev/md0
raid-level 5
nr-raid-disks 3
nr-spare-disks 1
persistent-superblock 1
chunk-size 4

device /dev/hda9
raid-disk 0
device /dev/hda10

9-10 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty raid-disk 1
device /dev/hda11
raid-disk 2
device /dev/hda12
spare-disk 0
Save the file
» # mkraid /dev/md0
» # mkraid -f /dev/md0
» # mkraid --really-force /dev/md0
» # mke2fs /dev/md0
» # mount /dev/md0 /mnt/raid
» # df
Write down how much space the /mnt/raid filesystem has.
» # cat /proc/mdstat
Repeat this command until the volume is synchronized.
» # raidsetfaulty /dev/md0 /dev/hda9
» # cat /proc/mdstat
Repeat this command until the volume is synchronized.
» # raidsetfaulty /dev/md0 /dev/hda10
» # cat /proc/mdstat
» # raidhotremove /dev/md0 /dev/hda9
» # raidhotremove /dev/md0 /dev/hda10
» # raidhotadd /dev/md0 /dev/hda9
» # raidhotadd /dev/md0 /dev/hda10
» # cat /proc/mdstat
Repeat this command until the volume is synchronized again. Can you
determine which of the partitions are used, and which is spare?
» # umount /mnt/raid
» # raidstop /dev/md0
__ 21. Remove the /etc/raidtab file.
» # rm -f /etc/raidtab

Working with LVM


__ 22. With fdisk, change the partition types of the three partitions to 0x8e (Linux LVM). If
necessary, reboot your system afterwards.
» # fdisk /dev/hda
» Command (m for help): t
» Partition number (1-11): 9
» Hex code (type L to list codes): 8e
» Command (m for help): t
» Partition number (1-11): 10

© Copyright IBM Corp. 2001, 2004 Exercise 9. Block Devices, RAID, and LVM 9-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» Hex code (type L to list codes): 8e


» Command (m for help): t
» Partition number (1-11): 11
» Hex code (type L to list codes): 8e
» Command (m for help): t
» Partition number (1-11): 12
» Hex code (type L to list codes): 8e
» Command (m for help): w
» # reboot
__ 23. Initialize each of the three partitions that you used earlier as Physical Volumes. If
you get an error message /etc/lvmtab does not exist, then run the vgscan command
to create it.
» # pvcreate /dev/hda9
» # pvcreate /dev/hda10
» # pvcreate /dev/hda11
» # pvcreate /dev/hda12
__ 24. Create a volume group vg00, consisting of only the first two LVM partitions. Use a
PE size of 4 MB.
» # vgcreate -s 4M vg00 /dev/hda9 /dev/hda10
__ 25. Create a logical volume lv00 of 50 MB in the volume group vg00.
» # lvcreate -L 50M -n lv00 vg00
__ 26. Format the logical volume with the mke2fs command. Create a mount point
/mnt/lv00 and mount the logical volume. Then run the df command to see how much
space is available.
» # mke2fs /dev/vg00/lv00
» # mkdir /mnt/lv00
» # mount /dev/vg00/lv00 /mnt/lv00
» # df
__ 27. Use the various LVM commands to retrieve information about the physical volumes,
the volume group and the logical volumes.
» # vgdisplay vg00
» # lvdisplay /dev/vg00/lv00
» # pvdisplay /dev/hda9
» # pvdisplay /dev/hda10
» # pvdisplay /dev/hda11
» # pvdisplay /dev/hda12
__ 28. Take a look at the files that were created in /etc/lvmconf. Can you read these files?
» # cd /etc/lvmconf
» # ls
» # cat vg00.conf

9-12 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » If your screen is messed up, use the reset command to restore it to working
order.
__ 29. Add the third and fourth LVM partitions to the volume group vg00, and migrate all
data onto these physical volumes. Then reduce the volume group so that the
volume group only contains the third and fourth partition. Do you need to unmount
the /dev/vg00/lv00 logical volume first?
» # vgextend vg00 /dev/hda11
» # vgextend vg00 /dev/hda12
» # pvmove /dev/hda9 /dev/hda11
» # pvmove /dev/hda10 /dev/hda12
» # vgreduce vg00 /dev/hda9 /dev/hda10
» # vgdisplay vg00
You don’t have to unmount logical volumes while migrating
__ 30. Add the first two LVM partitions back to your volume group, and create three more
logical volumes in this volume group, called lv01 through lv03. Each logical volume
needs to be 50 MB as well. We will need these in the next exercise.
» # vgextend vg00 /dev/hda9 /dev/hda10
» # lvcreate -L 50M -n lv01 vg00
» # lvcreate -L 50M -n lv02 vg00
» # lvcreate -L 50M -n lv03 vg00

Loopback Devices (optional)


__ 31. Create an empty, 32 MB file /var/tmp/filesystem and format this file as an ext2
filesystem.
» # dd if=/dev/zero of=/var/tmp/filesystem bs=1M count=32
» # mke2fs /var/tmp/filesystem
__ 32. Create a mountpoint /mnt/loop and mount the filesystem on this mountpoint. Check
the size of the filesystem and copy the /etc/passwd file onto it. Then unmount the
filesystem again.
» # mkdir /mnt/loop
» # mount -o loop /var/tmp/filesystem /mnt/loop
» # df
» # cp /etc/passwd /mnt/loop
» # umount /mnt/loop
__ 33. Use the strings and grep tools to check whether you can read information
(particularly, some content of the passwd file) from the /var/tmp/filesystem file
without mounting it.
» # strings /var/tmp/filesystem | grep root

© Copyright IBM Corp. 2001, 2004 Exercise 9. Block Devices, RAID, and LVM 9-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 34. If you have a 2.6 kernel with encryption enabled (Fedora Core 2), then create a
filesystem in /var/tmp/filesystem again, but this time make sure the filesystem is
encrypted. You will have to use losetup for this. Check again if you can read the file
with strings and grep.
» # modprobe loop blowfish cryptoloop
» # losetup -e blowfish /dev/loop0 /var/tmp/filesystem
Type a password when asked for. For convenience, you can use ibmlnx but
you don’t have to.
» # mke2fs /dev/loop0
» # mount /dev/loop0 /mnt/loop
» # cp /etc/passwd /mnt/loop
» # umount /mnt/loop
» # losetup -d /dev/loop0
» # strings /var/tmp/filesystem | grep root
__ 35. Mount the encrypted /var/tmp/filesystem again, but this time without using losetup.
Check if you can read the passwd file, then unmount the filesystem again.
» # mount -o loop,encryption=blowfish /var/tmp/filesystem /mnt/loop
Type the password when asked for.
» # cat /mnt/loop/passwd
» # umount /mnt/loop

Documenting your changes


__ 36. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

9-14 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 10. Filesystems

What This Exercise Is About


This exercise will let you work with filesystems.

What You Should Be Able to Do


After completing this exercise you should have experience with:
• Creating, mounting, and unmounting of Linux filesystems
• Mounting and unmounting non-Linux filesystems
• Automatic mounting of filesystems at system startup
• Configuring User Quota

© Copyright IBM Corp. 2001, 2004 Exercise 10. Filesystems 10-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Installing tools
__ 1. Make sure that all utilities for ext2/ext3, ReiserFS and JFS are installed. Also check
kernel support for each of these filesystems. Not all distributions include all utilities
by default, and not all distributions include support for all filesystems in their stock
kernel.
Utilities for ext2/ext3 are contained in the e2fsprogs RPM (Fedora/Red Hat/SuSE).
Utilities for ReiserFS are contained in the reiserfs-utils RPM (Fedora) and reiserfs
RPM (SuSE). RHEL3 does not include ReiserFS support.
Utilities for JFS are contained in the jfsutils RPM (Fedora/Red Hat/SuSE).
To determine kernel support, look in /lib/modules/version/kernel/fs.

Creating Linux Filesystems


We will now create various filesystems in the logical volumes we made earlier. Note that
/dev/vg00/lv00 already contains an ext2 filesystem.
__ 2. If your distribution supports it, create an ext3 filesystem in /dev/vg00/lv01.
__ 3. Create a mount point, /mnt/lv01 for this filesystem.
__ 4. Mount the filesystem on this mount point.
__ 5. If your distribution supports it, create a ReiserFS filesystem in /dev/vg00/lv02.
__ 6. Create a mount point, /mnt/lv02 for this filesystem.
__ 7. Mount the filesystem on this mount point.
__ 8. If your distribution supports it, create a JFS filesystem in /dev/vg00/lv03
__ 9. Create a mount point, /mnt/lv03 for this filesystem.
__ 10. Mount the filesystem on this mount point.
__ 11. Issue the mount and df commands to see the mounted filesystems. Can you see
how much space the journals are taking? Also, list the root directory of the mounted
filesystems. Are the journals visible?
__ 12. Create some files and/or directories on these mounted filesystems.

Automatically Mounting Filesystems at System Startup


Filesystems that you will want to mount automatically at system startup should be listed in
/etc/fstab.
__ 13. Edit the /etc/fstab file to include all the previously created filesystems.

10-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 14. Issue the sync command to ensure that all data is written to disk. Wait five seconds,
then turn off your computer with the power off button. (Do NOT do a proper
shutdown!) Turn on your computer and watch the boot messages. Which filesystem
was checked the fastest?

Changing filesystem size


__ 15. For each of the four different filesystems created, try to extend the filesystem size to
100 MB. Perform filesystem checks before and afterwards, if applicable.
Note that some filesystem types don’t allow you to extend the filesystem without
unmounting (yet). In that case, you’re going to have to unmount the filesystem first.
Note 2: Extending a JFS filesystem does not seem to work correctly. Most
distributions therefore do not include the extendfs command.

Working with Files with Multiple Names


As seen in the lecture, a file can have multiple names, as long as each name refers to the
same inode. An example of this situation is /bin/gzip, /bin/gunzip and /bin/zcat.
__ 16. Log in as root. Verify that /bin/gzip, /bin/gunzip and /bin/zcat indeed have the same
inode number.
__ 17. Go to /root and create a file named one, using vi. Put some text in the file, so that
you can identify that file for yourself.
__ 18. Verify the filename and the contents.
__ 19. Now create a second link to the file (a second filename) named two. Verify the
filename and the contents.
__ 20. Delete the file one.
__ 21. Verify the filename and contents of two. Note that the link count has dropped.
__ 22. Create a third link, called three, in the / directory. It should again point to the original
file. Verify the filename and contents of this file.
__ 23. Now try to create a fourth link on one of the filesystems you just created.
__ 24. Create a symbolic link from /root/two to /mnt/lv00/four. Read the manual page for ln
if necessary. Verify the name and contents of the file.
__ 25. Now delete /root/two, and verify the contents of both /tmp/three and /mnt/lv00/four.

Configuring User Quota


__ 26. Remount the /home filesystem so that quota are enabled, and ensure that quota are
enabled when the system reboots.
__ 27. Perform a recalculation of current quota and turn quota checking on.

© Copyright IBM Corp. 2001, 2004 Exercise 10. Filesystems 10-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 28. Set the soft limit of users tux1 and tux2 to 4 Megabyte, and the hard limit to 5
Megabyte.
__ 29. On another virtual terminal, log in as tux1 and create 5 files of one Megabyte each.
Watch what happens.
__ 30. Still logged in as tux1, check the quota.
__ 31. Switch back to your root session and check the quota of all users.

Documenting your changes


__ 32. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

10-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions with Hints


Installing tools
__ 1. Make sure that all utilities for ext2/ext3, ReiserFS and JFS are installed. Also check
kernel support for each of these filesystems. Not all distributions include all utilities
by default, and not all distributions include support for all filesystems in their stock
kernel.
Utilities for ext2/ext3 are contained in the e2fsprogs RPM (Fedora/Red Hat/SuSE).
Utilities for ReiserFS are contained in the reiserfs-utils RPM (Fedora) and reiserfs
RPM (SuSE). RHEL3 does not include ReiserFS support.
Utilities for JFS are contained in the jfsutils RPM (Fedora/Red Hat/SuSE).
To determine kernel support, look in /lib/modules/version/kernel/fs.

Creating Linux Filesystems


We will now create various filesystems in the logical volumes we made earlier. Note that
/dev/vg00/lv00 already contains an ext2 filesystem.
__ 2. If your distribution supports it, create an ext3 filesystem in /dev/vg00/lv01.
» # mke2fs -j /dev/vg00/lv01
__ 3. Create a mount point, /mnt/lv01 for this filesystem.
» # mkdir /mnt/lv01
__ 4. Mount the filesystem on this mount point.
» # mount /dev/vg00/lv01 /mnt/lv01
__ 5. If your distribution supports it, create a ReiserFS filesystem in /dev/vg00/lv02.
» # mkreiserfs /dev/vg00/lv02
__ 6. Create a mount point, /mnt/lv02 for this filesystem.
» # mkdir /mnt/lv02
__ 7. Mount the filesystem on this mount point.
» # mount /dev/vg00/lv02 /mnt/lv02
__ 8. If your distribution supports it, create a JFS filesystem in /dev/vg00/lv03
» # mkfs.jfs /dev/vg00/lv03
__ 9. Create a mount point, /mnt/lv03 for this filesystem.
» # mkdir /mnt/lv03
__ 10. Mount the filesystem on this mount point.
» # mount /dev/vg00/lv03 /mnt/lv03

© Copyright IBM Corp. 2001, 2004 Exercise 10. Filesystems 10-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 11. Issue the mount and df commands to see the mounted filesystems. Can you see
how much space the journals are taking? Also, list the root directory of the mounted
filesystems. Are the journals visible?
» # mount
» # df
» # df -i
» # cd /mnt/lv00
» # ls -la
» # cd /mnt/lv01
» # ls -la
» # cd /mnt/lv02
» # ls -la
» # cd /mnt/lv03
» # ls -la
__ 12. Create some files and/or directories on these mounted filesystems.
» # cd /mnt/lv00
» # touch testfile0
» # mkdir testdir0
» # cd /mnt/llv01
» # touch testfile1
» # mkdir testdir1
» # cd /mnt/lv02
» # touch testfile2
» # mkdir testdir2
» # cd /mnt/lv03
» # touch testfile3
» # mkdir testdir3

Automatically Mounting Filesystems at System Startup


Filesystems that you will want to mount automatically at system startup should be listed in
/etc/fstab.
__ 13. Edit the /etc/fstab file to include all the previously created filesystems.
» # vi /etc/fstab
Add the following lines:
/dev/vg00/lv00 /mnt/lv00 ext2 defaults 1 2
/dev/vg00/lv01 /mnt/lv01 ext3 defaults 1 2
/dev/vg00/lv02 /mnt/lv02 reiserfs defaults 1 2
/dev/vg00/lv03 /mnt/lv03 jfs defaults 1 2
__ 14. Issue the sync command to ensure that all data is written to disk. Wait five seconds,
then turn off your computer with the power off button. (Do NOT do a proper

10-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty shutdown!) Turn on your computer and watch the boot messages. Which filesystem
was checked the fastest?
» # sync

Changing filesystem size


__ 15. For each of the four different filesystems created, try to extend the filesystem size to
100 MB. Perform filesystem checks before and afterwards, if applicable.
Note that some filesystem types don’t allow you to extend the filesystem without
unmounting (yet). In that case, you’re going to have to unmount the filesystem first.
Note 2: Extending a JFS filesystem does not seem to work correctly. Most
distributions therefore do not include the extendfs command.
ext2 (using lvextend/resize2fs:
» # umount /mnt/lv00
» # e2fsck -f /dev/vg00/lv00
» # lvextend -L 100M /dev/vg00/lv00
» # resize2fs -p /dev/vg00/lv00
» # e2fsck -f /dev/vg00/lv00
» # mount /mnt/lv00
» # df
ext3 (using e2fsadm):
» # umount /mnt/lv01
» # e2fsadm -L 100M /dev/vg00/lv01
» # mount /mnt/lv01
» # df
ReiserFS:
» # lvextend -L 100M /dev/vg00/lv02
» # resize_reiserfs -v /dev/vg00/lv02
» # df
JFS: (As noted, this won’t work but should work as listed below.)
» # lvextend -L 100M /dev/vg00/lv03
» # extendfs /dev/vg00/lv03
» # df

Working with Files with Multiple Names


As seen in the lecture, a file can have multiple names, as long as each name refers to the
same inode. An example of this situation is /bin/gzip, /bin/gunzip and /bin/zcat.

© Copyright IBM Corp. 2001, 2004 Exercise 10. Filesystems 10-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 16. Log in as root. Verify that /bin/gzip, /bin/gunzip and /bin/zcat indeed have the same
inode number.
» Login: root
» Password: (Enter your password)
» # ls -li /bin/gzip /bin/gunzip /bin/zcat
__ 17. Go to /root and create a file named one, using vi. Put some text in the file, so that
you can identify that file for yourself.
» # cd /root
» # vi one
__ 18. Verify the filename and the contents.
» # ls -li one
» # cat one
__ 19. Now create a second link to the file (a second filename) named two. Verify the
filename and the contents.
» # ln one two
» # ls -li one two
» # cat two
__ 20. Delete the file one.
» # rm one
__ 21. Verify the filename and contents of two. Note that the link count has dropped.
» # ls -li two
» # cat two
__ 22. Create a third link, called three, in the / directory. It should again point to the original
file. Verify the filename and contents of this file.
» # cd /
» # ln /root/two three
» # ls -li three
» # cat three
__ 23. Now try to create a fourth link on one of the filesystems you just created.
» # cd /mnt/linux1
» # ln /root/two four
This command should fail.
__ 24. Create a symbolic link from /root/two to /mnt/lv00/four. Read the manual page for ln
if necessary. Verify the name and contents of the file.
» # cd /mnt/lv00
» # ln -s /root/two four
» # ls -li four
» # cat four

10-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 25. Now delete /root/two, and verify the contents of both /tmp/three and /mnt/lv00/four.
» # rm /root/two
» # ls -li /three /mnt/lv00/four
» # cat /three
» # cat /mnt/lv00/four

Configuring User Quota


__ 26. Remount the /home filesystem so that quota are enabled, and ensure that quota are
enabled when the system reboots.
» # vi /etc/fstab
Add the usrquota option to the entry describing your /home filesystem. The
line should now look like this:
/dev/hda8 /home ext3 defaults,usrquota 1 2
Note that there should not be a space between “defaults” and “userquota”,
just a comma!
» # mount -o remount /home
» # mount | grep /home
__ 27. Perform a recalculation of current quota and turn quota checking on.
» # touch /home/aquota.user
» # quotacheck /home
If you get a warning about the file being truncated, run the quotacheck
command again.
» # quotaon /home
__ 28. Set the soft limit of users tux1 and tux2 to 4 Megabyte, and the hard limit to 5
Megabyte.
» # edquota -u tux1
Change the soft limit to 4096 and the hard limit to 5120. The file should now
look like this:
Disk quotas for user tux1 (uid 500)
Filesystem Blocks Soft Hard Inodes Soft Hard
/dev/hda6 26 4096 5120 12 0 0
Save the file.
» # edquota -p tux1 -u tux2
__ 29. On another virtual terminal, log in as tux1 and create 5 files of one Megabyte each.
Watch what happens.
» Login: tux1
» Password: tux1
» $ dd if=/dev/zero of=one bs=1M count=1
» $ dd if=/dev/zero of=two bs=1M count=1

© Copyright IBM Corp. 2001, 2004 Exercise 10. Filesystems 10-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» $ dd if=/dev/zero of=three bs=1M count=1


» $ dd if=/dev/zero of=four bs=1M count=1
» $ dd if=/dev/zero of=five bs=1M count=1
» $ ls -l
__ 30. Still logged in as tux1, check the quota.
» $ quota
__ 31. Switch back to your root session and check the quota of all users.
» # repquota /home

Documenting your changes


__ 32. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

10-10 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 11. Memory Management

What This Exercise Is About


This exercise will demonstrate memory management in Linux, and will
let you create and use paging space.

What You Should Be Able to Do


After completing this exercise you should have experience with:
• The most important tools in memory management
• Creating and activating paging partitions and paging files

© Copyright IBM Corp. 2001, 2004 Exercise 11. Memory Management 11-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
If you have more than 128 Megabytes of memory
In this exercise we are going to look at memory management in Linux. As part of this
exercise we are going to exhaust the available memory. Experience has shown that if you
have more than 128 Megabytes of memory, that parts of this exercise will take too long.
(Yes, there is a disadvantage to having a lot of memory!) Therefore we are going to limit the
amount of memory that Linux detects to 128 Megabytes, just for this exercise.
__ 1. Reboot Linux
__ 2. If you use LILO, and the lilo boot:-prompt appears, start Linux and specify
mem=128M as startup parameter. If you use GRUB, modify the kernel line so that
the mem=128M parameter is added.

Using top
__ 3. Start top and identify the different pieces of information:
• The time, the up time, the number of users and the load information on the
first line.
• The number of processes on the second line.
• The CPU breakdown on the third line.
• The real memory breakdown on the fourth line
• The swap space breakdown on the fifth line
• The processes (sorted by CPU-time) on the next lines.
Verify that Linux detected only 128 Megabytes.
__ 4. top will automatically refresh itself after 10 seconds. To increase this to one second
enter the command s1.
__ 5. top will by default not show the amount of swap space used by each processes. To
show this amount too, call up the Field Order screen with the f command, and
enable the swap space display.
__ 6. To sort processes in a different order use the M, P or T command.
__ 7. Leave top running in a separate window.

Checking Swap Space


__ 8. There should be one active swap space (check the fifth line of top). Deactivate this
swap space. (If you don't know which partition is used as swapspace, check
/proc/swaps.)
__ 9. Go back to your top window and check what happened.

11-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 10. Reactivate the swap space.

Using the Cache


__ 11. Caching is done automatically. If you have performed the exercises so far, your
cache usage should be about 20 Megabytes. Let's see what happens if we really
start accessing the disk. Start a very disk-intensive program.
__ 12. Watch what happens to the amount of cached data in top. This number should
increase until your cache occupies almost all of your real memory. Only about 4 MB
will be left over for application use. But also note that virtually no processes will be
swapped out to disk.

Using the Swap space


The swap space will only be used if there is a real shortage in memory. First the amount of
cached data will decrease to about zero before processes are swapped to disk. Therefore,
we need to have a program which uses a lot of real memory. The easiest solution is to write
that ourselves.
__ 13. Create the directory /root/bin and cd into it.
__ 14. Create a program called usemem, with contents:
#!/usr/bin/perl
print "Allocating $ARGV[0] megabytes of memory...\n";
$big = "";
for( $i=0; $i<$ARGV[0]; $i++ )
{
$big .= "1234567890"x104858;
}
print "Press ENTER to release memory...\n";
<STDIN>;
When you start this program, it will gradually allocate the amount of memory you
specify on the command line, and then wait for you to press Enter. When you press
Enter, the program exits and thus will deallocate its memory.
Note: Your instructor might have this program available already.
__ 15. Do a chmod 755 of this program and start it with parameter 1. This will ensure that
the program allocates about 1 Megabyte of memory.
__ 16. Now go back to your top screen and select the “sort by memory usage” mode by
issuing the M command. Note how much memory is used by the usemem program.
__ 17. Stop usemem and start it with about half the amount of memory which is in your
system. So if you have 128 MB of real memory or decreased the amount to 128 MB,
use 64 as parameter. Watch what happens in top. First you should see the amount

© Copyright IBM Corp. 2001, 2004 Exercise 11. Memory Management 11-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

of cached data decrease, and maybe see some processes already being swapped
out.
__ 18. Now start usemem with about 80% of your memory and watch what happens.
__ 19. Stop usemem and watch what happens. Note that processes swapped out will not
automatically be swapped in as soon as memory comes available. They will be
swapped in when needed.
__ 20. Disable your swap space with swapoff and watch what happens.
__ 21. Enable swap space again and run usemem with about 90% of the total amount of
memory (real + swap). If you exhaust your real memory, and exhaust the swap
space you will see that usemem is automatically killed when it tries to allocate even
more memory.

Creating a Swap File


If you suddenly need more swap space on a running system but you have no more empty
partitions to spare you can use swap files. Using swap files however is less efficient than
swap partitions, so use this only in an emergency. It is even possible to put your swapfile
on an NFS-mounted directory, but there are easier ways of bringing down a network.
__ 22. First, find a filesystem where you have room for a large swapfile (at least 64 MB
free). Locate a suitable directory on this filesystem.
__ 23. Create the large file to be used as swapfile.
__ 24. Convert this file into a swapfile.
__ 25. Activate it.
__ 26. Go to your top window and check whether the swap space has increased. Also view
the /proc/swaps file. What, do you think, is the meaning of the Priority field, and why
is this different from the swap partition? Now try the usemem command that failed
last time again.
__ 27. Add the swap file to your /etc/fstab file so that it is activated next time you reboot
__ 28. Reboot your system to make sure that you are working with the correct amount of
memory again.

Documenting your changes


__ 29. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

11-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


If you have more than 128 Megabytes of memory
In this exercise we are going to look at memory management in Linux. As part of this
exercise we are going to exhaust the available memory. Experience has shown that if you
have more than 128 Megabytes of memory, that parts of this exercise will take too long.
(Yes, there is a disadvantage to having a lot of memory!) Therefore we are going to limit the
amount of memory that Linux detects to 128 Megabytes, just for this exercise.
__ 1. Reboot Linux
» # reboot
__ 2. If you use LILO, and the lilo boot:-prompt appears, start Linux and specify
mem=128M as startup parameter. If you use GRUB, modify the kernel line so that
the mem=128M parameter is added.

Using top
__ 3. Start top and identify the different pieces of information:
• The time, the up time, the number of users and the load information on the
first line.
• The number of processes on the second line.
• The CPU breakdown on the third line.
• The real memory breakdown on the fourth line
• The swap space breakdown on the fifth line
• The processes (sorted by CPU-time) on the next lines.
Verify that Linux detected only 128 Megabytes.
» # top
__ 4. top will automatically refresh itself after 10 seconds. To increase this to one second
enter the command s1.
» s1
__ 5. top will by default not show the amount of swap space used by each processes. To
show this amount too, call up the Field Order screen with the f command, and
enable the swap space display.
»f
» On Red Hat, press o. On Fedora/SuSE, press p.
» <Enter>
__ 6. To sort processes in a different order use the M, P or T command.
»M

© Copyright IBM Corp. 2001, 2004 Exercise 11. Memory Management 11-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

»P
»T
__ 7. Leave top running in a separate window.

Checking Swap Space


__ 8. There should be one active swap space (check the fifth line of top). Deactivate this
swap space. (If you don't know which partition is used as swapspace, check
/proc/swaps.)
» # cat /proc/swaps
» # swapoff /dev/hdn
__ 9. Go back to your top window and check what happened.
__ 10. Reactivate the swap space.
» # swapon /dev/hdn

Using the Cache


__ 11. Caching is done automatically. If you have performed the exercises so far, your
cache usage should be about 20 Megabytes. Let's see what happens if we really
start accessing the disk. Start a very disk-intensive program.
» # find /usr -type f -exec cat {} \; > /dev/null
__ 12. Watch what happens to the amount of cached data in top. This number should
increase until your cache occupies almost all of your real memory. Only about 4 MB
will be left over for application use. But also note that virtually no processes will be
swapped out to disk.

Using the Swap space


The swap space will only be used if there is a real shortage in memory. First the amount of
cached data will decrease to about zero before processes are swapped to disk. Therefore,
we need to have a program which uses a lot of real memory. The easiest solution is to write
that ourselves.
__ 13. Create the directory /root/bin and cd into it.
» # mkdir /root/bin
» # cd /root/bin
__ 14. Create a program called usemem, with contents:
#!/usr/bin/perl
print "Allocating $ARGV[0] megabytes of memory...\n";
$big = "";

11-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty for( $i=0; $i<$ARGV[0]; $i++ )


{
$big .= "1234567890"x104858;
}
print "Press ENTER to release memory...\n";
<STDIN>;
When you start this program, it will gradually allocate the amount of memory you
specify on the command line, and then wait for you to press Enter. When you press
Enter, the program exits and thus will deallocate its memory.
Note: Your instructor might have this program available already.
__ 15. Do a chmod 755 of this program and start it with parameter 1. This will ensure that
the program allocates about 1 Megabyte of memory.
» # chmod 755 usemem
» # usemem 1
» Do not yet press Enter!
__ 16. Now go back to your top screen and select the “sort by memory usage” mode by
issuing the M command. Note how much memory is used by the usemem program.
__ 17. Stop usemem and start it with about half the amount of memory which is in your
system. So if you have 128 MB of real memory or decreased the amount to 128 MB,
use 64 as parameter. Watch what happens in top. First you should see the amount
of cached data decrease, and maybe see some processes already being swapped
out.
» # usemem 64
__ 18. Now start usemem with about 80% of your memory and watch what happens.
__ 19. Stop usemem and watch what happens. Note that processes swapped out will not
automatically be swapped in as soon as memory comes available. They will be
swapped in when needed.
__ 20. Disable your swap space with swapoff and watch what happens.
» # swapoff /dev/hdn
__ 21. Enable swap space again and run usemem with about 90% of the total amount of
memory (real + swap). If you exhaust your real memory, and exhaust the swap
space you will see that usemem is automatically killed when it tries to allocate even
more memory.
» # swapon /dev/hdan
» # usemem 300

Creating a Swap File

© Copyright IBM Corp. 2001, 2004 Exercise 11. Memory Management 11-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

If you suddenly need more swap space on a running system but you have no more empty
partitions to spare you can use swap files. Using swap files however is less efficient than
swap partitions, so use this only in an emergency. It is even possible to put your swapfile
on an NFS-mounted directory, but there are easier ways of bringing down a network.
__ 22. First, find a filesystem where you have room for a large swapfile (at least 64 MB
free). Locate a suitable directory on this filesystem.
» # df
» In the hints, we will assume that /var has enough space and use
/var/tmp/swapspace as swapfile.
__ 23. Create the large file to be used as swapfile.
» # dd if=/dev/zero of=/var/tmp/swapspace bs=1M count=64
__ 24. Convert this file into a swapfile.
» # mkswap /var/tmp/swapspace
__ 25. Activate it.
» # swapon /var/tmp/swapspace
__ 26. Go to your top window and check whether the swap space has increased. Also view
the /proc/swaps file. What, do you think, is the meaning of the Priority field, and why
is this different from the swap partition? Now try the usemem command that failed
last time again.
» # cat /proc/swaps
» # usemem 300
__ 27. Add the swap file to your /etc/fstab file so that it is activated next time you reboot
» # vi /etc/fstab
Add the following line:
/var/tmp/swapspace swap swap defaults 0 0
__ 28. Reboot your system to make sure that you are working with the correct amount of
memory again.
» # reboot

Documenting your changes


__ 29. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

11-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 12. Linux on IBM eServer

Notice
The unit Linux on IBM eServer does not include any exercises
because the hardware required to do any exercises will most likely not
be available in most classrooms. This page is here to keep unit
numbers and exercise numbers synchronized.

© Copyright IBM Corp. 2001, 2004 Exercise 12. Linux on IBM eServer 12-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

12-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 13. Scheduling

What This Exercise Is About


This exercise provides the student with knowledge about scheduling in
Linux. Students will set up scheduling and start their own jobs through
scheduling.

What You Should Be Able to Do


After this exercise students should be able to:
• Name the commands and daemons that make up scheduling on
Linux
• Start and stop jobs through scheduling

© Copyright IBM Corp. 2001, 2004 Exercise 13. Scheduling 13-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Working with cron and at
In this exercise we are only going to work with cron and at. We won't be working with
Anacron since that will take a day to get the first job started (and Anacron is not included in
SuSE anyway), and we won't be working with batch because it is dependent on the load of
the system, and it is too hard to reliably create a situation where batch can be
demonstrated, given the wide range of configurations on which this course needs to run.
__ 1. Log in to Linux as root at VT one. Log in as tux1 at VT two.
__ 2. Go to VT one (where root is logged in).
__ 3. Check if the daemons necessary for scheduling are running.
__ 4. View the contents of you crontab file. Where are the crontab files for the users
stored?
__ 5. List the contents of the /var/spool/cron and /var/spool/at directories. What do you
see?
__ 6. Edit your crontab file: Make sure that your system runs the df command every five
minutes.
__ 7. Check the contents of the /var/spool/cron directory again. What do you see now?
__ 8. Start a job that will run in 10 minutes. The command that should be executed in 10
minutes is who. At what time will the command run according to at?
__ 9. Check if there are at jobs listed in the contents of the /var/spool/at directory. What do
you see?
__ 10. Look at the contents of the file. What do you see?
__ 11. Enter the next command:
• # at 9am
• at> ps aux
• at> <CTRL-D>
When will this command run?
__ 12. Switch to the VT where tux1 is logged in.
__ 13. Look at the crontab file of tux1.
__ 14. Make a crontab file for tux1 that executes the ls $HOME | wc -l command every
hour. Check if the crontab file for tux1 exists afterwards.
__ 15. Remove the crontab file.
__ 16. Switch back to the VT one. Set up the cron daemon so that tux1 isn't allowed to use
crond anymore.
__ 17. Go to VT two and try to create a crontab file again. What happened?

13-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 18. As root, check your mail. What kind of mail did you receive?
__ 19. Remove the crontab files of root. (Do not use the rm command.)
__ 20. Take a look at the system crontab files and directories.

Documenting your changes


__ 21. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 13. Scheduling 13-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions With Hints


Working with cron and at
In this exercise we are only going to work with cron and at. We won't be working with
Anacron since that will take a day to get the first job started (and Anacron is not included in
SuSE anyway), and we won't be working with batch because it is dependent on the load of
the system, and it is too hard to reliably create a situation where batch can be
demonstrated, given the wide range of configurations on which this course needs to run.
__ 1. Log in to Linux as root at VT one. Log in as tux1 at VT two.
» <ALT-F1> Log in as root
» <ALT-F2> Log in as tux1
__ 2. Go to VT one (where root is logged in).
» <ALT-F1>
__ 3. Check if the daemons necessary for scheduling are running.
» # ps aux | egrep "cron|at"
__ 4. View the contents of you crontab file. Where are the crontab files for the users
stored?
» # crontab -l
or
# more /var/spool/cron/root
(Gives an error message)
» The crontab files of users are stored in the directory /var/spool/cron
__ 5. List the contents of the /var/spool/cron and /var/spool/at directories. What do you
see?
» # ls -lR /var/spool/cron*
» # ls -lR /var/spool/at*
» You should see no user files.
__ 6. Edit your crontab file: Make sure that your system runs the df command every five
minutes.
» # crontab -e
» Enter the following line:
*/5 * * * * df
__ 7. Check the contents of the /var/spool/cron directory again. What do you see now?
» # ls -lR /var/spool/cron
» You should see a file with the name root.
__ 8. Start a job that will run in 10 minutes. The command that should be executed in 10
minutes is who. At what time will the command run according to at?
» # at now + 10 minutes

13-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » at> who


» at> <CTRL-D>
__ 9. Check if there are at jobs listed in the contents of the /var/spool/at directory. What do
you see?
» # atq
- OR -
# at -l
» # ls -lR /var/spool/at*
» You should see an extra file now.
__ 10. Look at the contents of the file. What do you see?
» # vi /var/spool/at*/<filename>
» You are looking at the shell scripts that get executed by the atd daemon at the
specified time. On the last line of the file, you find the command who, which
we want to execute.
__ 11. Enter the next command:
• # at 9am
• at> ps aux
• at> <CTRL-D>
When will this command run?
» This command will run tomorrow morning at 9am.
__ 12. Switch to the VT where tux1 is logged in.
» <ALT-F2>
__ 13. Look at the crontab file of tux1.
» $ crontab -l
__ 14. Make a crontab file for tux1 that executes the ls $HOME | wc -l command every
hour. Check if the crontab file for tux1 exists afterwards.
» $ crontab -e
» Add the following line:
0 * * * * ls $HOME | wc -l
» $ crontab -l
__ 15. Remove the crontab file.
» $ crontab -r
(Do not directly remove the crontab file with the rm command)
__ 16. Switch back to the VT one. Set up the cron daemon so that tux1 isn't allowed to use
crond anymore.
» <ALT-F1>

© Copyright IBM Corp. 2001, 2004 Exercise 13. Scheduling 13-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» redhat# vi /etc/cron.deny
suse# vi /var/spool/cron/deny
» Add tux1 to this file
__ 17. Go to VT two and try to create a crontab file again. What happened?
» <ALT-F2>
» $ crontab -e
» $ crontab -l
» You got an error message stating that you are not allowed to use crontab.
__ 18. As root, check your mail. What kind of mail did you receive?
» <ALT-F1>
» # mail
» The mail you see is the output of the crond daemon containing the output of
the commands you started with your crontab file and the atd daemon.
__ 19. Remove the crontab files of root. (Do not use the rm command.)
» # crontab -r
__ 20. Take a look at the system crontab files and directories.
» # less /etc/crontab
» # less /etc/cron.d/*
» # ls -l /etc/cron.hourly
» # ls -l /etc/cron.daily
» # ls -l /etc/cron.weekly
» # ls -l /etc/cron.monthly

Documenting your changes


__ 21. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

13-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 14. Backup and Restore

What This Exercise Is About


The purpose of these exercises is to familiarize you with backup and
restore techniques.

What You Should Be Able to Do


After completing this unit, students should be able to:
• Perform system, full and incremental backups
• Use tar and/or other commands to perform backup and restore

Required Materials
For this exercise you will need the following:
• One blank, formatted floppy disk.

Introduction
In these exercises, you will back up and restore a filesystem as well as
individual files. Some exercises may cover some options and
techniques that may be in the student notes but not necessarily
covered in the instructor's presentation. Refer back to the unit notes,
check the hints in the Exercise Instructions With Hints section, or read
the appropriate man pages.

© Copyright IBM Corp. 2001, 2004 Exercise 14. Backup and Restore 14-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Using tar
__ 1. Check the man pages for the discussed backup commands: tar, cpio.
__ 2. Create in your /home directory three subdirectories, called subdir1, subdir2 and
subdir3, and create five files, called testfilex, in each subdirectory.
__ 3. Create an extra logical volume in your volume group. Name this logical volume
“backuplv”. Its size should be about 10 Megabytes.
__ 4. Use the tar command to back up your /home directory to the partition you just
created.
__ 5. Verify the contents of the backup you just created.
__ 6. Delete your /home/subdirn directories and all the files init.
__ 7. Restore the backup you created.
__ 8. Produce a list (/tmp/1daytar.list) of all the files in /home that were accessed in the
last day.
__ 9. Create an incremental backup using the tar command.
__ 10. Restore the backup you created in the previous step.
Using cpio
__ 11. Produce a list /tmp/todaycpio.list of all the files in /home that were modified in the
last day.
__ 12. Create an incremental backup using cpio. Use the same partition you used earlier.
__ 13. Restore the backup you created in the previous exercise.
Using dump
__ 14. Verify that dump is installed. If not, install it.
__ 15. Dump the /home filesystem to the backup partition.
__ 16. Write down the dates of all files in /home/subdir*. Update all files in /home/subdir1
and make an incremental backup to floppy disk.
__ 17. See what files are dumped to the backup LV and the floppy disk.
__ 18. Unmount the /home filesystem and reformat it. Then restore both dumps in the
correct order. Verify that the dates on the files are correct.
Documenting your changes
__ 19. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

14-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


Using tar
__ 1. Check the man pages for the discussed backup commands: tar, cpio.
» # man tar
» # man cpio
__ 2. Create in your /home directory three subdirectories, called subdir1, subdir2 and
subdir3, and create five files, called testfilex, in each subdirectory.
» # ls /home
» # cd /home
» # for i in 1 2 3
» > do
» > mkdir subdir$i
» > for j in 1 2 3 4 5
» > do
» > touch subdir$i/testfile$j
» > done
» > done
__ 3. Create an extra logical volume in your volume group. Name this logical volume
“backuplv”. Its size should be about 10 Megabytes.
» # lvcreate -L 10M -n backuplv vg00
__ 4. Use the tar command to back up your /home directory to the partition you just
created.
» # tar cvf /dev/vg00/backuplv /home
__ 5. Verify the contents of the backup you just created.
» # tar tvf /dev/vg00/backuplv | less
__ 6. Delete your /home/subdirn directories and all the files init.
» # cd /home
» # rm -fr subdir*
__ 7. Restore the backup you created.
» # cd /
» # tar xvf /dev/vg00/backuplv
__ 8. Produce a list (/tmp/1daytar.list) of all the files in /home that were accessed in the
last day.
» # find /home -mtime -1 -print > /tmp/1daytar.list
__ 9. Create an incremental backup using the tar command.
» # tar -cv -T /tmp/1daytar.list -f /dev/vg00/backuplv

© Copyright IBM Corp. 2001, 2004 Exercise 14. Backup and Restore 14-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 10. Restore the backup you created in the previous step.


» # cd /
» # tar xvf /dev/vg00/backuplv

Using cpio
__ 11. Produce a list /tmp/todaycpio.list of all the files in /home that were modified in the
last day.
» # find /home -mtime -1 -print > /tmp/todaycpio.list
__ 12. Create an incremental backup using cpio. Use the same partition you used earlier.
» # cat /tmp/todaycpio.list | cpio -ov > /dev/vg00/backuplv
__ 13. Restore the backup you created in the previous exercise.
» # cpio -iduvm < /dev/vg00/backuplv

Using dump
__ 14. Verify that dump is installed. If not, install it.
» # which dump
» redhat# rpm -ivh /mnt/install/RedHat/RPMS/dump-version.i386.rpm
suse# rpm -ivh /mnt/install/suse/i586/dump-version.i386.rpm
__ 15. Dump the /home filesystem to the backup partition.
» # dump -0 -u -f /dev/vg00/backuplv /home
__ 16. Write down the dates of all files in /home/subdir*. Update all files in /home/subdir1
and make an incremental backup to floppy disk.
» # cd /home
» # ls -lR subdir*
» # cd /home/subdir1
» # touch *
» # ls -lR
» # cd /
» # dump -1 -u -f /dev/fd0 /home
__ 17. See what files are dumped to the backup LV and the floppy disk.
» # restore -t -f /dev/vg00/backuplv
» # restore -t -f /dev/fd0
__ 18. Unmount the /home filesystem and reformat it. Then restore both dumps in the
correct order. Verify that the dates on the files are correct.
» # mount | grep /home
Remember the device name.

14-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » # umount /home


» # mke2fs -j /dev/hdan
» # e2label /dev/hdan /home
» # mount /home
» # cd /home
» # restore -r -f /dev/vg00/backuplv /home
» # restore -r -f /dev/fd0 /home
» # cd /home
» # ls -lR

Documenting your changes


__ 19. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 14. Backup and Restore 14-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

14-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 15. User Administration

What This Exercise Is About


This exercise will teach students how to add users and groups and
where to find information about users and groups in their system.

What You Should Be Able to Do


At the end of the exercise, you should be able to:
• Add and delete users and groups
• Specify the files involved in user administration

© Copyright IBM Corp. 2001, 2004 Exercise 15. User Administration 15-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
User environment
__ 1. Log out every user.
__ 2. Log in as root at VT 1 and as tux1 at VT 2.
__ 3. Look at the following files:
• /etc/profile
• /etc/bashrc (Fedora/Red Hat) or /etc/bash.bashrc (SuSE)
• $HOME/.bash_profile (Fedora/Red Hat) or $HOME/.profile (SuSE)
• $HOME/.bashrc
• $HOME/.bash_logout (Fedora/Red Hat only)
What do these file do in your system? What information can be found in there?

User administration
These hints describe the command line tools. Don't forget that you also have the
system administration tools to do user and group administration.
__ 4. List all users defined in your system at this moment.
__ 5. Does every user have a password?
__ 6. As root using the command line, add a user with the username tux3 and full name
“Tux the Penguin (3)”.
__ 7. Look at the contents of /etc/shadow. What is the password of the new user?
__ 8. Give tux3 the password “penguin3”. Then take a look at the /etc/shadow file again.
__ 9. List the contents of the /etc/passwd- file. What is stored in this file?
__ 10. What is the login group of the user you added?
__ 11. Add the group penguins to the system.
__ 12. Place the user tux3 in the group penguins.
__ 13. Locate this change in /etc/group
__ 14. What is the syntax of the group file?
__ 15. Which users are specified in the last field of the /etc/group file?

Communicating with the users


__ 16. As root modify the /etc/issue file. Write in this file that the system is for authorized
users only. Remove all distribution and kernel information.

15-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 17. As root create the /etc/motd file. Write in this file your system name and the name of
the OS you are using.
__ 18. As tux1 log out and log in again. Look at the information shown on your screen.
__ 19. Create the file .hushlogin as tux1 in your home directory.
__ 20. Log out and then log in. Again look at the information showing up on your screen.
Did you notice any difference with the output from step 16?

Documenting your changes


__ 21. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 15. User Administration 15-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions With Hints


User environment
__ 1. Log out every user.
» # exit
or
# logout
__ 2. Log in as root at VT 1 and as tux1 at VT 2.
» <ALT-F1> Log in as root
» <ALT-F2> Log in as tux1
__ 3. Look at the following files:
• /etc/profile
• /etc/bashrc (Fedora/Red Hat) or /etc/bash.bashrc (SuSE)
• $HOME/.bash_profile (Fedora/Red Hat) or $HOME/.profile (SuSE)
• $HOME/.bashrc
• $HOME/.bash_logout (Fedora/Red Hat only)
What do these file do in your system? What information can be found in there?
» # vi /etc/profile
» fedora/redhat# vi /etc/bashrc
suse# vi /etc/bash.bashrc
» fedora/redhat# vi $HOME/.bash_profile
suse# vi $HOME/.profile
» # vi $HOME/.bashrc
» fedora/redhat# vi $HOME/.bash_logout

User administration
These hints describe the command line tools. Don't forget that you also have the
system administration tools to do user and group administration.
__ 4. List all users defined in your system at this moment.
» # cat /etc/passwd
- OR -
# getent passwd
__ 5. Does every user have a password?
» # cat /etc/shadow
- OR -
# getent shadow
» The * and !! in the password field mean that the user has no password.

15-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 6. As root using the command line, add a user with the username tux3 and full name
“Tux the Penguin (3)”.
» <ALT-F1>
» # useradd -m -c “Tux the Penguin (3)” tux3
__ 7. Look at the contents of /etc/shadow. What is the password of the new user?
» # cat /etc/shadow
The password for this user is “!!”, which means “no password assigned”.
__ 8. Give tux3 the password “penguin3”. Then take a look at the /etc/shadow file again.
» # passwd tux3
» New password: penguin3
» Re-enter new password: penguin3
» # cat /etc/shadow
__ 9. List the contents of the /etc/passwd- file. What is stored in this file?
» # cat /etc/passwd-
» This file is a backup of /etc/passwd. Whenever you change your /etc/passwd
with the proper tools, the old password file is copied to passwd-. This means
that passwd- always contains your user administration as it was before the
last change.
__ 10. What is the login group of the user you added?
» # cat /etc/passwd
» Remember the GID you see for this user
» # cat /etc/group | grep GID
» The first word on the line is the login group of the user.
__ 11. Add the group penguins to the system.
» # groupadd penguins
__ 12. Place the user tux3 in the group penguins.
» # usermod -G penguins tux3
__ 13. Locate this change in /etc/group
» # cat /etc/group
__ 14. What is the syntax of the group file?
» Group name:Password field:Group ID:Group members
__ 15. Which users are specified in the last field of the /etc/group file?
» The users how have the specific group as their secondary group. Users who
have the group as their login group don't show up in this field.

Communicating with the users

© Copyright IBM Corp. 2001, 2004 Exercise 15. User Administration 15-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 16. As root modify the /etc/issue file. Write in this file that the system is for authorized
users only. Remove all distribution and kernel information.
» # vi /etc/issue
This system is for authorized users only.
__ 17. As root create the /etc/motd file. Write in this file your system name and the name of
the OS you are using.
» # vi /etc/motd
Welcome to this system which is running Linux!
__ 18. As tux1 log out and log in again. Look at the information shown on your screen.
» <ALT-F2>
» exit
» Log in again.
» You should see the information you put in /etc/issue and /etc/motd.
__ 19. Create the file .hushlogin as tux1 in your home directory.
» # touch .hushlogin
__ 20. Log out and then log in. Again look at the information showing up on your screen.
Did you notice any difference with the output from step 16?
» # exit
» Log in again.
» You don't see the information in /etc/motd any more.

Documenting your changes


__ 21. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

15-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 16. User-Level Security

What This Exercise Is About


This exercise focuses on the security concepts in a Linux system.
Students will learn how file permissions work, where information about
logins is stored and where user data for user administration is stored.

What You Should Be Able to Do


At the end of the exercise, you should be able to:
• Locate the files involved in security on the system
• Explain the different file permissions and when to use them

© Copyright IBM Corp. 2001, 2004 Exercise 16. User-Level Security 16-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Security Logs
__ 1. Log out as root.
__ 2. Try to log in as root but use a wrong password.
__ 3. Try to log in as a non existing user (for instance: teacher).
__ 4. Log in as root with the correct password.
__ 5. Look at the contents of the following files and try to find the records of step 2, 3 and
4.
• /var/log/lastlog
• /var/log/messages
• /var/log/secure (Fedora/Red Hat only)
• /var/log/wtmp
• /var/run/utmp
__ 6. At virtual terminal 2 log in as tux1 and at virtual terminal 3 as tux2.
__ 7. Look as root at what users are currently logged on. Look also at the contents of
/var/log/wtmp.
__ 8. Log out as user tux2.
__ 9. As root find the last times that user tux1 and tux2 logged in. Also list the users that
logged in at virtual terminal 1.
__ 10. As tux1 check what groups you are a member of.

File Permissions
__ 11. Log in as root at VT 1 (if you're not already logged on as root at VT 1). Be sure that
tux1 is logged in at VT 2 and tux2 at VT 3.
__ 12. As root check if the SUID is set. Then remove the SUID bit from /usr/bin/passwd.
Be sure to leave the execute permissions in place.
__ 13. As tux1 run the passwd command. Answer all the questions and watch the output.
What is the error message and why did you get this message?
__ 14. Set the SUID bit again on /usr/bin/passwd and try to change the password now.
__ 15. As tux1 make a directory in your home directory with the name exercise. In this
directory make a file with df > df.out.
Set the permissions on df.out as rwx------ (700) and make your home directory
readable and executable for group members and others.

16-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty __ 16. As tux2 try to open df.out and read the contents of the file. Did you succeed? Also
try to add an extra line to df.out.
__ 17. As tux1 set the permissions on df.out as rwxr--r- (744).
__ 18. As tux2, try to open the file again. Did you succeed this time?
__ 19. As tux2, try to alter the file. Do you succeed?
__ 20. As tux1 set the permissions on df.out as rwxrwxrwx (777).
__ 21. As tux2, try to write to the file again. Did you succeed this time?
__ 22. Can you remove df.out? Why or why not? Is the data in df.out safe with these
permissions set on the file?
__ 23. As tux1 set the permissions on your exercise directory as rwxrwxrwx.
__ 24. As tux2 try to remove df.out. Is this possible and why is it or why not?

Team directories
__ 25. As root, create a team directory, /groups/penguins, for all members of the penguins
group.
__ 26. Check which users are currently member of the penguins group.
__ 27. As tux1, try to create and view files in the /groups/penguins directory. Does this
work?
__ 28. As tux3, try to create and view files in the /groups/penguins directory. Does this
work?
__ 29. Add tux1 and tux2 to the penguins group. Then try to create and delete files in the
/groups/penguins directory again. Also, try to modify files created by other users in
the same group. Does this work?
Explanation: On a Red Hat system, User Private Groups are used by default.
Among other things, this means that the default umask is 022, which leads to the
default rw-rw-r-- permissions on a file. This allows any other user in the same group
(penguins in this case) to modify the file.
On a SuSE system, User Private Groups are not used by default. This means that
the default umask is 002, which leads to the default rw-r--r-- permissions on a file.
This does not allow other users in the same group to modify the file. However,
because of the write permissions on the directory, tux3 is allowed to delete the file
owned by tux1 and replace it with a file owned by tux3. That’s what vi does
automatically in this case.

© Copyright IBM Corp. 2001, 2004 Exercise 16. User-Level Security 16-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Using the su command


__ 30. As tux1 go to your home directory and run the su command. Write down the
following information:
• The current working directory
• The contents of the $PATH variable
__ 31. Become yourself (tux1) again.
__ 32. As tux1 run the su - command and write the following information down:
• The current working directory
• The contents of the $PATH variable
__ 33. Compare this information with the information written down earlier. What is the
difference between su and su - ?
__ 34. As tux1, try to become tux2. Does this work?

Using the sudo command


__ 35. As tux1, try to execute the /sbin/ifdown eth0 command. Does this work?
__ 36. As root, create the /etc/sudoers file so that tux1 is allowed to execute the
/sbin/ifdown eth0 and /sbin/ifup eth0 command.
__ 37. As tux1, try to execute the /sbin/ifdown eth0 command again, this time with the
help of sudo. Does this work? If it works, bring the ethernet adapter back up again
as well.
Note: The first time a user runs the sudo command he or she will receive a warning
about responsible behavior. To confirm having read this, the user needs to type his
or her own password - not the root password!

Security Files
__ 38. As tux2, look at the content of the following files:
• /etc/passwd
• /etc/group
• /etc/profile

Documenting your changes


__ 39. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

16-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


Security Logs
__ 1. Log out as root.
» # exit
__ 2. Try to log in as root but use a wrong password.
__ 3. Try to log in as a non existing user (for instance: teacher).
__ 4. Log in as root with the correct password.
__ 5. Look at the contents of the following files and try to find the records of step 2, 3 and
4.
• /var/log/lastlog
• /var/log/messages
• /var/log/secure (Fedora/Red Hat only)
• /var/log/wtmp
• /var/run/utmp
» # lastlog
» # more /var/log/messages
» fedora/redhat# more /var/log/secure
» # who /var/log/wtmp
» # who /var/run/utmp or just who
» Look in the output of the above-mentioned commands for words like tux1,
tux2, root, and teacher.
__ 6. At virtual terminal 2 log in as tux1 and at virtual terminal 3 as tux2.
» <ALT-F2> log in as tux1
» <ALT-F3> log in as tux2
__ 7. Look as root at what users are currently logged on. Look also at the contents of
/var/log/wtmp.
» <ALT-F1>
» # who
» # who /var/log/wtmp
__ 8. Log out as user tux2.
» <ALT-F3>
» # exit
__ 9. As root find the last times that user tux1 and tux2 logged in. Also list the users that
logged in at virtual terminal 1.
» <ALT-F1>

© Copyright IBM Corp. 2001, 2004 Exercise 16. User-Level Security 16-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» # last tux2
» # last tty1
__ 10. As tux1 check what groups you are a member of.
» <ALT-F2>
» # groups

File Permissions
__ 11. Log in as root at VT 1 (if you're not already logged on as root at VT 1). Be sure that
tux1 is logged in at VT 2 and tux2 at VT 3.
» <ALT-F1> Log in as root (if necessary).
» <ALT-F2> Log in as tux1 (if necessary).
» <ALT-F3> Log in as tux2
__ 12. As root check if the SUID is set. Then remove the SUID bit from /usr/bin/passwd.
Be sure to leave the execute permissions in place.
» <ALT-F1>
» # ls -l /usr/bin/passwd
» # chmod -s /usr/bin/passwd
- or -
# chmod 755 /usr/bin/passwd
» # ls -l /usr/bin/passwd
__ 13. As tux1 run the passwd command. Answer all the questions and watch the output.
What is the error message and why did you get this message?
» <ALT-F2>
» $ passwd
» The error you get is “Passwd: Permission denied” or “passwd: Authentication
failure”. The passwd command will give you this error message because
without the SUID bit passwd is not allowed to write information in /etc/passwd
or /etc/shadow. So it can't store your new passwd.
__ 14. Set the SUID bit again on /usr/bin/passwd and try to change the password now.
» <ALT-F1>
» # chmod u+s /usr/bin/passwd
- or -
# chmod 4555 /usr/bin/passwd
» # ls -l /usr/bin/passwd
» <ALT-F2>
» $ passwd
You should now be able to change the password.
__ 15. As tux1 make a directory in your home directory with the name exercise. In this
directory make a file with df > df.out.

16-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Set the permissions on df.out as rwx------ (700) and make your home directory
readable and executable for group members and others.
» <ALT-F2>
» $ mkdir exercise
» $ df > exercise/df.out
» $ chmod u=rwx,go= exercise/df.out
- or -
$ chmod 700 exercise/df.out
» $ chmod go+rx /home/tux1
- or -
$ chmod 755 /home/tux1
__ 16. As tux2 try to open df.out and read the contents of the file. Did you succeed? Also
try to add an extra line to df.out.
» <ALT-F3>
» $ more ~tux1/exercise/df.out
» No, you don't have to permissions to read the file. You are not the owner of
the file and you are not a member of the tux1 group, so the other permissions
are in effect for you.
__ 17. As tux1 set the permissions on df.out as rwxr--r- (744).
» <ALT-F2>
» $ chmod go+r exercise/df.out
- or -
$ chmod 744 exercise/df.out
__ 18. As tux2, try to open the file again. Did you succeed this time?
» <ALT-F3>
» $ more ~tux1/exercise/df.out
» Yes because now you have the read permission.
__ 19. As tux2, try to alter the file. Do you succeed?
» <ALT-F3>
» $ vi ~tux1.exercise/df.out
» Make some changes to the file, then try to save it. This will not work because
you don't have write permissions.
» Quit vi with :q!
__ 20. As tux1 set the permissions on df.out as rwxrwxrwx (777).
» <ALT-F1>
» $ chmod ugo=rwx exercise/df.out
- or -
$ chmod 777 exercise/df.out
__ 21. As tux2, try to write to the file again. Did you succeed this time?

© Copyright IBM Corp. 2001, 2004 Exercise 16. User-Level Security 16-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» <ALT-F3>
» vi ~tux1/exercise/df.out
» Make some changes, then try to save the file.
» This time you can change the contents of the file because you have the write
permission.
__ 22. Can you remove df.out? Why or why not? Is the data in df.out safe with these
permissions set on the file?
» $ rm ~tux1/exercise/df.out
» You may not remove the file. You can't remove the file because you don't
have the correct permissions on the directory. To be able to delete a file, you
need to have the write permission on a directory.
» No the data in df.out is not safe. Because every user in the system has the
write permission, every user has the right to edit the file (add or delete
information).
__ 23. As tux1 set the permissions on your exercise directory as rwxrwxrwx.
» <ALT-F2>
» $ chmod ugo=rwx ~tux1/exercise
- or -
$ chmod 777 ~tux1/exercise
__ 24. As tux2 try to remove df.out. Is this possible and why is it or why not?
» <ALT-F3>
» $ rm ~tux1/exercise/df.out
» You can remove the file even if it is not your file. With the write permission on
directories, you grant users the right to create and remove files in that
directory.

Team directories
__ 25. As root, create a team directory, /groups/penguins, for all members of the penguins
group.
» <ALT-F1>
» # mkdir -p /groups/penguins
» # chgrp penguins /groups/penguins
» # chmod 2770 /groups/penguins
__ 26. Check which users are currently member of the penguins group.
» # grep penguins /etc/group
__ 27. As tux1, try to create and view files in the /groups/penguins directory. Does this
work?
» <Alt-F2>
» $ cd /groups/penguins

16-8 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » This command will fail, since tux1 is not a member of the penguins group.
__ 28. As tux3, try to create and view files in the /groups/penguins directory. Does this
work?
» <Alt-F4>
» Login: tux3
» Password: penguin3
» $ cd /groups/penguins
» $ touch testfile
» $ ls -l testfile
» $ rm testfile
__ 29. Add tux1 and tux2 to the penguins group. Then try to create and delete files in the
/groups/penguins directory again. Also, try to modify files created by other users in
the same group. Does this work?
» <Alt-F1>
» # usermod -G penguins tux1
- OR -
# gpasswd -a tux1 penguins
» # usermod -G penguins tux2
- OR -
# gpasswd -a tux2 penguins
» <Alt-F2>
» $ cd /groups/penguins
Note: It might be necessary to log out first and then log in again for this to
work.
» $ vi testfile
Add some lines of text.
» $ ls -l testfile
Write down the permissions
» <Alt-F4>
» $ cd /groups/penguins
» $ vi testfile
Add some lines of text. Then try to save this file. Does this work? Can you
explain this?
Explanation: On a Red Hat system, User Private Groups are used by default.
Among other things, this means that the default umask is 022, which leads to the
default rw-rw-r-- permissions on a file. This allows any other user in the same group
(penguins in this case) to modify the file.
On a SuSE system, User Private Groups are not used by default. This means that
the default umask is 002, which leads to the default rw-r--r-- permissions on a file.
This does not allow other users in the same group to modify the file. However,
because of the write permissions on the directory, tux3 is allowed to delete the file

© Copyright IBM Corp. 2001, 2004 Exercise 16. User-Level Security 16-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

owned by tux1 and replace it with a file owned by tux3. That’s what vi does
automatically in this case.

Using the su command


__ 30. As tux1 go to your home directory and run the su command. Write down the
following information:
• The current working directory
• The contents of the $PATH variable
» <ALT-F2>
» $ cd
» $ su
» Enter the root password
» # pwd
» # echo $PATH
__ 31. Become yourself (tux1) again.
» # exit
__ 32. As tux1 run the su - command and write the following information down:
• The current working directory
• The contents of the $PATH variable
» $ su -
» Enter the root password
» # pwd
» # echo $PATH
__ 33. Compare this information with the information written down earlier. What is the
difference between su and su - ?
» The difference between su - and su is the environment you will have. With su
without the dash (-) option, you will still have to environment of the user
issuing the su command. You only have root permissions in the system. The
su - (with dash) command will not only give you the root permissions, it will
also build the root environment for you.
__ 34. As tux1, try to become tux2. Does this work?
» # exit (to become tux1 again)
» $ su tux2
» You will become tux2 as long as you know the correct password.

Using the sudo command


__ 35. As tux1, try to execute the /sbin/ifdown eth0 command. Does this work?

16-10 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » $ /sbin/ifdown eth0


__ 36. As root, create the /etc/sudoers file so that tux1 is allowed to execute the
/sbin/ifdown eth0 and /sbin/ifup eth0 command.
» # visudo
Change the file so that it looks like this:
User_Alias OPERATORS = tux1
OPERATORS ALL = (root) /sbin/ifdown eth0
OPERATORS ALL = (root) /sbin/ifup eth0
__ 37. As tux1, try to execute the /sbin/ifdown eth0 command again, this time with the
help of sudo. Does this work? If it works, bring the ethernet adapter back up again
as well.
Note: The first time a user runs the sudo command he or she will receive a warning
about responsible behavior. To confirm having read this, the user needs to type his
or her own password - not the root password!
» $ sudo /sbin/ifdown eth0
» $ sudo /sbin/ifup eth0

Security Files
__ 38. As tux2, look at the content of the following files:
• /etc/passwd
• /etc/group
• /etc/profile
» <ALT-F3>
» $ vi /etc/passwd
» $ vi /etc/group
» $ vi /etc/profile
» Notice that an ordinary user has the right to view these important file. This file
should be readable for all users in the system.

Documenting your changes


__ 39. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 16. User-Level Security 16-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

16-12 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 17. Logging

What This Exercise Is About


This exercise will let you use the logging daemon.

What You Should Be Able to Do


At the end of the lab, you should have experience with:
• The syslogd daemon
• The /etc/syslog.conf configuration file
• The logger command
• The logrotate command
• Logfile analysis

© Copyright IBM Corp. 2001, 2004 Exercise 17. Logging 17-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Configuring logging
__ 1. Look at the file /etc/syslog.conf and try to find out to which files the logging actually
goes. Take a look at these files as well.
__ 2. Try to log in as a valid user (for instance, tux1) but with an invalid password, an try to
log in as an invalid user. Then view the log entries.
__ 3. Change the /etc/syslog.conf file and make sure that everything that has to do with
authentication is logged in /var/log/secure. Then restart the syslog daemon.
__ 4. Again, try to log in as a valid user but with an invalid password, and try to log in as
an invalid user. Then view the log entries again.

Using the logger command


__ 5. Look at your /etc/syslog.conf file and try to use the logger command so, that all the
different methods in the /etc/syslog.conf file are used once.
__ 6. Do the same, but this time when logged in as tux1.

Using the logrotate command


__ 7. Review the file /etc/logrotate.conf and all files in /etc/logrotate.d
__ 8. Make a long, recursive listing of all files in the /var/log directory.
__ 9. Manually run the logrotate command.
__ 10. Again make a long, recursive listing of all files in the /var/log directory. Do you see
any differences? Why not?
__ 11. Force a logrotate with the -f option.
__ 12. Again make a long, recursive listing of all files in the /var/log directory. Do you see
any differences? Why?

Using Logwatch (Fedora/Red Hat only)


__ 13. On a Red Hat system, logwatch is installed and activated automatically. The results
of this analysis will be mailed to root. So check your mail to see the results.

Documenting your changes


__ 14. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

17-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


Configuring logging
__ 1. Look at the file /etc/syslog.conf and try to find out to which files the logging actually
goes. Take a look at these files as well.
» # less /etc/syslog.conf
» # less /var/log/messages
» redhat# less /var/log/secure
suse# less /var/log/warn
» # less /var/log/mail*
» ...
__ 2. Try to log in as a valid user (for instance, tux1) but with an invalid password, an try to
log in as an invalid user. Then view the log entries.
» # less /var/log/messages
__ 3. Change the /etc/syslog.conf file and make sure that everything that has to do with
authentication is logged in /var/log/secure. Then restart the syslog daemon.
» # vi /etc/syslog.conf
» Change the /var/log/messages and the /var/log/secure lines so that they look
like this:
*.info;mail.none;auth.none;authpriv.none /var/log/messages
auth.*;authpriv.* /var/log/secure
» redhat# service syslog restart
suse# rcsyslog restart
__ 4. Again, try to log in as a valid user but with an invalid password, and try to log in as
an invalid user. Then view the log entries again.
» Switch to another virtual terminal
» Login: tux1
» Password: invalid
» Login: invalid
» Password: invalid
» Switch back to your previous virtual terminal
» # less /var/log/messages
» # less /var/log/secure

Using the logger command


__ 5. Look at your /etc/syslog.conf file and try to use the logger command so, that all the
different methods in the /etc/syslog.conf file are used once.
» # logger -p daemon.info This is priority daemon.info
» # logger -p authpriv.info This is priority authpriv.info
» # logger -p mail.debug This is priority mail.debug

© Copyright IBM Corp. 2001, 2004 Exercise 17. Logging 17-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» # logger -p kern.emerg This is priority kern.emerg


» # logger -p news.crit This is priority news.crit
» # logger -p local7.warn This is priority local7.warn
__ 6. Do the same, but this time when logged in as tux1.
» $ logger -p daemon.info This is priority daemon.info
» $ logger -p authpriv.info This is priority authpriv.info
» $ logger -p mail.debug This is priority mail.debug
» $ logger -p kern.emerg This is priority kern.emerg
» $ logger -p news.crit This is priority news.crit
» $ logger -p local7.warn This is priority local7.warn

Using the logrotate command


__ 7. Review the file /etc/logrotate.conf and all files in /etc/logrotate.d
» # less /etc/logrotate.conf
» # less /etc/logrotate.d/*
__ 8. Make a long, recursive listing of all files in the /var/log directory.
» # cd /var/log
» # ls -lR
__ 9. Manually run the logrotate command.
» # logrotate /etc/logrotate.conf
__ 10. Again make a long, recursive listing of all files in the /var/log directory. Do you see
any differences? Why not?
» # cd /var/log
» # ls -lR
» You should not see any difference since the logs were already rotated at 4am
this morning (unless you switched your system off overnight).
__ 11. Force a logrotate with the -f option.
» # logrotate -f /etc/logrotate.conf
__ 12. Again make a long, recursive listing of all files in the /var/log directory. Do you see
any differences? Why?
» # cd /var/log
» # ls -lR

17-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Using Logwatch (Fedora/Red Hat only)


__ 13. On a Red Hat system, logwatch is installed and activated automatically. The results
of this analysis will be mailed to root. So check your mail to see the results.
» # mail

Documenting your changes


__ 14. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 17. Logging 17-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

17-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 18. Printers

What This Exercise Is About


These exercises are designed to provide you with the opportunity to
configure printers and queues and make changes to queue
characteristics.

What You Should Be Able to Do


After completing this exercise, you should be able to install printers
and queues via the appropriate utility.

Introduction
These exercises are designed for you to become familiar with adding
and managing printers and queues. In the area of printing there are
many commands that can be used to do the same thing. In many of
these cases we have provided only one command method. If you are
already comfortable with certain UNIX commands for handling print
activities, like submitting a print job, please feel free to use that
command.

Known Hardware/Software Problems


Before starting this exercise it would be a good idea to check that the
printer you are going to use is connected and online and has a
reasonable supply of paper.

© Copyright IBM Corp. 2001, 2004 Exercise 18. Printers 18-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
Note
If there are no printers available in the classroom, you cannot do these exercises.

CUPS
__ 1. Ask your instructor for printer details.
__ 2. Start the CUPS printer daemon and make sure it is started on system boot.
__ 3. Start a browser and enter the location “http://localhost:631”. Log in as root and
configure your printer.
__ 4. Select the printer and print a test page.
__ 5. Submit a file to the printer using the lpr command and see if the page is printed.

Documenting your changes


__ 6. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

18-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise Instructions With Hints


Note
If there are no printers available in the classroom, you cannot do these exercises.

CUPS
__ 1. Ask your instructor for printer details.
__ 2. Start the CUPS printer daemon and make sure it is started on system boot.
» fedora/redhat# service cups restart
suse# rccups restart
» # chkconfig cups on
__ 3. Start a browser and enter the location “http://localhost:631”. Log in as root and
configure your printer.
» # konqueror
- or -
# mozilla
- or -
# galeon
» Enter “http://localhost:631” or “http://127.0.0.1:631” as location.
Note: Some browsers and/or distributions automatically configure proxies or
socks servers. If your browser refuses to connect, then check if all proxies or
socks servers are disabled.
» Click on “Administration”, and log in as root.
» Go to “Manage Printers” and click on “Add Printer”. When asked for a
username and password, enter “root” and your root password.
» Go through the different “Add new printer” screens, and configure a printer
name, location, description, device, make and model.
» Select the printer and go to “Configure Printer”. Select the correct paper size
and look for any options that you might need to modify.
__ 4. Select the printer and print a test page.
__ 5. Submit a file to the printer using the lpr command and see if the page is printed.
» # lpr -P <printer> /etc/passwd

Documenting your changes


__ 6. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 18. Printers 18-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

18-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Exercise 19. Troubleshooting

What This Exercise Is About


This exercise will let you troubleshoot some Linux problems and use
some techniques to solve these problems.

What You Should Be Able to Do


After completing this exercise you should have experience with:
• The rescue mode

Required Materials
To complete this exercise, you will need the following:
• A bootable network install diskette, which allows you to start the
rescue mode.

© Copyright IBM Corp. 2001, 2004 Exercise 19. Troubleshooting 19-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions
The Linux Rescue Mode
__ 1. Change your /etc/inittab file so that runlevel 6 is the default runlevel.
__ 2. Insert your Linux boot CD into the drive and reboot the system.
__ 3. When the boot:-prompt appears, start the rescue mode.
__ 4. Depending on the rescue mode and medium used, you may or may not get
questions about:
• Language to be used
• Keyboard type
• Mouse type
• Network adapter to be used
• Boot protocol to be used (or static IP addressing)
• NFS server to be used.
All these questions need to be answered the same way as when you installed the
system.
__ 5. Some rescue modes will give you the option to automatically attempt to find an
existing Linux installation and mount it. Do not allow this since we want to go
through this process manually.
__ 6. On a Fedora/Red Hat system, you will now get a command prompt. On a SuSE
system, you need to log in first as root, without a password.
__ 7. Check whether the device /dev/hda exists. If not, create the device node for your
hard disk
__ 8. Make a list of all partitions on your hard disk and create device nodes for them if
these don’t exist.
__ 9. Perform a filesystem check on all partitions that contain a filesystem.
Note: The partition table contains the partition id, which is used by fsck to determine
the filesystem type, and thus which fsck.* variant to invoke.
__ 10. If you have LVM volumes, perform a vgscan to scan for volume groups, and
activate all volume groups that were found.
Note: Some distributions (Red Hat, SuSE) include the actual, individual LVM tools,
while others (Fedora) include an all-in-one tool lvm, which acts as a sort of subshell
but allows you to type the exact same commands.
__ 11. Make a list of all logical volumes in the volume group(s), and check all logical
volumes that contain a filesystem.
__ 12. Create a directory /mnt/sysimage and mount your root filesystem on it.

19-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Note: On Fedora/Red Hat you can use e2label to determine which filesystem is your
root partition. On SuSE, there is no way to easily determine which partition is your
root partition. So you will need to use your documentation to find out which partition
is your root partition.
__ 13. Perform a chroot to the root filesystem.
__ 14. Mount all other partitions as well.
Note: If you mount /proc manually first, then you can use the mount -a command to
mount all other filesystems automatically.
__ 15. Change the /etc/inittab file and set the default runlevel to three.
__ 16. Unmount all filesystems and leave the chrooted shell. Then unmount the root
filesystem and exit the rescue mode.
__ 17. Remove the rescue media and wait until your system reboots. Was the rescue
attempt successful?

Documenting your changes


__ 18. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

© Copyright IBM Corp. 2001, 2004 Exercise 19. Troubleshooting 19-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise Instructions With Hints


The Linux Rescue Mode
__ 1. Change your /etc/inittab file so that runlevel 6 is the default runlevel.
» # vi /etc/inittab
Change the initdefault line so that it looks like this:
id:6:initdefault:
__ 2. Insert your Linux boot CD into the drive and reboot the system.
» # reboot
__ 3. When the boot:-prompt appears, start the rescue mode.
» On a Fedora/Red Hat system, this is done by entering “linux rescue” at the
boot:-prompt. On a SuSE system, select “Rescue System” from the menu.
__ 4. Depending on the rescue mode and medium used, you may or may not get
questions about:
• Language to be used
• Keyboard type
• Mouse type
• Network adapter to be used
• Boot protocol to be used (or static IP addressing)
• NFS server to be used.
All these questions need to be answered the same way as when you installed the
system.
__ 5. Some rescue modes will give you the option to automatically attempt to find an
existing Linux installation and mount it. Do not allow this since we want to go
through this process manually.
__ 6. On a Fedora/Red Hat system, you will now get a command prompt. On a SuSE
system, you need to log in first as root, without a password.
__ 7. Check whether the device /dev/hda exists. If not, create the device node for your
hard disk
» # [ -b /dev/hda ] || mknod /dev/hda
__ 8. Make a list of all partitions on your hard disk and create device nodes for them if
these don’t exist.
» # fdisk -l /dev/hda
» # for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
» > do
» > [ -b /dev/hda$i ] || mknod /dev/hda$i

19-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty » > done


__ 9. Perform a filesystem check on all partitions that contain a filesystem.
Note: The partition table contains the partition id, which is used by fsck to determine
the filesystem type, and thus which fsck.* variant to invoke.
» # fsck -y /dev/hda1
» # fsck -y /dev/hda2
» ...
__ 10. If you have LVM volumes, perform a vgscan to scan for volume groups, and
activate all volume groups that were found.
Note: Some distributions (Red Hat, SuSE) include the actual, individual LVM tools,
while others (Fedora) include an all-in-one tool lvm, which acts as a sort of subshell
but allows you to type the exact same commands.
Red Hat/SuSE:
» # vgscan
» # vgchange -a y vg00
Fedora:
» # lvm
» lvm> vgscan
» lvm> vgchange -a y vg00
» lvm> exit
__ 11. Make a list of all logical volumes in the volume group(s), and check all logical
volumes that contain a filesystem.
» # ls /dev/vg00
» # fsck -y /dev/vg00/lv00
» # fsck -y /dev/vg00/lv01
» # fsck -y /dev/vg00/lv02
» # fsck -y /dev/vg00/lv03
__ 12. Create a directory /mnt/sysimage and mount your root filesystem on it.
Note: On Fedora/Red Hat you can use e2label to determine which filesystem is your
root partition. On SuSE, there is no way to easily determine which partition is your
root partition. So you will need to use your documentation to find out which partition
is your root partition.
» # mkdir /mnt/sysimage
» redhat/fedora# e2label /dev/hda1
Do this for all filesystem partitions
» # mount /dev/hda5 /mnt/sysimage
__ 13. Perform a chroot to the root filesystem.
» # chroot /mnt/sysimage

© Copyright IBM Corp. 2001, 2004 Exercise 19. Troubleshooting 19-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

__ 14. Mount all other partitions as well.


Note: If you mount /proc manually first, then you can use the mount -a command to
mount all other filesystems automatically.
» # mount /proc
» # mount -a
__ 15. Change the /etc/inittab file and set the default runlevel to three.
» # vi /etc/inittab
Change the initdefault line to:
id:3:initdefault:
__ 16. Unmount all filesystems and leave the chrooted shell. Then unmount the root
filesystem and exit the rescue mode.
» # sync
» # umount -a
Note: it is not uncommon to find that /usr (and sometimes other filesystems
too) do not get unmounted. This is because you are using the mount
command from your root filesystem, which uses locale (timezone, error
messages in your local language and so forth) data that resides on the /usr
filesystem.
» # exit
» # umount /mnt/sysimage/usr
This is only required if /usr was not unmounted when you were in the
chroot-ed environment. Now that you’ve left this environment, the mount
command from the rescue environment is used, which takes its locale data
from a different place.
» # umount /mnt/sysimage
» # sync
» # exit
» A Red Hat system will now reboot automatically. On a SuSE system, press
Ctrl-Alt-Del to reboot.
__ 17. Remove the rescue media and wait until your system reboots. Was the rescue
attempt successful?

Documenting your changes


__ 18. Document any changes that you made in appendix A of this exercises guide.

END OF EXERCISE

19-6 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty Appendix A. Hardware Configuration Sheet


Use this sheet to write down the details of your hardware and keep it up to date during the
course
General information (/proc/cpuinfo, /proc/meminfo, hostname, free)
System name:

System location:

Processor(s):

Real memory in MB:

Keyboard type:

Mouse type: Connect to:

Local time zone:

Hard disks (/proc/devices)


Location (/dev/...) Manufacturer, type Capacity

Partition Table (fdisk -l, df, mount)


Partition Size in MB Type Mount point

© Copyright IBM Corp. 2001, 2004 Appendix A. Hardware Configuration Sheet A-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Other devices (/proc/devices)


Graphical adapter:

Sound adapter

Other devices:

Network information (ifconfig, /etc/modules.conf)


Device Model IP or “DHCP” Netmask Gateway Network name

Installation information (uname -a, rpm -qa)


Installation date:

Installation performed by:

Operating System and


general installation
choices (for example,
package groups)

Other software installed


and/or configured:

A-2 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Exercises

Uempty List of Services offered by this system (netstat -anut, ps -aux)


Service name Details

Local logon For users: root, ...

© Copyright IBM Corp. 2001, 2004 Appendix A. Hardware Configuration Sheet A-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Change log
Date, time, name Change performed

A-4 Linux System Administration I © Copyright IBM Corp. 2001, 2004


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0

backpg
Back page
®

S-ar putea să vă placă și