Linux under: Disk Management and File system management

Source: Internet
Author: User
Tags uuid

First, Disk basic knowledge
Here are some things to know before you learn this chapter:
? Stress: Everything in Linux is file.
? The I/O ports is the I/O device address that identifies the device address of the hardware for the operating system and CPU usage.
Note: The CPU's number of cores is not necessarily the more the better, due to the problem between the CPU coordination, performance may not rise down.

1. Equipment files
①, what is a device file
Device files are linked to a device driver, which enables communication with the corresponding hardware device
②, equipment File classification:
Block device: block. Access unit "Fast". Typical representative: Disk
? character device: Char, Access unit "character". Typical Representative keyboard

③, device file path:

#/dev/dev_file

④, device number identification:
Main device number: Major numbers, identifying device types
Secondary device number: Minor numbers, identifying different devices under the same device number

[Email protected] dev]# ls-l/dev/| Grep"SDA"lrwxrwxrwx.1Root root4May at  -:Panax NotoginsengRootSDA3BRW-RW----.1Root disk8, 0May in  to: +SDA "Note: This is the same device type, so the main device number is 8, because it is a different device under the same device type, so the secondary device number is different, and Sdade's secondary device number is 0"BRW-RW----.1Root disk8, 1May at  -:Panax NotoginsengSDA1BRW-RW----.1Root disk8, 2May at  -:Panax NotoginsengSDA2BRW-RW----.1Root disk8, 3May at  -:Panax NotoginsengSda3

⑤, HDD interface type
    Interface rate, not hardware device rate, different hard drive rates on the same interface

Parallel (for data serial work, similar to bidirectional two lanes, but with data interference)

ide:133mb/s

scsi:640mb/s

Serial port (data serial work, type one-way four-lane)

sata3:6gbps (need to divide by 8来 to get the actual rate)

sas:6gbps

usb:480mb/s

Unit (RPM): rotations per minute

⑥, device file naming for disk devices
Naming format:/dev/dev_file

    Different host device naming methods:/dev/sd#
"Note: #代表a-Z"
Such as:

· IDE::/DEV/HD SCSI, SATA, SAS, USB:/DEV/SD

Different partition names for the same host device:
"Direct use of numbers to differentiate"
such as:/dev/sda/dev/sda2/dev/sda2/dev/sda3

2, Mechanical hard disk "This part is written mainly to understand the role: to understand what is a track, sector, cylinder"

The mechanical hard disk consists of the following parts: the mechanical arm (Boom), the head (head), the rotating shaft (spindle), the disc (platter), in the actual application of the disc into the track, Sector (Sector) and cylinder (Cylinder)

  

In practice, the platters are divided into tracks (track), Sector (Sector) and cylinder (Cylinder)

       

                       

3, the Division principle Knowledge Pointmechanical hard disk is partitioned by cylinder  ①, 0 tracks 0 sectorsOn a traditional system, when we start the computer, the default is to read 0 tracks 0 sectors of data, the size is 512bytes ,it does not belong to any partition, it is used to identify the partition information we created, etc.0 Track 0 sector size is not counted in the partition
446bytes:boot Loader master boot record 64bytes: Partition table 16bytes: Identify a Partition " so a mechanical hard disk can only be divided into 4 primary partitions, or 3 primary partitions + extended partitions (n logical partitions)" 2bytes:5 5AA to identify the end

Practical Walkthrough: (To Know what "DD" command is)

# backup MBRDD if=/DEV/SDA1 of=/root/mbr bs= +Count=1# recovery MBR:DD if=/ROOT/MBR of=/dev/sda1 bs= +Count=1# Recovery partition table: DDif=/ROOT/MBR of=/dev/sda1 bs= +skip=446Count= theNOTE: MBR size 512 so BS= +Count=1bs= +skip=446Count= theUsed to determine the location of a partitioned table in a backup file

4. Disk Partition management tool: "fdisk, parted, Sfdisk"

This article is mainly about FDISK for disk partitioning operations

  fdisk manages partitioning prerequisites: up to 15 partitions can be managed

Syntax format 2:fdisk [-L,-u] [device]

Parameter description: Direct partitioning if not with parameters

-L: Displays the current system partition, and if it has a specific partition, it will show the partition structure.

-U: Partitioning disk operations

 

Note When you use the FDISK command:
# fdisk-u/dev/SDA-u/dev/sda1 "Error"

On a partition operation: The following is a subcommand management operation

P:print, showing existing partitions;

N:new, creating Note When partitioning: Because 1-4 of these 4 numbers must be reserved for primary and extended partitions, the number of logical partitions must start from 5 "D:delete, delete w:write, write to disk and exit Q:quit, discard Update and exit M: Get help L: List partition ID T: Adjust partition ID

