The NetBSD Guide

The NetBSD Developers

All brand and product names used in this guide are or may be trademarks or registered trademarks of their respective owners.

NetBSD® is a registered trademark of The NetBSD Foundation, Inc.

Published: 2010/01/16 07:55:45

$NetBSD: netbsd.xml,v 1.8 2010/01/16 07:55:45 snj Exp $


Table of Contents

Purpose of this guide
I. About NetBSD
1. What is NetBSD?
1.1. The story of NetBSD
1.2. NetBSD features
1.3. Supported platforms
1.4. NetBSD's target users
1.5. Applications for NetBSD
1.6. How to get NetBSD
II. System installation and related issues
2. Installing NetBSD: Preliminary considerations and preparations
2.1. Preliminary considerations
2.1.1. Dual booting
2.1.2. NetBSD on emulation and virtualization
2.2. Install preparations
2.2.1. The INSTALL document
2.2.2. Partitions
2.2.3. Hard disk space requirements
2.2.4. Network settings
2.2.5. Backup your data and operating systems!
2.2.6. Preparing the installation media
2.3. Checklist
3. Example installation
3.1. Introduction
3.2. The installation process
3.3. Keyboard layout
3.4. Starting the installation
3.5. MBR partitions
3.6. Disklabel partitions
3.7. Setting the disk name
3.8. Last chance!
3.9. The disk preparation process
3.10. Choosing the installation media
3.10.1. Installing from CD-ROM or DVD
3.10.2. Installing from an unmounted file system
3.10.3. Installing via FTP
3.10.4. Installing via NFS
3.11. Extracting sets
3.12. System configuration
3.13. Finishing the installation
4. Upgrading NetBSD
4.1. Overview
4.2. The INSTALL document
4.3. Performing the upgrade
III. System configuration, administration and tuning
5. The first steps on NetBSD
5.1. Troubleshooting
5.1.1. Boot problems
5.1.2. Misconfiguration of /etc/rc.conf
5.2. The man command
5.3. Editing configuration files
5.4. Login
5.5. Changing the root password
5.6. Adding users
5.7. Shadow passwords
5.8. Changing the keyboard layout
5.9. System time
5.10. Secure Shell (ssh(1))
5.11. Basic configuration in /etc/rc.conf
5.12. Basic network settings
5.13. Mounting a CD-ROM
5.14. Mounting a floppy
5.15. Installing additional software
5.16. Security alerts
5.17. Stopping and rebooting the system
6. Editing
6.1. Introducing vi
6.1.1. The vi interface
6.1.2. Switching to Edit Mode
6.1.3. Switching Modes & Saving Buffers to Files
6.1.4. Yanking and Putting
6.1.5. Navigation in the Buffer
6.1.6. Searching a File, the Alternate Navigational Aid
6.1.7. A Sample Session
6.2. Configuring vi
6.2.1. Extensions to .exrc
6.2.2. Documentation
6.3. Using tags with vi
7. The rc.d System
7.1. Basics
7.2. The rc.d Scripts
7.3. The Role of rcorder and rc.d Scripts
7.4. Additional Reading
8. Console drivers
8.1. wscons
8.1.1. wsdisplay
8.1.2. wskbd
8.1.3. wsmouse
8.2. pccons
9. X
9.1. What is X?
9.2. Configuration
9.3. The mouse
9.4. The keyboard
9.5. The monitor
9.6. The video card
9.7. Starting X
9.8. Customizing X
9.9. Other window managers or desktop environments
9.10. Graphical login with xdm
10. Linux emulation
10.1. Emulation setup
10.1.1. Configuring the kernel
10.1.2. Installing the Linux libraries
10.1.3. Installing Acrobat Reader
10.2. Directory structure
10.3. Emulating /proc
10.4. Using Linux browser plugins
10.5. Further reading
11. Audio
11.1. Basic hardware elements
11.2. BIOS settings
11.3. Configuring the audio device
11.4. Configuring the kernel audio devices
11.5. Advanced commands
11.5.1. audioctl(1)
11.5.2. mixerctl(1)
11.5.3. audioplay(1)
11.5.4. audiorecord(1)
12. Printing
12.1. Enabling the printer daemon
12.2. Configuring /etc/printcap
12.3. Configuring Ghostscript
12.4. Printer management commands
12.5. Remote printing
13. Using removable media
13.1. Initializing and using floppy disks
13.2. How to use a ZIP disk
13.3. Reading data CDs with NetBSD
13.4. Reading multi-session CDs with NetBSD
13.5. Allowing normal users to access CDs
13.6. Mounting an ISO image
13.7. Using video CDs with NetBSD
13.8. Using audio CDs with NetBSD
13.9. Creating an MP3 (MPEG layer 3) file from an audio CD
13.10. Using a CD-R writer with data CDs
13.11. Using a CD-R writer to create audio CDs
13.12. Creating an audio CD from MP3s
13.13. Copying an audio CD
13.14. Copying a data CD with two drives
13.15. Using CD-RW rewritables
13.16. DVD support
13.17. Creating ISO images from a CD
13.18. Getting volume information from CDs and ISO images
14. The cryptographic device driver (CGD)
14.1. Overview
14.1.1. Why use disk encryption?
14.1.2. Logical Disk Drivers
14.1.3. Availability
14.2. Components of the Crypto-Graphic Disk system
14.2.1. Kernel driver pseudo-device
14.2.2. Ciphers
14.2.3. Verification Methods
14.3. Example: encrypting your disk
14.3.1. Preparing the disk
14.3.2. Scrubbing the disk
14.3.3. Creating the cgd
14.3.4. Modifying configuration files
14.3.5. Restoring data
14.4. Example: encrypted CDs/DVDs
14.4.1. Introduction
14.4.2. Creating an encrypted CD/DVD
14.4.3. Using an encrypted CD/DVD
14.5. Suggestions and Warnings
14.5.1. Using a random-key cgd for swap
14.5.2. Warnings
14.6. Further Reading
15. Concatenated Disk Device (CCD) configuration
15.1. Install physical media
15.2. Configure Kernel Support
15.3. Disklabel each volume member of the CCD
15.4. Configure the CCD
15.5. Initialize the CCD device
15.6. Create a 4.2BSD/UFS filesystem on the new CCD device
15.7. Mount the filesystem
16. NetBSD RAIDframe
16.1. RAIDframe Introduction
16.1.1. About RAIDframe
16.1.2. A warning about Data Integrity, Backups, and High Availability
16.1.3. Getting Help
16.2. Setup RAIDframe Support
16.2.1. Kernel Support
16.2.2. Power Redundancy and Disk Caching
16.3. Example: RAID-1 Root Disk
16.3.1. Pseudo-Process Outline
16.3.2. Hardware Review
16.3.3. Initial Install on Disk0/wd0
16.3.4. Preparing Disk1/wd1
16.3.5. Initializing the RAID Device
16.3.6. Setting up Filesystems
16.3.7. Setting up kernel dumps
16.3.8. Migrating System to RAID
16.3.9. The first boot with RAID
16.3.10. Adding Disk0/wd0 to RAID
16.3.11. Testing Boot Blocks
16.4. Testing kernel dumps
17. NetBSD Logical Volume Manager (LVM) configuration
17.1. Anatomy of NetBSD Logical Volume Manager
17.2. Install physical media
17.3. Configure Kernel Support
17.4. Configure LVM on a NetBSD system
17.5. Disklabel each physical volume member of the LVM
17.6. Create Physical Volumes
17.7. Create Volume Group
17.8. Create Logical Volume
17.9. Example: LVM with Volume groups located on raid1
17.9.1. Loading Device-Mapper driver
17.9.2. Preparing raid1 installation
17.9.3. Creating PV, VG on raid disk
17.9.4. Creating LV's from VG located on raid disk
17.9.5. Integration of LV's in to the system
18. Pluggable Authentication Modules (PAM)
18.1. About
18.2. Introduction
18.3. Terms and conventions
18.3.1. Definitions
18.3.2. Usage examples
18.4. PAM Essentials
18.4.1. Facilities and primitives
18.4.2. Modules
18.4.3. Chains and policies
18.4.4. Transactions
18.5. PAM Configuration
18.5.1. PAM policy files
18.5.2. Breakdown of a configuration line
18.5.3. Policies
18.6. PAM modules
18.6.1. Common Modules
18.6.2. NetBSD-specific PAM Modules
18.7. PAM Application Programming
18.8. PAM Module Programming
18.9. Sample PAM Application
18.10. Sample PAM Module
18.11. Sample PAM Conversation Function
18.12. Further Reading
19. Tuning NetBSD
19.1. Introduction
19.1.1. Overview
19.2. Tuning Considerations
19.2.1. General System Configuration
19.2.2. System Services
19.2.3. The NetBSD Kernel
19.3. Visual Monitoring Tools
19.3.1. The top Process Monitor
19.3.2. The sysstat utility
19.4. Monitoring Tools
19.4.1. fstat
19.4.2. iostat
19.4.3. ps
19.4.4. vmstat
19.5. Network Tools
19.5.1. ping
19.5.2. traceroute
19.5.3. netstat
19.5.4. tcpdump
19.6. Accounting
19.6.1. Accounting
19.6.2. Reading Accounting Information
19.6.3. How to Put Accounting to Use
19.7. Kernel Profiling
19.7.1. Getting Started
19.7.2. Interpretation of kgmon Output
19.7.3. Putting it to Use
19.7.4. Summary
19.8. System Tuning
19.8.1. Using sysctl
19.8.2. tmpfs & mfs
19.8.3. Soft-dependencies
19.8.4. Journaling
19.8.5. LFS
19.9. Kernel Tuning
19.9.1. Preparing to Recompile a Kernel
19.9.2. Configuring the Kernel
19.9.3. Building the New Kernel
19.9.4. Shrinking the NetBSD kernel
20. NetBSD Veriexec subsystem
20.1. How it works
20.2. Signatures file
20.3. Generating fingerprints
20.4. Strict levels
20.5. Veriexec and layered file systems
20.6. Kernel configuration
21. Bluetooth on NetBSD
21.1. Introduction
21.2. Supported Hardware
21.3. System Configuration
21.4. Human Interface Devices
21.4.1. Mice
21.4.2. Keyboards
21.5. Personal Area Networking
21.5.1. Personal Area Networking User
21.6. Serial Connections
21.7. Audio
21.7.1. SCO Audio Headsets
21.7.2. SCO Audio Handsfree
21.8. Object Exchange
21.9. Troubleshooting
22. Miscellaneous operations
22.1. Installing the boot manager
22.2. Deleting the disklabel
22.3. Speaker
22.4. Forgot root password?
22.5. Password file is busy?
22.6. Adding a new hard disk
22.7. How to rebuild the devices in /dev
IV. Networking and related issues
23. Introduction to TCP/IP Networking
23.1. Audience
23.2. Supported Networking Protocols
23.3. Supported Media
23.3.1. Serial Line
23.3.2. Ethernet
23.4. TCP/IP Address Format
23.5. Subnetting and Routing
23.6. Name Service Concepts
23.6.1. /etc/hosts
23.6.2. Domain Name Service (DNS)
23.6.3. Network Information Service (NIS/YP)
23.6.4. Other
23.7. Next generation Internet protocol - IPv6
23.7.1. The Future of the Internet
23.7.2. What good is IPv6?
23.7.3. Changes to IPv4
24. Setting up TCP/IP on NetBSD in practice
24.1. A walk through the kernel configuration
24.2. Overview of the network configuration files
24.3. Connecting to the Internet with a modem
24.3.1. Getting the connection information
24.3.2. resolv.conf and nsswitch.conf
24.3.3. Creating the directories for pppd
24.3.4. Connection script and chat file
24.3.5. Authentication
24.3.6. pppd options
24.3.7. Testing the modem
24.3.8. Activating the link
24.3.9. Using a script for connection and disconnection
24.3.10. Running commands after dialin
24.4. Creating a small home network
24.5. Setting up an Internet gateway with IPNAT
24.5.1. Configuring the gateway/firewall
24.5.2. Configuring the clients
24.5.3. Some useful commands
24.6. Setting up a network bridge device
24.6.1. Bridge example
24.7. A common LAN setup
24.8. Connecting two PCs through a serial line
24.8.1. Connecting NetBSD with BSD or Linux
24.8.2. Connecting NetBSD and Windows NT
24.8.3. Connecting NetBSD and Windows 95
24.9. IPv6 Connectivity & Transition via 6to4
24.9.1. Getting 6to4 IPv6 up & running
24.9.2. Obtaining IPv6 Address Space for 6to4
24.9.3. How to get connected
24.9.4. Security Considerations
24.9.5. Data Needed for 6to4 Setup
24.9.6. Kernel Preparation
24.9.7. 6to4 Setup
24.9.8. Quickstart using pkgsrc/net/hf6to4
24.9.9. Known 6to4 Relay Routers
24.9.10. Tunneling 6to4 through an IPFilter firewall
24.9.11. Conclusion & Further Reading
25. The Internet Super Server inetd
25.1. Overview
25.2. What is inetd?
25.3. Configuring inetd - /etc/inetd.conf
25.4. Services - /etc/services
25.5. Protocols - /etc/protocols
25.6. Remote Procedure Calls (RPC) - /etc/rpc
25.7. Allowing and denying hosts - /etc/hosts.{allow,deny}
25.8. Adding a Service
25.9. When to use or not to use inetd
25.10. Other Resources
26. The Domain Name System
26.1. DNS Background and Concepts
26.1.1. Naming Services
26.1.2. The DNS namespace
26.1.3. Resource Records
26.1.4. Delegation
26.1.5. Delegation to multiple servers
26.1.6. Secondaries, Caching, and the SOA record
26.1.7. Name Resolution
26.1.8. Reverse Resolution
26.2. The DNS Files
26.2.1. /etc/namedb/named.conf
26.2.2. /etc/namedb/localhost
26.2.3. /etc/namedb/zone.127.0.0
26.2.4. /etc/namedb/diverge.org
26.2.5. /etc/namedb/1.168.192
26.2.6. /etc/namedb/root.cache
26.3. Using DNS
26.4. Setting up a caching only name server
26.4.1. Testing the server
27. Mail and news
27.1. postfix
27.1.1. Configuration of generic mapping
27.1.2. Testing the configuration
27.1.3. Using an alternative MTA
27.2. fetchmail
27.3. Reading and writing mail with mutt
27.4. Strategy for receiving mail
27.5. Strategy for sending mail
27.6. Advanced mail tools
27.7. News with tin
28. Introduction to the Common Address Redundancy Protocol (CARP)
28.1. CARP Operation
28.2. Configuring CARP
28.3. Enabling CARP Support
28.4. CARP Example
28.5. Advanced CARP configuration
28.6. Forcing Failover of the Master
29. Network services
29.1. The Network File System (NFS)
29.1.1. NFS setup example
29.1.2. Setting up NFS automounting for /net with amd(8)
29.2. The Network Time Protocol (NTP)
V. Building the system
30. Obtaining the sources
30.1. Preparing directories
30.2. Terminology
30.3. Downloading tarballs
30.3.1. Downloading sources for a NetBSD release
30.3.2. Downloading sources for a NetBSD stable branch
30.3.3. Downloading sources for a NetBSD-current development branch
30.4. Fetching by CVS
30.4.1. Fetching a NetBSD release
30.4.2. Fetching a NetBSD stable branch
30.4.3. Fetching the NetBSD-current development branch
30.4.4. Saving some cvs(1) options
30.5. Sources on CD (ISO)
31. Crosscompiling NetBSD with build.sh
31.1. Building the crosscompiler
31.2. Configuring the kernel manually
31.3. Crosscompiling the kernel manually
31.4. Crosscompiling the kernel with build.sh
31.5. Crosscompiling the userland
31.6. Crosscompiling the X Window System
31.7. Changing build behaviour
31.7.1. Changing the Destination Directory
31.7.2. Static Builds
31.7.3. Using build.sh options
31.7.4. make(1) variables used during build
32. Compiling the kernel
32.1. Requirements and procedure
32.2. Installing the kernel sources
32.3. Creating the kernel configuration file
32.4. Building the kernel manually
32.4.1. Configuring the kernel manually
32.4.2. Generating dependencies and recompiling manually
32.5. Building the kernel using build.sh
32.6. Installing the new kernel
32.7. If something went wrong
33. Updating an existing system from sources
33.1. The updating procedure
33.1.1. Building a new userland
33.1.2. Building a new kernel
33.1.3. Installing the kernel and userland
33.1.4. Updating the system configuration files
33.1.5. Summary
33.1.6. Alternative: using sysinst
33.2. More details about the updating of configuration and startup files
33.2.1. Using etcupdate with source files
33.2.2. Using etcupdate with binary distribution sets
33.2.3. Using etcmanage instead of etcupdate
34. Building NetBSD installation media
34.1. Creating custom install or boot floppies for your architecture e.g. i386
34.2. Creating a custom install or boot CD with build.sh
A. Information
A.1. Where to get this document
A.2. Guide history
B. Contributing to the NetBSD guide
B.1. Translating the guide
B.1.1. What you need to start a translation
B.1.2. Writing XML/DocBook
B.2. Sending contributions
B.3. XML/DocBook template
C. Getting started with XML/DocBook
C.1. What is XML/DocBook
C.2. Installing the necessary tools
C.3. Using the tools
C.4. Language-specific notes
C.4.1. Enabling hyphenation for the Italian language
C.5. Links
D. Acknowledgements
D.1. Original acknowledgements
D.2. Current acknowledgements
D.3. Licenses
D.3.1. Federico Lupi's original license of this guide
D.3.2. Networks Associates Technology's license on the PAM article
D.3.3. Joel Knight's license on the CARP article
E. Bibliography
Bibliography

