The disk and file system management in Linux systems is summed up in the fact that they are mutually reinforcing and often used together in peacetime work.
First, we introduce the management tools for disk partitioning.
Common disk partition management tools are Fdisk,parted,sfdisk
Here we introduce the common Fdsik tools
fdisk-l [DEVICE] ... : Lists the partitions on the specified disk device
fdisk [DEVICE]: Creating a partition
FDISK provides an interactive interface for managing partitions, which has a number of subcommands for different management functions, all of which are done in memory, not directly synchronized to disk, and saved to disk using the W command;
Common commands:
N: Create a new partition
D: Delete an existing partition
T: Modify the partition type
L: View all existing IDs
W: Save and exit
Q: Do not save exit
M: View Help information
P: Show existing partition information
Note: In a new partition created on a disk device that has been partitioned and mounted on one of the partitions, the kernel may not be recognized directly after the creation is complete;
At this point we see if the kernel has identified the new partition: Cat/proc/partitions
For disks that already have partitions in use, you need to have the kernel reread its partitioned table after you create a new partition:
Notifies the kernel to forcibly reread the disk partition table:
Centos5:partprobe[device]
Centos6,7:partx,kpartx
partx-a [Device]
KPARTX-AF [Device]
Here's a way to add a sync after deleting a disk partition:
Centos5,7:partprobe[device]
centos6:partx-d--NR # (partition code) [DEVICE]
Sometimes when we add a new physical disk, we usually need to restart the system in order for the system to check the newly added disk, here is a little trick, but check the newly added hard drive without rebooting
echo "---" >/sys/class/scsi_host/host2/scan
After introducing the Disk Management tool, the following is the Linux file system management
First of all, the classification of Linux file systems
Vfs:virtual File System
Linux File system: Ext2,ext3,ext4,xfs,reiserfs,btrfs
Disc: iso9660
Network File system: Nfs,cifs
Cluster file system: GFS2,OCFS2
Kernel-level Distributed File system: Ceph
Windows file System: Vfat,ntfs
Pseudo file system: Proc,sysfs,tmpfs,hugepagefs
UNIX File system: UFS,FFS,JFS
Swap file system: Swap
Distributed file system for user space: Mogilefs,moosefs,glusterfs
Depending on whether the log feature is supported or not, it can be divided into:
journaled File System: EXT3,EXT4,XFS
Non-journaled file system: Ext2,vfat
Before you describe how to create a file system, let's introduce the file system Management Tools
Create File System tool: MKFS
Mkfs.ext2,mkfs.ext3,mkfs.ext4,mkfs.xfs.
Tools for detecting and repairing file systems: fsck
Fsck.ext2,fsck.ext3,...
Tools to view their properties: DUMPE2FS,TUNE2FS
Adjust file system features: TUNE2FS
Let's take a detailed introduction to the above mentioned file system management tools
MKFS command: Make file system
-T Fstype [DEVICE]
Mkfs-t Fstype=mkfs. Fstype
Mkfs-t EXT4=MKFS.EXT4
-L ' LABEL ': Set volume label
Ext Series File system dedicated management tool: MKE2FS
Mke2fs[options] Device
-t {EXT2|EXT3|EXT4}: Indicates the type of file system to be created
Mkfs.ext4=mkfs-t ext4=mke2fs-t Ext4
-B {1024|2048|4096}: Indicates the block size of the file system;
-L LABEL: Indicates the volume label;
-j: Create a file system with log function ext3;
Mke2fs-j =mke2fs-t ext3 =mkfs-t ext3 =mkfs.ext3
-i#:bytes-per-inode, indicates the ratio of inode to byte, and creates an inode for each number of bytes;
-n#: Directly indicates the number of inode to be created for this file system;
-m#: Specifies the reserved space, percentage;
-o[^]feature: Creates a target file system with the specified attributes, plus ^ to turn off this feature;
E2label command: Checking and setting of volume label
View: E2label Device
Setting: E2label Device LABEL
TUNE2FS command: View or modify some properties of the EXT series file system
Adjust tunable filesystem parameters on Ext2/ext3/ext4 filesystems
NOTE: Block size cannot be changed after creation
TUNE2FS [OPTIONS] Device
-L: View Super block content;
To modify the properties of the specified file system:
-j:ext2-->ext3;
-L LABEL: Modify the volume label;
-M #: Adjust the percentage of reserved space
-O [^]feature: Turn a feature on or off
-O [^] mount_options: Turn on or off a default mount option;
ACL: Enable ACL
^acl: Close ACL
DUMPE2FS command: Displays the properties information for the EXT series file system
DUMPE2FS [-h] Device
FSCK: Tools to implement file system detection
The file system should be detected and repaired when the operating system terminates abnormally due to unexpected process termination or system crash, and the filesystem should be checked and fixed; recommended: off-line;
Special tools for the EXT series file system: E2fsck
e2fsck [OPTIONS] Device
-y: Automatic answer to all files is yes;
-F: Force detection even if the file system is in clean state;
Fsck:check and repair a Linux file system
-T Fstype: Indicates the file system type;
Fsck-t EXT4=FSCK.EXT4
-A: Automatically fix all errors without interaction;
-R: Interactive Repair
Blkid command:
Blkid Device
Blkid-l Label: Locate the device according to the label
Blkid-u UUID: Locating the device according to the UUID
File System mount
Previously we created a disk partition, after the format is completed to be used, we must first mount,
Other file systems other than the root filesystem must be accessed by "associating" to a directory on the root file system, which is "mounted", which is "mount point";
Fixed mount points on Linux systems are:/mnt,/media
Mount point: Mount_point, used as the access entry for another file system;
1. Pre-existing;
2. Directories that are not or will not be used by other processes should be used;
3. The existing files under the mount point will be hidden;
Mount Command:
Mount [-NRW] [-t vfstype] [-O options] Device dir
Command options:
-r:readonly, read-only mount;
-w:read and write, read-write Mount;
-N: By default, the device mount or unload operation is updated synchronously to the/etc/mtab file; n is used to prohibit this feature;
-T Vfstype: Indicates the type of file system on the device to be mounted, and in most cases can be omitted, at which point mount will determine the type of filesystem to mount by Blkid;
-L LABEL: Specifies the device as a volume label when mounted
Mount-l LABEL dir
-U UUID: Specifies the device as a UUID when mounted;
Mount-u UUID dir
-O Options: Mount options
Sync/async: synchronous/asynchronous operation;
Atime/noatime: Whether a file or directory updates its access timestamp when it is accessed;
Diratime/nodiratime: Whether the directory updates its access timestamp when it is accessed;
Remount: Re-mount;
ACL: Support the use of FACL function;
# mount-o ACL device dir
# Tune2fs-o ACL Device
RO: Read-only
RW: Read and Write
Dev/nodev: Whether to allow the creation of device files on this device;
Exec/noexec: Whether the program files on this device are allowed to run;
Auto/noauto:
User/nouser: Whether to allow ordinary users to mount the file system;
Suid/nosuid: Allow suid and Sgid special permissions on program files to take effect;
Defaults:use default OPTIONS:RW, suid, Dev, exec, auto, nouser, async, and Relatime.
One use technique:
Can be implemented to bind the directory to another directory, as its temporary access to the portal;
Mount--bind Source Directory destination Directory
View all devices that are already mounted on the current system;
# mount
# Cat/etc/mtab
# cat/proc/mounts
To mount a disc:
Mount-r/dev/cdrom Mount_point
Disc Device file:/dev/cdrom,/dev/dvd
Mount USB drive:
Pre-identified USB flash drive device files:
To mount a local loopback device:
#mount-O loop/path/to/some_loop_file mount_point
Umount command:
Umount Device | Dir
Note: The mount point being accessed cannot be uninstalled;
See which or which processes are occupied;
#lsof Mount_point
#fuser-V Mount_point
To terminate all processes that are accessing a mount point:
#fuser-km Mount_point
Mount Swap Partition
Enabling and disabling of swap partitions:
command to create swap partition: Mkswap
Enabled: Swapon
Swapon[option][device]
-A: All swap devices defined in the/etc/fstab file
Disabled: Swapoff
Swapoff DEVICE
Set a file system other than the root file system to mount automatically when booting:/etc/fstab file
Each row defines a file system and related properties to be mounted;
6 fields:
1. The device to be mounted;
equipment files;
LABEL
Uuid
Pseudo file system: such as SYSFS,PROC,TMPFS, etc.
2. Mount point
Swap is the mount point of a device of type swaps;
3. File system type;
4. Mount Options:
Defaults: Use the default mount option;
If you want to specify multiple mount options at the same time, separate each other with commas;
5. Dump Frequency:
0: Never back up;
1: daily backup;
2: Backup every other day
6. Self-Test order
0: No self-test
1: First self-test, usually only the root file system available 1;
2: Secondary self-test:
...
Mount-a: Automatically mounts all the devices that are defined in this file that support automatic mounting;
Two commands: DF and Du
DF Command:
Df[option] ... [FILE] ...
-L: Displays only information about local files;
-h:human-readable
-I: Display inode usage status instead of blocks
Du command:
Du [OPTION] ... [FILE] ...
-s:sumary Displays the sum of all file sizes when displaying a table of contents
-h:human-readable
Uninstalling the file system
Uninstall: The mount point is not accessed by the process before it can be uninstalled;
Uninstall command: Umonut DEVICE or Unmont mount_point
It is a good idea to check which processes are accessing the mounted device before uninstalling, using:
Fuser-v mount point
If you have a program that is using the device and you want to terminate a process that is in this mount point, you can use:
fuser-km mount point
This article is from the "11798474" blog, please be sure to keep this source http://11808474.blog.51cto.com/11798474/1843403
Linux disk and file system management