FreeBSD file system: hierarchy and mounting. File system Mounting usb drives in freebsd 11

NTFS is the native Windows file system. Therefore, it will not work just like that to connect flash drives, hard drives or other removable media unknown to us (in fact, it will work, but there will be problems). Therefore, we are rolling out our comprehensive manual on this matter.

  1. As always, it all starts with. Install the driver for NTFS: #cd / usr / ports / sysutils / fusefs-ntfs #make install clean
  2. Since FreeBSD 10, Fuse is part of the kernel. Make it load with system modules #nano /boot/loader.conf fuse_load \u003d «YES»

    This will work after reboot. In the current session, load this module manually

    #kldload fuse

    You can check whether the module is loaded or not with the command

    #kldstat

    If the list contains fuse.ko, it means everything is OK.

    #kldstat Id Refs Address Size Name 1 3 0xffffffff80200000 1fa7c38 kernel 2 1 0xffffffff821a9000 1a7c8 fuse.ko

  3. Next, we must decide how the system sees a USB flash drive or an external hard drive: #dmesg | grep da

    The output will be something like this:

    Da0 at umass-sim0 bus 0 scbus1 target 0 lun 0 da0: s / n 00H79BHRYGX22JBN detached (da0: umass-sim0: 0: 0: 0): Periph destroyed da0 at umass-sim0 bus 0 scbus1 target 0 lun 0 da0: Removable Direct Access SPC-4 SCSI device da0: Serial Number 00H79BHRYGX22JBN da0: 40.000MB / s transfers da0: 14870MB (30453760 512 byte sectors) da0: quirks \u003d 0x12 da1 at umass-sim1 bus 1 scbus2 target 0 lun 0 da1: s / n 8968888304C9BB52 detached (da1: umass-sim1: 1: 0: 0): Periph destroyed da1 at umass-sim1 bus 1 scbus2 target 0 lun 0 da1: Removable Direct Access SCSI-2 device da1: Serial Number 8968888306C9BB52 da1: 40.000MB / s transfers da1: 1999MB (4093952 512 byte sectors) da1: quirks \u003d 0x2

    We see that in the system we have two flash drives with identifiers da0 and da1… In our example, we will only use a USB flash drive. da0.

  4. Mount it with the following command: ntfs-3g / dev / da0 / mnt

    / dev / da0 — this is our flash drive, we found it out in point 3.
    / mnt Is the mount point. It can be anything.

    If an error appears, mount the flash drive partition. After entering

    Ntfs-3g / dev / da0

    press TAB and see the sections of the flash drive

    Da0 da0s1

    And we mount this section

    Ntfs-3g / dev / da0s1 / mnt

  5. Go to the directory where we mounted the USB flash drive and see its contents there: #cd / mnt #ll total 13 drwxrwxrwx 1 root wheel 0 Nov 4. 17:23 System Volume Information / -rwxrwxrwx 1 root wheel 9 Nov 4 18:05 xxx.xxx * -rwxrwxrwx 1 root wheel 22 Nov 4 18:04 ZIP archive — WinRAR.zip * -rwxrwxrwx 1 root wheel 9904 Nov 4. 18:04 Microsoft Office Excel sheet.xlsx *

    Now you can write files to a USB flash drive and read them from it.

  6. In order to unmount the USB flash drive, we first leave the directory where it is mounted. For example, #cd /

    And after that, we will use the command

    #umount / mnt

    note that the argument is not the flash drive, but its mount point!
    IMPORTANT: Do not pull out the USB flash drive immediately after entering the command! It will be possible to pull it out only after a few seconds, when the prompt for input appears again in the terminal!

Home\u003e Operating Systems\u003e UNIX\u003e BSD\u003e FreeBSD

Add a hard drive to FreeBSD in 5 minutes

I often draw attention to the fact that simple questions are often poorly covered on the Internet. Probably, this is because all gurus are sure that no one will ever ask such stupid questions, because everyone knows this. But my practice has shown that it is precisely such small, simple questions that are most frequent not only among beginners, but also among serious administrators who simply did not have to deal with this. Even serious administrators do not do this every day, and, in order not to forget, they keep a kind of cheat sheet for themselves, not admitting this to anyone. Let’s fix everything. Now you will learn how to add a hard drive to FreeBSD in 5 minutes. So. First, there will be a complete instruction for understanding the process, and at the end there will be a short list of actions, which will contain only a list of commands as a cheat sheet.