List of Figures

2.1. Partitions
3.1. Selecting the language
3.2. Selecting a keyboard type
3.3. The sysinst main menu
3.4. Confirming to install NetBSD
3.5. Choosing a hard disk
3.6. Full or custom installation
3.7. Selecting distribution sets
3.8. Choosing the partitioning scheme
3.9. fdisk
3.10. Partition options
3.11. Installing the boot selector
3.12. Edit partitions?
3.13. Setting partition sizes
3.14. The disklabel editor
3.15. Disklabel partition editing
3.16. Naming the NetBSD disk
3.17. Last chance to abort
3.18. Selecting bootblocks
3.19. Choosing the verbosity of the extraction process
3.20. Installation media
3.21. CD-ROM/DVD installation
3.22. Mounting a file system
3.23. Mounting a partition
3.24. Accessing a MSDOS file system
3.25. Which network interface to configure
3.26. Using DHCP for network configuration
3.27. Entering and configuring network data
3.28. Confirming network parameters
3.29. Defining the FTP settings
3.30. NFS install screen
3.31. NFS example
3.32. Extraction of sets completed
3.33. Selecting the system's time zone
3.34. Selecting a password encryption scheme
3.35. Set a root password?
3.36. Setting root password
3.37. Choosing a shell
3.38. Installation completed
3.39. Reboot to finish installation
4.1. Starting the upgrade
4.2. Continuing the upgrade
4.3. Choosing the hard drive
4.4. Choosing the distribution filesets
4.5. File system check
4.6. Choosing bootblocks
4.7. Upgrade process - verbosity level
4.8. Install medium
4.9. Upgrade complete
16.1. RAID-1 Disk Logical Layout
16.2. Perform generic install onto Disk0/wd0
16.3. Setup RAID Set
16.4. Reboot using Disk1/wd1 of RAID
16.5. Mirror Disk1/wd1 back to Disk0/wd0
16.6. Award BIOS i386 Boot Disk1/wd1
16.7. Award BIOS i386 Boot Disk0/wd0
17.1. Anatomy of Logical Volume Management
17.2. Example raid 1 configuration
23.1. IPv4-addresses are divided into more significant network- and less significant hostbits
23.2. Our demo-network
23.3. Attaching one subnet to another one
23.4. IPv6-addresses are divided into more significant network- and less significant hostbits, too
23.5. IPv6-addresses have a similar structure to class B addresses
23.6. Several interfaces attached to a link result in only one scope ID for the link
24.1. Network with gateway
24.2. A frequently used method for transition is tunneling IPv6 in IPv4 packets
24.3. 6to4 derives an IPv6 from an IPv4 address
24.4. Request and reply can be routed via different gateways in 6to4
24.5. Enabling packet forwarding is needed for a 6to4 router
27.1. Structure of the mail system

List of Tables

18.1. PAM chain execution summary
20.1. Veriexec fingerprints tools
20.2. Veriexec access type aliases

List of Examples

12.1. /etc/printcap
12.2. /usr/local/libexec/lpfilter
12.3. /etc/printcap
12.4. /usr/local/libexec/lpfilter-ps
24.1. resolv.conf
24.2. nsswitch.conf
24.3. Connection script
24.4. Chat file
24.5. Chat file with login
24.6. /etc/ppp/options
24.7. ppp-start
24.8. ppp-stop
24.9. /etc/hosts
26.1. strider's /etc/hosts file
26.2. localhost
30.1. .cvsrc

Purpose of this guide

This guide describes the installation and the configuration of the NetBSD operating system as well as the setup and administration of some of its subsystems. It primarily addresses people coming from other Unix-like operating systems, and aims to be a useful guide in the face of the many small problems one encounters when using a new tool.

This guide is not a Unix tutorial: basic knowledge of some concepts and tools is assumed. You should know, for example, what a file and a directory are, and how to use an editor. There are plenty of books explaining basic Unix and operating system concepts, and you should consult one if you need more background information. It is better to choose a general book and avoid titles like “Learning Unix-XYZ, version 1.2.3.4 in 10 days”, but this is a matter of personal taste.

Much work is still required to finish this introduction to NetBSD: some chapters are not finished (some are not even started) and some subjects need more testing. Corrections and additions are most certainly welcome.

This guide is currently maintained by the NetBSD www team (). Corrections and suggestions should be sent to that address. See also Appendix B, Contributing to the NetBSD guide.

Part I. About NetBSD

Chapter 1. What is NetBSD?

NetBSD is a free, fast, secure, and highly portable Unix-like Open Source operating system. It is available for many platforms, from 64-bit x86 servers and PC desktop systems to embedded ARM and MIPS based devices. Its clean design and advanced features make it excellent in both production and research environments, and it is user-supported with complete source. Many applications are easily available through pkgsrc, the NetBSD Packages Collection.

1.1. The story of NetBSD

The first version of NetBSD (0.8) dates back to 1993 and springs from the 4.3BSD Lite operating system, a version of Unix developed at the University of California, Berkeley (BSD = Berkeley Software Distribution), and from the 386BSD system, the first BSD port to the Intel 386 CPU. In the following years, modifications from the 4.4BSD Lite release (the last release from the Berkeley group) were integrated into the system. The BSD branch of Unix has had a great importance and influence on the history of Unix-like operating systems, to which it has contributed many tools, ideas and improvements which are now standard: the vi editor, the C shell, job control, the Berkeley fast file system, reliable signals, support for virtual memory and TCP/IP, just to name a few. This tradition of research and development survives today in the BSD systems and, in particular, in NetBSD.

1.2. NetBSD features

NetBSD operates on a vast range of hardware platforms and is very portable. The full source to the NetBSD kernel and userland is available for all the supported platforms; please see the details on the official site of the NetBSD Project.

A detailed list of NetBSD features can be found at: http://www.NetBSD.org/about/features.html.

