One of linux file system management trilogy: disk partition
linux file system management trilogy of the two: create a file system
It explained above, the hard disk partitioning and formatting, how to use it, not say, said here about how to use the created file system.
File system
As long as the file system "mount" to a directory, the directory can be accessed through the file system.
This directory is called: mount point (mount_point): As access to another file system entry.
Mount point directories conditions to be met:
1, pre-existing
2, used in the past, and will not be used for other processes
3, under the mount point, the original file, the mount will be hidden
This "link" up action, which is
mount
the command.The mount point, off to the action, which is
umount
the command.
umount command usage:
umount device|dir
Note: If a user in a process using this mount point, you can not umout, until the process using this mount point of exit.
For example, a user, cd into the mount point, then the system administrator to execute umount command is shown below:
# umount /mnt
umount: /mnt: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
1, which users see which processes are using mount points
lsof mount_point
]# lsof /mnt lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs Output information may be incomplete. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 5482 root cwd DIR 8,17 1024 2 /mnt
fuser -v mount_point
# fuser -v /mnt USER PID ACCESS COMMAND /mnt: root kernel mount /mnt root 5482 ..c.. bash
2, using mount points so kill the process:fuser -km mount_point
# fuser -km /mnt/
/mnt: 5482c
Use the mount command
Direct execution mount
command, showing that mount the current system. Note that in centOS7, content display more, more inside information to mount cgroup than CentOS6.
1, the basic usage
grammar:
mount [-fnrsvw][-t vfstype] [-o options] device dir
# mount /dev/sdb1 /mnt
Read-only mount:
-r
Both reading and writing mount:
-w
When the mount does not update / etc / mtab file:
-n
/ etc / mtab file, save the current situation of the mount, each mount a file system, an additional line in the file, the file system after uninstalling, delete the row added. When a file in the / etc directory can not write, you can use this option. However, in the CentOS7 even if you specify -n, also update the / etc / mtab file.
Specify the file system type to mount the device:
-t
Generally it can be omitted, mount the directory automatically based on the results blkid command, find the file system type to mount the device.
Do not specify a device file, but by specifying the label, to mount:
-L
# e2label /dev/sdb1 m1 # blkid /dev/sdb1 /dev/sdb1: LABEL="m1" UUID="4752177b-e026-483d-b166-19229b64e4c3" TYPE="ext2" # mount -L m1 /mnt
Do not specify a device file, but by specifying the UUID, to mount:
-U
# mount -U 4752177b-e026-483d-b166-19229b64e4c3 /mnt
2, mount option (-o options): The following is a specific value for the option -o behind.
sync / async: When writing to disk is immediately written to disk, or the first in no hurry, and so will be written to disk options together.
sync: immediately written to disk
async: wait a minute and then written to disk. So, async good performance!
atime / noatime: file or directory after being accessed, whether to update its access timestamp
diratime / nodiratime: directory after being accessed, whether to update its access timestamp
remount: when you want to increase mount options, but do not want to unmount the file system. Use this option to automatically re-mount the file system, and allows a new mount options to take effect.
For example, when mounted, read-only option is specified, but would like to change can read and write, you can use the following usage, / mnt / t1 is the mount point.
mount -o remount rw /mnt/t1
acl: the facl function effectively, that is, setfacl in effect.
ro: Tada读
rw: read-write
dev / nodev: whether to allow identification (Interpret) files on the file system device. Even nodev, also create a device file using the mknod command.
exec / noexec: whether to allow to run on this file system program
suid / nosuid: whether to allow suid and sgid special permissions on files take effect.
relatime / norelatime: whether to allow to update the access time according to modify time or change time.
defaults: When not in read-only options, actually: rw, suid, dev, exec, auto, nouser, and async is enabled.
3, binding directory to the mount point.
Not only can mount command to mount the device file to mount point, you can also mount other directories to the mount point. Use --bind
# mount --bind /etc /mnt
4, see what mounted device
mount
cat /etc/mtab
cat /proc/mounts
5, mount the CD
General CD-ROM device file is / dev / cdrom or / dev / dvd
# mount -r /dev/cdrom /mnt
6, u disk mount
And mount the partition no difference, just need to find the corresponding u disk device file by file size to determine which device is u disk file.
7, mount the local loop file (ios file, img files, etc.)
# mount -o loop /tmp/ttylinux.so /mnt
Enabling swap partition
Enable:
swapon [option] device
-a: all devices defined in the / etc / fstab file
# fdisk -l /dev/sdb6 Disk /dev/sdb6: 26 MB, 26214400 bytes, 51200 sectors # mkswap /dev/sdb6 mkswap: /dev/sdb6: warning: wiping old swap signature. Setting up swapspace version 1, size = 25596 KiB no label, UUID=a4dc9e83-5e28-49e1-9aa0-6e7059fcb227 # free -m total used free shared buff/cache available Mem: 3789 631 2547 21 610 2872 Swap: 3967 0 3967 # swapon /dev/sdb6 # free -m total used free shared buff/cache available Mem: 3789 631 2547 21 610 2872 Swap: 3992 0 3992 # swapoff /dev/sdb6 # free -m total used free shared buff/cache available Mem: 3789 631 2546 21 610 2871 Swap: 3967 0 3967
Disabled:
swapoff [option] device
-a: all devices defined in the / etc / fstab file
What is the root directory and the root directory on the same partition, which can be a directory in a separate partition it?
General usr, var, home directory and the root directory can not be on the same partition, and most of the other must root directory on the same partition.
So the question is, since usr directories in the root directory and not in the same partition, then how are they mounted automatically at system boot it up?
Defined in the device file / etc / fstab file, it will automatically mount the boot.
Interpretation of the meaning of each column of / etc / fstab file
The first column: device file, or UUID, or LABLE
The second column: mount point
Directory mount point is not the type of swap file system is directly [swap]
The third column: the file system type
The fourth column: Mount options
If there are multiple mount options, separated by commas. For example: defaults, acl, noexec
Fifth column: backup frequency
0: Never Backup
1: daily backups
2: back up the next day
The sixth column: self-test order
0: slatternly
1: The first self-test. Usually only the root file system may be used.
2: The second self-test. The file system may be other than the root file system 2 is arranged.
...
# cat /etc/fstab # # /etc/fstab # Created by anaconda on Fri Nov 29 16:44:28 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=3d3b316a-529e-484a-9895-e785fdde5365 /boot xfs defaults 0 0 /dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0
mount -a
The device will automatically catalog / etc / fstab file definition, all mount
The following line is additional own.
/dev/sdb5 /mnt/t2 ext3 defaults,acl 0 0
Display the file system space usage:df
Space to display all file system usage:
df
# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/centos-root 38815216 18982084 19833132 49% / devtmpfs 1923436 0 1923436 0% /dev tmpfs 1940308 9712 1930596 1% /run tmpfs 1940308 0 1940308 0% /sys/fs/cgroup /dev/mapper/centos-home 18950144 1842644 17107500 10% /home tmpfs 388064 4 388060 1% /run/user/42 tmpfs 388064 32 388032 1% /run/user/1000 /dev/sda1 1038336 182380 855956 18% /boot /dev/sdb5 45478 827 42091 2% /mnt/t2
Space to display all file system usage:
df -l
# df -l Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/centos-root 38815216 18982116 19833100 49% / devtmpfs 1923436 0 1923436 0% /dev tmpfs 1940308 9712 1930596 1% /run tmpfs 1940308 0 1940308 0% /sys/fs/cgroup /dev/mapper/centos-home 18950144 1842644 17107500 10% /home tmpfs 388064 4 388060 1% /run/user/42 tmpfs 388064 32 388032 1% /run/user/1000 /dev/sda1 1038336 182380 855956 18% /boot /dev/sdb5 45478 827 42091 2% /mnt/t2
Displays the file system space usage (for reading):
df -h
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 38G 19G 19G 49% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 9.5M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/centos-home 19G 1.8G 17G 10% /home tmpfs 379M 4.0K 379M 1% /run/user/42 tmpfs 379M 32K 379M 1% /run/user/1000 /dev/sda1 1014M 179M 836M 18% /boot /dev/sdb5 45M 827K 42M 2% /mnt/t2
The display inode usage for all file systems:
df -i
# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/mapper/centos-root 19417088 416785 19000303 3% / devtmpfs 480859 403 480456 1% /dev tmpfs 485077 751 484326 1% /run tmpfs 485077 16 485061 1% /sys/fs/cgroup /dev/mapper/centos-home 9480192 912 9479280 1% /home tmpfs 485077 6 485071 1% /run/user/42 tmpfs 485077 19 485058 1% /run/user/1000 /dev/sda1 524288 341 523947 1% /boot /dev/sdb5 12824 11 12813 1% /mnt/t2
Show directory space occupied by all files:du
Display space occupied by each file directory:
du
# du /home/ys/bin/ 56 /home/ys/bin/ 52 /home/ys/sbin/
Show directory space occupied by all files:
du -s
-h: human readable.
# du -s /etc/ 42732 /etc/ # du -sh /etc/ 42M /etc/