Detailed instructions with explanations

Choosing a hard drive name

First, you need to define the device name that we just added. The following command will help us with this:

Geom disk list

Or a command like this:

Camcontrol devlist

In a real system, these commands will show more useful information, namely: device names and their serial numbers.

Before installing the new device, we knew that our system was installed on ada0, which means, logically, our new disk is ada1. You can identify this by the name of the new device, its serial number or volume.

Now let’s check if there is markup on our new disk

Gpart show ada1

The disk has no markup.

Removing existing markup

If the disk has already been used and there is a need to remove the partitioning from it, just do:

Gpart destroy -F ada1

Generating GPT markup

First, we need to create a disk layout. I highly recommend to forget about MBR and switch to a new, more convenient and functional one — GPT.

Create the GPT markup on disk, then check what happened:

Gpart create -s gpt / dev / ada1 gpart show ada1

Now our disk is GPT. From the output you can see that absolutely the entire disk, from LBA 34 to LBA 8388541, is empty. LBA 0-33 — Reserved by the system for the partition table.

Let’s say we need to create two partitions on this disk:

  • swap — swap partition
  • data — a ufs-type section for storing any data we need.

Creating sections (slices)

If the installation is performed on modern hard disks with a sector size of 4 kb, then alignment must be used when creating partitions (partitions). There are two ways to do it:
1) if we specify the parameters of the section in blocks, then enter the block number in multiples of 8, for example: -b 40;
2) if we specify the size of the section in bytes, or do not specify the beginning and size at all, use the parameter -a 4k, which will fit the beginning and end of the partition to 4 kb sectors. Since in this example we are making a test installation on a virtual hard disk, this can be omitted. In any case, before creating partitions, you need to know exactly the sector size of your drive, otherwise it will result in terrible brakes in work.

Now let’s create partitions. For this there is a gpart add command with various parameters. First parameter -t — indicates the type of filesystem being created. In our case, two types will be used: freebsd-swap and freebsd-ufs. Then there are two optional parameters: -b — indicates the LBA number, starting from which you want to create the section. If you do not specify this parameter, the partition will be created automatically from the first free LBA. -s — indicates the size of the partition in LBA. The size of one LBA block \u003d 512 bytes. It is desirable to indicate in the number of LBA blocks, but it is also possible in kilo / mega / giga / … bytes (suffix k / M / G). If you do not specify this parameter, then the section will be created up to the maximum possible LBA within the empty area. You can also specify a section label as a parameter, for example: -l swap1 — in this case, the label / dev / gpt / swap1 will be created, by which you can more conveniently access the partition. The last required parameter is the path to the disk. In our case: / dev / ada1.

Let’s create two sections and then see what we get. We will create the first partition without specifying the initial LBA, but specifying the size of 1 GB (2097152 blocks). We will create the second section without specifying the initial LBA and without specifying the size — this way it will be created on all free space.

Gpart add -t freebsd-swap -s 2097152 / dev / ada1 gpart add -t freebsd-ufs / dev / ada1 gpart show ada1

The size can be specified in bytes, not blocks. It is much more convenient. The only drawback is that the system cannot always calculate the number of blocks correctly. There are cases when a certain number of blocks will remain empty on the disk when specifying the size of the partition in bytes.

File system creation (formatting)

There is no need to format swap partitions. But partitions like ufs must be formatted before use. It would be more correct to say: a file system must be created on them.

To create a file system on the second partition, just run the following command:

Newfs -U / dev / ada1p2

In this case, the -U parameter was used — it says that the Soft Updates mechanism should be used in this file system. You can omit this parameter to not enable this mechanism.

Mounting

The next step is to mount the partitions. First, so as not to forget, let’s add our new partitions to / etc / fstab. My file looks like this after editing:

In order to remount all partitions according to the / etc / fstab file, simply run the command:

Mount -a

As you can see from the output, the / dev / ada1p2 partition is mounted. Now let’s see what happened to the SWAP section. Let’s execute the command:

As you can see, the new SWAP section is not mounted. To mount SWAP, you must enable it with a special command:

