On Linux disk and file system management

Source: Internet
Author: User
Tags readable

Before discussing disk and file system management, we have a simple understanding of the following disk structure: 1) platters, that is, the portion of the recording data, the number of the same as the number of heads, 2) the head, read and write data on the disc, 3) spindle motor, drive disc rotation, household grade speed in 5400rpm-7200rpm, Enterprise-Class up to 15000rpm;4) sector, the smallest physical storage unit, size 512 bytes; 5) track, when the disk rotates, if the head remains in one position, each head will draw a circular trajectory on the disk surface, these circular tracks are called tracks (track), 6) cylinder, A cylindrical face (Cylinder) consisting of multiple tracks of different platters, but in the same radius circle.

Next is the disk partition, the so-called disk partition, is the calibration data block (blocks) Start and end range, so that the operating system quickly to block the file data in/read/write/check and other operations. The benefits of partitioning are: optimizing I/O performance, implementing disk space quota limits, improving repair speed, isolating systems and programs, installing multiple OSes, using different file systems, and more. The Common partitioning command is fdisk:

-L/DEV/SDX viewing partition information for a specified block device
/DEV/SDX modifying partitions on a specified hard disk
M: Help
o: Create MSDOS partition label
N: Create a new partition
D: Delete partition
P: View the current partition table
A: Add/Cancel Boot tag
T: Convert partition Type ID
L/L: Show partition type ID table

Note that the hard disk on which the operating system is located needs to be notified to the kernel to reread the partition table information, centos5/7:partprobe/dev/sdx;centos6:partx-a/DEV/SDX (new partition)/partx-d--nr n/dev/ SdX (delete partition)

The format operation is required after partitioning is complete, because the file attributes/permissions set by each operating system are different, and the partition needs to be formatted in order to store the data needed for those files. In traditional disk and file system applications, a partition can only be formatted as a file system, so a file system can be considered a partition. But with the development of new technologies such as LVM, multiple partitions can synthesize a filesystem, and we call a data file system that can be mounted, rather than a partition. File System format command for MKFS

Mkfs.ext4/xfs/dev/sdx

After formatting the partition, you can tap the Blkid command at the command line to view all file system names/file system types, and to view and modify the file system using the TUNE2FS command under EXT system.

Tune2fs-l/DEV/SDX lists detailed information about the specified file system, which is derived from the Super Block (Superblock)

-L set Label (Volume label)

-M set Reserve percentage

-O acl/^acl Enable or disable the file system ACL function (This command is used in CENTOS6)

We then discuss mounting (mount). In Linux, everything is file, and the Mount command is profound. Each filesystem has its own inode, block, Superblock, and other information that can be linked to a directory tree to be used. The operation of combining a file system with a directory tree is what we call mount. The mount point must be a directory, and it is an empty directory. If the file system is mounted to a non-empty directory, all files under that directory are temporarily hidden. As shown, the execution of the MOUNT/DEV/SDA6/command will cause the entire system to crash, only by manually pressing the power button to restart! Fortunately the system has been protected, the above command is invalid!

Mount

-A mounts a file system that is not mounted according to the data in the configuration file/etc/fstab;

-L read/etc/mtab, display the current mount information;

-N force not to write/etc/mtab, single-user maintenance mode is commonly used, when the DF or mount command can not view the new mount information, but readable/proc/mounts file access;

-L Specify the volume label to Mount;

-O post-attach additional parameters, such as account number, password, read and write permissions, etc.

RO,RW mount file system becomes read-only, read-write mode DEFAULT--RW

Async,sync whether this file system uses synchronous write (sync) or asynchronous (async) memory mechanisms, Default--async

Auto,noauto Allow/Disallow partitioning to mount in mount-a mode (auto), Default--auto

Dev,nodev allows you to create a device file on this partition, Default--dev

Suid,nosuid allows this partition to contain the Suid/sgid file format, Default--suid

Exec,noexec whether this partition is allowed to have binary files, default--exec

User,nouser whether to allow ordinary users to execute the Mount command, by default only the root can mount, add the user parameter, the ordinary user can also mount

Defaults default all default values

Remount The Mount option can be updated directly without uninstalling

Acl,noacl (CENTOS6) to turn ACL on or off, Default--noacl

