Q. How do I add a second hard disk to my FreeBSD server? How do I partition, label and mount a new hard disk under FreeBSD for backup or additional data?
A. There are two ways to install a new hard disk under FreeBSD system. You can use all command line utilities such as fdisk,bsdlabel and newfs to create partitions, label and format it. This method requires complete understanding of BSD partitions and other stuff.
Using sysinstall - Easy way to add a new hard disk
The sysinstall utility is used for installing and configuring FreeBSD systems including hard disks. sysinstall offers options to partition and label a new disk using its easy to use menus. Login as root user. Run sysinstall and enter the Configure menu. Within the FreeBSD Configuration Menu, scroll down and select the Fdisk option:
Alternatively, use sudo (if configured) to run sysinstall:
$ sudo sysinstall
The new drive will probably be the second in the list with a name like ad1 or ad2 and so on. In above example it is ad6.
Once inside fdisk, pressing A will use the entire disk for FreeBSD. When asked if you want to "remain cooperative with any future possible operating systems", answer YES. Write the changes to the disk using W. Now exit the FDISK editor by pressing Q. Next you will be asked about the "Master Boot Record". Since you are adding a disk to an already running system, choose None. The next dialog will say that the operation was successful. Press [enter]. Type Q to quit FDISK.
Next, you need to exit sysinstall and start it again. Restart sysinstall by typing sysinstall:
Select Configure and press [enter]. Select Label and press [enter]. A dialog asking you to select the drive will appear. Select the appropriate drive and press [enter].
This is where you will create the traditional BSD partitions:
- A disk can have up to eight partitions, labeled a-h.
- The a partition is used for the root partition (/). Thus only your system disk (e.g, the disk you boot from) should have an a partition.
- The b partition is used for swap partitions, and you may have many disks with swap partitions.
- The c partition addresses the entire disk in dedicated mode, or the entire FreeBSD slice in slice mode.
- The other partitions are for general use.
Now press C to create a partition.
- Set partition size, to use the whole drive, press [enter].
- Next, choose fs and press [enter].
- Type /disk2 as mount point and press [enter] (don't use the name of a directory that already exists because sysinstall will mount the new partition on top of it)
- To finalize the changes, press W, select yes and press [enter].
The last step is to edit /etc/fstab to add an entry for your new disk, enter:
# vi /etc/fstab
Append entry like as follows (make sure you replace parition name with actual values):
/dev/ad6s1d /disk2 ufs rw 2 2
Here is my sample /etc/fstab file:
/dev/ad4s1a 520M 393M 85M 82% / devfs 1.0k 1.0k 0B 100% /dev /dev/ad6s1d 243G 75G 148G 34% /disk2 /dev/ad4s1d 520M 22M 456M 5% /tmp /dev/ad4s1f 230G 4.6G 207G 2% /usr /dev/ad4s1e 10G 130M 9.4G 1% /var devfs 1.0k 1.0k 0B 100% /var/named/dev devfs 1.0k 1.0k 0B 100% /usr/home/jail/www.example.com/dev
Save and close the file. The new drive should mount automatically at /disk2 after reboot. To mount it immediately, enter:
# mount -a
# df -H