21.07.2021

The FreeBSD Filesystem: Hierarchy and Mounting. Freebsd file system mounting partitions by their labels


They need to be mounted, and when all the necessary actions are completed, unmount them. Usually, mount(8) / umount(8) commands are used for mounting / unmounting, and no one thinks about automating these operations. In my opinion, this is not the best approach, especially given the fact that the FreeBSD operating system includes a special auto-mount daemon.

Formulation of the problem

The FreeBSD amd(8) operating system automount daemon is designed to transparently mount absolutely any file system as files and folders located on it are accessed, as well as to subsequently unmount these file systems if there is no activity for a specified period of time. This article is about setting up amd to automatically mount filesystems exported by NFS servers and shared folders provided by SMB servers. In addition, it describes diagnosing amd using the amq(8) utility and allocating its own log to it using the standard syslogd(8) and newsyslog(8) log management tools.

Initial data

This task does not require any additional software, but you will need to create a , allowing the root superuser to mount selected shared folders provided by SMB servers without entering a password.

Automatic mounting of NFS file systems

To ensure automatic mounting of file NFS systems just add the following line to the /etc/rc.conf file:

amd_enable="YES"

and start amd with /etc/rc.d/amd start . By default, amd will use the /.amd_mnt alternate directory, send its status messages to the daemon section of the syslog, and allow NFS mounts to the /host and /net local filesystem folders according to the /etc/amd.map mount map (this mount map included with the FreeBSD operating system and contains rules governing how NFS file systems are mounted and unmounted using the Network Host Filesystem). If you translate what has been said into human language, then immediately after starting amd you will be able to access the share file system exported by the NFS server nfsserver as a regular local folder with the name /host/nfsserver/share or /net/nfsserver/share . If any such access is made and the necessary file system is not in the list of mounted file systems, amd will create the /.amd_mnt/nfsserver/host/share mount point, mount the share file system to it, create the /host/nfsserver or /net/nfsserver folder and add to it symbolic link to the above mount point. If the /host/nfsserver/share or /net/nfsserver/share folder is left unused for 5 minutes, amd will unmount the share file system and then remove the unneeded folders and symbolic link.

Automatic mounting of SMBFS file systems

To enable automatic mounting of SMBFS file systems, one or more additional mount maps must be created, each of which must contain rules based on the use of the Program Filesystem . To be able to access shared folders by template names like /smbfs/smbserver/share, each SMB server should have a separate card mount. For example, to specify the mount rules for the shared folders share1 and share2 provided by the SMB server smbserver , you can create a mount map named /etc/amd.map-smbserver (you can change given name according to your own tastes) and add the lines to it:

Share1 type:=program;fs:=$(autodir)/$(path);mount:="/sbin/mount mount -t smbfs \\\/\\\/ [email protected]/share1 $(fs)"; share2 type:=program;fs:=$(autodir)/$(path);mount:="/sbin/mount mount -t smbfs \\\/\\\/ [email protected]/share2$(fs)";

The specified rules will force amd to mount shared folders to the $(autodir) mount point (the $(autodir) variable contains the name of the alternative folder) with the commands /sbin/mount -t smbfs // [email protected]/share... . The absence of the umount or unmount option suggests using the default umount $(fs) unmount commands (the variable $(fs) contains the name of the mount point).
To bind the created mount map to the /smbfs/smbserver mount point, add the following line to the /etc/rc.conf file:

amd_flags="$amd_flags /smbfs/smbserver /etc/amd.map-smbserver"

and restart amd with /etc/rc.d/amd restart . Once you complete these steps, you will be able to access the shared folders share1 and share2 provided by the SMB server smbserver as if they were normal local folders /smbfs/smbserver/share1 and /smbfs/smbserver/share2 .

Analysis of amd status with amq utility

For a quick clarification current state amd file, you can use the amq -m command to display a list of mounted filesystems, including the number of links to each, and information about mount errors, something like this:

"root" root 1 localhost is up /etc/amd.map /host toplvl 1 localhost is up /etc/amd.map /net toplvl 1 localhost is up /etc/amd.map-smbserver /smbfs/smbserver toplvl 1 localhost is up nfsserver:/host/nfsserver /.amd_mnt/nfsserver host 1 nfsserver is up mount -t smbfs // [email protected]/share1 ... /.amd_mnt/smbfs/smbserver/share1 program 1 localhost is up

