Linux studies four Linux file system and disk management

1 know Linux file system

  The most traditional Linux disk file system (filesystem) using EXT2, and the file system is built on the disk, so we have to understand the physical disk components.

1.1 disks and partitions

  Disk physical composition:

    A circular disk plate (part of the main data is recorded);

    Mechanical arm, on the robot arm in the disk read heads (rewritable disk data on the disk);

    A spindle motor rotating the disk tray may allow the robot arm read head reads the data on the disk tray.

  The physical composition disk drive:

    Sector (Sector) is the smallest physical storage unit, and depending on the design of disks, there are mainly two formats 512bytes and 4K;

    The sectors of a circle, that is, cylinders (Cylinder);

    Early partition cylinders mainly the smallest partition unit, now commonly used sector partition of the smallest partition units (each sector has its own number, the same as if the seat);

    There are two main disk partition table format, one is more restrictive MBR partition table, one is newer and less restrictive GPT partition table;

    MBR partition table in a first sector of the most important, there are: (1) primary boot sector (Master boot record, MBR) and partition table (partition table), wherein the MBR possession 446bytes, the partition table is occupied 64bytes;

    GPT partition table in addition to the large number of partitions to expand, disk capacity can support more than 2TB.

  Disk file name format:

    / Dev / sd [ap] [1-128]: disk to disk file name of the entity;

    / Dev / vd [ad] [1-128]: disk file name for the virtual disk.

1.2 File System Features

  Linux orthodox file system EXT2 (Linux second extended file system, ext2fs)

  Typically, files file permissions (rwx) with the file attributes (owner, group, time parameters, etc.) the two parts of data are stored in different blocks, permission attribute to the inode is placed, as the actual data are placed data block to block. Super Block (Superblock) file records the entire information for the entire system, including the total used amount, and the remaining amount of block inode.

  superblock: General information recording this filesystem, including the total amount of inode / block, the amount of the remaining amount, and the format of the file system related information;

  inode: Record file attributes of a file occupies one inode, while recording data block numbers for this file is located;

  block: the actual contents of the log file, if the file is too large, it will take more than block.

The 1.3 Linux EXT2 file system (inode)

  File system inode and block the outset planned, unless reformatted (or use resize2fs and other instruction to change the file system size), otherwise it will not change after the inode fixed and block.

 

   There is a front file system boot sector (boot sector), you can install the boot sector boot manager.

1.3.1 data block (data block)

  data block is where to place the contents of the data file in the file system EXT2 supported block sizes have 1K, 2K and 4K three.

              block size                                1KB                            2KB                  4KB         
The largest single file limit 16GB 256GB 2TB
The maximum total capacity of the file system 2TB 8TB 16TB

  block fundamental limitation:

    In principle, the size and number of the block formatting can be not completely changed again (unless reformatting);

    At most a data file that can be placed within each block;

    Deck, if the file is larger than the size of the block, then a file will occupy more than the number of block;

    Deck, if the file is smaller than the block, the remaining capacity of the block can not be used (wasted disk space).

1.3.2 inode table (inode table rating)

  inode record file data content:

    The file access mode (read / write / excute);

    With a group owner of the file (owner / group);

    The capacity of the file;

    The time of file creation or change of state (the ctime);

    Last read time (atime);

    Last modified time (mtime);

    Characteristic definition file flag (flag), as SetUID ...;

    The document points to the real content (pointer).

  inode Features:

    Each inode size was fixed at 128 bytes (xfs new ext4 and may be set to 256 bytes);

    Each file inode only occupies one;

    From the previous, so the number of relevant documents to the inode number of the file system can be established;

    When you need to find the file system reads the inode, inode and analyze whether the recorded rights in line with the user, if they meet to be able to read the contents of the actual start of the block.

1.3.3 Superblock (super block)

  Superblock is the place to record the entire filesystem-related information, the information recorded are:

    And the total amount of the inode block;

    / Block inode number has been used and not used;

    Block size and the inode (block as 1,2,4K, inode or to 128bytes 256bytes);

    filesystem mount time, the last time data is written, the latest survey and information about the disk (fsck) the time of the file system;

    A valid bit value if this file system has been mounted, the valid bit is 0, if not been mounted, the valid bit is 1.

1.3.4 Filesystem Description (File System Descriptor Description)

  This section may describe the start and end of each block of the block number of the Group, and instructions between which a block number of each segment (superblock, bitmap, inodemap, data block) interposed, respectively.

