Linux disk and file management

Source: Internet
Author: User
Tags readable disk usage

Linux OPS operations personnel mainly for the server I/O Device Management: Disk and network card, here is mainly about the management of the disk

Linux all files, hardware devices also have corresponding files. Accessing the device in Linux is actually accessing the corresponding file interface.

File interface: Open (), read (), write (), close (), and so on.

Device Type:

Block: Random access attribute, data exchange unit "block"

Character device (character): Linear device, data exchange unit is "character". For example: keyboard input

Device files: FHS (file system hierarchy Standard)

Linux/dev/directory for device files, device files are associated to device drivers and access to the device's portal

Device Management: Device number

Device number: Main device number (major), secondary device number (minor)

Major: Device type, different device type, used to indicate required driver

Minor: Different devices under the same type, driver-driven specific devices (c, character devices, B-block devices)

650) this.width=650; "title=" clip_image002 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image002 "src=" http://s3.51cto.com/wyfs02/M02/73/19/ Wkiom1x0z83ruhioaacusydj5pa546.jpg "" 244 "height=" 179 "/>

Linux disk device file naming:

IDE (ATA): 133MB/S,/DEV/HD

scsi:640mb/s

sata:6gbps

sas:6gbps

usb:480mb/s

Identifying hard disk devices in Linux other than IDE:/DEV/SD

Mark a different hard drive device:/dev/sd[a-z]

Mark different partitions on the same device:/dev/sd[a-z][1-]

1-4: Primary or extended partition identification

5 +: Logical partition identification

Mechanical HDD Introduction: Track tracks, sector sector, cylinder cylinder

Mbr:0 Track 0 sector, primary boot sector (master boot record)

MBR divided into three parts: 446bytes:bootloader, boot program

64bytes: Partition Table

16bytes: Mark a partition

2BYTES:55AA, whether the current MBR information is valid for marking

MBR partitions cannot be used if a single hard drive is more than 2T, only GPT partitions can be used

Partitioning: Separates the storage space into multiple small spaces, each of which can use the file system independently;

Partitioning tools:

Fdisk, parted, Sfdisk

Use of the Fdisk tool:

Fdisk supports up to 15 partitions on a single hard drive;

FDISK Partition Management sub-command:

M: Get help to show the function of subcommands

P: Show existing partition table

N: Create

D: Delete

T: Modify the partition ID

L: List all support ID types

W: Save exit

Q: Discard Changes and exit

After the creation is complete, check to see if the kernel has identified the new partition:

# cat/proc/partitions

There are three commands that allow the kernel to reread the disk partition table:

CentOS 5:partprobe [DEVICE]

CentOS 6, 7:

Partx

Kpartx

PARTX command: Note: The partition on the mounted hard disk needs to be executed, may require the command to repeat 2 or more times to read the partition successfully

Partx DEVICE

Partx-a DEVICE

Partx-a-N m:n DEVICE

M

M:

: N

KPARTX command:

Kpartx-af DEVICE

650) this.width=650; "title=" clip_image003 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image003 "src=" http://s3.51cto.com/wyfs02/M00/73/19/ Wkiom1x0z86zszisaadnjlj53to325.jpg "" 222 "height=" 244 "/>

650) this.width=650; "title=" clip_image004 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image004 "src=" http://s3.51cto.com/wyfs02/M01/73/19/ Wkiom1x0z86sypmjaabdqbniyyo096.jpg "" 244 "height="/>

Create a file system and format after you create a partition

Linux File System Management

File system:

Vfs:virtual File System

Linux:ext2, Ext3, Ext4, ReiserFS, XFS, Btrfs, swap

Disc: iso9660

Windows:fat32 (VFAT), NTFS

Unix:ffs, UFS, JFS, JFS2

Network File System: NFS, CIFS

Cluster file system: OCFS2, GFS2

Distributed File systems: Ceph,

Moosefs, MogileFS, HDFs, GFS, Glusterfs

(1) journaled file system

Non-journaled file system: ext2

journaled File System: ext3

(2) Swap: Swap partition

To create a file system:

Perform formatting on a partition (advanced formatting)

To use a file system, two conditions are met:

Kernel: Support for this file system

User space: There are file System management tools

Create tool: Mkfs (make filesystem)

MKFS-T type DEVICE

Mkfs.type DEVICE

650) this.width=650; "title=" clip_image005 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image005 "src=" http://s3.51cto.com/wyfs02/M02/73/19/wKiom1X0Z8-yHjO_ Aacrbz7btw4212.jpg "" 244 "height=" 196 "/>

Special management tools for the EXT series file system:

mke2fs-t {EXT2|EXT3|EXT4} DEVICE

-B block:1024, 2048, 4096

-L ' LABEL ': Set volume label

Blkid command:

Blkid DEVICE

LABEL, UUID, TYPE

650) this.width=650; "title=" clip_image006 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image006 "src=" http://s3.51cto.com/wyfs02/M00/73/16/ Wkiol1x0agcr03r5aaabzdykcvm310.jpg "" 244 "height=" "/>

Linux File System Management:

MKFS, mkfs-t type = Mkfs.type

Ext:mke2fs

To create a file system:

MKE2FS [OPTION] ... DEVICE

-T {EXT2|EXT3|EXT4}

-B {1024|2048|4096}

-L ' LABEL '

-j:mke2fs-t ext3

-I. #:

-N #:

-M #: Reserved disk space occupies a large percentage of space for post-management use;

-O feature[,...]

-O ^feature: Turn off this attribute

Has_journal

File System Properties View and adjustment tools:

E2label

E2lable DEVICE [LABEL]

Tune2fs

Displays the properties of the Ext series file system, or adjusts its properties;

-L: Displays information in the Super block, and displays information about the properties and layout of the entire file;

-L ' LABEL ': Modify the volume label;

-M #: Adjust the percentage of administrative space reserved to administrators;

-J:EXT2-Ext3

-O: File System Properties start or close

-O: File system default mount option enabled or closed

DUMPE2FS:

-H: Displays only the Super block information;

File System Detection:

Fsck:filesystem Check

FSCK-T type

Fsck.type

-A: Auto fix error

-r: Interactive fix error

-F: Force detection

E2fsck:ext Series file system-specific detection and repair tools;

-Y: Auto Answer "yes"

-f:force

File system mount and use:

Kernel--ROOTFS (partition)

ROOTFS Partition:

Bin, Sbin, etc, Lib, lib64, Dev, tmp, proc, SYS

/sbin/init

The additional file system is associated with an existing directory of the root file system, which makes this directory the behavior of accessing the portal as other file systems, called Mount;

The process of releasing this association: uninstall;

Mount points: mount point, device mounted to directory;

Note: After the mount point is mounted, its internal files are temporarily hidden, and an empty directory is used as the mount point;

Mount Method:

Mount: Displays all devices that are already mounted on the current system by reading the/etc/mtab file;

MOUNT-A: Mounts all file systems in the/etc/fstab file that support automatic mounting;

mount [Options] [-o options] DEVICE mount_point

[Options]: Command options

[-O options]: Mount options

Device: Devices to be mounted

(1) Device file:/dev/sda5

(2) Volume Label:-L ' LABEL '

(3) uuid:-u ' UUID '

(4) pseudo file system name

Mount_point: Mount point

Common options:

-T type: File system type

-r: Mount this file system as "read-only" mode

-W: Mount this file system in read-write mode

-N: Each file system will automatically update the/etc/mtab file when it is mounted,-n is used to prohibit this function;

At this point, if you want to view all the file systems that are mounted: cat/proc/mounts

-A: Automatically mount all devices that support automatic mounting;

-B: Bind the directory to another directory;

-O mount option:

Async: Async Mode

Sync: Synchronous mode

Atime/noatime: Whether to update the access timestamp;

Diratime/nodiratime: Whether to update the access timestamp of the directory;

Auto/noauto: Whether this device is allowed to be automatically mounted;

Exec/noexec: Whether the application is allowed to execute on this file system;

Dev/nodev: Whether to support the use of device files on this device;

Suid/nosuid:

Remount: Re-mount

Ro

rw

User/nouser: Is it permissible to mount the device normally;

ACL: whether to support the use of FACL on this device;