Umount: Uninstalling device files

-F forced uninstallation, available for NFS (where the network file system is unreadable)

-N Do not update/etc/mtab

Note that when a mount point is occupied (entering a mount point or being occupied by a process), you need to leave the file system mount point or kill the process with the command fuser and then do Umount

Fuser mount point View the program running on the specified mount point, showing its process number

-V Detailed View

-m recursion, such as without m, to view only the mount point itself, without viewing subdirectories

-K Kills

Fuser usually paired with options-VMK

The above is a brief introduction to the contents of the disk Management, we discuss the Linux file system Advanced Management Part I: Quota (disk quotas). In short, quota is a technique that restricts the use of space to a file system by a general user, and is often implemented in 3 ways:

1> limit the maximum disk quota for a user (using user restrictions)

2> limit the maximum disk quotas that a user group can use (using user-attached group limits, often with the Sgid command)

3> a link to make the message available as a restricted quota (change the/var/spool/mail path)

It is important to note that the quota is limited to the entire file system, such as your/dev/sda3 mounted under/home, all directories under/home are restricted, and the settings are divided into the following sections

1. Limit capacity or number of files (block or inode)

2.soft/hard (soft limit and hard limit) usually have a hard limit value slightly higher than the soft limit. When the user-discretionary disk quota exceeds the soft limit but is below the hard limit, the system initiates a grace period countdown and warns until the user cleans up the data to the soft value. If the user does not perform any action during the grace period, the hard limit value will fall back to the soft limit value, when the user's right to use is locked and the file cannot be added.

Quota of the EXT series file system

1> Pre-configured quota (ext, XFS) (the following actions will still take effect after the next boot)

Vim/etc/fstab, add Usrquota,grpquota as follows when you need to turn on the quota File system Mount option defaults

/dev/sda5/app Ext4 Defaults,usrquota,grpquota 1 0

2> generate quota database for specified file system

quotacheck-cugm/app/

3> Open the specified file system quota

Quotaon/app

In command-line mode, QUOTA-V displays the current user's own quota limit. Root, quota-v username is used to display the quota limit for a specified user, Repquota-v/app displays the quota limit for all users of the specified mount point

4> Set Normal User quota

The edquota-u/g username/groupname-u option specifies that the USER,-G specifies the group

Edquota-p usr1 USR2 Copy usr1 quota settings to USR2

Quota for XFS file systems

1> Reference EXT Series pre-configured quota

2> Direct Configuration Quota options

Xfs_quota-x-C "print" To view all XFS file systems in the current system which have quota enabled

Xfs_quota-x-C "report-ugibh" View quota settings

-U View user's quota settings

-G View Group Quota settings

-I view inode quota limits

-B View block's quota limit (default)

-H human-readable

Xfs_quota-x-C "state"/app View quota status, show Grace time

Set quota for user

Xfs_quota-x-C "Limit-u bsoft=30m bhard=40m user1"/app

Set quota for user groups

Xfs_quota-x-C "limit-g bsoft=80m bhard=200m group1"/app

Finally, we discuss the second part of Linux file System Advanced Management: LVM (logical Volume manager), which is designed to elastically adjust file system capacity online! Not in terms of performance and data preservation. LVM can integrate multiple physical partitions together to make these partitions look like a disk, and this disk capacity is variable! The implementation process is roughly the following: Physical disk or partition (not mounted)-->PV (LVM physical volume)-->VG (LVM Volume user group)-->LV (logical volume), as follows

1. partition or add a new hard drive

If it is a partition, be careful to change the system identifier to 8e with the-t option of the FDISK command

2. Create a physical volume PV

Pvscan, there is no PV on the query system

Pvcreate/dev/sdax

Pvdisplay Display PV Status

3. Create a user volume group VG

vgcreate [-S XM] (specify PE size, default 4M) VGNAME/DEV/SDX

Vgscan

Vgdisplay [Vgname]

4. Creating a logical Volume

Lvcreate-l xm/g-N lvname vgname

Lvscan

Lvdisplay [/dev/vgname/lvname]

Uninstalling LVM

1.umount/mnt/lvm

2.lvremove/dev/vgname/lvname

3.vgremove Vgmage

4.pvremove/dev/sdx

On Linux disk and file system management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.