The first column of this table contains the name of the mount map for mount points or mount options for mounted file systems, the second column is the name of the mount point, the third column is the amd file system type, the fourth column is the number of references to the mount point or file system, the fifth column is the name of the computer on which the file system is located, the sixth is the status of the mount point or file system, the seventh is mount error messages (if there are no errors, the seventh column is not displayed). Because amd and the rpcbind(8) it runs support TCP Wrappers , amq -m can result in error messages like this:

Amq: localhost: RPC: Port mapper failure - RPC: Authentication error amq: localhost: RPC: Authentication error; why = Failed (unspecified error)

To eliminate these errors, add rules to the /etc/hosts.allow file that allow access to amd and rpcbind from localhost:

amd: 127.0.0.1: allow amd: ALL: deny rpcbind: 127.0.0.1: allow rpcbind: ALL: deny

Giving amd its own log

The default startup options set in the /etc/defaults/rc.conf file cause amd to send its status messages to the daemon section of the system log. If you want to provide amd with a separate log called /var/log/amd.log , you will have to redirect these messages to another syslog section (local6 in my case), and change the configuration accordingly syslogd daemon.
Taking into account all the changes in the configuration files described in this article, to redirect amd messages to the /var/log/amd.log log, you first need to change the definition of the amd_flags variable in the /etc/rc.conf file to the following form:

Amd_flags="-a /.amd_mnt -l syslog:local6 /host /etc/amd.map /net /etc/amd.map /smbfs/smbserver1 /etc/amd.map-smbserver1"

and restart amd with the /etc/rc.d/amd restart command, and secondly, add the following line to the /etc/syslog.conf file:

Local6.* /var/log/amd.log

create an empty log with touch /var/log/amd.log and restart syslogd with /etc/rc.d/syslogd restart .
To prevent the amd log from growing, you should enable its rotation using the newsyslog utility. For example, to truncate the log /var/log/amd.log on a daily basis while preserving seven previous copies compressed by the bzip2(1) archiver, add the following line to the /etc/newsyslog.conf file:

/var/log/amd.log 644 7 * @T00 JC

Conclusion

After following the steps described in this article, you no longer have to monitor the need to mount and unmount NFS and SMBFS file systems. I hope that you will appreciate this feature as useful and be sure to pay attention to amd.

from

The FHS standard was originally designed to streamline the directory structure of numerous Linux distributions. And only later it was adapted for other Unix-like systems (including the BSD clan). However, it is the FreeBSD directory hierarchy that can serve as an example of exemplary adherence to the spirit of the FHS. And literally piece deviations in it from its letter are always functionally conditioned.

The FHS standard is based on two fundamental principles a clear separation in the file hierarchy of directories shared and unshared on the one hand, and immutable and mutable on the other.

The opposition between shared and non-shared directories is due to the inherent networking nature of Unix in general and FreeBSD in particular. That is, data related to the local machine (for example, configuration files for its devices) must lie in directories separate from those whose data is available from other machines on the network, local or global (an example of which is not only user data, but also programs) .

The essence of the opposition of immutable and mutable directories is easy to explain with an example. Yes, the same user programs by their nature, they should be immutable (or rather, available for modification only to the system administrator, but not to the user himself, who uses them in his work). At the same time, these programs during their work generate not only data files, say, texts or images (their variable nature is clear without comment), but all kinds of service information, such as log files, temporary files, etc.). Which should be grouped in directories separated from the actual executable files of programs, libraries, configuration files, etc. necessary for their launch.

Strict adherence to the concept of separating shared and non-shared, immutable and immutable directories from each other allows, within the framework of a single tree-like file hierarchy, to isolate its individual branches physically that is, in the form of independent file systems located on isolated devices (disks, disk slices, partitions; in the general case and on remote media connected over a network, but this will not be discussed now). There are many reasons for this and an increase in performance, and an increase in reliability, and simply considerations of convenience, but we will not talk about them now. Because now the only important thing for us is that these branches of the file tree should be incorporated into a common file system.

The previous note said that any file (including a directory) is recognized by the system not by its name, but by the unique identifier of its entry in the inodes table. There are means to view these file identifiers. One of them is the ls command with the i option, which will list the IDs of each named file. Given for the root directory - $ ls -i

