Linux Learning II: Linux disk and file management system

Source: Internet
Author: User
Tags disk usage file permissions

The last time I wrote Linux files and operations, this time continue to write Linux disk and file management system.

First, we need to get to know the EXT2 file system, which is the most traditional Linux disk system.

1.EXT2 File System

Before you say the file system, you have to say the disk composition, because the files are built on disk. is one of the disks:

From this diagram we can see:

1) The sector is the smallest physical storage unit, each sector is 512bytes;

2) make a circle of the sector, that is, the magnetic column, the magnetic column is the bottom unit of the separation groove

3) The first sector is the most important, there are: (1) The main boot area and partition table, wherein the MBR occupies 446bytes, and partition table occupies 64bytes.

After you know the disk, how does the file system move? A file in addition to the actual content, but also contains a lot of properties, such as the file owner and file permissions. The file system typically places these two sections in different chunks.

1). Superblock: Records the overall information of the filesystem, including the total amount of inode/block, usage, amount remaining, and file system format and related information.

2). INode: Records the attributes of a file, a file occupies an iNode, and records the number of the block where the data for this file resides;

3) Block: Actual record of the contents of the file, if the file is too large, will occupy more than block.

Each inode and block is numbered, and each file occupies a block number within a inode,inode that has the file data placed. The size of each inode is fixed at 128bytes, while block is divided into 1k,2k,4k. In general, the size of the superblock is 1024bytes, and the relevant information can be observed with DUMPE2FS instructions.

Relationship to the directory tree: When we build a directory under Linux's ext2 file system, ext2 allocates an inode with at least one block to the directory. Where the Inode records the permissions and attributes of the directory, and can record the block number assigned to it, and block records the file name in this directory with the Inode number data that the filename occupies.

The inode itself does not record the file name and the file name is in the block of the directory.

You can use the Ls-i command to see the inode number of the file.

2. Simple operation of the file system

1) DF: List The overall disk usage of the file system

Command format: DF [-ahikhtm] [directory or file name]

Common commands:

-H: Display in a format that is easier for people to read, such as Gbytes,mbytes,kbytes.

-I: Do not use the hard disk capacity, but the number of inode to display.

2) du: Evaluating the disk usage of the file system (Toad Hall in the estimated directory)

Command format: du [-ahskm] file or directory name

Common parameters:

-S: Lists the total, not the capacity that each individual directory occupies.

3. Entity links and Symbolic links

1) Entity Link: Creates a new file name through the Inode link of the filesystem without generating a new file.

Entity linking with ll-i data except for filenames, the others are the same, because they are linked to the same inode.

2) Symbolic Link: A file similar to the Windows shortcut feature that allows you to quickly link to a directory file.

3) Related Commands ln

Command format: LN [-SF] source file destination file

Related parameters:

-S: If you do not add any parameters to the link, it is hard link, plus-s is a symbolic link.

-F: If the destination file exists, the target file is actively removed after it is established.

4. Partitioning, formatting, checking and mounting of disks

1) partition of the disk Fdisk

Command format: fdisk [-l] Appliance name

Common parameters:

-L: Outputs all partiton contents of the device after it.

2) disk Format MKFS,MKE2FS

command format [-t file System format] Appliance file name

Options to Parameters:

-T: The file system format can be received.

3) disk Inspection: Fsck,badblocks

Command format: fsck [-T file system] [-acay] Appliance Name

-T: Like Mkfs, Fsck is a comprehensive software! So we also need to led the file system. Now Linux is too clever, he will be self-superblock to distinguish the file system, so bands can not need this election! Take a look at the following example description.

-A: Scan the required device according to/etc/fstab content. /etc/fstab to the next section, the bands will be executed during the boot process this led order.

-A: Self-repair Check to the problem contact area, so you do not use always write Y! -y: Not a similar, but some filesystem only support-y this parameter!

C: You can use a histogram to show the current import degree in the process of testing! Ext2/ext3 Additional Features: (E2fsck this led order)

-F: Mandatory check! In general, if FSCK does not have anticipation now anything what unclean flag, will not be the main import into the gentry inspection, if you want to force fsck import into the gentry inspection, you have to add the-f flag!

-D: Optimized configuration for login import line under File system.

Badblocks

Command format: badblocks-[SVW] Appliance Name

Options and Parameters:

-S: List import on the screen

-V: You can see the import degree on the screen

-W: Use Write to test, it is recommended not to use this parameter, especially when the device to be checked has a file!

4) Mount mount unload of disk: Unmount

Before we mount, we first need to confirm a few things:

? A single file system should not be repeatedly mounted on different mount points (login);
? Single-mesh login should not be repeated to mount multiple file systems;
? To be a mount point login, taboo should be empty login 扄 is.

Command format: Mount [-t file system] [-l label name] [-o extra option] [-n] Appliance file name mount point

Common parameters:

-A: Mount all the disks that are not mounted according to the configuration file/etc/fstab data

-L: The simple input mount will display the information currently mounted. Plus-l to add a Label name!

-T: MKFS is not bands similar, you can add a file system type to led the type of mount. Bands see Linux support types are: ext2, ext3, VFAT, ReiserFS, iso9660 (disc format), NFS, CIFS, SMBFS (these three are the Web-type file system types)

-N: Under the obituary attaining, the system will actually mount the attaining in real time to/etc/mtab, in order to facilitate the operation of other programs. However, under certain circumstances attaining (such as single-player maintenance mode), in order to avoid the problem, will deliberately not write. You'll have to use the-n option at this point.

-L: The system can also use the file system header name (label) to import a row mount, in addition to the device file name (for example,/DEV/HDC6) cookbook. It's best to canceled a unique name for your file system!

-O: You can attach some additional parameters after mounting! For example, account number, password, read and Write permissions: RO, rw: Mount file system becomes just read (RO) ring erasable (rw) Async, Sync: This file system uses synchronous write (sync) ring Asynchronous (async) memory mechanism, refer to how the file system works. Pre-OU is async. Auto, Noauto: Allow to speak this partition is mount-a self-mounted (auto) dev, Nodev: Is it permissible to talk about this partition, you can set up a device file? Dev for suid, Nosuid: Is it permissible to talk about this partition ton of suid/sgid file format? EXEC, noexec: Is it permissible to say that there are executable binary files on this partition 拞? User, Nouser: Is it permissible to speak this partition ridiculed anything what user executes mount? In general, Mount only has root to import rows, but with the user parameter, ridiculed general user can also partition import row mount. Defaults: The default obituary value is: RW, suid, dev, exec, auto, Nouser, and async remount: Re-mount, which is useful when the system goes wrong and the parameter is re-updated, vigilance!

5) Set the boot mount

Manually handling mount is not very user-friendly, we always need to have the system automatically mounted at boot time. This will need to be/etc/fstab inside to modify.

Linux Learning II: Linux disk and file management system

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.