DEFAULTS:RW, suid, Dev, exec, auto, Nouser, and Async

Umount: Uninstall command

# Umount DEVICE

# Umount Mount_point

To view the process that is accessing the specified mount point:

# fuser-v Mount_point

Terminates all processes that are accessing the specified mount point:

# fuser-km Mount_point

Swap partition:

Free command:

View the usage status of memory and swap

-M: in megabytes

-G: in gigabytes

Mkswap: Creating Swap partitions

mkswap [option] DEVICE

-L ' LABEL '

Swapon: Enable swap partition

swapon [option] [DEVICE]

-A: Activate all swap partitions

-P Priority: set its precedence;

Swapoff: Disable swap partition

swapoff [option] [DEVICE]

A view of space occupancy information such as file systems:

Df:disk Free

-h:human-readable

Number of-i:inode

-P: Output in POSIX-compatible format

Du:disk usage

-h:human-readable

-s:summary

File system-related Mount profile:/etc/fstab

Each row defines a file system;

Device to mount or pseudo file system mount point file System type Mount options dump frequency self-test order

Devices to mount:

Device files, label=, uuid=, pseudo file system names

Mount Options:

Defaults

Dump frequency:

0: No dumps

1: Daily dumps

2: Dump every other day

Self-Test order:

0: No self-test

1: First self-test, usually only/only 1

2:

...

Linked files on the file system:

Hard Links:

Two paths pointing to the same inode

cannot be performed on the directory;

cannot be done across partitions

Multiple different paths pointing to the same inode; Creating a hard link to a file increases the reference count of the inode; deleting a hard link deletes only one of its access paths, and only the last path is deleted;

Symbolic Links:

The data of the linked file points to another file path;

Can be done to the directory;

can span partitions;

Point to another file path, not an inode;

Creating a symbolic link to a file does not increase its reference count, and deleting the original file will not make the symbolic link file.

ln [-S] SRC DEST

-s:symbolic Link

-v:verbose

Exercise: Create a 10G file system, type EXT4, require the boot can be automatically mounted to the/mydata directory;

1. Create a mount point

650) this.width=650; "title=" clip_image008 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image008 "src=" http://s3.51cto.com/wyfs02/M01/73/16/ Wkiol1x0agdsmb2paaad9rdt-wq806.jpg "244" height= "Max"/>

2. Create a partition:

650) this.width=650; "title=" clip_image009 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image009 "src=" http://s3.51cto.com/wyfs02/M02/73/16/ Wkiol1x0agcymuouaacf3kkbplw316.jpg "" 244 "height=" 147 "/>

650) this.width=650; "title=" clip_image011 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image011 "src=" http://s3.51cto.com/wyfs02/M00/73/16/ Wkiol1x0aghgnxqraab2gl5k8dy522.jpg "" 244 "height=" 184 "/>

650) this.width=650; "title=" clip_image012 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image012 "src=" http://s3.51cto.com/wyfs02/M00/73/19/ Wkiom1x0z9dchsfqaaaumyov4bw906.jpg "" 244 "height="/>

650) this.width=650; "title=" clip_image013 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image013 "src=" http://s3.51cto.com/wyfs02/M01/73/19/ Wkiom1x0z9cwc-obaabrqd4kwqi618.jpg "244" height= "/>"

3. Partition file System Advanced format:

650) this.width=650; "title=" clip_image005[1] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image005[1] "src=" http://s3.51cto.com/wyfs02/M01/73/16/ Wkiol1x0agkr-64eaacrbz7btw4591.jpg "" 244 "height=" 196 "/>

4. Configuration mount File:/etc/fstab

650) this.width=650; "title=" clip_image015 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image015 "src=" http://s3.51cto.com/wyfs02/M02/73/19/ Wkiom1x0z9gtwgmfaaayz3nvfzk481.jpg "" 244 "height="/>

5. Mount to/mydata

650) this.width=650; "title=" clip_image017 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image017 "src=" http://s3.51cto.com/wyfs02/M00/73/19/ Wkiom1x0z9kttqagaacdsf9dknq053.jpg "" 244 "height=" 225 "/>

Linux disk and file 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.