The following steps are needed after the partition has been saved.

①, see if the kernel has recognized the partition command:

    # cat/proc/partaions

②, if the kernel is not recognized, notifies the kernel to re-read the disk partition table

Method One:
      # PARTX [-a,-n]/dev/device
-A: Read all partition tables
-N: Reads the specified partition table

Method Two:
#kpartx [-a,-f]/dev/device
-A: Read all partition tables
-F: Forced read partition table "Note: This method is not recommended, if the above reading method does not work, the last use of this method"

Method Three: "Note: This method only applies to the centos5.x series"
# Partprobe [/dev/device]

③, after doing the above steps, if you want to use the disk of the current partition, you also need to format the disk

      

Case Analysis:

[Email protected] ~]# fdisk-l"View all partitions in the current system"disk/dev/sda:10.7 GB, 10737418240 bytes255 heads, sectors/track, 1305 cylindersunits = cylinders of 16065 * 512 = 822 5280 bytessector Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): + bytes/512 Bytesdisk ident      ifier:0x0006ac8d Device Boot Start End Blocks Id system/dev/sda1 * 1 26 204800 linuxpartition 1 does not end on cylinder BOUNDARY./DEV/SDA2-113 694272 Nux Swap/solarispartition 2 does not end on cylinder BOUNDARY./DEV/SDA3 113 1306 9585664 Nux
[Email protected] ~]#fdisk-u/DEV/SDA        "Create a new partition on disk SDA"Warning:dos-compatible mode is deprecated. It ' s strongly recommended to switch off the mode (command ' C '). Command (M for help): Ncommand action E Extended P primary partition (1-4) E"Extended Partition"Selected partition 4First sector (63-20971519, default): Using default value 63Last sector, +sectors or +size{k,m,g} (6 3-2047, default 2047): 1000Command (M for help): P"View partition information"disk/dev/sda:10.7 GB, 10737418240 bytes255 heads, sectors/track, 1305 cylinders, total 20971520 sectorsunits = sector S of 1 * bytessector = size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 b Ytesdisk identifier:0x0006ac8d Device Boot Start End Blocks Id system/dev/sda1 * 2048 411647 204800 linuxpartition 1 does not end on cylinder boundary./dev/sda2 411648 1800191 6 94272 swap/solarispartition 2 does not end on cylinder Boundary./dev/sda3 1800192 20971519 95 85664 linux/dev/sda4 469 5 extendedpartition 4 does not end on cylinder Boun Dary. Partition table entries is not on disk Ordercommand (M for help): W"Save partition information and exit"The partition table has been altered! Calling IOCTL () to re-read partition table. Warning:re-reading the partition table failed with error 16:device or resource busy. The kernel still uses the old table. The new table is being used atthe next reboot or after you run Partprobe (8) or KPARTX (8) Syncing disks. [Email protected] ~]#cat/proc/partitions    "See if the kernel has recognized the partition, where the kernel does not recognize the partition"Major minor #blocks name 8 0 10485760 SDA 8 1 204800 sda1 8 2 694272 sda2 8 3 9585664 sda3[[email protected] ~]#partx-a/DEV/SDA      "Notifies the kernel to re-read disk partition information"Blkpg:device or resource Busyerror adding partition 1blkpg:device or resource busyerror adding partition 2blkpg:device or resource Busyerror adding partition 3[[email protected] ~]# cat/proc/partitions"Check again, the kernel has identified the partition"Major minor #blocks name 8 0 10485760 SDA 8 1 204800 sda1 8 2 694272 sda2 8 3 9585664 Sda3 8 4 469 SDA4

5. File System Management Operation

1) file System type Description:

  Linux file system types: ext2, ext3, Ext4, XFS "Btfrs, ReiserFS, JFS, swap (swap partition), disc (iso9660)"
Swap: Swap partition

Windows:fat32, UTFs
Unix:ffs, UFS, JFS2
Network File system: NFS, CIFS
Cluster file system: GFS2, OCFS2
Distributed File System: Ceph

  Depending on whether it supports the "journal" function, it is also divided into
Log file system: EXT3,EXT4,XFS,...
Non-date file system: Ext2,vfat

  Part of the file system:

Modules in the kernel: Ext4, XFS, VFAT User space management tools: MKFS.EXT4, MKFS.XFS, Mkfs.vfat "actually one by one corresponds"

virtual file system for Linux: VFS------Linux Systems can use a variety of file system types at the same time, eventually unified into the VFS to manage,