it will show us a somewhat unexpected picture (for simplicity, information about ordinary files and symbolic links in the root is excluded from the output, and the remaining directories are sorted by their identifiers) 2 ../ 2 ./ 2 dev/ 2 home/ 2 tmp/ 2 usr/ 2 var/ 3 cdrom/ 4 mnt/ 5 root/ 8257 dist/ 8258 bin/ 8294 proc/ 8295 sbin/ 16512 stand/ 24768 etc/ 24776 boot/

From this example (relating to the file system of the machine on which these lines are written) it can be seen that as many as 7 directories have the same digital identifiers equal to 2. The question is, what is the uniqueness here?

The first two elements of the list are easy to understand: ./ represents the current directory (in this case, the root), and ../ is the parent directory of the current one; and since there is, by definition, nothing above the root in the file hierarchy, it stands for itself. So it's not surprising that ./ and ../ have the same identifier - they are different designations (hard links, or, in other words, duplicate names) for the same root directory.

But the same, as it seems at first glance, the value of the identifier for the /dev, /home, /tmp, /usr, /var directories requires explanation. However, it is simple: they are all directories that have independent file systems mounted, either located on separate devices disk partitions, like /home, /usr, /var directories, or virtual file systems that do not build on any real disk device ( the /dev directory with the device file system and, in this case, the /tmp directory where the file system is mounted in random access memory, which is yet to be discussed). And since the inodes table is different for each file system, it is not surprising that the root of each of them is identified by the number 2 the inodes in them are numbered in their own reference system.

So, mounting is the inclusion of a file system from the system into any of the existing directory in the root system (not necessarily directly at the root, it can be of any nesting level, which will be illustrated below). Without this, the directories and files of such a mounted system are simply inaccessible. This is important to understand when faced with expressions like "create /usr filesystem". From what has been said above, it is obvious that something is created (by the newfs command) just some kind of abstract file system, and it acquires its “name” only at the time of mounting to the specified directory.

Interestingly, the identifier of the directory to mount (it is also called the mount point, mount point) is acquired only at the time of mounting. To verify this, let's conduct a simple experiment. In the /mnt directory, designed specifically for mounting temporarily mounted file systems), you can see three subdirectories /mnt/disk, mnt/iso, /mnt/usb (this is on my system, I created them for my own convenience; originally the /mnt directory in FreeBSD is empty). When the system starts, nothing is mounted in them, and their usual state is to be empty. If you look at their IDs, you'll see something like this: $ ls -i1 /mnt 16:46 ttyp0 18 disk/ 24 iso/ 19 usb/

Now let's take and mount a flash drive with a USB interface in / mnt / usb (that's what I intended it for) and repeat the review. And we see: 18 disk/ 24 iso/ 2 usb/

That is, the identifiers of the directories that remained empty (/mnt/disk and /mnt/iso) did not change, and the identifier of the /mnt/usb directory magically changed to 2. For at the time of mounting it became the root for its own file system and the starting point for calculation of inodes of all files written on it.

Let's digress a bit and remember about hard links, by means of which different names can be assigned to the same inode and related data blocks. Now it’s clear why all such duplicate files should be in the same file system: after all, different file systems have their own, non-matching, numbering of inodes, and it is impossible to identify them by numbers (otherwise, how would the system distinguish the /usr and /var directories from our example because the names of the files are deeply careless to her). For symbolic links that have their own inodes (in fact, nothing but them) with their identifiers numbered in the reference system of the file system in which they are located, there is no such restriction. And symbolic links can lie anywhere (including on a remote machine not only on a different partition).

Let's return, however, to the example of our root directory. From all that has been considered, it can be seen that a number of its branches lie on separate partitions and form their own file systems (in fact, this is why we created both of them). And, therefore, they all need to be mounted.9. Mounting Practice

The purpose of mounting is the mount command, which is either executed automatically during system boot or manually from command line. Actually, in the full sense, only the root file system is automatically mounted in any case. Not necessarily located on the disk when starting from a rescue CD or other safety media, it can be located on a virtual disk in RAM. However, the process of mounting the root file system is as inevitable as the victory of socialism on a global scale: just as socialism, without winning on a global scale, simply loses its ability to exist (which we observed not so long ago), so does an OS exist without a root system. can not. On Linux, this triggers kernel panic mode roughly the state our leaders fell into 20 years ago. True, they turned out to be stronger than Linux "and and recovered quite quickly so until now we have to reboot" yat (or reboot? and we are getting stronger :)). However, this does not apply to the case of mounting, which I will now try to present to you.

