This chapter collects various topics, in sparse order, which didn't find a place in the previous chapters.
This section (Creating install boot floppies for i386) has been contributed by Eric Delcamp
First of all, you need to be running a kernel with the vnd pseudo device enabled (this is the default for a GENERIC kernel.).
First, you must create a valid kernel to put on your floppies, let's call it FLOPPY. This kernel must be derived from some INSTALL model. Then, you have a valid /sys/arch/i386/compile/FLOPPY/netbsd file.
Go to /usr/src/distrib/i386/floppies/ramdisk and do
This will create the ramdisk.fs file in the directory.
Go to /usr/src/distrib/i386/floppies/fdset and do
# make KERN=/sys/arch/i386/compile/FLOPPY/netbsd
This will create one or two (depending on the size of kernel) files named boot1.fs and boot2.fs
Transfer these files to the floppies with the commands
# dd if=boot1.fs of=/dev/fd0a bs=36b # dd if=boot2.fs of=/dev/fd0a bs=36b
Put the first floppy in the drive and power on!
To create a data CD-ROM the mkisofs and cdrecord programs can be used: both SCSI and IDE recorders are supported. IDE/ATAPI drives are supported by NetBSD without the need of an emulation layer, because the driver can receive ATAPI commands directly, which is a simple and elegant solution.
Two steps are required to create a CD: first the ISO image of the CD must be created on the hard drive with the mkisofs program. Next, the image must be written to the CD with cdrecord. In the following example an IDE/ATAPI CD-Writer supported by cdrecord is used. This is the dmesg output:
cd1 at atapibus1 drive 0: <HP CD-Writer Plus 8100> type 5 cdrom removable
Note: when burning a CD the execution speed is critical: the data flow to the CD-Writer must be constant and there can be no pauses; the data buffer of cdrecord must never be empty. This means that it is better to burn CD's when the system is idle or nearly idle (don't recompile the kernel or encode an MP3 while you are running cdrecord...)
CD-ROM file systems
CD-ROM's can be created using different (and sometimes incompatible) file systems. Therefore it is possible that a CD created on one system cannot be read (or loses information) on another system. This situation is manifest, for example, when you try to read under NetBSD a CD created under Windows. The following paragraphs give a brief overview of the most common file systems for CD-ROM's.
The ISO9660 is the first format, having appeared in 1988, and represents a sort of common denominator between different operating systems: Apple, MS-DOS, Unix and VMS. A CD-ROM written under Windows with this format will have several limitations: 8.3 format for file names and only 8 levels of nesting for subdirectories. For this reason if, for example, you create a NetBSD installation CD under Windows, the file names which appeared normal with Explorer will be truncated on the CD.
To solve this type of limitation, some sets of extensions to the original ISO9660 format have been introduced. The drawback of these extensions is that they are not supported on all platforms.
The Joliet format, introduced by Microsoft for DOS/Windows systems, extends ISO9660 with the support of long file names and more nested directories. This format is usually not readable by Unix systems (it is supported by NetBSD-current.)
The Rock Ridge extensions were introduced for Unix systems to support Unix conventions for file systems without losing the compatibility with the original ISO9660. This is the format to use when creating a CD under NetBSD or another Unix system (in the following paragraphs it will be explained how to create a CD compatible with both Joliet and Rock Ridge.
In addition to these standards, there are other standards (for example El Torito which are used to produce bootable CD's, supported by all recent PC's.
Since ISO images tend to be quite large, it is better to check that there is sufficient space on the hard disk for the data that you are writing (up to 700MB.) To create the image, if the data are in the mydata directory and its subdirectories, write the following command:
# mkisofs -aflrTv -o cdimage mydata/
When the cdimage file has been created, it can be examined and browsed like a regular file system, to check that there are no errors before writing it to the CD. For example:
# ls -l cdimage -rw-rw-r-- 1 auser user 284672 Dec 1 11:58 cdimage # vnconfig -v vnd0 cdimage 512/556/1/1 # mount -r -t cd9660 /dev/vnd0c /mnt ... browsing su /mnt ... # umount /mnt # vnconfig -u vnd0
The value 556 is the result of the size of the cdimage file divided by 512.
Creating a hybrid CD: mkisofs can create CDs using the Joliet format; such CDs will be readable on Microsoft platforms. It is also possible to create hybrid CDs, with both RockRidge and Joliet extensions, which will be readable on Unix and Windows platforms. For example:$ mkisofs -l -J -R -o cd.iso mydata/
Check the mkisofs man page for the details of the available options.
In the second step the image is written to the CD with the following command:
# cdrecord -v speed=2 dev=/dev/rcd1d cdimage
Note: for ATAPI drives the rcd#d must be used because the a device does not accept ATAPI commands.
before writing the image it is possible to perform a test, disabling the laser: just add the -dummy and -nofix options to the command line. For example:
# cdrecord -v -dummy -nofix speed=2 dev=/dev/rcd1d cdimage
The two steps, creating and burning the image, can be combined in a single command, without the need to create a (big) temporary file on the hard disk. The command looks like this:
# (nice -18 mkisofs -aflrT mydata/) | cdrecord -v fs=16m speed=2 dev=/dev/rcd1d -
The option fs=16m is used to allocate a bigger fifo, avoiding cdrecord buffer underflow errors (this means that cdrecord has no data to write.)
To copy directly a CD the -isosize option of cdrecord can be used. For example:
# cdrecord -v fs=16m -isosize speed=2 dev=/dev/rcd1d /dev/rcd0d
Note: if you are using two IDE/ATAPI CD(-RW) it is better if they are connected to two different IDE controllers (one to the primary and one to the secondary) because the data flow is better. This is an example configuration:wd0: hard disk, IDE primary master cd0: CD reader, IDE primary slave cd1: CD writer, IDE secondary master
Creating a bootable CD is only a matter of having a boot binary file to put on the CD: this boot file emulates a floppy. Then the -b option of mkisofs can be used. For example:
# mkisofs -avr -b boot.fs -o cdimage mydata/
boot.fs is the boot binary for the CD. Note that the path of boot.fs must be relative to the mydata/ directory.
It is not unusual to find that the system clock is wrong, often by several minutes: for some strange reason it seems that computer clocks are not very accurate. The problem gets worse if you administer many networked hosts: keeping the clocks in sync can easily become a nightmare. To solve this problem, the NTP protocol (version 3) comes to our aid: this protocol can be used to synchronize the clocks of a network of workstations using one or more NTP servers.
Thanks to the NTP protocol it is possible to adjust the clock of a single workstation but also to synchronize an entire network. The NTP protocol is quite complex, defining a hierarchical master-slave structure of servers divided in strata: the top of the hierarchy is occupied by stratum 1 servers, connected to an external clock (ex. a radio clock) to guarantee a high level of accuracy. Underneath, stratum 2 servers synchronize their clocks with stratum 1, and so on. The accuracy decreases as we proceed towards lower levels. This hierarchichal structure avoids the congestion which could be caused by having all hosts refer to the same (few) stratum 1 servers. If, for example, you want to synchronize a network, you don't connect all the hosts to the same public stratum 1 server. Instead, you create a local server which connects to the main server and the remaining hosts synchronize their clocks with the local server.
Fortunately, to use the NTP tools you don't need to understand the details of the protocol and of its implementation (if you are interested, refer to RFC 1305) and you only need to know how to configure and start some programs. The base system of NetBSD already contains the necessary tools to utilize this protocol (and other time related protocols, as we'll see), derived from the xntp implementation. This section describes a simple method to always have a correct system time.
First, it is necessary to find the address of the public NTP servers to use as a reference; a detailed listing can be found at http://www.eecis.udel.edu/~mills/ntp/servers.html. As an example, for Italy the two stratum 1 servers tempo.cstv.to.cnr.it and time.ien.it can be used.
Next, to adjust the system clock give the following command as root:
# ntpdate -b tempo.cstv.to.cnr.it time.ien.it(substitute the names ot the servers in the example with the ones that you are actually using. Option -b tells ntpdate to set the system time with the settimeofday system call, instead of slewing it with adjtime (the default.) This option is suggested when the difference between the local time and the correct time can be considerable.
As you've seen, ntpdate is not difficult to use. The next step is to start it automatically, in order to always have the correct system time. If you have a permanent connection to the Internet, you can start the program at boot with the following line of /etc/rc.conf:
ntpdate=YES ntpdate_hosts="time.ien.it"The name of the NTP server to use is specified in the ntpdate_hosts variable; if you leave this field empty, the boot script will try to extract the name from the /etc/ntp.conf file.
If you don't have a permanent Internet connection (ex. you have a dial-up modem connection through an ISP) you can start ntpdate from the ip-up script, as explained in Chapter 10. In this case add the following line to the ip-up script:
/usr/sbin/ntpdate -s -b time.ien.it(the path is mandatory or the script will probably not find the executable.) Option -s diverts logging output from the standard output (this is the default) to the system syslog(3) facility, which means that the messages from ntpdate will usually end up in /var/log/messages.
Besides ntpdate there are other useful NTP commands. It is also possible to turn one of the local hosts into an NTP server for the remaining hosts of the network. The local server will synchronize its clock with a public server. For this type of configuration you must use the xntpd daemon and create the /etc/ntp.conf configuration file. For example:
server time.ien.it server tempo.cstv.to.cnr.it
Xntpd can be started too from rc.conf, using the relevant option:
NTP is not your only option if you want to synchronize your network: you can also use the timed daemon, which was developed for 4.3BSD. Timed too uses a master-slave hierarchy: when started on an host, timed asks the network time to a master and ajusts the local clock accordingly. A mixed structure, using both timed and xntpd can be used. One of the local hosts gets the correct time from a public NTP server and is the timed master for the remaining hosts of network, which become its clients and synchronize their clocks using timed. This means that the local server must run both NTP and timed; care must be taken that they don't interfere with each other (timed must be started with the -F hostname option so that it doesn't try to adjust the local clock.)
Sysinst, the NetBSD installation program, can install the NetBSD boot manager on the hard disk. The boot manager can also be installed or reconfigured at a later time, if needed, with the fdisk command. For example:
# fdisk -B wd0
If NetBSD doesn't boot from the hard disk, you can boot it from the installation floppy and start the kernel on the hard disk. Insert the installation disk and, at the boot prompt, give the following command:
> boot wd0a:netbsd
This boots the kernel on the hard disk (use the correct device, for example sd0a for a SCSI disk.)
Note: sometimes fdisk -B doesn't give the expected result (at least it happened to me), probably if you install/remove other operating systems like Windows 95. In this case, try a fdisk /mbr from DOS and then run again fdisk from NetBSD.
Though this is not an operation that you need to perform frequently, it can be useful to know how to do it in case of need. Please be sure to know exactly what you are doing before performing this kind of operation. For example:
# dd if=/dev/zero of=/dev/rwd0c bs=8k count=1
The previous command deletes the disklabel (not the MBR partition table.) To completely delete the disk, the wd0d device must be used. For example:
# dd if=/dev/zero of=/dev/rwd0d bs=8k
I found this tip on a mailing list (I don't remember the author.) To output a sound from the speaker (for example at the end of a long script) the kernel spkr device can be used, which is mapped on /dev/speaker. For example:
echo 'BPBPBPBPBP' > /dev/speaker
Note: the spkr device is not enabled in the generic kernel; a customized kernel is needed.
If you forget root's password, not all is lost and you can still "recover" the system with the following steps: boot single user, mount / and change root's password. In detail:
Boot single user: when the boot prompt appears and the five seconds countdown starts, give the following command:
> boot -s
At the following prompt
Enter pathname of shell or RETURN for sh:press Enter.
Write the following commands:
# fsck -y / # mount -u / # fsck -y /usr # mount /usr
Change root's password with passwd.
Use the exit command to go to multiuser mode.
This section describes how to add a new hard disk to an already working NetBSD system. In the following example a new SCSI controller and a new hard disk, connected to the controller, will be added. If you don't need to add a new controller, skip the relevant part and go to the hard disk configuration. The installation of an IDE hard disk is identical; only the device name will be different (wd# instead of sd#).
As always, before buying new hardware, consult the hardware compatibility list of NetBSD and make sure that the new device is supported by the system.
When the SCSI controller has been physically installed in the system and the new hard disk has been connected, it's time to restart the computer and check that the device is correctly detected, using the dmesg command. This is the sample output for an NCR-875 controller:
ncr0 at pci0 dev 15 function 0: ncr 53c875 fast20 wide scsi ncr0: interrupting at irq 10 ncr0: minsync=12, maxsync=137, maxoffs=16, 128 dwords burst, large dma fifo ncr0: single-ended, open drain IRQ driver, using on-chip SRAM ncr0: restart (scsi reset). scsibus0 at ncr0: 16 targets, 8 luns per target sd0(ncr0:2:0): 20.0 MB/s (50 ns, offset 15) sd0: 2063MB, 8188 cyl, 3 head, 172 sec, 512 bytes/sect x 4226725 sectorsIf the device doesn't appear in the output, check that it is supported by the kernel that you are using; if necessary, compile a customized kernel (see Chapter 7.)
Now the partitions can be created using the fdisk command. First, check the current status of the disk:
# fdisk sd0 NetBSD disklabel disk geometry: cylinders: 8188 heads: 3 sectors/track: 172 (516 sectors/cylinder) BIOS disk geometry: cylinders: 524 heads: 128 sectors/track: 63 (8064 sectors/cylinder) Partition table: 0: sysid 6 (Primary 'big' DOS, 16-bit FAT (> 32MB)) start 63, size 4225473 (2063 MB), flag 0x0 beg: cylinder 0, head 1, sector 1 end: cylinder 523, head 127, sector 63 1: <UNUSED> 2: <UNUSED> 3: <UNUSED>
In this example the hard disk already contains a DOS partition, which will be deleted and replaced with a native NetBSD partition. The command fdisk -u sd0 allows to modify interactively the partitions. The modified data will be written on the disk only before exiting and fdisk will request a confirmation before writing, so you can work relaxedly.
The geometry of the disk reported by fdisk can appear confusing. Dmesg reports 4226725 sectors with 8188/3/172 for C/H/S, but 8188*3*172 gives 4225008 and not 4226725. What happens is that most modern disks don't have a fixed geometry and the number of sectors per track changes depending on the cylinder: the only interesting parameter is the number of sectors. The disk reports the C/H/S values but it's a fictitious geometry: the value 172 is the result of the total number of sectors (4226725) divided by 8188 and then by 3.
To make things more confusing, the BIOS uses yet another "fake" geometry (C/H/S 524/128/63) which gives a total of 4225536, a value which is a better approximation to the real one than 425008. To partition the disk we will use the BIOS geometry, to mantain compatibility with other operating systems, although we will loose some sectors (4226725 - 4225536 = 1189 sectors = 594 KB.)
To create the BIOS partitions the command fdisk -u must be used; the result is the following:
Partition table: 0: sysid 169 (NetBSD) start 63, size 4225473 (2063 MB), flag 0x0 beg: cylinder 0, head 1, sector 1 end: cylinder 523, head 127, sector 63 1: <UNUSED> 2: <UNUSED> 3: <UNUSED>
Now it's time to create the disklabel fot the NetBSD partition. The correct steps to do this are:
# disklabel sd0 > tempfile # vi tempfile # disklabel -R -r sd0 tempfile
Now we create some disklabel partitions, editing the tempfile as already explained. The result is:
# size offset fstype [fsize bsize cpg] a: 2048004 63 4.2BSD 1024 8192 16 # (Cyl. 0*- 3969*) c: 4226662 63 unused 0 0 # (Cyl. 0*- 8191*) d: 4226725 0 unused 0 0 # (Cyl. 0 - 8191*) e: 2178658 2048067 4.2BSD 1024 8192 16 # (Cyl. 3969*- 8191*)
Note: when the disklabel has been created it is possible to optimize it studying the output of the command newfs -N /dev/sd0a, which warns about the existence of unallocated sectors at the end of a disklabel partition. The values reported by newfs can be used to adjust the sizes of the partitions with an iterative process.
The final operation is the creation of the file systems for the newly defined partitions (a and e.)
# newfs /dev/sd0a # newfs /dev/sd0eThe disk is now ready for usage, and the two partitions can be mounted. For example:
# mount /dev/sd0a /mnt
If you try to modify a password and you get the mysterious message "Password file is busy", it probably means that the file /etc/ptmp has not been deleted from the system. This file is a temporary copy of the /etc/master.passwd file: check that you are not loosing important information and then delete it (ptmp, not master.passwd.)
Note: if the file /etc/ptmp exists you can also receive a warning message at system startup. For example:root: password file may be incorrect - /etc/ptmp exists
This section has been contributed by Reinoud Koornstra
First shutdown to single user, partitions still mounted "rw" (read-write); You can do that by just typing shutdown now while you are in multi user mode, or reboot with the -s option and make / and /dev read-writable by doing.
# mount -u / # mount -u /dev
# mkdir /nudev # cd /nudev # cp /dev/MAKEDEV* . # sh ./MAKEDEV all # cd / # mv dev odev # mv nudev dev # rm -r odev
Or if you fetched all the sources in /usr/src:
# mkdir /nudev # cd /nudev # cp /usr/src/etc/MAKEDEV.local . # cp /usr/src/etc/etc.$arch/MAKEDEV . # sh ./MAKEDEV all # cd / # mv dev odev; mv nudev dev # rm -r odev
You can determine $arch by
# uname -m
# sysctl hw.machine_arch
Using the second way by copying the new MAKEDEV's from the source tree will add some additional devices in at least the i386 architecture. For example now it's possible to have 16 partitions instead of 8. If you use the "old" MAKEDEV's from /dev, the additional devices wont be made.