The basic features of NetBSD are:

  • Code quality and correctness

  • Portability to a wide range of hardware

  • Secure defaults

  • Adherence to industry standards

  • Research and innovation

These characteristics bring also indirect advantages. For example, if you work on just one platform you could think that you're not interested in portability. But portability is tied to code quality; without a well written and well organized code base it would be impossible to support a large number of platforms. And code quality is the base of any good and solid software system, though surprisingly few people seem to understand it.

One of the key characteristics of NetBSD is that its developers are not satisfied with partial implementations. Some systems seem to have the philosophy of “If it works, it's right”. In that light NetBSD's philosophy could be described as “It doesn't work unless it's right”. Think about how many overgrown programs are collapsing under their own weight and “features” and you'll understand why NetBSD tries to avoid this situation at all costs.

1.3. Supported platforms

NetBSD supports many platforms, including the popular PC platform (i386 and amd64), SPARC and UltraSPARC, Alpha, Amiga, Atari, and m68k and PowerPC based Apple Macintosh machines. Technical details for all of them can be found on the NetBSD site.

1.4. NetBSD's target users

The NetBSD site states that: “The NetBSD Project provides a freely available and redistributable system that professionals, hobbyists, and researchers can use in whatever manner they wish”. It is also an ideal system if you want to learn Unix, mainly because of its adherence to standards (one of the project goals) and because it works equally well on the latest PC hardware as well as on hardware which is considered obsolete by many other operating systems. To learn and use Unix you don't need to buy expensive hardware; you can use that old PC or Mac in your attic. It is important to note that although NetBSD runs on old hardware, modern hardware is well supported and care has been taken to ensure that supporting old machines does not inhibit performance on modern hardware. In addition, if you need a Unix system which runs consistently on a variety of platforms, NetBSD is probably your best choice.

1.5. Applications for NetBSD

Aside from the standard Unix productivity tools, editors, formatters, C/C++ compilers and debuggers and so on that are included with the base system, there is a huge collection of packages (currently over 8,000) that can be installed both from source and in pre-compiled form. All the packages that you expect to find on a well configured system are available for NetBSD for free. The framework that makes this possible, pkgsrc, also includes a number of commercial applications. In addition, NetBSD provides binary emulation for various other *nix operating systems, allowing you to run non-native applications. Linux emulation is probably the most relevant example. You can run the Linux versions of

  • Firefox

  • the Adobe Flash player plugin

  • Acrobat Reader

  • many other programs

1.6. How to get NetBSD

NetBSD is an Open Source operating system, and as such it is freely available for download from ftp.NetBSD.org and its mirrors.

There is no “official” supplier of NetBSD CD-ROMs but there are various resellers. You can find the most up to date list on the relevant page on the NetBSD site.

Part II. System installation and related issues

Chapter 2. Installing NetBSD: Preliminary considerations and preparations

2.1. Preliminary considerations

2.1.1. Dual booting

It is possible to install NetBSD together with other operating systems on one hard disk.

If there is already an operating system on the hard disk, think about how you can free some space for NetBSD; if NetBSD will share the disk with other operating systems you will probably need to create a new partition (which you will do with sysinst). Often times this will not be possible unless you resize an existing partition.

Unfortunately, it is not possible to resize an existing partition with sysinst, but there are some commercial products (like Partition Magic) and some free tools (GNU Parted, FIPS, pfdisk) available for this.

You can also install NetBSD on a separate hard disk.

Advice

Unless you are comfortable with setting up a partitioning scheme for two or more operating systems, and unless you understand the risk of data loss if you should make a mistake, it is recommended that you give NetBSD its own hard disk. This removes the risk of damage to the existing operating system.

2.1.2. NetBSD on emulation and virtualization

It is possible to install and run NetBSD on top of other operating systems without having to worry about partitioning. Emulators or virtualization environments provide a quick and secure way to try out NetBSD. The host operating system remains unchanged, and the risk of damaging important data is minimized.

Information about NetBSD as a Xen host and guest system is available on the NetBSD/xen web page.

The NetBSD on emulated hardware web page provides detailed information about various emulators and the supported NetBSD platforms. It should also be noted that NetBSD runs as a VMware guest.

2.2. Install preparations

2.2.1. The INSTALL document

The first thing to do before installing NetBSD is to read the release information and installation notes in one of the INSTALL files: this is the official description of the installation procedure, with platform-specific information and important details. It is available in HTML, PostScript, plain text, and an enhanced text format to be used with more. These files can be found in the root directory of the NetBSD release (on the install CD or on the FTP server). For example:

  • ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-5.0/port/INSTALL.html

2.2.2. Partitions

The terminology used by NetBSD for partitioning is different from the typical DOS/Windows terminology; in fact, there are two partitioning schemes involved when running NetBSD on a typical PC. NetBSD installs in one of the four primary BIOS partitions (the partitions defined in the hard disk partition table).

Within a BIOS partition (also called slice) NetBSD defines its BSD partitions using a disklabel: these partitions can be seen only by NetBSD and are identified by lowercase letters (starting with “a”). For example, wd0a refers to the “a” partition of the first IDE disk (wd0) and sd0a refers to the “a” partition of the first SCSI disk. In Figure 2.1, “Partitions” there are two primary BIOS partitions, one used by DOS and the other by NetBSD. NetBSD describes the disk layout through the disklabel.

Figure 2.1. Partitions

Partitions

Note

The meaning of partitions “c” and “d” is typical of the i386 port. On most other ports, “c” represents the whole disk.

Note

If NetBSD shares the hard disk with another operating system (like in the previous example) you will want to install a boot manager, i.e., a program which lets you choose which OS to start at boot time. sysinst can do this for you and will ask if you want to install one. Unless you have specific reasons not to, you should let sysinst perform this step.

2.2.3. Hard disk space requirements

The exact amount of space required for a given NetBSD installation varies depending on the platform being used and which distribution sets are selected. In general, if you have 1GB of free space on your hard drive, you will have more than enough space for a full installation of the base system.

2.2.4. Network settings

If you plan to fetch distribution sets over the network (not necessary if you downloaded a full-size install ISO) and do not use DHCP, write down your basic network settings. You will need:

  • Your IP address (example: 192.168.1.7)

  • the netmask (example: 255.255.255.0)

  • the IP address of your default gateway (example: 192.168.1.1)

  • the IP address of the DNS server you use (example: 145.253.2.75)

2.2.5. Backup your data and operating systems!

Before you begin the installation, make sure that you have a reliable backup of any operating systems and data on the used hard disk. Mistakes in partitioning your hard disk can lead to data loss. Existing operating systems may become unbootable. "Reliable backup" means that the backup and restore procedure is tested and works flawlessly!

2.2.6. Preparing the installation media

The NetBSD installation system consists of two parts. The first part is the installation kernel. This kernel contains the NetBSD install program sysinst and it is booted from a CD (or DVD), memory card, USB flash drive, or floppy disk. The sysinst program will prepare the disk: it separates the disk space into partitions, makes the disk bootable and creates the necessary file systems.

The second part of the install system is made up of the binary distribution sets: the files of the NetBSD operating system. The installer needs to have access to the distribution sets. sysinst will usually fetch these files from the CD or DVD you burned, but it can also get them via FTP, NFS, or local filesystem.

The NetBSD Project provides complete install media for every supported hardware architecture. This is usually in the form of bootable CD images (.iso files). For example:

  • ftp://ftp.NetBSD.org/pub/NetBSD/iso/5.0/

Note

Please see the list of mirrors and choose a local server near you for downloads

2.2.6.1. Booting the install system from CD

To use a bootable NetBSD install CD download the iso file for your hardware architecture and burn it to a CD or DVD. You will need to handle this step alone, as burning programs vary widely. Ensure that your computer is set up to boot from CD-ROM before hard drives, insert the disc, and reboot the computer.

2.2.6.2. Booting the install system from floppy

If you need to create installation floppies, you need to copy floppy images to a diskette. The floppy images are available on the NetBSD FTP servers or on a NetBSD install CD. To perform this operation in DOS you can use the rawrite program in the i386/installation/misc directory. For Windows, there's a version in rawr32.zip. The image files are i386/installation/floppy/boot1.fs and i386/installation/floppy/boot2.fs for installation of a “normal” PC. The other floppies that are available are described in more detail in the INSTALL document.

Note

Before you write the boot images to floppies, you should always check that the floppies are good: this simple step is often overlooked, but can save you a lot of trouble!

