How to mount disks using mount and/or fstab file ?
Mount & Umount
Mount is use to mount and unmount a disk temporally / or for the current session on Linux.
Syntax:
mount –t [Type] –o [Options] [Device/Source] [Mount Point]
Example: Mount the partition sdb2 on /media/mydata
sudo mount /dev/sdb2 /media/mydata
sudo mount -o defaults,rw /dev/sdb2 /media/mydata (read write rights)
sudo umount /dev/sdb2
See options table for options
“fstab” file
The Fstab file is use to mount partitions automatically at the system boot. Here you can found the root, swap …
Syntax:
[Device/Source] [Mount Point] [File System Type] [Options] [Dump] [Pass]
Device/Source: The source can be
- UUID of the partition
- Device (/dev/sdb1)
- A folder (/home/you/the_www_folder)
Mount Point: Is the destination
- / (root)
- none (Ex: for the swap)
- /var/www (To override an existing folder)
File System Type: Examples:
auto, bind
ext2, ext3, ext4, swap
- (Fat16),
vfat
(Fat32),ntfs (ntfs-3g)
reiserfs, btrfs, tmpfs, udf, iso9660, hfs
cifs, nfs, fuse (Remote partitions)
Options :
- defaults = rw, suid, dev, exec, auto, nouser, async
- Please see the options table
Dump: to use with the backup utility ‘dump’ (0 or 1)
- 0 = no backup
- 1 = file system is backed up
Pass: is the fsdisk order (0, 1 or 2)
- 0 == do not check (swap, windows …)
- 1 == check this partition first (High priority, Ex: root /)
- 2 == check this partition(s) next (Low priority, other partitions)
NTFS Mount error
If you are unable to mount Windows (NTFS) filesystem after hibernation or powerdown ..., you can try:
sudo ntfsfix /dev/sdXY
noauto (fstab)
The noauto option of the /etc/fstab allow to prepare mount but not mount on boot or with mount -a
Example :
On : /etc/fstab
# Prepare mount point with noauto
//192.168.0.1/DATA /media/DATA/ cifs noauto,rw 0 0
Mount
sudo mount //192.168.0.1/DATA
Unmount
sudo umount /media/DATA/
Mostly used options:
Options | Description | Compatibility |
---|---|---|
defaults |
Equal to rw,suid,dev,exec,auto,nouser,async |
All |
rw/ro |
Read/write or Read Only | All |
suid/nosuid |
The SUID and SGID bits , the rights given to the executables on this partition | All |
dev/nodev |
Device or not a device | All |
exec/noexec |
Allow program execution | All |
auto/noauto |
Auto mount when calling 'mount -a' | All |
nouser |
can use by the root user only (user = root) | All |
_netdev |
Need network configuration before mount | ?? |
async |
mount asynchrone (par défaut) | All |
atime/noatime |
write access time (Set noatime for the SSD) |
Norme POSIX |
sw |
swap partitions | swap |
discard |
active the TRIM on SSD partitions (To add manually) | ext4, btrfs (SSD) |
Other options
Options | Description | Compatibility |
---|---|---|
user |
Allow current user to mount / unmount the file system. This leads to the use of options noexec, nosuid, and nodev (unless exec, dev, suid are specified) | All |
sync |
Synchronous mount (not recommended) | ext2-3, fat, vfat, ufs |
uid= |
Specifies the ID of the owner of the files for non-Linux file systems (where it is not specified). You can find it in your "/etc/passwd".
|
non-Linux |
gid= |
Same for the owners groups (Group IDs are in /etc/group) |
non-Linux |
umask= |
Specifies the permissions (access rights) on the partition, like uid and gid . |
non-Linux (fat) |
dir_mode= |
Specifies usage rights for the folders (with : umask ) |
non-Linux |
dmask= |
Specifies usage rights for the folders (with : umask ) |
non-Linux (fat) |
file_mode= |
Specifies usage rights for the files (with : umask ) |
non-Linux |
fmask= |
Specifies usage rights for the files (with : umask ) |
non-Linux (fat) |
utf8 |
Convert file name encoding from unicode 16 bits to utf8 | ISO9660 (Images CD/DVD), Ntfs, Fat32 |
windows_names |
Prevents the use of non-compatible characters with Windows in filenames (/ \ : ? * < > " |) |
fat, ntfs |
Links :
https://doc.ubuntu-fr.org/mount_fstab
https://help.ubuntu.com/community/Fstab
Comments