Use the cat/proc/filesystems command to view the file system types supported by the system,

             lsmod command to view loaded modules

2) Create file System (format):

mkfs command:

Grammar 1:mkfs. Fs_type/dev/device

Grammar 2:mkfs-t Fs_type/dev/device [the above one can be described as a shorthand for the following]

Fs_type options:

Ext4, XFS, Btrfs, VFAT

Common parameters:

-L #: Set the volume label name #

Detailed Case Study:

[[email protected] ~]# mkfs.ext4-l "myname"/dev/sda4  "Create file system while specifying volume label" MKE2FS 1.41.12 (17-may-2010) Filesystem label= Mynameos type:linuxblock size=1024 (log=0) Fragment size=1024 (log=0) stride=0 blocks, Stripe width=0 blocks64 inodes, 468 Blocks23 blocks (4.91%) reserved for the Super Userfirst data block=1maximum filesystem blocks=5242881 block group8192 blo Cks per group, 8192 fragments per group64 inodes per groupwriting inode tables:done                            Filesystem too small for a Journa Lwriting superblocks and filesystem accounting information:donethis filesystem would be automatically checked every MOU NTS or180 days, whichever comes first.  Use Tune2fs-c or-i to override. [Email protected] ~]# BLKID/DEV/SDA4    
View Code

3) file system-specific management tools:

  mke2fs Command "is the Ext series file system dedicated management tool"

syntax: mke2fs [OPTIONS]/dev/device

Parameters:

-T: (EXT2\EXT3\EXT4)
-B: Specify block size, default if not specified (1024.2048.4096)
-L: Specify the volume label
-j: Equivalent to-t ext3

-I #: Create a inode;ci size for less than a few bytes in the data space should not drizzle block size
-N #: How many inode to create for the data space
-M #: Percentage of space reserved for managers; default 5 space
-O feature[,...]: Enable specified attributes
-O ^feature[,...]: Turn off specified properties

Example: Mke2fs-b 2048-m 3-l mydata/dev/sda4

4) Create swap partition

Command:mkswap

Prerequisites for using the command: You must first adjust the ID of its partition to 82 (implemented using the "t" option in Fdisk)

Command format: mkswap [OPTIONS] ... DEVICE

Parameter:-L: "lable"

5) Other common tools

blkid Command : Quick Device Properties Information view

Syntax: Blkid [OPTIONS] ... [/dev/device]

Parameter:-L: Find the device for the lable according to the specified device-u: Find the device based on the UUID of the specified devices
Note: If the parameters are followed, the device files are located according to the specified parameters, and the following path is not written (it is useless to write);
If the parameter is not previously given, it is to look at the device file UUID and label, and then must be written on which device file "
[[email protected] ~]# blkid/dev/sda4     "View Device file property information"/dev/sda4:label= "lable" uuid= " d33ffdae-f171-492e-b3d5-6099dcbe5856 "type=" EXT4 "[[email protected] ~]# blkid-l lable  " Locate the device file according to the lable of the device file "     /dev/sda4[[email protected] ~] #blkid-U "d33ffdae-f171-492e-b3d5-6099dcbe5856"   "Locate the device file based on the UUID of the device file"
usage of the Blkid command

  e2lable Command : Manage the lable of the EXT series file system

Syntax: e2lable [lable] DEVICE

TUNE2FS command : Reset the values of the EXT series file system adjustable parameters  

Parameters:
-L: View the file system's Super block information: Super blocks
-L ' lable ': Modify volume label
-j: Upgrade ext2 to ext3 (equivalent to "-t ext3")
-M #: Percentage of space reserved for managers; default 5 space
-O feature[,...]: Enable specified attributes
-O ^feature[,...] turn off specified properties
Tune2fs-o Has_journal/dev/sda5, the original ext2 file system will be changed to Ext3,
Tune2fs-o ^has_journal/dev/sda5 Disable this property
-O: Adjusts the default mount option for the file system, using the same as above, about the property name can be viewed by man tune2fs,
For example Tune2fs-o ^acl/dev/sda5 #禁用默认挂载选项的acl功能
-U uuid: Modify the UUID number; UUID but randomly generated, not many scenes to modify

    

    dumpe2fs Command

-H: View Super Quick Info

Example: DUMPE2FS/DEV/SDA4 will display the file system information in detail, or layout information, such as grouping, block information, inode location, etc.

  

6) File System Detection Tool ( often used for abnormal shutdown causing file system error ):

    Note: Whether it is abnormal shutdown or normal shutdown, do not carry out automatic file detection when booting, it is best to manually detect the file after the boot

    

    

Linux under: Disk Management and File system management

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.