The procedure to write floppies is:

  1. Format the floppy.

  2. Go to the I386\INSTALLATION\FLOPPY directory of the CD-ROM.

  3. Run the ..\MISC\RAWRITE program (or extract ..\MISC\RAWR32.ZIP if you're on a Windows system, and run the RAWRITE32 program in that file). Usually the “Source file”s are BOOT1.FS and BOOT2.FS and the “Destination drive” is A:

To create a boot floppy in a Unix environment, the dd command can be used: For example:

# cd i386/installation/floppy
      # dd if=boot.fs of=/dev/fd0a bs=36b

Note

A 1440K floppy contains 1474560 bytes and is made up of 80 cylinders, 2 tracks, 18 sectors and 512 bytes per sector, i.e., 80 * 2 * 18 = 2880 blocks. Thus bs=36b copies one cylinder (18 * 2 blocks) at a time and repeats the operation 80 times instead of 2880.

2.3. Checklist

This is the checklist about the things that should be clear and on-hand now:

  • Available disk space

  • Bootable medium with the install system

  • CD/DVD or server with the distribution sets

  • Your network information (only if you will be fetching distribution sets via the network and do not use DHCP)

  • A working backup

  • A printout of the INSTALL document

Chapter 3. Example installation

3.1. Introduction

This chapter will guide you through the installation process. The concepts presented here apply to all installation methods. The only difference is in the way the distribution sets are fetched by the installer. Some details of the installation differ depending on the NetBSD release: The examples from this chapter were created with NetBSD 5.0.

Note

The following install screens are just examples. Do not simply copy them, as your hardware and configuration details may be different!

3.2. The installation process

The installation process is divided logically in two parts. In the first part you create a partition for NetBSD and write the disklabel for that partition. In the second part you decide which distribution sets (subsets of the operating system) you want to install and then extract the files into the newly created partition(s).

3.3. Keyboard layout

The NetBSD install program sysinst allows you to change the keyboard layout during the installation. If for some reason this does not work for you, you can use the map in the following table.

US IT DE FR
- ' ß )
/ - - !
= ì ' -
: ç Ö M
; ò ö m
# £ § 3
" ° Ä %
* ( ( 8
( ) ) 9
) = = 0
' à ä ù
` \ ^ @
\ ù # `

3.4. Starting the installation

To start the installation of NetBSD, insert your chosen boot media (CD/DVD, USB drive, floppy, etc.) and reboot the computer. The kernel on the installation medium will be booted and start displaying a lot of messages on the screen about hardware being detected.

Figure 3.1. Selecting the language

Selecting the language

When the kernel has booted you will find yourself in the NetBSD installation program, sysinst, shown in Figure 3.1, “Selecting the language”. From here on you should follow the instructions displayed on the screen, using the INSTALL document as a companion reference. You will find the INSTALL document in various formats in the root directory of the NetBSD release. The sysinst screens all have more or less the same layout: the upper part of the screen shows a short description of the current operation or a short help message, and the rest of the screen is made up of interactive menus and prompts. To make a choice, use the cursor keys, the “Ctrl+N” (next) and “Ctrl+P” (previous) keys, or press one of the letters displayed left of each choice. Confirm your choice by pressing the Return key.

Start by selecting the language you prefer to use for the installation process.

The next screen Figure 3.2, “Selecting a keyboard type” will allow you to select a suitable keyboard type.

Figure 3.2. Selecting a keyboard type

Selecting a keyboard type

This will bring you to the main menu of the installation program (Figure 3.3, “The sysinst main menu”).

Figure 3.3. The sysinst main menu

The sysinst main menu

Choosing the “Install NetBSD to hard disk” option brings you to the next screen (Figure 3.4, “Confirming to install NetBSD”), where you need to confirm that you want to continue the installation.

Figure 3.4. Confirming to install NetBSD

Confirming to install NetBSD

After choosing “Yes” to continue, sysinst displays a list of one or more disks and asks which one you want to install NetBSD on. In the example given in Figure 3.5, “Choosing a hard disk”, there are two disks, and NetBSD will be installed on “wd0”, the first IDE disk found. If you use SCSI or external USB disks, the first will be named “sd0”, the second “sd1” and so on.

Figure 3.5. Choosing a hard disk

Choosing a hard disk

The installer will then ask whether you want to do a full, minimal or custom installation. NetBSD is broken into a collection of distributions sets. “Full installation” is the default and will install all sets; “Minimal installation” will only install a small core set, the minimum of what is needed for a working system. If you select “Custom installation” you can select which sets you would like to have installed. This step is shown in Figure 3.6, “Full or custom installation”.

Figure 3.6. Full or custom installation

Full or custom installation

If you choose to do a custom installation, sysinst will allow you to choose which distribution sets to install, as shown in Figure 3.7, “Selecting distribution sets”. At a minimum, you must select a kernel and the “Base” and “System (/etc)” sets.

Figure 3.7. Selecting distribution sets

Selecting distribution sets

3.5. MBR partitions

The first important step of the installation has come: the partitioning of the hard disk. First, you need to specify whether NetBSD will use a partition (suggested choice) or the whole disk. In the former case it is still possible to create a partition that uses the whole hard disk (Figure 3.8, “Choosing the partitioning scheme”) so we recommend that you select this option as it keeps the BIOS partition table in a format which is compatible with other operating systems.

Figure 3.8. Choosing the partitioning scheme

Choosing the partitioning scheme

The next screen shows the current state of the MBR partition table on the hard disk before the installation of NetBSD. There are four primary partitions, and as you can see, this example disk is currently empty. If you do have other partitions you can leave them around and install NetBSD on a partition that is currently unused, or you can overwrite a partition to use it for NetBSD.

Figure 3.9. fdisk

fdisk

Deleting a partition is simple: after selecting the partition, a menu with options for that partition will appear (Figure 3.10, “Partition options”). Change the partition kind to “Delete partition” to remove the partition. Of course, if you want to use the partition for NetBSD you can set the partition kind to “NetBSD”.

You can create a partition for NetBSD by selecting the partition you want to install NetBSD to. The partition names “a” to “d” correspond to the four primary partitions on other operating systems. After selecting a partition, a menu with options for that partition will appear, as shown in Figure 3.10, “Partition options”.

Figure 3.10. Partition options

Partition options

To create a new partition, the following information must be supplied:

  • the type (kind) of the new partition

  • the first (start) sector of the new partition

  • the size of the new partition

Choose the partition type “NetBSD” for the new partition (using the “type” option). The installation program will try to guess the “start” position based on the end of the preceding partition. Change this value if necessary. The same thing applies to the “size” option; the installation program will try to fill in the space that is available until the next partition or the end of the disk (depending on which comes first). You can change this value if it is incorrect, or if you do not want NetBSD to use the suggested amount of space.

After you have chosen the partition type, start position, and size, it is a good idea to set the name that should be used in the boot menu. You can do this by selecting the “bootmenu” option and providing a label, e.g., “NetBSD”. It is a good idea to repeat this step for other bootable partitions so you can boot both NetBSD and a Windows system (or other operating systems) using the NetBSD bootselector. If you are satisfied with the partition options, confirm your choice by selecting “Partition OK”. Choose “Partition table OK” to leave the MBR partition table editor.

If you have made an error in partitioning (for example you have created overlapping partitions) sysinst will display a message and suggest that you go back to the MRB partition editor (but you are also allowed to continue). If the data is correct but the NetBSD partition lies outside the range of sectors which is bootable by the BIOS, sysinst will warn you and ask if you want to proceed anyway. Doing so may lead to problems on older PCs.

Note

This is not a limitation of NetBSD. Some old BIOSes cannot boot a partition which lies outside the first 1024 cylinders. To fully understand the problem you should study the different type of BIOSes and the many addressing schemes that they use (physical CHS, logical CHS, LBA, ...). These topics are not described in this guide.

On modern computers (those with support for int13 extensions), it is possible to install NetBSD in partitions that live outside the first 8 GB of the hard disk, provided that the NetBSD boot selector is installed.

Next, sysinst will offer to install a boot selector on the hard disk. This screen is shown in Figure 3.11, “Installing the boot selector”.

Figure 3.11. Installing the boot selector

Installing the boot selector

At this point, the BIOS partitions (called slices on BSD systems) have been created. They are also called PC BIOS partitions, MBR partitions or fdisk partitions.

Note

Do not confuse the slices or BIOS partitions with the BSD partitions, which are different things.

3.6. Disklabel partitions

Some platforms, like PC systems (amd64 and i386), use DOS-style MBR partitions to separate file systems. The MBR partition you created earlier in the installation process is necessary to make sure that other operating systems do not overwrite the diskspace that you allocated to NetBSD.

NetBSD uses its own partition scheme, called a disklabel, which is stored at the start of the MBR partition. In the next few steps you will create a disklabel(5) and set the sizes of the NetBSD partitions, or use existing partition sizes, as shown in Figure 3.12, “Edit partitions?”.

Figure 3.12. Edit partitions?

Edit partitions?

When you choose to set the sizes of the NetBSD partitions you can define the partitions you would like to create. The installation program will generate a disklabel based on these settings. This installation screen is shown in Figure 3.13, “Setting partition sizes”.

Figure 3.13. Setting partition sizes

Setting partition sizes

The default partition scheme of just using a big / (root) file system (plus swap) works fine with NetBSD, and there is little need to change this. Figure 3.13, “Setting partition sizes” shows how to change the size of the swap partition to 600 MB. Changing /tmp to reside on a RAM disk (mfs(8)) for extra speed may be a good idea. Other partition schemes may use separate partitions for /var, /usr and/or /home, but you should use your own experience to decide if you need this.

The next step is to create the disklabel and edit its partitions, if necessary, using the disklabel editor (Figure 3.14, “The disklabel editor”). If you predefined the partition sizes in the previous step, the resulting disklabel will probably fit your wishes. In that case you can complete the process immediately by selecting “Partition sizes ok”.

Figure 3.14. The disklabel editor

The disklabel editor

There are two reserved partitions, “c”, representing the NetBSD partition, and “d”, representing the whole disk. You can edit all other partitions by using the cursor keys and pressing the return key. You can add a partition by selecting an unused slot and setting parameters for that partition. The partition editing screen is shown in Figure 3.15, “Disklabel partition editing”.

Figure 3.15. Disklabel partition editing

Disklabel partition editing

3.7. Setting the disk name

After defining the partitions in the new disklabel, the last item is to enter a name for the NetBSD disk as shown in Figure 3.16, “Naming the NetBSD disk”. This can be used later to distinguish between disklabels of otherwise identical disks.

Figure 3.16. Naming the NetBSD disk

Naming the NetBSD disk

3.8. Last chance!

The installer now has all the data it needs to prepare the disk. Nothing has been written to the disk at this point but, and now is your last chance to abort the installation process before actually writing data to the disk. Choose “no” to abort the installation process and return to the main menu, or continue by selecting “yes”.

Figure 3.17. Last chance to abort

Last chance to abort

3.9. The disk preparation process

After confirming that sysinst should prepare the disk, it will run disklabel(8) to create the NetBSD partition layout and newfs(8) to create the file systems on the disk.

After preparing the NetBSD partitions and their filesystems, the next question (shown in Figure 3.18, “Selecting bootblocks”) is which bootblocks to install. Usually you will choose the default of BIOS console, i.e., show boot messages on your computer's display.

If you run a farm of machines without monitor, it may be more convenient to use a serial console running on one of the serial ports. The menu also allows changing the serial port's baud rate from the default of 9600 baud, 8 data bits, no parity and one stopbit.

Figure 3.18. Selecting bootblocks

Selecting bootblocks

3.10. Choosing the installation media

At this point, you have finished the first and most difficult part of the installation!

The second half of the installation process consists of populating the file systems by extracting the distribution sets that you selected earlier (base, compiler tools, games, etc). Before unpacking the sets, sysinst asks what information you would like to see during that process, as shown in Figure 3.19, “Choosing the verbosity of the extraction process”. You can choose between a progress bar, a display of the name of each extracted file, or nothing.

Figure 3.19. Choosing the verbosity of the extraction process

Choosing the verbosity of the extraction process

Now sysinst needs to find the NetBSD sets and you must tell it where to find them. The menu offers several choices, as shown in Figure 3.20, “Installation media”. The options are explained in detail in the INSTALL documents.

Figure 3.20. Installation media

Installation media

3.10.1. Installing from CD-ROM or DVD

When selecting “CD-ROM / DVD”, sysinst asks the name of the CD-ROM or DVD device and the directory in which the set files are stored, see Figure 3.21, “CD-ROM/DVD installation”. The device is usually cd0 for the first CD-ROM or DVD drive, regardless of whether it is IDE or SCSI (or even USB or FireWire).

Figure 3.21. CD-ROM/DVD installation

CD-ROM/DVD installation

The CD-ROM/DVD device name

If you don't know the name of the CD-ROM/DVD device, you can find by doing the following:

  1. Press Ctrl-Z to pause sysinst and go to the shell prompt.

  2. Type the command:

    # dmesg

    This will show the kernel startup messages, including the name of the CD-ROM device, for example cd0.

  3. If the display scrolls too quickly, you can also use more:

    # dmesg | more
  4. Go back to the installation program with the command:

    # fg

3.10.2. Installing from an unmounted file system

Figure 3.22, “Mounting a file system” shows the menu to install NetBSD from an unmounted file system. It is necessary to specify the device ("Device"), the file system of the device ("File system") and the path to the install sets ("Set directory"). The setting for the "Base directory" is optional and can be kept blank.

In the following example the install sets are stored on a MSDOS file system, on partition "e" on the device "sd0".

Figure 3.22. Mounting a file system

Mounting a file system

It is usually necessary to specify the device name and the partition. Figure 3.23, “Mounting a partition ” shows how to specify device "sd0" with partition "e".

Figure 3.23. Mounting a partition

Mounting a partition

In Figure 3.24, “Accessing a MSDOS file system” the file system type is specified. It is “msdos” but it could also be the NetBSD file system “ffs” or “ext2fs”, a Linux file system. The “Base directory” item is left blank and the binary sets are stored under “/sets”. Choosing “Continue” will start the extraction of the sets.

Figure 3.24. Accessing a MSDOS file system

Accessing a MSDOS file system

3.10.3. Installing via FTP

If you choose to install from a local network or the Internet via FTP, sysinst will configure the system's network connection, download the selected set files to a temporary directory, and then extract them.

NetBSD currently supports installation via ethernet, USB ethernet or wireless, and wireless LAN. Installation via DSL (PPP over Ethernet) is not supported during installation.

The first step shown in Figure 3.25, “Which network interface to configure” consists of selecting which network card to configure. sysinst will determine a list of available network interfaces, present them and ask which one to use.

Note

The exact names of your network interfaces depend on the hardware you use. Example interfaces are “wm” for Intel Gigabit interfaces, “ne” for NE2000 and compatible ethernet cards, and “ath” for Atheros based wireless cards. This list is by no means complete, and NetBSD supports many more network devices.

To get a list of network interfaces available on your system, interrupt the installation process by pressing “Ctrl+Z”, then enter

# ifconfig -a
ne2: flags=8822<UP,BROADCAST,NOTRAILERS,SIMPLEX,MULTICAST> mtu 1500
        address: 00:06:0d:c6:73:d5
        media: Ethernet autoselect 10baseT full-duplex
        status: active
        inet 0.0.0.0 netmask 0xffffff00 broadcast 0.0.0.0
        inet6 fe80::206:dff:fec6:73d5%ne2 prefixlen 64 scopeid 0x1
lo0: flags=8009<UP,LOOPBACK,MULTICAST> mtu 33196
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
ppp0: flags=8010<POINTOPOINT,MULTICAST> mtu 1500
ppp1: flags=8010<POINTOPOINT,MULTICAST> mtu 1500
sl0: flags=c010<POINTOPOINT,LINK2,MULTICAST> mtu 296
sl1: flags=c010<POINTOPOINT,LINK2,MULTICAST> mtu 296
strip0: flags=0 mtu 1100
strip1: flags=0 mtu 1100 

To get more information about all the devices found during system startup, including network devices, type

# dmesg | more

You can return to the NetBSD installation by typing

# fg

Figure 3.25. Which network interface to configure

Which network interface to configure

Next, you have a chance to set your network medium.

Note

It is unlikely that you will need to enter anything other than the default here. If you experience problems like very slow transfers or timeouts, you may, for example, force different duplex settings for ethernet cards. To get a list of supported media and media options for a given network device (ne2, for example), escape from sysinst by pressing “Ctrl+Z”, then enter:

# ifconfig -m ne2
ne2: flags=8822<UP,BROADCAST,NOTRAILERS,SIMPLEX,MULTICAST> mtu 1500
        address: 00:03:0d:c6:73:d5
        media: Ethernet 10baseT full-duplex
        status: active
        supported Ethernet media:
                media 10baseT
                media 10baseT mediaopt full-duplex
                media 10base2
                media autoselect

The various values printed after “media” may be of interest here, including keywords like “autoselect” but also including any “mediaopt” settings.

Return to the installation by typing:

# fg

The next question will be whether you want to perform DHCP autoconfiguration as shown in Figure 3.26, “Using DHCP for network configuration”. Answer “Yes” if you have a DHCP Dynamic Host Configuration Protocol (DHCP) running somewhere on your network, and sysinst will fetch a number of defaults from it. Answer “No” to enter all the values manually.

We will assume you answered “No” and go into all the questions asked in detail.

Figure 3.26. Using DHCP for network configuration

Using DHCP for network configuration

Figure 3.27, “Entering and configuring network data” shows the questions asked for the network configuration. The values to be entered are:

Your DNS Domain:

This is the name of the domain you are in.

Your hostname:

The name by which other machines can usually address your computer. Not used during installation.

Your IPv4 number:

Enter your numerical Internet Protocol address in “dotted quad” notation here, for example, 192.168.1.3

IPv4 Netmask:

The netmask for your network, either given as a hex value (“0xffffff00”) or in dotted-quad notation (“255.255.255.0”).

IPv4 gateway:

Your router's (or default gateway's) IP address. Do not use a hostname here!