So, to mount all file systems, except for the root, you need to take some action. We will first look at how to execute them by hand, and then how to perpetuate them in the appropriate configuration files.

So the mount command. Actually, this is a whole family of programs, each of which is designed to mount file systems certain types not only UFS, but any of the FreeBSD supported. The list of these is quite extensive you can get an idea about it by browsing the /sbin directory on this subject: $ ls /sbin/mount*

which will give us /sbin/mount /sbin/mount_msdosfs /sbin/mount_smbfs /sbin/mount_cd9660 /sbin/mount_nfs /sbin/mount_std /sbin/mount_devfs /sbin/mount_ntfs /sbin/mount_udf /sbin/mount_ext2fs /sbin/mount_nullfs / sbin/mount_umapfs /sbin/mount_fdescfs /sbin/mount_nwfs /sbin/mount_unionfs /sbin/mount_linprocfs /sbin/mount_portalfs /sbin/mount_mfs /sbin/mount_procfs

Each command from this list is responsible for a different type of file system, some of which we will return to later. In the meantime, we note only the actual / sbin / mount, designed to work with UFS and UFS2.

Called from the command line, it takes two arguments the name of the device to be mounted and the mount point (that is, the directory into which the underlying file system is to be mounted). The device name must refer to a patrician already marked on an existing BSD slice with a UFS2 (UFS) file system created on it, for example, $ mount /dev/ads0d /usr

mounts the file system on the specified partition to the /usr directory at the root of the file tree. If the file system on the device is not created or has a type other than 4.2BSD, an error message will follow an indication of incorrect super block: unlike the Linux utility of the same name, the FreeBSD mount command itself cannot recognize the file system type.

The mount point has the following requirements: a) a directory with that name must exist at the time of mounting, and b) be as empty as possible. The first is mandatory, the second not really. Mounting to a directory with any files will go smoothly (remember, in Linux not so long ago this caused the system to crash), but all its contents will become inaccessible until unmounted. And if the files contained in it play a significant role for any subsystem, this can cause all sorts of bad consequences. For example, if the contents of the /tmp directory are locked by mounting a filesystem there while the X window system is running, the result is likely to be a crash of the X server. Fortunately, if necessary, you can perform a combined mount (see below).

In the specified form, the mount will be performed with some default characteristics: the file system will be available for reading / writing in the so-called mode. noasync (the one in which metadata operations are performed synchronously, and data operations asynchronously). You can change this position using the -o option values. There are quite a few of them, but practically the main ones at this stage for us will be:

  • async will provide a completely asynchronous mode (despite the ominous warnings in the previous notes, I will later talk about a situation where this can be justified);
  • sync on the contrary, the inclusion of a fully synchronous mode (although I don’t really understand why this is practically necessary);
  • noatime a very useful option that prevents updating the last access time attribute on files, which improves performance a lot;
  • rdonly mounts the filesystem in read-only mode (sometimes necessary);
  • union the same option that allows you to perform a union mount, in which the previous contents of the mount point directory remain visible; true with some limitations see man (8) mount.

There are several other values ​​for the -o option, which prevent certain types of files from being placed on the mounted file system, such as executable (-o noexec), device files (-o nodev), or files with the so-called. suidity bit (-o nosuid), but they are of practical importance mainly for server administrators and serve security purposes. On a desktop machine, the usual form of mount would be something like this: $ mount -o noatime /dev/ads0d /usr; $ mount -o noatime /dev/ads0e /var; $ mount -o noatime /dev/ads0f /home