Swapon / dev / ada1p1

Likewise, you must disable the SWAP section using the swapoff command before you can perform any action on it.

This completes all the steps to add a new hard drive to the system.

Brief instruction

Given: hard drive / dev / ada1

purpose: delete existing markup, create new GPT markup, create two partitions: swap and data and connect them to the production system.

After each step, do gpart showto watch the result. Sequencing:

  1. Remove existing markup:
    gpart destroy -F ada1
  2. Create new markup:
    gpart create -s gpt / dev / ada1
  3. Create two partitions: swap and data:
    gpart add -t freebsd-swap -s 2097152 / dev / ada1 gpart add -t freebsd-ufs / dev / ada1
  4. Create filesystem UFSv2 on the second section:
    newfs -U / dev / ada1p2
  5. Add lines to the / etc / fstab file to auto-mount at boot:
    / dev / ada1p1 none swap sw 0 0 / dev / ada1p2 / mnt ufs rw 2 2
  6. Mount a new partition (the command mounts all partitions from the / etc / fstab file):
    mount -a
  7. Enable the new swap partition with the command:
    swapon / dev / ada1p1 Material taken from the site:

You can change the access rights and owner of files and directories in, using the commands chmod and chown… The mask for setting rights to created files can be changed globally, in / etc / profile for Linux and in /etc/login.conf for FreeBSD. Usually, the default mask 022
… Value umask subtracted from 777
so the permissions will matter 755
… exec — execution allowed read — read access write — write access SUID bit — the file attribute, in conjunction with the executable file attribute, allows the executable to execute with the effective UID of the owner of the file, not the one who launches the file 1 —x execute # Rights 764 \u003d exec / read / write | read / write | read 2 -w- write # For: | — Owner — | | — Group- | | Oth | 4 r— read ugo \u003d a u \u003d user, g \u003d group, o \u003d others, a \u003d everyone # chmod MODE [, MODE] FILE # MODE has the form: *([-+=]())

# chmod 640 / var / log / maillog # Set access rights equal -rw-r ——
# chmod u \u003d rw, g \u003d r, o \u003d / var / log / maillog # As above # chmod -R o-r / home / * # Recursively change permissions, disallow reading for Other
# chmod u + s / path / to / prog # Install SUID bit per executable file (be careful here, you must understand what you are doing) # find / -perm -u + s -print # Find all programs with installed SUID bit # chown user: group / path / to / file # Set user and group as file owner # chgrp group / path / to / file # Change the group that owns the file # chmod 640 `find ./ -type f -print` # Change access rights to 640
for all files
# chmod 751 `find ./ -type d -print` # Change access rights to 751
for all directories

Disc information

# diskinfo -v / dev / ad2 # View disk information ( sector / size) FreeBSD # hdparm -I / dev / sda # Information about IDE / ATA disk (Linux) # fdisk / dev / ad2 # Show change disk partitions # smartctl -a / dev / ad2 # Show SMARTdisk information

Loading

FreeBSD

To boot the old kernel, in an emergency, for example after a failed build and installing a new one, stop the boot by pressing 6 during the countdown to get to the command line prompt. # unload # load kernel.old # boot

Mount points, disk usage

# mount | column -t # Show mounted filesystems # df # Show the amount of free space and mounted devices # cat / proc / partitions # Show all registered partitions (Linux)

Directory Information

# du -sh * # Directory sizes as a list # du -csh # The total size of the current directory # du -ks * | sort -n -r # List of directories sorted by size in kilobytes # ls -lSr # List directories, reverse sort

Who opened which files

Sometimes it is necessary to find out which file has locked a section, which is why the command umount throws a corresponding error. # umount / home / umount: unmount of / home # It is not possible to unmount the partition until / home locked failed: Device busy

FreeBSD and most Unix-like systems

# fstat -f / home # for mount point # fstat -p PID # for application with PID # fstat -u user # for username Find open file for Xorg: # ps ax | grep Xorg | awk «(print $ 1)» 1252 # fstat -p 1252 USER CMD PID FD MOUNT INUM MODE SZ | DV R / W root Xorg 1252 root / 2 drwxr-xr-x 512 r root Xorg 1252 text / usr 216016 -rws— x — x 1679848 r root Xorg 1252 0 / var 212042 -rw-r — r— 56987 w Find file with inum 212042
in the directory / var you can like this: # find -x / var -inum 212042 /var/log/Xorg.0.log