IPv4 name server:

Your (first) DNS server's IP address. Again, don't use a hostname.

Figure 3.27. Entering and configuring network data

Entering and configuring network data

After answering all of your network configuration info, it will be displayed, and you will have a chance to go back and make changes (Figure 3.28, “Confirming network parameters”).

Figure 3.28. Confirming network parameters

Confirming network parameters

sysinst will now run a few commands (not displayed in detail here) to configure the network: flushing the routing table, setting the default route, and testing if the network connection is operational.

Now that you have a functional network connection, you must tell the installer how to get the distribution sets, as shown in Figure 3.29, “Defining the FTP settings”.

When you are satisfied with your settings (the defaults work most of the time), choose “Get Distribution” to continue.

Figure 3.29. Defining the FTP settings

Defining the FTP settings

3.10.4. Installing via NFS

If you want to install NetBSD from a server in your local network, NFS is an alternative to FTP.

Note

Using this installation method requires the ability to set up an NFS server, a topic which is not discussed here.

As shown in Figure 3.30, “NFS install screen”, you must specify the IP address of the NFS server with "Host", the "Base directory" that is exported by the NFS server, and the "Set directory", which contains the install sets.

Figure 3.30. NFS install screen

NFS install screen

Figure 3.31, “NFS example” shows an example: Host “192.168.1.50 ” is the NFS server that provides the directory “/home/username/Downloads” The NetBSD install sets are stored in the directory “/home/username/Downloads/sets” on the NFS server. Choose “Continue” to start the installation of the distribution sets.

Figure 3.31. NFS example

NFS example

3.11. Extracting sets

After the method for obtaining distribution sets has been chosen, and (if applicable) after those sets have been transferred, they will be extracted into the new NetBSD file system.

After extracting all selected sets, sysinst will create device nodes in the /dev directory and then display a message saying that everything went well.

Another message (see Figure 3.32, “Extraction of sets completed”) will let you know that the set extraction is now completed, and that you will have an opportunity to configure some essential things before finishing the NetBSD installation.

Figure 3.32. Extraction of sets completed

Extraction of sets completed

3.12. System configuration

The first thing you can configure is your timezone. It is Universal Time Coordinated (UTC) by default, and you can use the two-level menu of continents/countries and cities shown in Figure 3.33, “Selecting the system's time zone” to select your timezone with the Return key. Next, press “x” followed by Return to exit timezone selection.

Figure 3.33. Selecting the system's time zone

Selecting the system's time zone

At this point, you are given the option to choose a password encryption scheme. While “DES” is the standard algorithm used on most Unix systems, “MD5”, “Blowfish”, and “SHA1” allow longer passwords than DES, which only uses the first eight characters of the password that is entered. DES is still useful for interoperability with other operating systems.

Figure 3.34. Selecting a password encryption scheme

Selecting a password encryption scheme

After choosing the password cipher you are asked if you want to set the root password. It is recommended to set a root password at this point for security reasons.

Figure 3.35. Set a root password?

Set a root password?

When you agree to set a root password, sysinst will run the passwd(1) utility for you. Please note that the password is not echoed.

Figure 3.36. Setting root password

Setting root password

The next menu allows you to choose which command line interpreter - also known as a “shell” - will be used for the root account. The default is the classic Bourne shell, sh(1). Other choices are the Korn shell (ksh(1)) and the C shell (csh(1)). If, upon reading this, you don't have some idea of which shell you prefer, simply use the default, as this is a highly subjective decision. Should you later change your mind, root's shell can always be changed.

Figure 3.37. Choosing a shell

Choosing a shell

3.13. Finishing the installation

At this point the installation is finished.

Figure 3.38. Installation completed

Installation completed

After passing the dialog that confirms the installation, sysinst will return to the main menu. Remove any installation media (CD, floppy, etc.) and choose “Reboot the computer” to boot your new NetBSD installation.

Figure 3.39. Reboot to finish installation

Reboot to finish installation

Chapter 4. Upgrading NetBSD

4.1. Overview

This chapter describes the binary upgrade of a NetBSD system. To do the upgrade, you must have some form of bootable media (CD-ROM, USB drive, floppy, etc.) available and at least the base and kern distribution sets. Since files already installed on the system are overwritten in place, you only need additional free space for files which weren't previously installed or to account for growth of the sets between releases. Usually this is not more than a few megabytes.

Note

Since upgrading involves replacing the kernel, boot blocks, and most of the system binaries, it has the potential to cause data loss. Before beginning, you are strongly advised to back up any important data on the NetBSD partition or on any other partitions on your disk.

The upgrade procedure is similar to an installation, but without the hard disk partitioning. sysinst will attempt to merge the settings stored in your /etc directory with the new version of NetBSD. Also, file systems are checked before unpacking the sets. Fetching the binary sets is done in the same manner as in the installation procedure.

4.2. The INSTALL document

Before doing an upgrade it is essential to read the release information and upgrading notes in one of the INSTALL files: this is the official description of the upgrade procedure, with platform specific information and important details. It can be found in the root directory of the NetBSD release (on the install CD or on the FTP server)

It is advisable to print the INSTALL document out. It is available in four formats: .txt, .ps, .more, and .html

4.3. Performing the upgrade

The following section provides an overview of the binary upgrade process. Most of the following sysinst dialogs are similar to those of the installation process. More verbose descriptions and explanations of the dialogs are available in Chapter 3, Example installation.

After selecting the installation language and the keyboard type, the main menu appears. Choosing option “b: Upgrade NetBSD on a hard disk” will start the the upgrade process.

Figure 4.1. Starting the upgrade

Starting the upgrade

The dialog in Figure 4.2, “Continuing the upgrade” will request permission to continue with the upgrade. At this point nothing has been changed yet and the upgrade can still be cancelled. This is a good time to ask yourself whether you have made a backup, and if you know for certain that you will be able to restore from it.

Figure 4.2. Continuing the upgrade

Continuing the upgrade

After choosing to continue with “Yes”, the next dialog will ask you to specify the hard disk with the NetBSD system that shall be upgraded. If more than one disk is available a list of the disks will be displayed.

Figure 4.3. Choosing the hard drive

Choosing the hard drive

The system used for the example has only one hard disk available: “wd0”.

The following dialog provides a menu to choose the installation type. The choices are “Full installation”, “Minimal installation”, or “Custom installation”.

Figure 4.4. Choosing the distribution filesets

Choosing the distribution filesets

At this point, sysinst will perform a check of the file system to ensure its integrity.

Figure 4.5. File system check

File system check

The next step is to choose which type of bootblocks to install.

Figure 4.6. Choosing bootblocks

Choosing bootblocks

The next dialog will ask how much information should be displayed during the extraction of the distribution sets.

Figure 4.7. Upgrade process - verbosity level

Upgrade process - verbosity level

The following dialog asks for the install method of choice and provides a list of possible options. The install medium contains the new NetBSD distribution sets. You will be prompted for different information depending on which option you choose. For example, a CD-ROM or DVD install requires you to specify which device to use and which directory the sets are in, while an FTP install requires you to configure your network and specify the hostname of an FTP server. More details can be found in Section 3.10, “Choosing the installation media”.

Figure 4.8. Install medium

Install medium

sysinst will now unpack the distribution sets, replacing your old binaries. After unpacking these sets, it runs the postinstall script to clean up various things. If no problems occur, you are done. If postinstall produces errors, you will have to manually resolve the issues it brings up. See postinstall's man page for more information. You should also read the remarks in INSTALL about upgrading, as specific compatibility issues are documented there.

Figure 4.9. Upgrade complete

Upgrade complete

When you are back at the main menu, remove the boot medium (if applicable) and reboot. Have fun with your new version of NetBSD!

Part III. System configuration, administration and tuning

Table of Contents

