> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-27-the-ufs-file-system/di-27.2-jie-tian-jia-ufs-ci-pan.md).

# 27.2 Adding UFS Disks

This section describes how to add a new NVMe Solid-State Drive (SSD) to a computer that currently has only one disk. First, power off the computer and install the disk according to the instructions from the computer, controller, and disk manufacturers. Restart the system and switch to the `root` user.

Check the **/var/run/dmesg.boot** file to ensure the new disk has been recognized.

```sh
nda1 at nvme0 bus 0 scbus2 target 0 lun 2
nda1: <VMware Virtual NVMe Disk 1.4 VMware NVME_0000>
nda1: Serial Number VMware NVME_0000
nda1: nvme version 1.4
nda1: 10240MB (20971520 512 byte sectors)

...other irrelevant output omitted...
```

In this example, the newly added 10G NVMe disk appears as **nda1**.

## Creating a Partition Table

This example creates a single partition on the new disk. The GPT partition scheme is preferred over the less flexible MBR scheme.

> **Note**
>
> If the disk to be added is not empty, you can use `gpart delete` to remove old partition information.
>
> **Example 1** Delete partition **1** on disk **nda1**:
>
> ```sh
> # gpart delete -i 1 nda1
> ```
>
> **Example 2** Destroy the entire partition table and all partitions on disk **nda1**:
>
> ```sh
> # gpart destroy -F nda1
> ```

Create a GPT partition table for **nda1**:

```sh
# gpart create -s GPT nda1
```

## Creating a Single Partition

Then add a partition. To improve performance on disks with larger hardware block sizes, the partition is aligned to a 1MB boundary:

```sh
# gpart add -t freebsd-ufs -a 1M nda1
```

> **Tip**
>
> The `-t` option here only writes the partition type GUID; it does not perform actual formatting and is unrelated to the file system being formatted.

You can use `gpart show` to view disk partition information:

```sh
# gpart show -p nda1
=>      40  20971440    nda1  GPT  (10G)
        40      2008          - free -  (1004K)
      2048  20967424  nda1p1  freebsd-ufs  (10G)
  20969472      2008          - free -  (1004K)
```

The above commands created a GPT partition table and a new 10G disk partition **nda1p1** using the UFS file system.

## Creating Multiple Partitions

For convenience, multiple partitions can be created.

The following creates 4 partitions on disk **nda1** with capacities of 1GB, 2GB, 3GB, and 4GB respectively. Use the `-s` parameter to specify partition sizes (supports units such as G and M).

* Create the 1st partition: 1G

```sh
# gpart add -t freebsd-ufs -a 1M -s 1G nda1
```

* Create the 2nd partition: 2G

```sh
# gpart add -t freebsd-ufs -a 1M -s 2G nda1
```

* Create the 3rd partition: 3G

```sh
# gpart add -t freebsd-ufs -a 1M -s 3G nda1
```

* Create the 4th partition using all remaining capacity:

```sh
# gpart add -t freebsd-ufs -a 1M nda1
```

You can use `gpart show` to view disk partition information:

```sh
# gpart show -p nda1
=>      40  20971440    nda1  GPT  (10G)
        40      2008          - free -  (1004K)
      2048   2097152  nda1p1  freebsd-ufs  (1.0G)
   2099200   4194304  nda1p2  freebsd-ufs  (2.0G)
   6293504   6291456  nda1p3  freebsd-ufs  (3.0G)
  12584960   8384512  nda1p4  freebsd-ufs  (4.0G)
  20969472      2008          - free -  (1004K)
```

The above commands created partitions **nda1p1**, **nda1p2**, **nda1p3**, and **nda1p4** respectively.

## Formatting the File System

Create a file system on the new partition of the new disk:

```sh
# newfs -U /dev/nda1p1
```

Format **/dev/nda1p1**, **/dev/nda1p2**, **/dev/nda1p3**, and **/dev/nda1p4** all at once:

```sh
# for i in 1 2 3 4; do newfs -U /dev/nda1p$i; done
```

## Mounting the File System

Create an empty directory as a **mount point**, which is the location in the original disk's file system where the new disk will be mounted:

```sh
# mkdir -p /mnt/newdisk
```

Temporarily mount **/dev/nda1p3** to **/mnt/newdisk**:

```sh
# mount /dev/nda1p3 /mnt/newdisk
```

Perform a write test:

```sh
# cd /mnt/newdisk && touch test.txt
/mnt/newdisk # ls -al
total 9
drwxr-xr-x  3 root wheel    512 May 30 17:42 .
drwxr-xr-x  4 root wheel      4 May 30 17:39 ..
drwxrwxr-x  2 root operator 512 May 30 17:32 .snap
-rw-r--r--  1 root wheel      0 May 30 17:42 test.txt
```

Finally, add an entry in **/etc/fstab** to automatically mount the new disk at startup:

```sh
/dev/nda1p3     /mnt/newdisk    ufs     rw              0       0
```

You can manually mount the new disk without restarting the system:

```sh
# mount /mnt/newdisk
```

Verify the mount:

Use the `mount` command to verify (without any arguments)

```sh
# mount
/dev/nda1p3 on /mnt/newdisk (ufs, local, soft-updates)

...other output omitted...
```

You can also use the `df` command to verify the mount:

```sh
# df -hl
/dev/nda1p3           2.9G    8.0K    2.7G     0%    /mnt/newdisk

...other output omitted...
```

View the contents of the mounted file system:

```sh
# ls /mnt/newdisk/
/mnt/newdisk/.snap/    /mnt/newdisk/test.txt
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-27-the-ufs-file-system/di-27.2-jie-tian-jia-ufs-ci-pan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