Linux

Find an open file in a directory with fuser or lsof: # fuser -m / home # List of processes that have access to / home
# lsof / home COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME tcsh 29029 eedcoba cwd DIR 0.18 12288 1048587 / home / eedcoba (guam: / home) lsof 29140 eedcoba cwd DIR 0.18 12288 1048587 / home / eedco / home) Find by PID applications: ps ax | grep Xorg | awk «(print $ 1)» 3324 # lsof -p 3324 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME Xorg 3324 root 0w REG 8.6 56296 12492 /var/log/Xorg.0.log By filename: # lsof / var /log/Xorg.0.log COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME Xorg 3324 root 0w REG 8.6 56296 12492 /var/log/Xorg.0.log

Mounting / remounting file systems

for example cdromwritten in / etc / fstab: # mount / cdrom Or you can find the device in / dev or in the output dmesg

FreeBSD

# mount -v -t cd9660 / dev / cd0c / mnt # Mount disk Cdrom (method one) # mount_cd9660 / dev / wcd0c / cdrom # Mount disk Cdrom (method two) # mount -v -t msdos / dev / fd0c / mnt # Floppy Disk Writing to / etc / fstab: # Device Mountpoint FStype Options Dump Pass # / dev / acd0 / cdrom cd9660 ro, noauto 0 0 Allow users to mount drives: # sysctl vfs.usermount \u003d 1 # Or write a line «vfs.usermount \u003d 1» in /etc/sysctl.conf

Linux

# mount -t auto / dev / cdrom / mnt / cdrom # Typical disk mount command cdrom
# mount / dev / hdc -t iso9660 -r / cdrom # Mount disk IDE
# mount / dev / scd0 -t iso9660 -r / cdrom # Mount disk SCSI cdrom # mount / dev / sdc0 -t ntfs-3g / windows # Mount disk SCSI
Recording in / etc / fstab: / dev / cdrom / media / cdrom subfs noauto, fs \u003d cdfss, ro, procuid, nosuid, nodev, exec 0 0

Mounting a FreeBSD partition with Linux

Look up the section number in fdisk, usually this is the root section, but it can be on another BSD slice. If there are many slices on the FreeBSD partition, they will not be visible through fdiskbut they can be found in dev / sda * or / dev / hda *… # fdisk / dev / sda # Find FreeBSD partition / dev / sda3 * 5357 7905 20474842+ a5 FreeBSD # mount -t ufs -o ufstype \u003d ufs2, ro / dev / sda3 / mnt / dev / sda10 \u003d / tmp; / dev / sda11 / usr # Another slice

Remounting

Remount the device without first unmounting it, for example to fsck # mount -o remount, ro / # Linux # mount -o ro / # FreeBSD Copy data stream from CDROM«and to the file ISO image… # dd if \u003d / dev / cd0c of \u003d file.iso

Creating a swap partition on the fly

Suppose you need to increase the swap partition, say to 2
gigabyte, / swap2gb (for Linux) # dd if \u003d / dev / zero of \u003d / swap2gb bs \u003d 1024k count \u003d 2000 # mkswap / swap2gb # Create swap # swapon / swap2gb # Enable swap, now it can be used # swapoff / swap2gb # Disable swap # rm / swap2gb

Mount SMB partition

CIFS — Common Internet File System
SMB — server message block Suppose you need to access a shared SMB section myshare on server smbserver, the address typed on the Windows machine will be \\\\ smbserver \\ myshare \\… We will mount on / mnt / smbshare… Don’t forget for cifs an IP address or domain name is required.

Linux

# smbclient -U user -I 192.168.16.229 -L // smbshare / # List the shares # mount -t smbfs -o username \u003d winuser // smbserver / myshare / mnt / smbshare # mount -t cifs -o username \u003d winuser, password \u003d winpwd //192.168.16.229/myshare / mnt / share Also package mount.cifs allows you to store privileges in a file like /home/user/.smb: username \u003d winuser password \u003d winpwd And now mount: # mount -t cifs -o credentials \u003d / home / user / .smb //192.168.16.229/myshare / mnt / smbshare

