mount(2) | System Calls Manual | mount(2) |
mount - monta i filesystem
Standard C library (libc, -lc)
#include <sys/mount.h>
int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *_Nullable data);
mount() collega il filesystem specificato da source (che è spesso un nome di percorso che individua un dispositivo, ma può anche essere il nome di percorso di una directory o di un file, o una stringa fittizia) alla posizione (una directory o un file) specificata dal nome di percorso in target.
Per montare dei filesystem è necessario avere le autorizzazioni adeguate (Linux: la funzionalità CAP_SYS_ADMIN).
I valori dell'argomento filesystemtype supportati dal kernel sono elencati in /proc/filesystems (p.es, "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse", "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660"). Ulteriori tipi di filesystem possono essere resi disponibili se sono stati caricati i moduli appropriati.
L'argomento data è interpretato dai differenti filesystem. Tipicamente è una stringa di opzioni, separate da virgole, riconosciute da un determinato filesystem. Vedere mount(8) per dettagli sulle opzioni disponibili per ciascun tipo di filesystem. Questo argomento può essere specificato come NULL, se non ci sono opzioni.
Una chiamata a mount() esegue una tra le molte operazioni di tipo generale, basandosi sui bit specificati in mountflags. La scelta dell'operazione da eseguire è determinata controllando i bit impostati in mountflags, effettuando dei test nell'ordine qui elencato:
Ciascuna di queste operazioni è descritta nel dettaglio più avanti in questa pagina. Ulteriori flag possono essere specificati in mountflags per modificare il comportamento di mount(), come'è descritto qua sotto.
L'elenco seguente descrive i flag aggiuntivi che possono venir specificati in mountflags. Si noti che alcuni tipi di operazione ignorano alcuni o tutti questi flag, come descritto più avanti in questa pagina.
Da Linux 2.4 in poi, alcuni dei flag visti sopra sono impostabili a livello di ogni singolo montaggio, mentre altri si applicano al superblocco del filesystem montato, il che vuol dire che tutti i montaggi dello stesso filesystem condividono tali flag. (Precedentemente, tutti i flag erano a livello di superblocco.)
I flag per singolo punto di montaggio sono i seguenti:
The following flags are per-superblock: MS_DIRSYNC, MS_LAZYTIME, MS_MANDLOCK, MS_SILENT, and MS_SYNCHRONOUS. The initial settings of these flags are determined on the first mount of the filesystem, and will be shared by all subsequent mounts of the same filesystem. Subsequently, the settings of the flags can be changed via a remount operation (see below). Such changes will be visible via all mounts associated with the filesystem.
Da Linux 2.6.16 MS_RDONLY può essere impostato o annullato a livello di ogni singolo punto di montaggio, nonché a livello del superblocco del filesystem sottostante. Il filesystem montato sarà scrivibile solo se né il filesystem né il punto di montaggio sono marcati come di sola lettura.
Un montaggio esistente può essere montato di nuovo specificando MS_REMOUNT in mountflags. Questo permette di cambiare mountflags e i dati di un montaggio già in essere senza dover smontare e rimontare il filesystem. target deve avere gli stessi valori specificati nella chiamata mount() iniziale.
Gli argomenti source e filesystemtype sono ignorati.
Gli argomenti mountflags e data dovrebbero corrispondere ai valori nella chiamata mount() originale, ad eccezione dei parametri che si desidera modificare.
The following mountflags can be changed: MS_LAZYTIME, MS_MANDLOCK, MS_NOATIME, MS_NODEV, MS_NODIRATIME, MS_NOEXEC, MS_NOSUID, MS_RELATIME, MS_RDONLY, MS_STRICTATIME (whose effect is to clear the MS_NOATIME and MS_RELATIME flags), and MS_SYNCHRONOUS. Attempts to change the setting of the MS_DIRSYNC and MS_SILENT flags during a remount are silently ignored. Note that changes to per-superblock flags are visible via all mounts of the associated filesystem (because the per-superblock flags are shared by all mounts).
A partire da Linux 3.17, se nessuno tra MS_NOATIME, MS_NODIRATIME, MS_RELATIME, or MS_STRICTATIME viene specificato in mountflags, l'operazione di rimontaggio preserva i valori esistenti di questi flag (piuttosto che impostarli al valore predefinito MS_RELATIME).
Since Linux 2.6.26, the MS_REMOUNT flag can be used with MS_BIND to modify only the per-mount-point flags. This is particularly useful for setting or clearing the "read-only" flag on a mount without changing the underlying filesystem. Specifying mountflags as:
MS_REMOUNT | MS_BIND | MS_RDONLY
will make access through this mountpoint read-only, without affecting other mounts.
Se mountflags comprende MS_BIND (disponibile da Linux 2.4 in poi) viene eseguito un montaggio di tipo bind. Un montaggio di tipo bind rende un file o un sottoalbero di directory visibile a un altro punto all'interno dell'unica gerarchia di directory. I montaggi di tipo bind possono attraversare i filesystem e oltrepassare le gabbie chroot(2).
Gli argomenti filesystemtype e data sono ignorati.
The remaining bits (other than MS_REC, described below) in the mountflags argument are also ignored. (The bind mount has the same mount options as the underlying mount.) However, see the discussion of remounting above, for a method of making an existing bind mount read-only.
In modo predefinito, quando una directory è montata con un montaggio di tipo bind, viene montata solo quella particolare directory; se ci sono dei sottomontaggi nell'albero della directory, questi non sono montati nel montaggio di tipo bind. Se viene specificato anche il flag MS_REC, viene effettuata un'operazione di montaggio di tipo bind ricorsiva: tutti i sottomontaggi nel sottoalbero source (tranne i montaggi non condivisibile (unbindable) con un'operazione di bind) sono anche montati con un montaggio di tipo bind alla posizione corrispondente nel sottoalbero target.
Se mountflags include uno tra MS_SHARED, MS_PRIVATE, MS_SLAVE o MS_UNBINDABLE (tutti disponibili a partire da Linux 2.6.15), il tipo di condivisione di un montaggio esistente viene cambiato. Se si specifica più d'uno di questi flag, viene prodotto un errore.
I soli altri flag che possono essere specificati nel cambiare il tipo di condivisione sono MS_REC (descritto sotto) e MS_SILENT (che viene ignorato).
Gli argomenti source, filesystemtype e data sono ignorati.
I tipi di condivisione richiesti dai flag hanno il seguente significato:
By default, changing the propagation type affects only the target mount. If the MS_REC flag is also specified in mountflags, then the propagation type of all mounts under target is also changed.
Per ulteriori dettagli sui tipi di condivisione del montaggio (compreso il tipo di condivisione predefinito assegnato ai nuovi montaggi, si veda mount_namespaces(7).
If mountflags contains the flag MS_MOVE (available since Linux 2.4.18), then move a subtree: source specifies an existing mount and target specifies the new location to which that mount is to be relocated. The move is atomic: at no point is the subtree unmounted.
I rimanenti bit nell'argomento mountflags vengono ignorati, poiché essi sono gli argomenti di filesystemtype e data.
If none of MS_REMOUNT, MS_BIND, MS_MOVE, MS_SHARED, MS_PRIVATE, MS_SLAVE, or MS_UNBINDABLE is specified in mountflags, then mount() performs its default action: creating a new mount. source specifies the source for the new mount, and target specifies the directory at which to create the mount point.
Vengono impiegati gli argomenti filesystemtype e data, e ulteriori bit possono essere specificati in mountflags per modificare il comportamento della chiamata.
In caso di successo restituisce zero. In caso di errore restituisce -1, e errno verrà impostato per indicare l'errore.
I valori di errore indicati di seguito sono causati da errori indipendenti dal tipo di filesystem. Ciascun tipo di filesystem può avere i propri errori speciali e il suo comportamento speciale. Vedere il codice sorgente del kernel per dettagli.
The definitions of MS_DIRSYNC, MS_MOVE, MS_PRIVATE, MS_REC, MS_RELATIME, MS_SHARED, MS_SLAVE, MS_STRICTATIME, and MS_UNBINDABLE were added to glibc headers in glibc 2.12.
Questa funzione è specifica di Linux e non deve essere usata in programmi pensati per essere portabili.
A partire da Linux 2.4 un singolo filesystem può essere montato su punti di montaggio multipli, e su uno stesso punto di montaggio possono essere impilati più montaggi.
The mountflags argument may have the magic number 0xC0ED (MS_MGC_VAL) in the top 16 bits. (All of the other flags discussed in DESCRIPTION occupy the low order 16 bits of mountflags.) Specifying MS_MGC_VAL was required before Linux 2.4, but since Linux 2.4 is no longer required and is ignored if specified.
Il flag originale MS_SYNC è stato rinominato MS_SYNCHRONOUS in 1.1.69 quando è stato aggiunto un diverso MS_SYNC a <mman.h>.
Prima di Linux 2.4, un tentativo di eseguire un programma che usa set-user-ID o set-group-ID su un filesystem montato con MS_NOSUID falliva con EPERM. A partire da Linux 2.4 la richiesta di set-user-ID e set-group-ID in questo caso è ignorata senza emettere messaggi.
Starting with Linux 2.4.19, Linux provides mount namespaces. A mount namespace is the set of filesystem mounts that are visible to a process. Mount namespaces can be (and usually are) shared between multiple processes, and changes to the namespace (i.e., mounts and unmounts) by one process are visible to all other processes sharing the same namespace. (The pre-2.4.19 Linux situation can be considered as one in which a single namespace was shared by every process on the system.)
Un processo figlio creato da fork(2) condivide lo spazio dei nomi di montaggio del suo genitore: lo spazio dei nomi di montaggio viene preservato se si invoca execve(2).
Un processo può ottenere uno spazio dei nomi di montaggio privato se: è stato creato usando il flag CLONE_NEWNS di clone(), e in questo caso il suo nuovo spazio dei nomi viene inizializzato come copia degli spazi dei nomi del processo che ha chiamato clone(); oppure se chiama unshare(2) con il flag CLONE_NEWNS, che permette allo spazio dei nomi del chiamante di ottenere una copia privata dello spazio dei nomi che in precedenza condivideva con altri processi, in modo che chiamate a montaggi e smontaggi futuri siano invisibili agli altri processi (ad eccezione di processi figli creati successivamente dal chiamante), e viceversa.
Per ulteriori dettagli sugli spazi dei nomi dei montaggi si veda: mount_namespaces(7).
Each mount has a parent mount. The overall parental relationship of all mounts defines the single directory hierarchy seen by the processes within a mount namespace.
The parent of a new mount is defined when the mount is created. In the usual case, the parent of a new mount is the mount of the filesystem containing the directory or file at which the new mount is attached. In the case where a new mount is stacked on top of an existing mount, the parent of the new mount is the previous mount that was stacked at that location.
The parental relationship between mounts can be discovered via the /proc/[pid]/mountinfo file (see below).
The Linux-specific /proc/[pid]/mounts file exposes the list of mounts in the mount namespace of the process with the specified ID. The /proc/[pid]/mountinfo file exposes even more information about mounts, including the propagation type and mount ID information that makes it possible to discover the parental relationship between mounts. See proc(5) and mount_namespaces(7) for details of this file.
mountpoint(1), chroot(2), ioctl_iflags(2), mount_setattr(2), pivot_root(2), umount(2), mount_namespaces(7), path_resolution(7), findmnt(8), lsblk(8), mount(8), umount(8)
La traduzione italiana di questa pagina di manuale è stata creata da Giulio Daprelà <giulio@pluto.it>, Elisabetta Galli <lab@kkk.it>, Antonio Giovanni Colombo <azc100@gmail.com> e Marco Curreli <marcocurreli@tiscali.it>
Questa traduzione è documentazione libera; leggere la GNU General Public License Versione 3 o successiva per le condizioni di copyright. Non ci assumiamo alcuna responsabilità.
Per segnalare errori nella traduzione di questa pagina di manuale inviare un messaggio a pluto-ildp@lists.pluto.it.
5 febbraio 2023 | Linux man-pages 6.03 |