1.3.5 block bitmap (block table)

  From the block bitmap them know which block is empty.

1.3.6 inode bitmap (inode table)

  Recorded using an unused inode number.

1.3.7 dumpe2fs: query instruction Ext family superblock information

  dumpe2fs [-bh] device file name

  Options and parameters:

    -b: list reserved for the bad rail section (generally less than)

    -h: Lists only data superblock will not list other regions ruin content

  means blkid list current system formatted

Easy to operate 2 file system

2.1 capacity disk and directory

  df [-ahikHTm] [directory or file name] lists the overall disk usage, file system

  Options and parameters:

    -a: List all file systems, including system-specific / proc file system and the like;

    -k: KBytes capacity to display each file system;

    -m: MBytes display each file system volume;

    -h: Self people easier to read the display GBytes, MBytes, KBytes format;

    -H: In M = M = 1000K carry substituents embodiment of 1024K;

    -T: partition along with the name of the filesystem (e.g. XFS) also lists;

    -i: different disk capacity, and to the inode number to display

  Disk Usage du [-ahskmS] file or directory name assess the file system

  Options and parameters:

    -a: lists all files and directories capacity because the amount of the default file under the directory statistics only just;

    -h: displays people to easily read volume format (G / M);

    -s lists the total, rather than listing each respective directory occupancy capacity;

    -S: do not include subdirectories under the total;

    -k: In KBytes capacity display lists;

    -m: MBytes lists the capacity to display.

2.2 entity links and symbolic links: ln

  ln [-sf] source file destination

  Options and parameters:

    -s: If no arguments to be connected, that is hard link, as for -s is the symbolic link;

    -f: If the target file exists, it will take the initiative to remove the files directly target and then build.

  Hard Link (physical link, hard link or destination) only in a directory adds their link to the file name associated with a record inode numbers only.

  Symbolic Link (symbolic links, that is the shortcut) is establishing a separate file, and the file will read the data file that points to the file name of his link!

3 disk partitioning, formatting, testing and mount

  Disk operations:

    1, partition the disk to create usable partition;

    2, the partition format (the format), to establish a filesystem available to the system;

    3, if you want a little careful, it can be tested for just created filesystem;

    4, on a Linux system, you need to establish a mount point (ie a directory), and mount him up.

3.1 observe the disk partition status

  lsblk [-dfimpt] [device] list lists all the disks on the system

  Options and parameters:

    -d: list only the disk itself, and it does not list the disk partition data

    -f: while listing the file system within the disk name

    -i: Use ASCII output line, do not use complex coding

    -m: while the output of the device in the rights data / dev bottom (rwx data)

    -p: Lists the full file name of the device! Instead of listing only the last name only

    -t: List of detailed data of the magnetic disk apparatus, comprising a disk queue mechanism, the pre-write data size, etc.

  blkid peer device parameters listed UUID

  parted device_name print partition table lists the types of disk and partition information

3.2 disk partition: gdisk / fdisk

  Please use the MBR partition table fdisk partition, GPT partition expression using gdisk partition!

  gdisk apparatus name: pressed just leave gdisk [q], then all the actions will not be effective [reverse], press [w] is the meaning of the operation force.

  gdisk internal command:

    p: query the current state disk

    ?: Query command

    n: Add District

    d: delete partition

 

   partprobe [-s] updated Linux kernel partition table information

   cat / proc / partitions to see core partition record