FreeBSD

Use the key -Ito set the IP address (or DNS); smbserver, this is the Windows name. # smbutil view -I 192.168.16.229 // [email protected] # List of shared resources # mount_smbfs -I 192.168.16.229 // [email protected]/ myshare / mnt / smbshare

Mount image

Linux loop-back

# mount -t iso9660 -o loop file.iso / mnt # Mount CD image # mount -t ext3 -o loop file.img / mnt # Mount image with file system ext3

FreeBSD

Using md — memory device (if necessary, do kldload md.ko): # mdconfig -a -t vnode -f file.iso -u 0 # mount -t cd9660 / dev / md0 / mnt # umount / mnt; mdconfig -d -u 0 # Clear memory device Or using a pseudo device ( VN, Virtual node): # vnconfig / dev / vn0c file.iso; mount -t cd9660 / dev / vn0c / mnt # umount / mnt; vnconfig -u / dev / vn0c # Clear pseudo device

Create and burn an ISO image

We will copy cd or dvd sector by sector. # dd if \u003d / dev / hdc of \u003d / tmp / mycd.iso bs \u003d 2048 conv \u003d notrunc Use mkisofs to create an image from a file in a directory. To overcome file name restrictions use the option -rincluding the extension RockRidge, basic for UNIX systems, -J includes Jolietused by Microsoft, -L allows ISO9660 names starting with a dot. # mkisofs -J -L -r -V TITLE -o imagefile.iso / path / to / dir On FreeBSD, mkisofs can be installed from ports / usr / ports / sysutils / cdrtools.

Burn CD / DVD ISO images

FreeBSD

FreeBSD does not install DMA on the ATAPI devices, this can be done through the variable sysctl or in file /boot/loader.confby the following entries. hw.ata.ata_dma \u003d «1» hw.ata.atapi_dma \u003d «1» Use burncd for ATAPI devices ( burncd, standard program, part of the base system) and cdrecord (of / usr / ports / sysutils / cdrtools) for SCSI devices. # burncd -f / dev / acd0 data imagefile.iso fixate # For ATAPI devices # cdrecord -scanbus # Find recorder # cdrecord dev \u003d 1,0,0 imagefile.iso

Linux

Also use cdrecordas described above. Alternatively, you can use the native ATAPI interface: # cdrecord dev \u003d ATAPI -scanbus Write as described above.

dvd + rw-tools

The dvd + rw-tools package (FreeBSD: ports / sysutils / dvd + rw-tools) has all the functionality you need to work with DVD, plus growisofs, for recording CD or DVD. Documentation with examples can be found in the FreeBSD handbook Chapter 18.7 # -dvd-compat closes the disk # growisofs -dvd-compat -Z /dev/dvd\u003dimagefile.iso # Burn existing iso image # growisofs -dvd-compat -Z / dev / dvd -J -R / p / to / data # Write directly

Convert image from Nero .nrg file to .iso file

Nero adds a 300kb title to the image, it can be cropped using dd… # dd bs \u003d 1k if \u003d imagefile.nrg of \u003d imagefile.iso skip \u003d 300

Convert bin / cue image to .iso

This can be done with a small program, bchunk. On FreeBSD it can be found in ports / usr / ports / sysutils / bchunk… # bchunk imagefile.bin imagefile.cue imagefile.iso

Create an image from a file

For example, a 1GB partition uses the file /usr/vdisk.img… In this case, we use the key -u 0, but the number can be anything.

FreeBSD

# dd if \u003d / dev / random of \u003d / usr / vdisk.img bs \u003d 1K count \u003d 1M # mdconfig -a -t vnode -f /usr/vdisk.img -u 0 # Create a device / dev / md1
# bsdlabel -w / dev / md0 # newfs / dev / md0c # mount / dev / md0c / mnt # umount / mnt; mdconfig -d -u 0; rm /usr/vdisk.img # Clear md An image created from a file can be mounted during system boot by writing a line to /etc/rc.conf and / etc / fstab… You can check the correctness of your settings using the command /etc/rc.d/mdconfig start (after removing the device md0 using the command # mdconfig -d -u 0). Keep in mind that automatic image mounting will work only if the image file is NOT in the root partition, due to the fact that the script /etc/rc.d/mdconfig executed early in the boot phase, when the root partition is not yet writable. Images located outside the root partition will be mounted later, by the script /etc/rc.d/mdconfig2.