5. The first steps on NetBSD
5.1. Troubleshooting
5.1.1. Boot problems
5.1.2. Misconfiguration of /etc/rc.conf
5.2. The man command
5.3. Editing configuration files
5.4. Login
5.5. Changing the root password
5.6. Adding users
5.7. Shadow passwords
5.8. Changing the keyboard layout
5.9. System time
5.10. Secure Shell (ssh(1))
5.11. Basic configuration in /etc/rc.conf
5.12. Basic network settings
5.13. Mounting a CD-ROM
5.14. Mounting a floppy
5.15. Installing additional software
5.16. Security alerts
5.17. Stopping and rebooting the system
6. Editing
6.1. Introducing vi
6.1.1. The vi interface
6.1.2. Switching to Edit Mode
6.1.3. Switching Modes & Saving Buffers to Files
6.1.4. Yanking and Putting
6.1.5. Navigation in the Buffer
6.1.6. Searching a File, the Alternate Navigational Aid
6.1.7. A Sample Session
6.2. Configuring vi
6.2.1. Extensions to .exrc
6.2.2. Documentation
6.3. Using tags with vi
7. The rc.d System
7.1. Basics
7.2. The rc.d Scripts
7.3. The Role of rcorder and rc.d Scripts
7.4. Additional Reading
8. Console drivers
8.1. wscons
8.1.1. wsdisplay
8.1.2. wskbd
8.1.3. wsmouse
8.2. pccons
9. X
9.1. What is X?
9.2. Configuration
9.3. The mouse
9.4. The keyboard
9.5. The monitor
9.6. The video card
9.7. Starting X
9.8. Customizing X
9.9. Other window managers or desktop environments
9.10. Graphical login with xdm
10. Linux emulation
10.1. Emulation setup
10.1.1. Configuring the kernel
10.1.2. Installing the Linux libraries
10.1.3. Installing Acrobat Reader
10.2. Directory structure
10.3. Emulating /proc
10.4. Using Linux browser plugins
10.5. Further reading
11. Audio
11.1. Basic hardware elements
11.2. BIOS settings
11.3. Configuring the audio device
11.4. Configuring the kernel audio devices
11.5. Advanced commands
11.5.1. audioctl(1)
11.5.2. mixerctl(1)
11.5.3. audioplay(1)
11.5.4. audiorecord(1)
12. Printing
12.1. Enabling the printer daemon
12.2. Configuring /etc/printcap
12.3. Configuring Ghostscript
12.4. Printer management commands
12.5. Remote printing
13. Using removable media
13.1. Initializing and using floppy disks
13.2. How to use a ZIP disk
13.3. Reading data CDs with NetBSD
13.4. Reading multi-session CDs with NetBSD
13.5. Allowing normal users to access CDs
13.6. Mounting an ISO image
13.7. Using video CDs with NetBSD
13.8. Using audio CDs with NetBSD
13.9. Creating an MP3 (MPEG layer 3) file from an audio CD
13.10. Using a CD-R writer with data CDs
13.11. Using a CD-R writer to create audio CDs
13.12. Creating an audio CD from MP3s
13.13. Copying an audio CD
13.14. Copying a data CD with two drives
13.15. Using CD-RW rewritables
13.16. DVD support
13.17. Creating ISO images from a CD
13.18. Getting volume information from CDs and ISO images
14. The cryptographic device driver (CGD)
14.1. Overview
14.1.1. Why use disk encryption?
14.1.2. Logical Disk Drivers
14.1.3. Availability
14.2. Components of the Crypto-Graphic Disk system
14.2.1. Kernel driver pseudo-device
14.2.2. Ciphers
14.2.3. Verification Methods
14.3. Example: encrypting your disk
14.3.1. Preparing the disk
14.3.2. Scrubbing the disk
14.3.3. Creating the cgd
14.3.4. Modifying configuration files
14.3.5. Restoring data
14.4. Example: encrypted CDs/DVDs
14.4.1. Introduction
14.4.2. Creating an encrypted CD/DVD
14.4.3. Using an encrypted CD/DVD
14.5. Suggestions and Warnings
14.5.1. Using a random-key cgd for swap
14.5.2. Warnings
14.6. Further Reading
15. Concatenated Disk Device (CCD) configuration
15.1. Install physical media
15.2. Configure Kernel Support
15.3. Disklabel each volume member of the CCD
15.4. Configure the CCD
15.5. Initialize the CCD device
15.6. Create a 4.2BSD/UFS filesystem on the new CCD device
15.7. Mount the filesystem
16. NetBSD RAIDframe
16.1. RAIDframe Introduction
16.1.1. About RAIDframe
16.1.2. A warning about Data Integrity, Backups, and High Availability
16.1.3. Getting Help
16.2. Setup RAIDframe Support
16.2.1. Kernel Support
16.2.2. Power Redundancy and Disk Caching
16.3. Example: RAID-1 Root Disk
16.3.1. Pseudo-Process Outline
16.3.2. Hardware Review
16.3.3. Initial Install on Disk0/wd0
16.3.4. Preparing Disk1/wd1
16.3.5. Initializing the RAID Device
16.3.6. Setting up Filesystems
16.3.7. Setting up kernel dumps
16.3.8. Migrating System to RAID
16.3.9. The first boot with RAID
16.3.10. Adding Disk0/wd0 to RAID
16.3.11. Testing Boot Blocks
16.4. Testing kernel dumps
17. NetBSD Logical Volume Manager (LVM) configuration
17.1. Anatomy of NetBSD Logical Volume Manager
17.2. Install physical media
17.3. Configure Kernel Support
17.4. Configure LVM on a NetBSD system
17.5. Disklabel each physical volume member of the LVM
17.6. Create Physical Volumes
17.7. Create Volume Group
17.8. Create Logical Volume
17.9. Example: LVM with Volume groups located on raid1
17.9.1. Loading Device-Mapper driver
17.9.2. Preparing raid1 installation
17.9.3. Creating PV, VG on raid disk
17.9.4. Creating LV's from VG located on raid disk
17.9.5. Integration of LV's in to the system
18. Pluggable Authentication Modules (PAM)
18.1. About
18.2. Introduction
18.3. Terms and conventions
18.3.1. Definitions
18.3.2. Usage examples
18.4. PAM Essentials
18.4.1. Facilities and primitives
18.4.2. Modules
18.4.3. Chains and policies
18.4.4. Transactions
18.5. PAM Configuration
18.5.1. PAM policy files
18.5.2. Breakdown of a configuration line
18.5.3. Policies
18.6. PAM modules
18.6.1. Common Modules
18.6.2. NetBSD-specific PAM Modules
18.7. PAM Application Programming
18.8. PAM Module Programming
18.9. Sample PAM Application
18.10. Sample PAM Module
18.11. Sample PAM Conversation Function
18.12. Further Reading
19. Tuning NetBSD
19.1. Introduction
19.1.1. Overview
19.2. Tuning Considerations
19.2.1. General System Configuration
19.2.2. System Services
19.2.3. The NetBSD Kernel
19.3. Visual Monitoring Tools
19.3.1. The top Process Monitor
19.3.2. The sysstat utility
19.4. Monitoring Tools
19.4.1. fstat
19.4.2. iostat
19.4.3. ps
19.4.4. vmstat
19.5. Network Tools
19.5.1. ping
19.5.2. traceroute
19.5.3. netstat
19.5.4. tcpdump
19.6. Accounting
19.6.1. Accounting
19.6.2. Reading Accounting Information
19.6.3. How to Put Accounting to Use
19.7. Kernel Profiling
19.7.1. Getting Started
19.7.2. Interpretation of kgmon Output
19.7.3. Putting it to Use
19.7.4. Summary
19.8. System Tuning
19.8.1. Using sysctl
19.8.2. tmpfs & mfs
19.8.3. Soft-dependencies
19.8.4. Journaling
19.8.5. LFS
19.9. Kernel Tuning
19.9.1. Preparing to Recompile a Kernel
19.9.2. Configuring the Kernel
19.9.3. Building the New Kernel
19.9.4. Shrinking the NetBSD kernel
20. NetBSD Veriexec subsystem
20.1. How it works
20.2. Signatures file
20.3. Generating fingerprints
20.4. Strict levels
20.5. Veriexec and layered file systems
20.6. Kernel configuration
21. Bluetooth on NetBSD
21.1. Introduction
21.2. Supported Hardware
21.3. System Configuration
21.4. Human Interface Devices
21.4.1. Mice
21.4.2. Keyboards
21.5. Personal Area Networking
21.5.1. Personal Area Networking User
21.6. Serial Connections
21.7. Audio
21.7.1. SCO Audio Headsets
21.7.2. SCO Audio Handsfree
21.8. Object Exchange
21.9. Troubleshooting
22. Miscellaneous operations
22.1. Installing the boot manager
22.2. Deleting the disklabel
22.3. Speaker
22.4. Forgot root password?
22.5. Password file is busy?
22.6. Adding a new hard disk
22.7. How to rebuild the devices in /dev

Chapter 5. The first steps on NetBSD

After installing and rebooting, the computer will boot from the hard disk. If everything went well you'll be looking at the login prompt within a few seconds (or minutes, depending on your hardware). The system is not yet fully configured, but basic configuration is easy. You will see how to quickly configure some important things, and in doing so you will learn some basics about how the system works.

5.1. Troubleshooting

5.1.1. Boot problems

If the system does not boot it could be that the boot manager was not installed correctly or that there is a problem with the MBR (Master Boot Record). Boot the machine from your install medium (CD, DVD, floppy, etc.) and when you see the boot menu, select the option to drop to the boot prompt.

type "?" or "help" for help.
> ?
commands are:
boot [xdNx:][filename] [-12acdqsvxz]
     (ex. "hd0a:netbsd.old -s")
ls [path]
dev xd[N[x]]:
consdev {pc|com[0123]|com[0123]kbd|auto}
modules {enabled|disabled}
load {path_to_module}
multiboot [xdNx:][filename] [<args>]
help|?
quit
> boot hd0a:netbsd

The system should now boot from the hard disk. If NetBSD boots correctly from the hard disk, there is probably a Master Boot Record problem. You can install the boot manager or modify its configuration with the fdisk -B command. See Section 22.1, “Installing the boot manager” for a detailed description.

5.1.2. Misconfiguration of /etc/rc.conf

If you or the installation software haven't done any configuration of /etc/rc.conf (sysinst normally will), the system will drop you into single user mode and show the message

/etc/rc.conf is not configured. Multiuser boot aborted

When the system asks you to choose a shell, simply press RETURN to get to a /bin/sh prompt. If you are asked for a terminal type, respond with vt220 (or whatever is appropriate for your terminal type) and press RETURN. You may need to type one of the following commands to get your delete key to work properly, depending on your keyboard:

# stty erase '^h'
# stty erase '^?'

At this point, you need to configure at least one file in the /etc directory. However, the root file system (/) is mounted read-only, so you will first need to make it writable with:

# /sbin/mount -u -w /

Next, take a look at the /etc/rc.conf file. Modify it to your tastes, making sure that you set “rc_configured=YES ” so that you don't end up in this position again. Default values for the various programs can be found in /etc/defaults/rc.conf. More complete documentation can be found in rc.conf(5).

When you have finished, type exit at the prompt to leave the single-user shell and continue with the multi-user boot.

5.2. The man command

If you have never used a Unix(-like) operating system before, your best friend is now the man command, which displays a manual page. The NetBSD manual pages are among the best and most detailed you can find, although they are very technical.

A good manual to read after booting a new NetBSD system is afterboot(8). It contains information about various necessary and useful configuration settings.

man name shows the man page of the “name” command and man -k name shows a list of man pages dealing with “name” (you can also use the apropos command).

To learn the basics of the man command, type:

# man man

Manual pages contain not only information about commands but also descriptions of some NetBSD features and structures. For example, take a look at the hier(7) man page, which describes in detail the layout of the filesystem used by NetBSD.

# man hier

Other similar pages are release(7) and pkgsrc(7).

# man 8 intro

Manual pages are divided in several sections, depending on what they document:

  1. general commands (tools and utilities), see intro(1)

  2. system calls and error numbers, see intro(2)

  3. C libraries, see intro(3)

  4. special files and hardware support, see intro(4)

  5. file formats, see intro(5)

  6. games, see intro(6)

  7. miscellaneous information pages, see intro(7)

  8. system maintenance and operation commands, see intro(8)

  9. kernel internals, see intro(9)

A subject may appear in more than one section of the manual; to view a specific page, supply the section number as an argument to the man command. For example, time appears in section 1 (the time user command) and in section 3 (the time function of the C library). To see the man page for the time C function, write:

# man 3 time

To see all the available pages:

# man -w time
# man -a time

5.3. Editing configuration files

Other than a shell, a text editor is the most essential tool for NetBSD system administration.