3.3 Disk Format (Build File System)

  mkfs.xfs [-b bsize] [-d params] [-i params] [-l params] [-L label] [-f] [-r params] Device Name

  Options and parameters:

    About Unit: As long as it comes under the value [], compared bytes value without unit, can be k, m, g, t, p (lowercase) is explained. S is the special unit, which refers to the sector number.

    -b: followed by the block capacity by 512 to 64k, but the maximum capacity is limited to Linux, 4k!

    -d: contact related parameter value followed by the data section, the main values ​​are:

      agcount = Value: setting requires several means (AG) of the storage group, usually associated with CPU

      agsize = Value: each AG meaning set how much capacity, usually agcount / agsize only be set is selected from a

      file: refers to the [formatted device is a file instead of a device]! (Such as virtual disk)

      size = value: data section capacity, i.e. you can not run the entire capacity of the apparatus

      su = value: When a RAID, meaning that the value stripe, and with the use of the underlying sw

      sw = Value: When a RAID, number of disks for storing data (to be deducted from the backup disc and backup plate)

      sunit = value: and su considerable, but the number of units using [sector (512bytes size)]

      swidth = Value: su * sw is the value, but at a few [sector (512bytes size)] is set

    -f: If you already have a file system within the device, is required to force the format -f

    -i: inode and have a more relevant set, the main settings are:

      size = value: Minimum maximum is 256bytes is 2k, in general it is sufficient to use 256 Reserved

      internal = [0 | 1]: log means whether the built-in, a built-in default, if you use an external device, set under the use of

      logdev = device: log means is followed by the top apparatus means that, needs to set before internal = 0

      size = value: this entry section specified capacity, generally have to have a minimum Block 512, above about 2M job!

    -L: followed by the header name Label name of the file system of meaning!

    -r: Specifies the realtime section related to the set value, the common are:

      extsize = Value: the value is that significant extent, not typically be set, but when the RAID, is preferably set in the same preferred value swidth! A minimum of 4K up to 1G.

  mkfs.ext4 [-b size] [-L label] EXT4 file system formatted name means

  Options and parameters:

    -b: set the size of the block, has a capacity of 1K, 2K, 4K of

    -L: followed by the name of this device header

3.4 file system check

  xfs_repair [-fnd] xfs file system name confusion apparatus using this command

  Options and parameters:

    -f: the back of the device is actually a file rather than a physical device

    -n: simple check does not modify any data (checks only) file system

    -d: usually under the single maintenance mode, and operates with the inspection and repair for the directory (/)! Do not use

  fsck.ext4 [-pf] [-b superblock] EXT4 file system name of the processing means

  Options and parameters:

    -p: When the file system at the time of repair, if necessary respond to the action of y, y autoresponders to continue with the remediation action.

    -f: Force checking! In general, if fsck did not find any unclean flag, will not take the initiative to check into the details, if you want to force a fsck check into the details, you have to add -f flag!

    -D: optimized configuration for the directory in the file system

    -b: followed by the position of the superblock! This option is generally less than. But if for some reason your superblcok damage through superblcok backup within this parameter can use the file system to attempt rescue. In general, superblock backup: 1K block on 8193,2K block on 16384,4K block on 32768.

3.5 file system mount and dismount

  Mount precautions:

    1) a single file system mounted should not be repeated at different points of the mount (directory);

    2) a single directory should not be repeated to mount a plurality of file systems;

    3) To mount point as a directory, in theory, should all be empty directory is.

  mount -a

  mount [-l]

  mount [-t filesystem] LABEL = '' mount point

  mount [-t filesystem] UUID = '' mount point

  mount [-t filesystem] filename mount point apparatus

  Options and parameters:

    -a: In accordance with the configuration file / etc / fstab data will all unmounted disks mount up

    -l: simply enter the mount displays information presently mounted. Label names can be added with the -l!

    -t: add a file system can specify the type of class type to be mounted. Common Linux support types are: xfs, ext3, ext4, reiserfs, vfat, iso9660 (CD format), nfs, cifs, smbfs (the latter three as a network file system type)

    -n: In case of default, the system will actually mounts the real-time write / etc / mtab in order to facilitate the operation of other programs. However, in some cases (such as single maintenance mode) To avoid the problems will deliberately not written. Then you must use the -n option.

    -o: back can take some of the mount when adding additional parameters! Let's say the account, password, read and write permissions, etc.

  umount [-fn] file name or device mount point

  Options and parameters:

    -f: Force dismount! Used in cases like the Network File System (NFS) can not be read;

    -l: Immediately unmount the file system, stronger than -f!

    -n: Do not update removed under / etc / mtab situation.

3.6 disk / file system parameters Revision

  means mknod filename [bcp] [Major] [Minor] NUMERICAL by major and minor amendments to the document

  Options and parameters:

    The type of device:

      b: setting a device name becomes the file storage peripherals, such as disks and the like;

      c: setting means as a peripheral input device name of the file, such as a mouse / keyboard and the like;

      p: setting means as a FIFO file name;

    Major: primary devices Code

    Minor: secondary device Code

    A disk file name         Major         Minor    
/ Dev / sda 8 0-15
/dev/sdb 8 16-31
/ Dev / loop0 7 0
/ Dev / loop1 7 1

 

 

 

 

 

 

  

 

 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/zhouweijie/p/11754297.html