/boot/loader.conf: md_load \u003d «YES» /etc/rc.conf: mdconfig_md0 \u003d «- t vnode -f /usr/vdisk.img» # / usr not in the root section / etc / fstab: (0 0 at the end, very important, this will indicate fsck ignore device check since it doesn’t exist yet) / dev / md0 / usr / vdisk ufs rw 0 0

In addition, you can later increase the size of the image, say by 300 MB. # umount / mnt; mdconfig -d -u 0 # dd if \u003d / dev / zero bs \u003d 1m count \u003d 300 \u003e\u003e /usr/vdisk.img # mdconfig -a -t vnode -f /usr/vdisk.img -u 0 # growfs / dev / md0 # mount / dev / md0c / mnt # Now the file partition is 300 MB larger

Linux

# dd if \u003d / dev / zero of \u003d / usr / vdisk.img bs \u003d 1024k count \u003d 1024 # mkfs.ext3 /usr/vdisk.img # mount -o loop /usr/vdisk.img / mnt # umount / mnt; rm /usr/vdisk.img # Clear

Linux and losetup

/ dev / zero much faster than urandombut less secure for encryption. # dd if \u003d / dev / urandom of \u003d / usr / vdisk.img bs \u003d 1024k count \u003d 1024 # losetup / dev / loop0 /usr/vdisk.img #Create / dev / loop0
# mkfs.ext3 / dev / loop0 # mount / dev / loop0 / mnt # losetup -a # Check # umount / mnt # losetup -d / dev / loop0 # Detach # rm /usr/vdisk.img

Creating an in-memory file system

The in-memory file system is very fast, it makes sense to use it for applications with high disk IO. Create a 64 MB partition and mount it in / memdisk:

FreeBSD

# mount_mfs -o rw -s 64M md / memdisk # umount / memdisk; mdconfig -d -u 0 #Clear md device md / memdisk mfs rw, -s64M 0 0 # write to / etc / fstab

Linux

# mount -t tmpfs -osize \u003d 64m tmpfs / memdisk

Disk performance

Read and write 1GB file in section ad4s3c (/ home) # time dd if \u003d / dev / ad4s3c of \u003d / dev / null bs \u003d 1024k count \u003d 1000 # time dd if \u003d / dev / zero bs \u003d 1024k count \u003d 1000 of \u003d / home / 1Gb.file # hdparm -tT / dev / hda # Linux only

I often draw attention to the fact that simple questions are often poorly covered on the Internet. Probably, this is because all gurus are sure that no one will ever ask such stupid questions, because everyone knows this. But my practice has shown that it is precisely such small, simple questions that are most frequent not only among beginners, but also among serious administrators who simply did not have to deal with this. Even serious administrators do not do this every day, and, in order not to forget, they keep a kind of cheat sheet for themselves, not admitting this to anyone. Let’s fix everything. Now you will learn how to add a hard drive to FreeBSD in 5 minutes. So. First, there will be a complete instruction for understanding the process, and at the end there will be a short list of actions, which will contain only a list of commands as a cheat sheet.

Detailed instructions with explanations

Choosing a hard drive name

First, you need to define the device name that we just added. The following command will help us with this:

Geom disk list

Or a command like this:

Camcontrol devlist

In a real system, these commands will show more useful information such as device names and serial numbers.

Before installing the new device, we knew that our system was installed on ada0, which means, logically, our new disk is ada1. You can identify this by the name of the new device, its serial number or volume.

Now let’s check if there is markup on our new disk

Gpart show ada1

The disk has no markup.

Removing existing markup

If the disk has already been used and there is a need to remove the partitioning from it, just do:

Gpart destroy -F ada1

Generating GPT markup

First, we need to create a disk layout. I highly recommend to forget about MBR and switch to a new, more convenient and functional one — GPT.

Create the GPT markup on disk, then check what happened:

Gpart create -s gpt / dev / ada1 gpart show ada1

