-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmount & umount
180 lines (88 loc) · 8.1 KB
/
mount & umount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Mount: All files in a Linux filesystem are arranged in form of a big tree rooted at ‘/‘.
The mount command mounts a storage device or filesystem, making it accessible and attaching it to an existing directory structure.
The umount command "unmounts" a mounted filesystem, informing the system to complete any pending read or write operations, and safely detaching it.
Some Important Options:
l : Lists all the mounted file systems
h : Displays options for command
V : Displays the version information
a : Mounts all devices described at /etc/fstab
t : Type of filesystem device uses
T : Describes an alternative fstab file
r : Read-only mode mounted
Find device and filesystem type:
# fdisk -l
# ls -l /dev/disk/by-id/usb*
# dmesg
# lsblk
The standard form of the mount command is:
# mount -t type device dir
Display information about file systems mounted:
# mount -l -t efs
or <-- The -l adds labels to this listing.
# mount -l
Mount file system:
# mount /dev/sda4 /mnt/mountpoint
Display mount version:
# mount -V
Unount file system:
# umount /dev/sda4
or
# umount /mnt/mountpoint
Unmount a busy file system as soon as it is not busy anymore:
# umount -l /dev/sda4 <-- -l (--lazy)
Unmount an unreachable NFS system:
# umount -f /dev/sda4 <-- -f (--force)
* Generally not a good idea to force unmount as it may corrupt the data on the file system.
Move a mounted tree to another place:
# mount --move olddir newdir
or
# mount -M olddir newdir
The recommended setup is to use "LABEL=<label>" or "UUID=<uuid>" tags rather than "/dev/disk/by-{label,uuid}" udev symlinks in the /etc/fstab file.
Mount uses UUIDs as strings. The UUIDs from command line or fstab are not converted to internal binary representation. The string representation of the UUID should be based on lowercase characters.
/etc/fstab may contain lines describing what devices are usually mounted where, using which options:
# mount -a [-t type] [-O optlist]
When the proc filesystem is mounted (at /proc, for instance), the files /etc/mtab and /proc/mounts have very similar contents.
Non-Superuser Mounts
Normally, only the superuser can mount filesystems. However, when fstab contains the user option on a line, anybody can mount the corresponding system.
Thus, given an fstab line
/dev/cdrom /cd iso9660 ro,user,noauto,unhide
any user can mount the iso9660 filesystem found on a CD-ROM, using the command
# mount /dev/cdrom
proc (or "procfs") is a special filesystem on Unix-like operating systems which presents running processes in a hierarchical file-like structure. It is typically mounted at the location /proc at boot time.
Helpful Link on FSTab - https://linoxide.com/file-system/understanding-each-entry-of-linux-fstab-etcfstab-file/
Each line in fstab correspond to a particular device or partitions. A sample entry on fstab file is as follows:
#device mounting_directory filesystem_type options dump fsck
/dev/hdc /cdrom iso9660 rw,noauto,user 0 0
• The first field
corresponds to the device name. If you have plugged in an external device and confused about the device name, you need to use ‘dmesg’ or ‘tail –f /var/log/messages’ to find the device name. For SCSI hard disks, devices will be names like /dev/sda (first drive), /dev/sdb (second drive).
• The second field
mentions the mount point on which the device needs to be mounted. This directory should exist. That is, you need to create th directory before using mount command.
• Third field
is the filesystem type. The various important file system types are,
- ext2 and ext3: Commonly all latest Linux partitions are Ext3. Ext3 is a newer filesystem type that differs from Ext2 in that it's journaled, meaning that if you turn the computer off without properly shutting down, you shouldn't lose any data and your system shouldn't spend ages doing filesystem checks the next time you boot up.
- reiserfs - ReiserFS is a journaled filesystem, but it's much more advanced than Ext3. Many Linux distros (including SuSE) have started using ReiserFS as their default filesystem for Linux partitions.
- Swap- The filesystem type "swap" is used in your swap partitions.
- vfat and ntfs : The USB stick is most likely formatted as Vfat (more widely known as FAT32). The Windows partitions are probably either Vfat or NTFS.
- ISO 9660 – This is a common format that target Compact Discs, DVDs and Blu-ray discs.
- Auto- The option "auto" simply means that the filesystem type is detected automatically. Normally floppy or CDROMs will be given this option as their filesystem type may vary.
• The fourth field
describes the mount options. There are latrge number of mount options available. We will go through the important options that a server admin should be aware of.
- auto and noauto : auto specifies that the device/partition should be automatically mounted on boot time and ‘noauto’ specifies that the device should be explicitly mounted. When you execute ‘mount –a’ all partition that has ‘auto’ value set will get mounted automatically. The root partitions should have the ‘auto’ option set so that the partition will get mounted automatically.
- exec and noexec : The option ‘exec’ specifies that the files residing in that device will be able to execute and ‘noexec’ remove the execute feature. The partitions which are intended to keep non executable files like /var or /tmp can have noexec feature enabled for better security.
- user and nouser : The ‘user’ option specifies that the users will be able to mount the partitions and ‘nouser’ specifies that only root user can mount any partitions. The ‘user’ option should be set for devices like ‘floppy or cdrom’ so that the users will be able to mount the device rather than being root.
Example
This will allow user to mount to directory other than root. Make sure you enabled permission on mountpoint directory for the required user before mounting. On a mounted directory even if you set permission it normally don't work.
/source/location /destination/mountpoint ext3 user,defaults 0 2
Other options, here you can explicitly set owner and group name
/source/location /destination/mountpoint ext3 -o uid=linux -o gid=opensource
or
/source/location /destination/mountpoint ext3 uid=linux,gid=opensource
- ro and rw : The option ‘ro’ specifies that the filesystem should be mounted as read-only and the option ‘rw’ enables read-write.
- sync and async – This specifies how the input and output to the filesystem should be done. sync means it should be done synchronously. That is, when you copy a file to the floppy, the changes are physically written to the floppy at the same time you issue the copy command. For ‘async’, the changes will be written only at the time of unmounting the floppy.
- suid / nosuid – The option ‘suid’ permit the operation of suid, and sgid bits and the option ‘nosuid’ block the operation of suid and sgid bits.
- Defaults - The normal default for Ext3 file systems is equivalent to rw,suid,dev,exec,auto,nouser,async(no acl support).
• The fifth field
specifies the option that need to be used by the dump program. If the value is set to 0, then the partition is execluded from taking backup and if the option is a nonzero value, the device will be backed up.
• The sixth field
mentions the fsck option. That is if the value is set to zero, the device or partition will be excluded from fsck check and if it is nonzero the fsck check will be run in the order in which the value is set. The root partition will have this value set to one so that it will be checked first by fsck.
If you face any troubles on mounting a partition, the file /etc/fstab should be checked for any misconfiguration.`