All of this only applies to mounting FreeBSD filesystems. However, in practice, it often becomes necessary to incorporate other types of file systems into its directory tree. This is especially often required for ISO9660 (the usual file system for all CDs except Mac's) and FAT's of various kinds. In this case, the appropriate mount command must be invoked explicitly, e.g. $ mount_cd9660 /dev/acd0 /cdrom

to mount a compact, or $ mount_msdosfs /dev/ad## /mnt

for FAT "but of any kind (including FAT32). However, this can also be done indirectly by specifying the mount command with the option -t filesystem_type. So, the command $ mount -t ext2fs /dev/ad## /mnt/linux

will mount the Linux filesystem (if enabled in the kernel). In this case, the standard mount for BSD partitions is simply replaced by the /mount_ext2fs command, which is designed to mount ext2fs partitions (and ext3fs too but, of course, without any logging functions). That is, the form $ mount -t fstype ... ...

would be the full equivalent of the $mount_fstype ... ... command

All file system mounts (including removable media) in FreeBSD require superuser privileges. Among the values ​​of the -o option here, unlike the Linux version of the mount command, there is no user parameter that allows mounting by ordinary users. True, there are several ways to get around this, but now it’s out of place to talk about them. Setting up automatic mounting

However, in practice, manual mounting is used only for rarely used file systems. All file systems fundamentally important for the functioning of FreeBSD are mounted automatically at system startup, and frequently used in a semi-automatic, so to speak, mode.

For automatic mounting, the mount program is run during the boot process from the initialization scripts. It looks up its configuration file /etc/fstab and mounts whatever it finds there, with a few exceptions (noted below).

The /etc/fstab file itself is automatically generated when FreeBSD is installed, including all filesystems needed to keep it running. However, later it can be edited manually in order to introduce new devices for mounting or additional options for already included devices.

The /etc/fstab file is a simple database in text format (separated fields with spaces or tabs), including the following fields:

  • Device filename of the device on which the file system is located, similar to the first argument of the mount command when using it manually;
  • Mountpoint mount point (corresponds to the second argument of the mount command);
  • FStype type of the file system, specified in the same way as the value of the -t option;
  • Options additional mount options, similar to the values ​​of the -o option;
  • Dump execution conditions Reserve copy file system with the dump utility;
  • Pass# conditions for checking the file system with the fsck utility.

In a freshly installed FreeBSD, /etc/fstab will necessarily include the following entries (example for the 1st slice of the Master disk on the 1st IDE channel): # Device Mountpoint FStype Options Dump Pass# /dev/ad0s1a / ufs rw 1 1 /dev/ad0s1b none swap sw 0 0

If you follow the advice of reasonable people (and sysinstall defaults) and select some branches of the file system from the root, entries like /dev/ad0s1d /var ufs rw 0 0 /dev/ad0s1e / usr ufs rw 0 0 /dev/ad0s1f /tmp ufs rw 0 0

responsible for the file system with user home directories.

Obviously, in the Options field, you can add any available (and reasonable) values ​​​​of the -o option (separated by commas, without spaces), for example, noatime for all file systems, and for /tmp also async, because the contents of this directory are not expected save after reboot.

The above applies to filesystems mounted automatically at startup. However, no one bothers to make entries in /etcfstab for systems that are connected from time to time in this case, they can be mounted according to a simplified scheme (this is what I meant above under semi-automatic mode). So, for a CD drive, you can add a line (in fact, it automatically appears when generating the /etc/fstab file) /dev/acd0 /cdrom cd9660 ro,noauto 0 0

in which the options, as you might guess, prescribe refusing to mount at startup (noauto) and read-only mode (ro). After that, to mount the CD, it will be enough to specify only the mount point - $ mount / cdrom

Similar entries can be made for all removable drives (Zip, USB drives, even floppy disks) and for non-BSD partitions (FAT or Ext2fs). By the way, you can mount file systems according to the forgiven scheme immediately after making changes to /etc/fstab, without waiting for the machine to be rebooted.

All involved file systems must be unmounted before turning off the power or rebooting the machine. Upon graceful shutdown, this is done automatically, as a result of which each of the writable file systems (or rather, the partition that carries it) receives a clean unmount bit in its superblock.

However, in some cases (for example, when enabling or disabling the Soft Updates mechanism or to perform an integrity check), it becomes necessary to manually unmount (and remount) file systems, for which the umount command is used. It requires a single argument specifying the mount point of the file system to be "removed" from the directory tree, for example: $ umount /tmp

You can unmount multiple filesystems with one line: $ umount /usr /var /home

Alternatively, all mounted filesystems, or all filesystems listed in /etc/fstab (except root), which would require the $ umount -A options

or $ umount -a

respectively. It is also possible to unmount filesystems of certain types by specifying the values ​​of the -t option. So, the command $ umount -t ufs

unmounts only BSD partitions without affecting the CD and everything else that is involved in the system.

File systems at the time of unmounting should not be used, that is, there should be no access to the files located on them. Thus, the location of a file system in some directory is enough reason to refuse to unmount it (with a message like device busy), which is why none of the above commands will be able to unmount the root file system. But reading a data file by some program is not a reason for refusing to unmount the system carrying this file (after all, in the general case, communication between a file in memory and a file on disk occurs only at the moment changes are written.

However, you can also unmount the file system you are using for this you need to give the umount command with the -f option. True, this can lead to errors, so it is better not to resort to it unless absolutely necessary. And the forced unmount option will have no effect on the root file system. Bulk mount

To continue working after performing low-level operations on file systems, they will need to be mounted back. This can be done not only without a reboot, but also without a tedious individual mount. It is enough to resort to the -a option: $ mount -a

which will mount all filesystems for which there are entries in /etc/fstab. In this case, an attempt will be made to mount those of them that are marked with the noauto flag. To avoid this, you can additionally specify the file system type. That is, the command $ mount -a -t ufs

mounts only BSD partitions, not encroaching on CDs or flash drives. Or, on the contrary, you can exclude some of the file systems listed in /etc/fstab from the global mount process, for example, currently unnecessary FATs: $ mount -a -t nomsdosfs Preamble instead of conclusion

By the way, the mount command without options and arguments (and in this form, unlike all the cases discussed above, it can also be given by an ordinary user) will display a list of currently mounted file systems indicating the mount point, its conditions and operating mode. For example, for the machine on which these lines are written, its output will look like this: /dev/ad0s1a on / (ufs, local, noatime, soft-updates) devfs on /dev (devfs, local) /dev/ccd0e on /var (ufs, local, noatime, soft-updates) /dev/ccd1e on /usr (ufs, local, noatime, soft-updates) /dev/ccd2e on /home (ufs, local, noatime, soft-updates) /dev/ md0 on /tmp (ufs, local, noatime, async)

The first line of the output shows that the /dev/ad0s1a partition is mounted in our root directory, carries a UFS file system (specifically in this case UFS2, but they do not differ in the output of the mount command) with the Soft Updates mechanism enabled, is local ( i.e. located on the drive of this machine network drives are also mounted by the mount command) and is not affected by the update of the atime attribute.

But then there are lines for devices and file systems, which were not discussed in the previous narratives. Moreover, if we look at the /etc/fstab file corresponding to the current configuration: $ more /etc/fstab /dev/ad0s1b none swap sw 0 0 /dev/ar0s1b none swap sw 0 0 /dev/ad0s1a / ufs rw,noatime 1 1 /dev/ccd0e /var ufs rw,noatime 2 2 /dev/ccd1e /usr ufs rw,noatime 2 2 /dev/ccd2e /home ufs rw,noatime 2 2 /dev/acd0 /cdrom cd9660 ro,noauto 0 0 / dev/da0s1 /mnt/usb ext2fs rw,noauto,noatime 0 0 /dev/md0 /tmp mfs rw,noatime,async,-s32m 2 0

we will see that one of the output lines (devfs on /dev (devfs, local) does not match at all among its entries. What are these devices and file systems?

Regarding devices like /dev/ccd0? I will only say for now that these are software RAID arrays (more on them will be discussed later). And here are devfs and mfs virtual file systems, about which directly in the next note.

I often pay attention to the fact that simple questions are often poorly covered on the Internet. This is probably because all the 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 the most frequent not only for beginners, but also for serious administrators who simply have not had to deal with this. Even serious administrators do not do this every day, but in order not to forget, they keep a kind of cheat sheet for themselves, without admitting it to anyone. Let's fix everything. Now you will learn how to add a hard drive to FreeBSD in 5 minutes. So. First, a complete instruction will be provided to understand 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

Selecting a hard drive name

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

Geom disk list

Or this command:

Cam control devlist

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

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

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

gpart show ada1

The disk has no partition.

Removing existing markup

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

Gpart destroy -F ada1

Creating a GPT Markup

First we need to create a disk layout. I highly recommend forgetting about MBR and switching to a new, more convenient and functional one - GPT.

Create a GPT partition on the disk, then check what happened:

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

Now we have a GPT disk partition. From the output, you can see that absolutely the entire disk, starting from LBA 34 and ending with 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 drive:

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

Creating sections (slices)

If the installation is carried out on modern hard drives, whose sector size = 4 kb, then when creating partitions (partitions), you must use alignment. There are two ways to proceed: 1) if we specify the section parameters 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 section to 4 kb sectors. Since we are in this example we make a test installation on virtual hard disk, you don't have to. 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 sections. To do this, there is a gpart add command with various options. First parameter -t- indicates the type of file system being created. In our case, two types will be used: freebsd-swap and freebsd-ufs. The following are two optional parameters: -b- indicates the LBA number 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 the LBA. The size of one LBA block = 512 bytes. It is desirable to specify 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 partition 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 partitions and then see what we got. 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 partition 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 rather than blocks. It's much more convenient. The only negative is that the system cannot always correctly calculate the number of blocks. There may be cases when a certain number of blocks will remain empty on the disk when specifying the partition size in bytes.

Creating a file system (formatting)

Swap partitions do not need to be formatted. But sections like ufs must be formatted before use. It would be more correct to say: a file system must be created on them.

In order 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 indicates that the Soft Updates mechanism should be used in this file system. You can choose not to use this option to disable this mechanism.

Mounting

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

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 partition. Let's run the command:

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

Swapon /dev/ada1p1

In the same way, using the swapoff command, you need to turn off the SWAP partition before performing any actions on it.

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

Brief instruction

Given: hard drive /dev/ada1

Target: delete the existing partition, create a new GPT partition, create two partitions: swap and data, and connect them to the working system.

After each step, do gpart show to see the result. Sequencing:

  1. Remove existing markup: gpart destroy -F ada1
  2. Create new layout: 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 file system UFSv2 on the second partition: newfs -U /dev/ada1p2
  5. Add lines to /etc/fstab to automount on 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.

You can change the access rights and the owner of files and directories in using the commands chmod and chown. Mask for setting rights to generated files, can be changed globally, in /etc/profile for Linux and /etc/login.conf for FreeBSD. Usually the default mask 022 . Meaning umask subtracted from 777 , so the permissions will matter 755 . exec- execution allowed read - read permission write - write permission SUID bit - the file attribute, in conjunction with the executable file attribute, allows the file being run to be executed with the effective UID of the file's owner rather than the one who runs the file 1 --x execute # Permissions 764 = exec/read/write | read/write | read 2 -w-write # For: |-- Owner --| |-Group-| |Oth| 4 r-- read ugo=a u=user, g=group, o=others, a=everyone# chmod MODE[,MODE] FILE # MODE has the form: *([-+=]()) # chmod 640 /var/log/maillog # Set permissions equal to -rw-r----- # chmod u=rw,g=r,o= /var/log/maillog # As above # chmod -R o-r /home/* # Recursively change permissions, disable reading for Other # chmod u+s /path/to/prog # Install SUID bits per executable (be careful here, you should 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 owners# chgrpgroup /path/to/file # Change the group that owns the file# chmod 640 `find ./ -type f -print` # Change permissions to 640 for all files# chmod 751 `find ./ -type d -print` # Change permissions 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 SMART disk information

Loading

FreeBSD

To load the old kernel, in an emergency, such as after a failed build and installation of 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 free space and mounted devices# cat /proc/partitions # Show all registered partitions (Linux)

Directory Information

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

Who opened what files

Sometimes you need to find out which file has locked a partition, which is why the command umount gives the corresponding error. # umount /home/ umount: unmount of /home # The partition cannot be unmounted until /home blocked 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 an 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 do 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/eedcoba (guam: /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 Filesystems

For example cdrom written 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 Write 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=1 # Or enter a line "vfs.usermount=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=cdfss,ro,procuid,nosuid,nodev,exec 0 0

Mounting a FreeBSD Linux Partition

Look for the section number in fdisk, usually this is the root partition, but it can be on another BSD slice. If there are many slices on a FreeBSD partition, they will not be visible through fdisk, but 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=ufs2,ro /dev/sda3 /mnt /dev/sda10 = /tmp; /dev/sda11 /usr # Another slice

Remount

Remount the device without first unmounting, for example to fsck# mount -o remount,ro / # Linux # mount -o ro / # FreeBSD Copy data stream from CDROM"and to file ISO image. # dd if=/dev/cd0c of=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=/dev/zero of=/swap2gb bs=1024k count=2000 # mkswap /swap2gb # Create swap # swapon /swap2gb # Enable swap, now it can be used# swapoff /swap2gb # Disable swap # rm /swap2gb

Mounting an 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 dialed on a Windows machine will be \\smbserver\myshare\. We will install 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=winuser //smbserver/myshare /mnt/smbshare # mount -t cifs -o username=winuser, password=winpwd //192.168.16.229/myshare /mnt/share Also package mount.cifs allows you to store privileges in a file, e.g. /home/user/.smb: username=winuser password=winpwd And now mount: # mount -t cifs -o credentials=/home/user/.smb //192.168.16.229/myshare /mnt/smbshare

FreeBSD

use the key -I to set the IP address (or DNS); smbserver, 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, make 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 storage 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=/dev/hdc of=/tmp/mycd.iso bs=2048 conv=notrunc Use mkisofs to create an image from a file in a directory. To overcome filename restrictions, use the option -r, which includes the extension Rock Ridge, basic for UNIX systems, -J includes Joliet, used by Microsoft, -L allows ISO9660 names that start with a dot. # mkisofs -J -L -r -V TITLE -o imagefile.iso /path/to/dir On FreeBSD, mkisofs can be installed from /usr/ports/sysutils/cdrtools.

Burn CD/DVD ISO images

FreeBSD

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

linux

Also use cdrecord as described above. You can also use the native ATAPI interface: # cdrecord dev=ATAPI -scanbus Record as described above.

dvd+rw-tools

The dvd+rw-tools package (FreeBSD: ports/sysutils/dvd+rw-tools) has all the functionality needed to work with DVDs, plus growisofs, to burn a CD or DVD. Documentation with examples can be found in the FreeBSD handbook Chapter 18.7 # -dvd-compat closes the disc# growisofs -dvd-compat -Z /dev/dvd=imagefile.iso # Write existing iso image # growisofs -dvd-compat -Z /dev/dvd -J -R /p/to/data # Record directly

Convert image from Nero .nrg file to .iso file

Nero adds a 300kb header to the image, it can be trimmed with dd. # dd bs=1k if=imagefile.nrg of=imagefile.iso skip=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=/dev/random of=/usr/vdisk.img bs=1K count=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 if your settings are correct using the command /etc/rc.d/mdconfig start(previously removing the device md0 using the command # mdconfig -d -u 0). Keep in mind that auto-mounting the image will only work if the image file is NOT in the root partition, because the script /etc/rc.d/mdconfig executed at an early stage of boot, 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="YES" /etc/rc.conf: mdconfig_md0="-t vnode -f /usr/vdisk.img" # /usr not in the root partition/etc/fstab: (0 0 at the end, very important, this will indicate fsck ignore device check as it doesn't exist yet) /dev/md0 /usr/vdisk ufs rw 0 0
In addition, later you can increase the size of the image, say by 300 mb. # mount /mnt; mdconfig -d -u 0 # dd if=/dev/zero bs=1m count=300 >> /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=/dev/zero of=/usr/vdisk.img bs=1024k count=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 urandom, but less secure for encryption. # dd if=/dev/urandom of=/usr/vdisk.img bs=1024k count=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. Let's 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=64m tmpfs /memdisk

Drive performance

Reading and writing 1gb file in section ad4s3c (/home) # time dd if=/dev/ad4s3c of=/dev/null bs=1024k count=1000 # time dd if=/dev/zero bs=1024k count=1000 of=/home/1Gb.file # hdparm -tT / dev/hda # Linux only

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


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

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

    #kldload fuse

    You can check if 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 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=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=0x2

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

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

    /dev/da0- this is our flash drive, we found out in paragraph 3.
    /mnt is the mount point. She can be anyone.

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

    Ntfs-3g /dev/da0

    press TAB and see the partitions of the flash drive

    Da0 da0s1

    And mount this section

    Ntfs-3g /dev/da0s1 /mnt

  5. We go to the directory where we mounted the flash drive and see its contents there: #cd /mnt #ll total 13 drwxrwxrwx 1 root wheel 0 4 Nov. 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 Liszt Microsoft Office Excel.xlsx*

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

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

    And after that, we use the command

    #umount /mnt

    note that the argument is not a flash drive, but its mount point!
    IMPORTANT: Do not pull out the 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!


2022
maccase.ru - Android. Brands. Iron. News