Now our disk is GPT. From the output you can see that absolutely the entire disk, from LBA 34 to LBA 8388541, is empty. LBA 0-33 — Reserved by the system for the partition table.

Let’s say we need to create two partitions on this disk:

  • swap — swap partition
  • data — a ufs-type section for storing any data we need.

Creating sections (slices)

If the installation is performed on modern hard disks with a sector size of 4 kb, then alignment must be used when creating partitions (partitions). You can act in two ways: 1) if we specify the parameters of the section in blocks, then enter the block number in multiples of 8, for example: -b 40; 2) if we specify the size of the section in bytes, or do not specify the beginning and size at all, use the parameter -a 4k, which will fit the beginning and end of the partition to 4 kb sectors. Since in this example we are making a test installation on a virtual hard disk, this can be omitted. In any case, before creating partitions, you need to know exactly the sector size of your drive, otherwise it will result in terrible brakes in work.

Now let’s create partitions. For this there is a gpart add command with various parameters. First parameter -t — indicates the type of filesystem being created. In our case, two types will be used: freebsd-swap and freebsd-ufs. Next are two optional parameters: -b — indicates the LBA number, starting from which the partition should be created. If you do not specify this parameter, then the partition will be created automatically from the first free LBA. -s — indicates the size of the partition in LBA. The size of one LBA block \u003d 512 bytes. It is desirable to indicate in the number of LBA blocks, but it is also possible in kilo / mega / giga / … bytes (suffix k / M / G). If you do not specify this parameter, then the section will be created up to the maximum possible LBA within the empty area. You can also specify a section label as a parameter, for example: -l swap1 — in this case, the label / dev / gpt / swap1 will be created, by which you can more conveniently access the partition. The last required parameter is the path to the disk. In our case: / dev / ada1.

Let’s create two sections and then see what we get. We will create the first partition without specifying the initial LBA, but specifying the size of 1 GB (2097152 blocks). We will create the second section without specifying the initial LBA and without specifying the size — this way it will be created on all free space.

Gpart add -t freebsd-swap -s 2097152 / dev / ada1 gpart add -t freebsd-ufs / dev / ada1 gpart show ada1

The size can be specified in bytes, not blocks. It is much more convenient. The only drawback is that the system cannot always calculate the number of blocks correctly. There may be cases when a certain number of blocks will remain empty on the disk when specifying the size of the partition in bytes.

File system creation (formatting)

There is no need to format swap partitions. But partitions like ufs must be formatted before use. It would be more correct to say: a file system must be created on them.

To create a file system on the second partition, just run the following command:

Newfs -U / dev / ada1p2

In this case, the -U parameter was used — it says that the Soft Updates mechanism should be used in this file system. You can choose not to use this parameter to not enable this mechanism.

Mounting

The next step is to mount the partitions. First, so as not to forget, let’s add our new partitions to / etc / fstab. My file looks like this after editing:

In order to remount all partitions according to the / etc / fstab file, simply run the command:

Mount -a

As you can see from the output, the / dev / ada1p2 partition is mounted. Now let’s see what happened to the SWAP section. Let’s execute the command:

As you can see, the new SWAP section is not mounted. To mount SWAP, you must enable it with a special command:

Swapon / dev / ada1p1

Likewise, you must disable the SWAP section using the swapoff command before you can perform any action on it.

This completes all the steps to add a new hard drive to the system.

Brief instruction

Given: hard drive / dev / ada1

purpose: delete existing markup, create new GPT markup, create two partitions: swap and data and connect them to the production system.

After each step, do gpart showto watch the result. Sequencing:

  1. Remove existing markup: gpart destroy -F ada1
  2. Create new markup: gpart create -s gpt / dev / ada1
  3. Create two partitions: swap and data: gpart add -t freebsd-swap -s 2097152 / dev / ada1 gpart add -t freebsd-ufs / dev / ada1
  4. Create filesystem UFSv2 on the second partition: newfs -U / dev / ada1p2
  5. Add lines to the / etc / fstab file to auto-mount at boot: / dev / ada1p1 none swap sw 0 0 / dev / ada1p2 / mnt ufs rw 2 2
  6. Mount a new partition (the command mounts all partitions from the / etc / fstab file): mount -a
  7. Enable the new swap partition with the command: swapon / dev / ada1p1

This completes the setup.