There are two provided in the base system

  • ed(1), a line orientated text editor. ed is a very simplistic text editor. It has a command mode (active when first started) and an input mode. Its primary advantage is that it will work even without a correct terminal type set. In an emergency, ed is worth knowing, but note that vi(1) is now available in /rescue, which brings us to...

  • vi(1), a screen orientated text editor. vi is the only screen editor available in the base install, and requires a valid terminal type to run. Refer to Chapter 6, Editing to learn more about NetBSD's default editor.

Advice

Before you continue you should know or learn how to open, edit and save files within vi. Make sure to read Chapter 6, Editing.

5.4. Login

For the first login you will use the root user, which is the only user defined at the end of the installation. At the password prompt type the password for root that you set during the installation. If you didn't set a password, just press Enter.

NetBSD/i386 (Amnesiac) (ttyE0)
login: root
password:
We recommend creating a non-root account and using su(1) for 
root access.
#

5.5. Changing the root password

If you did not set a password for root during the installation, you should use the /usr/bin/passwd command to do so now.

# /usr/bin/passwd
Changing local password for root.
New password:
Retype new password:

Passwords are not displayed on the screen while you type.

Choose a password that has numbers, digits, and special characters (not space) as well as from the upper and lower case alphabet. Do not choose any word in any language. It is common for an intruder to use dictionary attacks.

5.6. Adding users

For security reasons, it is bad practice to login as root during regular use and maintenance of the system. Instead, administrators are encouraged to add a regular user, add the user to the wheel group, then use the su(1) command when root privileges are required. NetBSD offers the useradd(8) utility to create user accounts. For example, to create a new user:

# useradd -m joe

The defaults for the useradd command can be changed; see the useradd(8) man page.

User accounts that can su to root are required to be in the "wheel" group. This can be done when the account is created by specifying a secondary group:

# useradd -m -G wheel joe

As an alternative, the usermod(8) command can be used to add a user to an existing group:

# usermod -G wheel joe

In case you just created a user but forgot to set a password, you can still do that later using the passwd(1) command.

# passwd joe

Note

You can edit /etc/group directly to add users to groups, but do not edit the /etc/passwd directly; use vipw(8).

5.7. Shadow passwords

Shadow passwords are enabled by default. What this means is that all the passwords in /etc/passwd are simply “*”; the encrypted passwords are stored in a file that can only be read by root, /etc/master.passwd. When you start vipw(8) to edit the password file, the program opens a copy of /etc/master.passwd; when you exit, vipw checks the validity of the copy, creates a new /etc/passwd and installs the new /etc/master.passwd file. Finally, vipw launches pwd_mkdb(8), which creates the files /etc/pwd.db and /etc/spwd.db, two databases which are equivalent to /etc/passwd and /etc/master.passwd but faster to process.

It is very important to always use vipw and the other tools for account administration (chfn(1), chsh(1), chpass(1), passwd(1)) and to never directly modify /etc/master.passwd or /etc/passwd.

5.8. Changing the keyboard layout

If you do not have a US layout keyboard, you will probably want to change keymaps. For example, to use an italian keyboard, enter the following command:

# wsconsctl -k -w encoding=it
encoding -> it

To save the keyboard layout permanently, add the following line to the /etc/wscons.conf file:

encoding it

See Section 8.1.2.1, “Keyboard mappings” for a list of available keymaps.

5.9. System time

NetBSD, like all Unix systems, uses a system clock based on Greenwich time (GMT) and this is what you should set your system clock to. If you want to keep the system clock set to the local time (because, for example, you have a dual boot system with Windows installed), you must notify NetBSD, adding rtclocaltime=YES to /etc/rc.conf:

# echo rtclocaltime=YES >> /etc/rc.conf
# sh /etc/rc.d/rtclocaltime restart

The number of minutes west of GMT is calculated automatically and is set in the kern.rtc_offset sysctl variable.

To display the current setting of the kern.rtc_offset variable:

# sysctl kern.rtc_offset
kern.rtc_offset = -60

This automatic configuration only works if you have set the proper time zone with a symbolic link to /etc/localtime. Normally this is done as part of the install procedure, but if for some reason it wasn't, you can set it by creating a symbolic link from a file in the /usr/share/zoneinfo directory to /etc/localtime.

The following example sets the time zone to Eastern Europe Summer Time:

# ln -fs /usr/share/zoneinfo/Europe/Helsinki /etc/localtime

5.10. Secure Shell (ssh(1))

By default, all services are disabled in a fresh NetBSD installation, and ssh(1) is no exception. You may wish to enable it so you can log in to your system remotely. Set sshd=YES in /etc/rc.conf and then start the server with the command

# /etc/rc.d/sshd start

The first time the server is started, it will generate a new keypair, which will be stored inside the directory /etc/ssh.

5.11. Basic configuration in /etc/rc.conf

NetBSD uses /etc/rc.conf to determine what will be executed when the system boots. Understanding this file is important. The rc.conf(5) manual page contains a detailed description of all available options.

The /etc/defaults/rc.conf file contains the default values for most settings. To override a default value, the new value must be put into /etc/rc.conf. The definitions there override the ones in /etc/defaults/rc.conf (which you should leave unchanged).

# man rc.conf

The first modifications are:

  • Set “rc_configured=YES” (this modification should already have been done by the installation software.)

  • Set “dhclient=YES” to configure your system's network using DHCP.

  • Define a hostname for your machine (use a fully qualified hostname, i.e., one including domain). If you have a standalone machine you can use any name (for example, vigor3.your.domain). If your machine is connected to a network, you should supply the correct name.

  • If your are connected to a local network or the Internet through a router, set the defaultroute variable to the IP address of your router (sometimes called a default gateway). For example, “defaultroute=192.168.1.1”.

5.12. Basic network settings

To resolve the names and IP addresses of remote hosts, the system needs access to a (remote or local) DNS nameserver. Tell the system which nameserver(s) to use by adding the IP address of one or more nameservers to the /etc/resolv.conf file, using the following as an example:

nameserver 145.253.2.75

To set the names of local hosts that are not available through DNS, edit the /etc/hosts file, which has the form:

IP-address  hostname  host

For example:

192.168.1.3 vigor3.your.domain vigor3

5.13. Mounting a CD-ROM

New users are often surprised by the fact that although the installation program recognized and mounted their CD-ROM perfectly, the installed system seems to have “forgotten” how to use the CD-ROM. There is no special magic for using a CD-ROM; you can mount it like any other file system. All you need to know is the device name and some options to the mount(8) command. You can find the device name with the aforementioned dmesg(8) command. For example, if dmesg displays:

# dmesg | grep ^cd
cd0 at atapibus0 drive 1: <ASUS CD-S400/A, , V2.1H> type 5 cdrom removable

the device name is cd0, and you can mount the CD-ROM with the following commands:

# mkdir /cdrom
# mount -t cd9660 -o ro /dev/cd0a /cdrom

To make things easier, you can add a line to the /etc/fstab file:

/dev/cd0a /cdrom cd9660 ro,noauto 0 0

Without the need to reboot, you can now mount the CD-ROM with:

# mount /cdrom

When the CD-ROM is mounted you can't eject it manually; you will have to unmount it before you can do that:

# umount /cdrom

There is also a software command which unmounts the CD-ROM and ejects it:

# eject /dev/cd0a

5.14. Mounting a floppy

To mount a floppy you must know the name of the floppy device and the file system type of the floppy. Read the fdc(4) manpage for more information about device naming, as this will differ depending on the exact size and kind of your floppy disk. For example, to read and write a floppy in MS-DOS format you use the following command:

# mount -t msdos /dev/fd0a /mnt

Instead of /mnt, you can use another directory of your choice; you could, for example, create a /floppy directory like you did for the CD-ROM. If you do a lot of work with MS-DOS floppies, you will want to install the mtools package, which enables you to access a MS-DOS floppy (or hard disk partition) without the need to mount it. It is very handy for quickly copying a file to or from a floppy:

# mcopy foo bar a:
# mcopy a:baz.txt baz
# mcopy a:\*.jpg .

5.15. Installing additional software

Using packages from pkgsrc

If you wish to install any of the software freely available for UNIX-like systems you are strongly advised to first check the NetBSD package system, pkgsrc. pkgsrc automatically handles any changes necessary to make the software run on NetBSD. This includes the retrieval and installation of any other packages on which the software may depend.

  • See the list of available packages

  • Precompiled binaries are available on the NetBSD FTP server for some ports. To install them the PKG_PATH variable needs to be adjusted in the following way (under the sh(1) shell):

    # export PKG_PATH="http://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/<PORT>/<RELEASE-NUMBER>/All"
    # export PKG_PATH

    Where <RELEASE-NUMBER> needs to be replaced by the release number of an existing NetBSD release (for example, 5.0). <PORT> needs to be replaced by the Port name for the used architecture (for example, amd64)

    Applications can now be installed by the superuser root with the pkg_add command:

    # pkg_add -v perl
    # pkg_add -v apache
    # pkg_add -v firefox
    # pkg_add -v kde
        

    The above commands will install the Perl programming language, Apache web server, Firefox web browser and the KDE desktop environment as well as all the packages they depend on.

    Installed applications can be updated in the following way:

    # pkg_add -uv firefox

    The following command will force an update of firefox and all of its dependencies:

    # pkg_add -fuuv firefox

    All details about package management can be found in The pkgsrc guide

Storing third-party software

On many UNIX-like systems the directory structure under /usr/local is reserved for applications and files which are independent of the system's software management. This convention is the reason why most software developers expect their software to be installed under /usr/local. NetBSD has no /usr/local directory, but it can be created manually if needed. NetBSD does not care about anything installed under /usr/local, so this task is left to you as the system administrator.

5.16. Security alerts

By the time that you have installed your system, it is quite likely that bugs in the release have been found. All significant and easily fixed problems will be reported at http://www.NetBSD.org/support/security/. It is recommended that you check this page regularly.

5.17. Stopping and rebooting the system

Use one of the following two shutdown commands to halt or reboot the system:

# shutdown -h now
# shutdown -r now

Two other commands to perform the same tasks are:

# halt
# reboot

halt, reboot and shutdown are not synonyms: the latter is more sophisticated. On a multiuser system you should really use shutdown, which allows you to schedule a shutdown time and notify users. It will also take care to stop processes properly. For more information, see the shutdown(8), halt(8) and reboot(8) manpages.

Chapter 6. Editing

6.1. Introducing vi

It is not like the vi editor needs introducing to seasoned UNIX users. The vi editor, originally developed by Bill Joy of Sun Microsystems, is an endlessly extensible, easy to use light ASCII editor and the bane of the newbie existence. This section will introduce the vi editor to the newbie and perhaps toss in a few ideas for the seasoned user as well.

The first half of this section will overview editing, saving, yanking/putting and navigating a file within a vi session. The second half will be a step by step sample vi session to help get started.

This is intended as a primer for using the vi editor, it is not by any means a thorough guide. It is meant to get the first time user up and using vi with enough skills to make changes to and create files.

6.1.1. The vi interface

Using the vi editor really is not much different than any other terminal based software with one exception, it does not use a tab type (or curses if you will) style interface, although many versions of vi do use curses it does not give the same look and feel of the typical curses based interface. Instead it works in two modes, command and edit. While this may seem strange, it is not much different than windows based editing if you think about it. Take this as an example, if you are using say gedit and you take the mouse, highlight some text, select cut and then paste, the whole time you are using the mouse you are not editing (even though you can). In vi, the same action is done by simply deleting the whole line with dd in command mode, moving to the line you wish to place it below and hitting p in command mode. One could almost say the analogy is “mouse mode vs. command mode” (although they are not exactly identical, conceptually the idea is similar).

To start up a vi session, one simply begins the way they might with any terminal based software:

$ vi filename

One important note to remember here is that when a file is edited, it is loaded into a memory buffer. The rest of the text will make reference to the buffer and file in their proper context. A file only changes when the user has committed changes with one of the write commands.

