Copyright © 1999, 2000, 2001, 2002 Federico Lupi
Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The NetBSD Foundation
Published: 2010/01/16 07:55:45
$NetBSD: netbsd.xml,v 1.8 2010/01/16 07:55:45 snj Exp $
Table of Contents
List of Figures
List of Tables
List of Examples
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
(<www@NetBSD.org>). Corrections and suggestions
should be sent to that address. See also Appendix B, Contributing to the NetBSD guide.
Table of Contents
Table of Contents
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.
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.
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.
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.
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.
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
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.
Table of Contents
Table of Contents
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.
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.
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.
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
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.
The meaning of partitions “c” and “d” is typical of the i386 port. On most other ports, “c” represents the whole disk.
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.
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.
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)
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!
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/
Please see the list of mirrors and choose a local server near you for downloads
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.
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.
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:
Format the floppy.
Go to the I386\INSTALLATION\FLOPPY directory
of the CD-ROM.
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
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.
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
Table of Contents
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.
The following install screens are just examples. Do not simply copy them, as your hardware and configuration details may be different!
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).
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 |
| ' | à | ä | ù |
| ` | \ | ^ | @ |
| \ | ù | # | ` |
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.
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.
This will bring you to the main menu of the installation program (Figure 3.3, “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.
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.
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”.
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.
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.
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.
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”.
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.
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”.
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.
Do not confuse the slices or BIOS partitions with the BSD partitions, which are different things.
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?”.
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”.
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”.
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”.
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.
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”.
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.
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.
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.
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).
If you don't know the name of the CD-ROM/DVD device, you can find by doing the following:
Press Ctrl-Z to pause sysinst and go to the shell prompt.
Type the command:
#dmesg
This will show the kernel startup messages, including the name of the CD-ROM device, for example cd0.
If the display scrolls too quickly, you can also use more:
#dmesg | more
Go back to the installation program with the command:
#fg
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".
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".
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.
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.
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 -ane2: 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
Next, you have a chance to set your network medium.
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 ne2ne2: 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.27, “Entering and configuring network data” shows the questions asked for the network configuration. The values to be entered are:
This is the name of the domain you are in.
The name by which other machines can usually address your computer. Not used during installation.
Enter your numerical Internet Protocol address in “dotted quad” notation here, for example, 192.168.1.3
The netmask for your network, either given as a hex value (“0xffffff00”) or in dotted-quad notation (“255.255.255.0”).
Your router's (or default gateway's) IP address. Do not use a hostname here!
Your (first) DNS server's IP address. Again, don't use a hostname.
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”).
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.
If you want to install NetBSD from a server in your local network, NFS is an alternative to FTP.
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.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.
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.
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.
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.
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.
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.
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.
At this point the installation is finished.
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.
Table of Contents
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.
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.
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
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.
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.
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.
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”.
At this point, sysinst will perform a check of the file system to ensure its integrity.
The next step is to choose which type of bootblocks to install.
The next dialog will ask how much information should be displayed during the extraction of the distribution sets.
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”.
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.
When you are back at the main menu, remove the boot medium (if applicable) and reboot. Have fun with your new version of NetBSD!
Table of Contents
Table of Contents
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.
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.
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.
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:
general commands (tools and utilities), see intro(1)
system calls and error numbers, see intro(2)
C libraries, see intro(3)
special files and hardware support, see intro(4)
file formats, see intro(5)
games, see intro(6)
miscellaneous information pages, see intro(7)
system maintenance and operation commands, see intro(8)
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
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.
Before you continue you should know or learn how to open, edit and save files within vi. Make sure to read Chapter 6, Editing.
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:rootpassword:We recommend creating a non-root account and using su(1) for root access.#
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/passwdChanging 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.
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
You can edit /etc/group directly to add
users to groups, but do not edit
the /etc/passwd directly; use vipw(8).
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.
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=itencoding -> 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.
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_offsetkern.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
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.
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”.
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-addresshostnamehost
For example:
192.168.1.3vigor3.your.domainvigor3
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 ^cdcd0 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
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 .
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"#exportPKG_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
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.
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.
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.
Table of Contents
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.
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:
$vifilename
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.
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.
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.
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.
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
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
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.
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
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.
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.)
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.
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:
cd to the base directory of the sources.
$cd/path
Write the following commands:
$find . -name "*.[ch]" >filelist$catfilelist| xargs ctags
Add the following line to .exrc
set tags=/path/tags
(substitute the correct path instead of path.)
Table of Contents
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.
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.confsshd=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.
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 startStarting sshd.
Later, if you wish to stop the SSH daemon, run the following command:
#/etc/rc.d/sshd stopStopping 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 reloadReloading 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 onestartStarting 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.
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