News
Seven days of Black Friday madness — great deal from Serverspace!
Serverspace Black Friday
DF
Daniil Fedorov
August 2, 2021
Updated May 25, 2023

Adding a Volume and Creating Partitions in FreeBSD

AD Windows

After adding a volume in the control panel, you need to make it available in the operating system.

Log on to the server as sudo or root and browse all volumes, execute the following command:

geom disk list

Example:

Geom name: vtbd0
Providers:
Name: vtbd0
Mediasize: 26843545600 (25G)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r1w1e3
descr: (null)
ident: BHYVE-72B8-3EC6-7459
rotationrate: unknown
fwsectors: 0
fwheads: 0
Geom name: vtbd1
Providers:
Name: vtbd1
Mediasize: 42949672960 (40G)
Sectorsize: 512
Stripesize: 4096
Stripeoffset: 0
Mode: r0w0e0
descr: (null)
identr: BHYVE-679A-4260-62AE
rotationrate: unknown
fwsectors: 0
fwheads: 0

This tutorial will show how to mount the /dev/vtbd1 40 GB device as a standard ufs (Unix Fast File System) partition and how to add a swap partition.
Note: if the added volume does not show up in the list, you have to restart the server.

Create a GPT partitioned volume with the command:

gpart create -s gpt /dev/vtbd1

Note: GPT is a GUID Partition Table format which uses a Logical Block Addressing (LBA) system.

To view the volume, run the command:

gpart show vtbd1
=> 40 83886000 vtbd1 GPT (40G)
40 83886000 - free - (40G)

Example 1

To add the first 10 GB partition, use the command:

gpart add -t freebsd-ufs -s 10G /dev/vtbd1
vtbd1p1 added

This example will add the second partition of 20 GB:

gpart add -t freebsd-ufs -s 20G /dev/vtbd1
vtbd1p2 added

The third partition can be added without specifying an initial LBA and size, so it will be created on all available space:

gpart add -t freebsd-ufs /dev/vtbd1
vtbd1p3 added

To check the resulting partitions:

gpart show vtbd1
=> 40 83886000 vtbd1 GPT (40G)
40 20971520 1 freebsd-ufs (10G)
20971560 41943040 2 freebsd-ufs (20G)
62914600 20971440 3 freebsd-ufs (10G)

To create a file system on volume partitions, run the following commands. The -U option specifies the use of the Soft Update mechanism, which increases the speed of creating and deleting files:

newfs -U /dev/vtbd1p1
newfs -U /dev/vtbd1p2
newfs -U /dev/vtbd1p3

Next you need to create a mount point for each partition:

mkdir /mnt/volume1
mkdir /mnt/volume2
mkdir /mnt/volume3

To change the access mode of the partitions, you need to execute the following command:

chmod -R 660 /mnt/volume1
chmod -R 660 /mnt/volume2
chmod -R 660 /mnt/volume3

To mount partitions automatically after the server restart, you need to make changes in /etc/fstab file. Use a text editor like vi or nano to open this file:

vi /etc/fstab

In the file that opens, you need to add the following lines and save your changes:

/dev/vtbd1p1 /mnt/volume1 ufs rw 0 0
/dev/vtbd1p2 /mnt/volume2 ufs rw 0 0
/dev/vtbd1p3 /mnt/volume3 ufs rw 0 0

To mount partitions use:

mount -a

To display the list of mounted devices and the occupied space, use the command:

df -h
Filesystem Size Used Avail Capacity Mounted on
...
/dev/vdbd1p1 9.7G 8.0K 8.9G 0% /mnt/volume1
/dev/vdbd1p2 19G 8.0K 18G 0% /mnt/volume2
/dev/vdbd1p3 9.7G 8.0K 8.9G 0% /mnt/volume3

Example 2 (adding a swap partition)

First we need to add 1GB swap partition:

gpart add -t freebsd-swap -s 1G /dev/vtbd1
vtbd1p1 added

The second partition can be added without specifying an initial LBA and size, so it will be created in all free space:

gpart add -t freebsd-ufs /dev/vtbd1
vtbd1p2 added

To check the resulting partitions:

gpart show vtbd1
=> 40 83886000 vtbd1 GPT (40G)
40 2097152 1 freebsd-swap (1.0G)
2097192 81788848 2 freebsd-ufs (39G)

To create a file system on the volume partitions, run the following command. The -U option specifies the use of the Soft Update mechanism, which speeds up the creation and deletion of files:

newfs -U /dev/vtbd1p2

Note: the swap partition does not need to be formatted.

Next, you need to create a mount point for every partition except swap:

mkdir /mnt/volume1

To change the access mode of the partitions, you need to execute the following command:

chmod -R 660 /mnt/volume1

To mount partitions automatically after the server restart, you need to make changes in /etc/fstab file. Use a text editor like vi or nano to open this file:

vi /etc/fstab

You need to add the following lines and save your changes:

/dev/vtbd1p1 none swap sw 0 0
/dev/vtbd1p2 /mnt/volume1 ufs rw 0 0 0

Use the following command to mount partitions:

mount -a

Next you need to mount the swap partition:

swapon /dev/vtbd1p1

You can use the command swapinfo to check if the partition was mounted successfully:

swapinfo
Device 1K-blocks Used Avail Capacity
/dev/vtbd1p1 1048576 0 1048576 0%

Use this command to display a list of mounted devices and space occupied:

Note: The swap-type partition is not displayed in this list.

df -h
Filesystem Size Used Avail Capacity Mounted on
...
/dev/vdbd1p2 38G 8.0K 35G 0% /mnt/volume

Vote:
2 out of 5
Аverage rating : 2.8
Rated by: 8
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.