File System and disk operations in Linux

Source: Internet
Author: User
Tags inode usage
In terms of file systems, Linux can be regarded as a Swiss Army knife in the operating system. Linux supports many file systems, from log file systems to cluster file systems and encrypted file systems. what is a file system? The file system organizes data and metadata on a storage device... information & in terms of file systems, Linux can be regarded as the "Swiss Army knife" in the operating system ". Linux supports many file systems, from log file systems to cluster file systems and encrypted file systems. what is "file system "? A file system organizes data and metadata on a storage device.
Common File Systems: ext2, ext3, ext4, xfs, jfs, reiserfs, iso9660, swap, VFAT,
 
VFS, etc.
For example, EXT2 xfs jfs REISERF3 is used by a single file system.
Speaking of the file system, we should talk about the hard disk. The first formatting after the hard disk is released is called low-level formatting. its function is mainly to create a track and form a cylinder with the same number, during partitioning, the system partitions the data according to the cylinder, from external to internal, from low to high. Each partition can create a file system independently.
Linux treats all file systems from the perspective of a set of common objects. These objects are superblocks, inode, dentry, and files. The super block describes and maintains the state of the file system on the root of each file system. Each object (file or directory) managed in the file system is represented as an inode in Linux.
 
Inode contains all the metadata required to manage objects in the file system (including operations that can be performed on objects ). Another group of structures is called dentry, which is used to map names and inode. a directory cache is used to save the recently used dentry. Dentry also maintains the relationship between directories and files to support moving in the file system. Finally, the VFS file represents an open file. note: inode is used to store permissions, which belongs to the main group, size, type, and disk block. Directory: each directory requires an inode, storage file name; bitmap: index inode is not 0/1; disk block bitmap: indicates whether a disk block is used.
Commands associated with the file system:
1. ln:
Format: ln [options] by default, src dst creates hard links (not across partitions, hard links are actually used by inode numbers of a file multiple times, with different pointers. as long as the number of connections at the node is not 0, the file will always exist, whether you delete the source file or the connected file.
Common parameter:-s: creates a soft connection. it is an independent file that uses a new inode number and referenced path. It can also be created for a directory and can be used across partitions.
Therefore, when copying, cutting, and deleting some files, the essence is: Copy the disk block where the stored data is located, and use the new inode number, the corresponding ING is created, while the cut does not move the data block, but the file path ing in the inode is modified, this is why we can quickly move a large file in the same partition, and delete the inode to 0 to clear the information, the disk block is marked as unused. when new data is stored, the original data is overwritten, when some data is accidentally deleted, as long as new data has not been written to the original location, the deleted data can be retrieved, for example, some software's crushing function is to re-write 01 code to the location where the original file data is stored, so as to delete the original data.
2. file management
(1). du: used to estimate the usage of directories and files
Parameters:
-H: unit conversion, so that the size is displayed in MB
-S: displays the directory and the size of all files in the directory.
Example: # du-sh/etc
 
(2). df: used to display the usage of the current system disk
-H: unit conversion
-I: displays inode usage
Example: # df-ih
 
(3). fdisk: Disk Management
-L: list the status of each disk and its current partition in the current system.
Example: # fdisk-l
 
(4). compression tool gzip/bzip2/zip/compress/xz/7z
[1] gzip: compressed file --> gunzip: decompress the file
Example: # gzip FILENAME
# Gunzip FILEMAME
Parameters:
-D: extract
-C: gzip-c messages> messages.gz: the source file is retained after compression.
-T: test whether the compressed file is complete after compression
-# (1-9) specify the compression ratio. the default value is 6.
Zcat: View files without any pressure
 
[3] zip: the directory can be compressed
Format: zip [option] file name behind the zip file. zip file to be compressed
Example: # zip message.zip message
Example: # zip myfilezip.zip message inittab compresses multiple files
Unzip: extract
 
[4] tar: file archiving tool
Tar tarfile.tar file or directory
-C: create an archive
-X: expand the archive
-F: file name after archiving
-T: do not expand to view files in the archive
-V: displays the entire archive expansion process.
-Z: compress gzip directly at creation.
-J: compress bzip2 directly at creation.
-C: specify the storage path after expansion
Example: # tar-cf mytar.tar message inittab to create an archive
Example: # tar-xf mytar.tar
Example: # tar-tf mytar.tar
Example: # tar-zcf
Example: # tar-zxf
Example: # tar xf mytar.tar.gz-C/tmp/test
 
3. partitioning: in the hard disk's 0-sector 0 track, the MBR is stored in 512 bytes. The first 446 bytes are the boot sector, which is also known as "BootLoader ", stores boot data. the 64 bytes are the FAT partition list. Each 16 bytes can direct a primary partition. this is what we usually call a hard disk, only up to four primary partitions can be created, or three primary partitions can be expanded. The remaining two bytes occupy the encapsulation code.
When a partition table is faulty or damaged, the system cannot be accessed normally. Therefore, you need to back up the partition table of the system.
Command:
Sfdisk: stores information about the backup partition table.
-D: # sfdisk-d/dev/sdb>/root/sdb. part. bak save the partition table of a disk
# Sfdisk/dev/sdb </root/sdb. part. bak
 
Linux disk device identification rules: IDE or ATA devices are recognized as hd; SATA, SCSI, USB, and other devices are recognized as sd; a, B, c and other letters, such as:/dev/hda/dev/hdb/dev/sda/dev/sdb
 
Create a partition: fdisk/dev/sda
Sub-commands:
W: save the modification and exit.
P: displays the disk list.
N: add a new partition.
D: Delete a partition.
Q: discard the modification and exit
After the partition is created, it does not take effect immediately. you need to run the following command:
Partprobe/dev/sda notifies the kernel to re-scan the disk sda information. if it is not followed by the disk name, all disks will be scanned.
 
4. Format: this formatting is called Advanced formatting.
In linux, no disk or partition is formatted.
Mkfs-t TYPE DEVICE
Example: # mkfs-t ext3/dev/sdb1
-L: specify the volume label
For example: # e2label/dev/sdb1 display its volume label
Example: # e2label/dev/sdb1 HELLO set the volume label
 
Mke2fs/dev/sdb2
-J: create the corresponding disk partition as the ext3 type.
-L: specify the volume label
-B: specify the block size {1024 | 2048 | 4096}
-C: Check whether the disk has bad channels when creating a file system.
-I: specify a ratio. each byte uses an inode number {128 default | 256}
-N: specifies the number of inodes.
-M: specify the disk percentage reserved for the administrator.
 
5. Mount
To access any storage device in Linux, you must associate the device with a directory in the root as an access interface. this process is called mounting, removing associations is called detaching.
Format: mount device mount point
For example, # mount: display all mounted file systems
# Mount/dev/cdrom/media mount the cdrom disk under dev to media
Parameter format: mount [-t fstype] [option] device mount point
-A: mount all file systems/etc/fstab # mount-
-N: the/etc/mtab file is not updated during mounting.
-R: Read-only mounting
-W: read/write mounting
-L label: specify the volume label for mounting.
-U: specify the uuid for mounting.
-O: specify the mount option explicitly.
Async: asynchronous write
Atime: the time automatically updated during access
Auto: Automatic mounting is supported.
Exec: Allows execution of files with execution permissions
Nouser: prohibit normal users from attaching this device
Remount: re-mount (this option is used when a property is not opened and needs to be opened)
Ro: Read-only
Rw: write only
For example: # mount-o ro/dev/sdb1/mnt mount the sdb1 partition under dev to/mnt in read-only mode
Example: # mount-o remount, rw/mnt
Loop: Mount a local device
For example: # mount-o loop rhci. iso/mnt mount an iso
 
6. umount: uninstall the device
Umount mount point/mounted device
Example: # umount/dev/sdb2
Blkid DEV: view the file type of the device.
 
7. check the file system
(1). fsck check file system inconsistency (check inode and file inconsistency)
Parameter:-t FILETYPE: specifies the type of the detected file system
Example: # fsck-e ext3
Efsck: used to specifically detect ext file systems
Parameter:-f: forced detection
-P: automatically fixes file system inconsistencies
-B: specify the disk block size.
 
(2). dumpe2fs: detailed display of ext2 ext3 file system information
Parameter:-f: displays detailed information even if the file system is inconsistent.
-H: only the details of the super block are displayed.
Example: # dumpe2fs/dev/sda


Tune2fs: modifies the attributes of the file system of the ext class.
Parameter:-j: upgrade the ext2 file type to ext3 (data on the disk is not affected)
-M: change the percentage of disk blocks and inode retained to the root user.
-R: directly specify the number of blocks.
-L: set the volume label
-L: displays super fast information.
-C: modify the number of mounting times and perform self-check.
-I: set the number of days for self-check. the default unit is day.
-U: specifies the user
-O: specifies the default mounting function.
 
(3) swap partition swap (it must be an independent partition, which is equivalent to the virtual memory in windows. it will be used only when the physical memory is about to run out or is not enough)
Free-m: displays memory information in MB.
Format: mkswap
Parameter:-L: specify the volume label
Enable swap partition: swapon DEV
Disable swap partition: swapoff DEV
Start all: swapon-
Check its status: swapon-s
 
(4). create a local loop file, which can also be understood as a copy. it can be said that the disk block is copied directly.
Format: dd if = FILE of = FILE bs = NU count = NU
If = FILE: the FILE to be copied
Of = FILE: Target
Bs: the maximum size of a copy, in bytes by default.
Count: Number of copies
# Dd if =/etc/issue of =/tmp/abc
# Dd if =/dev/sda of =/root/mbr. bak bs = 512 count = 1 backup mbr Mater Boot Record
# Dd if =/dev/zero of =/var/swapfile bs = 1 M count = 1 create a 1 M local loop file
 
/Dev/null
/Dev/zero is used to initialize a partition.
 
(5)./ect/fstab file system automatically mounted upon startup
Six fields:
DEV-name | DEV-label | DEV-uuid
Mount point:
File system type:
Mount option (defaults );
Dumping frequency: backup {0, 1, 2 }{ never backup, once a day, twice a day}
Self-check order: {0, 1, 2} {never, first, second}, first can only be the root
 
 
 
 
 
This article is from the blog "Xiangyang grass ● Mickey ".
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.