6.1.2. Switching to Edit Mode

The vi editor sports a range of options one can provide at start up, for the time being we will just look at the default startup. When invoked as shown above, the editors default startup mode is command mode, so in essence you cannot commence to typing into the buffer. Instead you must switch out out of command mode to enter text. The following text describes edit start modes:

a     Append after cursor.
A     Append to end of line.
C     Change the rest of current line.
cw    Change the current word.
i     Insert before cursor.
I     Insert before first non blank line.
o     Open a line below for insert
O     Open a line above for insert.

6.1.3. Switching Modes & Saving Buffers to Files

Of course knowing the edit commands does not do much good if you can't switch back to command mode and save a file, to switch back simply hit the ESC key. To enter certain commands, the colon must be used. Write commands are one such set of commands. To do this, simply enter :.

Hitting the colon then will put the user at the colon (or command if you will) prompt at the bottom left corner of the screen. Now let us look at the save commands:

:w    Write the buffer to file.
:wq   Write the buffer to file and quit.

6.1.4. Yanking and Putting

What good is an editor if you cannot manipulate blocks of text? Of course vi supports this feature as well and as with most of the vi commands it somewhat intuitive. To yank a line but not delete it, simply enter yy or Y in command mode and the current line will be copied into a buffer. To put the line somewhere, navigate to the line above where the line is to be put and hit the p key for the “put” command. To move a line, simply delete the whole line with the dd command, navigate and put.

6.1.4.1. Oops I Did Not Mean to do that!

Undo is pretty simple, u undoes the last action and U undoes the last line deleted or changes made on the last line.

6.1.5. Navigation in the Buffer

Most vi primers or tutorials start off with navigation, however, not unlike most editors in order to navigate a file there must be something to navigate to and from (hence why this column sort of went in reverse). Depending on your flavor of vi (or if it even is vi and not say elvis, nvi or vim) you can navigate in both edit and command mode.

For the beginner I feel that switching to command mode and then navigating is a bit safer until one has practiced for awhile. The navigation keys for terminals that are not recognized or do not support the use of arrow keys are the following:



k     Moves the cursor up one line.
j     Moves the cursor down one line.
l     Moves the cursor right one character.
h     Moves the cursor left one character.

If the terminal is recognized and supports them, the arrow keys can be used to navigate the buffer in command mode.

In addition to simple “one spot navigation” vi supports jumping to a line by simply typing in the line number at the colon prompt. For example, if you wanted to jump to line 223 the keystrokes from editor mode would look like so:

ESC
:223

6.1.6. Searching a File, the Alternate Navigational Aid

The vi editor supports searching using regular expression syntax, however, it is slightly different to invoke from command mode. One simply hits the / key in command mode and enters what they are searching for, as an example let us say I am searching for the expression foo:

/foo

That is it, to illustrate a slightly different expression, let us say I am looking for foo bar:

/foo bar

6.1.6.1. Additional Navigation Commands

Searching and scrolling are not the only ways to navigate a vi buffer. Following is a list of succinct navigation commands available for vi:

0     Move to beginning of line.
$     Move to end of line.
b     Back up one word.
w     Move forward one word.
G     Move to the bottom of the buffer.
H     Move to the top line on the screen.
L     Move to the last line on the screen.
M     Move the cursor to the middle of the screen.
N     Scan for next search match but opposite direction.
n     Scan for next search match in the same direction.

6.1.7. A Sample Session

Now that we have covered the basics, let us run a sample session using a couple of the items discussed so far. First, we open an empty file into the buffer from the command line like so:

# vi foo.txt

Next we switch to edit mode and enter two lines separated by an empty line, remember our buffer is empty so we hit the i key to insert before cursor and enter some text:

This is some text

there we skipped a line
~
~
~
~

Now hit the ESC key to switch back into command mode.

Now that we are in command mode, let us save the file. First, hit the : key, the cursor should be sitting in the lower left corner right after a prompt. At the : prompt enter w and hit the ENTER or RETURN key. The file has just been saved. There should have been a message to that effect, some vi editors will also tell you the name, how many lines and the size of the file as well.

It is time to navigate, the cursor should be sitting wherever it was when the file was saved. Try using the arrow keys to move around a bit. If they do not work (or you are just plain curious) try out the hjkl keys to see how they work.

Finally, let us do two more things, first, navigate up to the first line and then to the first character. Try out some of the other command mode navigation keys on that line, hit the following keys a couple of times:

$
0
$
0

The cursor should hop to the end of line, back to the beginning and then to the end again.

Next, search for an expression by hitting the / key and an expression like so:

/we

The cursor should jump to the first occurrence of we.

Now save the file and exit using write and quit:

:wq

6.2. Configuring vi

The standard editor supplied with NetBSD is, needless to say, vi, the most loved and hated editor in the world. If you don't use vi, skip this section, otherwise read it before installing other versions of vi. NetBSD's vi (nvi) was written by Keith Bostic of UCB to have a freely redistributable version of this editor and has many powerful extensions worth learning while being still very compatible with the original vi. Nvi has become the standard version of vi for BSD.

Amongst the most interesting extensions are:

  • Extended regular expressions (egrep style), enabled with option extended.

  • Tag stacks.

  • Infinite undo (to undo, press u; to continue undoing, press .).

  • Incremental search, enabled with the option searchincr.

  • Left-right scrolling of lines, enabled with the option leftright; the number of columns to scroll is defined by the sidescroll option.

  • Command line history editing, enabled with the option cedit.

  • Filename completion, enabled by the filec option.

  • Backgrounded screens and displays.

  • Split screen editing.

6.2.1. Extensions to .exrc

The following example shows a .exrc file with some extended options enabled.

set showmode ruler
set filec=^[
set cedit=^[

The first line enables the display of the cursor position (row and column) and of the current mode (Command, Insert, Append) on the status line. The second line (where ^[ is the ESC character) enables filename completion with the ESC character. The third line enables command line history editing (also with the ESC character.) For example, writing “:” and then pressing ESC opens a window with a list of the previous commands which can be edited and executed (pressing Enter on a command executes it.)

6.2.2. Documentation

The source tarball (src.tgz) contains a lot of useful documentation on (n)vi and ex, in the /usr/src/usr.bin/vi/docs directory. For example:

  • Edit: A tutorial

  • Ex Reference Manual

  • Vi man page

  • An Introduction to Display Editing with Vi by William Joy and Mark Horton

  • Ex/Vi Reference Manual by Keith Bostic

  • Vi Command & Function Reference

  • Vi tutorial (beginner and advanced)

If you have never used vi, the “Vi tutorial” is a good starting point. It is meant to be read using vi and it gradually introduces the reader to all the vi commands, which can be tested while reading. An Introduction to Display Editing with Vi by William Joy and Mark Horton is also a very good starting point.

If you want to learn more about vi and the nvi extensions you should read the Ex/Vi Reference Manual by Keith Bostic which documents all the editor's commands and options.

6.3. Using tags with vi

This topic is not directly related to NetBSD but it can be useful, for example, for examining the kernel sources.

When you examine a set of sources in a tree of directories and subdirectories you can simplify your work using the tag feature of vi. The method is the following:

  1. cd to the base directory of the sources.

    $ cd /path
  2. Write the following commands:

    $ find . -name "*.[ch]" > filelist
    $ cat filelist | xargs ctags
  3. Add the following line to .exrc

    set tags=/path/tags

    (substitute the correct path instead of path.)

Chapter 7. The rc.d System

NetBSD uses individual scripts for controlling services, similar to what System V and Linux use, but without runlevels. This chapter is an overview of the rc.d system and its configuration.

7.1. Basics

The system startup files reside in the /etc directory. They are:

  • /etc/rc

  • /etc/rc.conf

  • /etc/rc.d/*

  • /etc/rc.lkm

  • /etc/rc.local

  • /etc/rc.shutdown

  • /etc/rc.subr

  • /etc/defaults/*

  • /etc/rc.conf.d/*

First, a look at controlling and supporting scripts (also documented in rc(8)).

  • After the kernel has initialized all devices at startup, it starts init(8), which in turn runs /etc/rc.

  • /etc/rc sorts the scripts in /etc/rc.d using rcorder(8) and then runs them in that order. See the rcorder(8) man page for details of how the order of rc.d scripts is determined.

  • /etc/rc.subr contains common functions used by /etc/rc and various rc.d scripts.

  • When shutting down the system with shutdown(8), /etc/rc.shutdown is run, which runs the scripts in /etc/rc.d in reverse order (as defined by rcorder(8)). Note that if you shut down the system using the halt(8) command, these scripts will not be run.

Additional scripts outside of the rc.d directory:

  • /etc/rc.lkm loads or unloads Loadable Kernel Modules (LKMs). See modload(8) and /etc/rc.d/lkm[123].

  • /etc/rc.local is almost the last script called at boot up. This script can be edited by the administrator to start local daemons that don't fit the rc.d model.

rc.d scripts are controlled by a central configuration file, /etc/rc.conf, which loads its default settings from /etc/defaults/rc.conf. If you want to change a default setting, do not edit /etc/defaults/rc.conf; instead, override the setting in /etc/rc.conf.

It is a good idea to read the rc.conf(5) man page to learn about the services that are available to you.

The following example shows how to enable the SSH daemon, which is disabled by default:

# cd /etc; grep ssh defaults/rc.conf
sshd=NO                 sshd_flags=""
# echo "sshd=YES" >> rc.conf

Now sshd(8) will be started automatically at system startup. The next section describes how to start and stop services at any time.

Last but not least, files can be created in the /etc/rc.conf.d/ directory to override the behavior of a given rc.d script without editing the script itself.

7.2. The rc.d Scripts

The actual scripts that control services are in /etc/rc.d. These scripts are automatically run at boot time, but they can be called manually if necessary. The following example shows how to start the SSH daemon that we enabled in the previous section:

# /etc/rc.d/sshd start
Starting sshd.

Later, if you wish to stop the SSH daemon, run the following command:

# /etc/rc.d/sshd stop
Stopping sshd.
Waiting for PIDS: 123.

The rc.d scripts take one of the following arguments:

  • start

  • stop

  • restart

  • status

Some scripts may support other arguments (e.g., “reload”), but every script will support at least the above commands.

As an example, after adding a new record to a named(8) database, the daemon can be told to reload its configuration files with the following command:

# /etc/rc.d/named reload
Reloading named config files.

Note that all of the commands discussed above will only take action if the particular service is is enabled in /etc/rc.conf. It is possible to bypass this requirement by prepending “one” to the command, as in:

# /etc/rc.d/httpd onestart
Starting httpd.

The above command will allow you to start the httpd(8) service one time. To stop a service that has been started in this manner, pass “onestop” to the script.

7.3. The Role of rcorder and rc.d Scripts

The startup system of every Unix system determines, in one way or another, the order in which services are started. On some Unix systems this is done by numbering the files and/or putting them in separate run level directories. Solaris relies on wildcards like /etc/rc[23].d/S* being sorted numerically when expanded. Some simply put all the commands that should be started into a single monolithic script (this is the traditional BSD method, and is what NetBSD did before the rc.d system). On modern NetBSD this is done by the rc.d scripts and their contents. Please note that NetBSD does not have multiple runlevels as found in SysV-style systems like Solaris and Linux.

At the beginning of each rc.d script there is a series of commented out lines that have one of the following items in them:

  • REQUIRE

  • PROVIDE

  • BEFORE

  • KEYWORD

These describe the dependencies of that particular script and allow rcorder to easily work either “up” or “down” as the situation requires. As an example, here is the ordering information contained in /etc/rc.d/nfsd:

...
 PROVIDE: nfsd
 REQUIRE: rpcbind mountd
...

Here we can see that this script provides the “nfsd” service and that it requires “rpcbind” and “mountd” to be running first. The