UNIX System Administration Handbook - Evi Nemeth [100]
We refer to our disk by the device files /dev/da0 and /dev/rda0, which are, respectively, the block and character (raw) devices for the entire disk. These names followed by a letter (e.g., /dev/da0a) specify a BSD partition (a-h) on the first FreeBSD slice. The four slices can be accessed separately through the files /dev/[r]da0s[1-4]. Your device names may vary depending on your disk controller, so double-check that you are referring to the right device for your disk before you go and format it.
As with other operating systems, the utility to edit slices is called fdisk. fdisk can be run in automatic mode or in interactive mode. Until you have added a few disks by hand, the interactive mode is simplest. You can edit the current slice table with the -e flag or create a new one with the -i flag.
# fdisk -i da0
The default with -i is to make the entire disk a FreeBSD slice and to make it slice 4. Since FreeBSD is the only operating system that we are going to use on this disk, we’ll just accept the defaults (the session is not shown). You may need to experiment if you are editing an existing partition table. fdisk will try to warn you if you are doing anything that might affect other operating systems. Remember that nothing is saved until you allow fdisk to write out the new slice table, so you can always start over.
After the new slices have been written out, we run fdisk again to make sure everything looks good:
# fdisk da0
******* Working on device /dev/rda0 *******
parameters extracted from in-core disklabel are:
cylinders=261 heads=255 sectors/track=63 (16065 blks/cyl)
parameters to be used for BIOS calculations are:
cylinders=261 heads=255 sectors/track=63 (16065 blks/cyl)
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
The data for partition 2 is: The data for partition 3 is: The data for partition 4 is: sysid 165,(FreeBSD/NetBSD/386BSD) start 1, size 4192964 (2047 Meg), flag 80 (active) beg: cyl 0/ sector 2/ head 0; end: cyl 260/ sector 63/ head 254 Our new slice is now ready to be labeled. A BSD disk label (partition label, really) allows up to 8 partitions, named a through h. Partition a is normally used for the root partition, b for swap, and c for the whole slice. To write the label, you use disklabel with the -r and -w flags. The -r flag tells disklabel to access the disk directly rather than using the device driver’s notion of what the disk label is, which is likely to be wrong when you are dealing with a new disk. The -w flag takes as arguments the disk device name and the type of disk as specified in /etc/disktab. For most disks, you can specify the disk type as auto; disklabel uses autodetected parameters to write a basic label. For example: # disklabel -r -w da0 auto If automatic detection does not work, you will have to create a new entry for your disk in /etc/disktab. Once a label has been written, you can edit it with disklabel -e. This command converts the disk label to a nice human-readable format and starts a vi session on the results. If the numbers do not look right, you can change them within the editor. The partition information appears at the bottom of the file. If you did not specify an /etc/disktab entry when labeling the disk, you will probably start with a single partition that contains the entire slice. You can copy that line to use as the basis for other partitions. Update the partition letter, the size in sectors, the offset, the filesystem type (4.2BSD or swap), and the fragment and block sizes to be used by newfs. We partitioned our disk with a 1GB root partition and a 1GB swap partition, as shown below. The device passed to disklabel, /dev/rda0c, specifies the raw FreeBSD slice that we want to partition. # disklabel -r -e /dev/rda0c type: SCSI