Friday, December 26, 2003

Adding a New Disk in NetBSD

People complain about FreeBSD's '/stand/sysinstall' program, but I wish I could have used it yesterday when adding an 8 GB HDD to my NetBSD box. I loosely followed the official documentation but laughed when I read "Now we create some disklabel partitions, editing the tempfile as already explained. The result is...", followed by a disklabel output created from scratch! This reminded me of the "intuitively obvious" phrase from my college calculus books.

Here's how I did it. This is what the disk looked in dmesg output:

wd1 at pciide0 channel 0 drive 1:
wd1: drive supports 16-sector PIO transfers, LBA addressing
wd1: 8063 MB, 16383 cyl, 16 head, 63 sec, 512 bytes/sect x 16514064 sectors
wd1: 32-bit data port
wd1: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 2 (Ultra/33)
wd1(pciide0:0:1): using PIO mode 4, Ultra-DMA mode 2 (Ultra/33) (using DMA data
transfers)

First I ran fdisk. Notice the BIOS never seems to get the HDD geometry correct. Luckily the OS makes good guesses and I remembered the geometry when I saw it on the HDD label:

bash-2.05b# fdisk -u wd1
Disk: /dev/rwd1d
NetBSD disklabel disk geometry:
cylinders: 16383 heads: 16 sectors/track: 63 (1008 sectors/cylinder)

BIOS disk geometry:
cylinders: 1023 heads: 255 sectors/track: 63 (16065 sectors/cylinder)

Do you want to change our idea of what BIOS thinks? [n] y
BIOS's idea of #cylinders: [1023] 16383
BIOS's idea of #heads: [255] 16
BIOS's idea of #sectors: [63] 63
Disk: /dev/rwd1d
NetBSD disklabel disk geometry:
cylinders: 16383 heads: 16 sectors/track: 63 (1008 sectors/cylinder)

BIOS disk geometry:
cylinders: 16383 heads: 16 sectors/track: 63 (1008 sectors/cylinder)

Are you happy with this choice? [n] y
Partition table:
The data for partition 0 is:
sysid 11 (Primary DOS with 32 bit FAT)
start 63, size 5445972 (2659 MB), flag 0x80
beg: cylinder 0, head 1, sector 1
end: cylinder 338, head 254, sector 63
Do you want to change it? [n] y
sysid: [11] 169
start: [63]
size: [5445972] 8000M
8000M is not a valid decimal number.
size: [5445972] 16384000
Explicitly specify beg/end address? [n] n
sysid 169 (NetBSD)
start 63, size 16384000 (8000 MB), flag 0x80
beg: cylinder 0, head 1, sector 1
end: cylinder 894, head 0, sector 31
Is this entry okay? [n] y
The data for partition 1 is:
sysid 15 (Ext. partition - LBA)
start 5446035, size 11020590 (5381 MB), flag 0x0
beg: cylinder 339, head 0, sector 1
end: cylinder 1022, head 254, sector 63
Extended partition table:
0: sysid 11 (Primary DOS with 32 bit FAT)
start 5446098, size 5510232 (2690 MB), flag 0x0
beg: cylinder 339, head 1, sector 1
end: cylinder 681, head 254, sector 63
1: sysid 5 (Extended partition)
start 10956330, size 5510295 (2690 MB), flag 0x0
beg: cylinder 682, head 0, sector 1
end: cylinder 0, head 254, sector 63
Extended partition table:
0: sysid 11 (Primary DOS with 32 bit FAT)
start 10956393, size 5510232 (2690 MB), flag 0x0
beg: cylinder 682, head 1, sector 1
end: cylinder 0, head 254, sector 63
1:
2:
3:
2:
3:
Do you want to change it? [n] y
sysid: [15] 0
start: [5446035] 0
size: [11020590] 0
Explicitly specify beg/end address? [n]

Is this entry okay? [n] y
The data for partition 2 is:

Do you want to change it? [n] n
The data for partition 3 is:

Do you want to change it? [n] n

We haven't written the MBR back to disk yet. This is your last chance.
Disk: /dev/rwd1d
NetBSD disklabel disk geometry:
cylinders: 16383 heads: 16 sectors/track: 63 (1008 sectors/cylinder)

BIOS disk geometry:
cylinders: 16383 heads: 16 sectors/track: 63 (1008 sectors/cylinder)

Partition table:
0: sysid 169 (NetBSD)
start 63, size 16384000 (8000 MB), flag 0x80
beg: cylinder 0, head 1, sector 1
end: cylinder 894, head 0, sector 31
1:
2:
3:
Should we write new partition table? [n] y

Next I created a disklabel:

bash-2.05b# disklabel -i -I wd1

Basically I messed around with disklabel until something that looked ok was produced. I'm not sure how to get rid of the 'd' and 'e' entries or if it's possible. My understanding is that a is the 'root' partition, 'b' is usually the swap file, 'c' is the entire disk, and 'd' and on are other paritions. This is a second non-booting disk:

8 partitions:
# size offset fstype [fsize bsize cpg/sgs]
a: 16514001 63 4.2BSD 0 0 0 # (Cyl. 0*- 16382)
c: 16514064 0 unused 0 0 # (Cyl. 0 - 16382)
d: 16514064 0 unused 0 0 # (Cyl. 0 - 16382)
e: 16384000 63 unused 0 0 # (Cyl. 0*- 16254*)

Then I did 'newfs':

bash-2.05b# newfs /dev/wd1a

Warning: 64 sector(s) in last cylinder unallocated
/dev/wd1a: 16514000 sectors in 16383 cylinders of 16 tracks, 63 sectors
8063.5MB in 50 cyl groups (328 c/g, 161.44MB/g, 20352 i/g)
super-block backups (for fsck -b #) at:
32, 330720, 661408, 992096, 1322784, 1653472, 1984160,
2314848, 2645536, 2976224, 3306912, 3637600, 3968288, 4298976,
4629664, 4960352, 5290016, 5620704, 5951392, 6282080, 6612768,
6943456, 7274144, 7604832, 7935520, 8266208, 8596896, 8927584,
9258272, 9588960, 9919648, 10250336, 10580000, 10910688, 11241376,
11572064, 11902752, 12233440, 12564128, 12894816, 13225504, 13556192,
13886880, 14217568, 14548256, 14878944, 15209632, 15540320, 15869984,
16200672,

When done I could mount the new drive on a new directory called '/var/extra':

bash-2.05b# mount /dev/wd1a /var/extra

I added the last entry to /etc/fstab:

/dev/wd0a / ffs rw 1 1
/dev/wd0b none swap sw 0 0
/dev/wd0e /var ffs rw 1 2
/dev/wd0f /home ffs rw 1 2
/dev/wd0g /tmp ffs rw 1 2
/dev/wd1a /var/extra ffs rw 1 2