Linux disk and File System Management (1) _ partition formatting

Source: Internet
Author: User

Linux disk and File System Management (1) _ partition formatting
Linux disk management Hard Disk: mechanical hard disk SSD solid state disk mechanical: track sector: minimum texture storage unit, each sector size is 512 bytes cylinder cylindrical: partition basic unit; the first sector of the hard disk is 512 bytes MBR: Master Boot Record the hard disk Master Boot records MBR accounted for 446 bytes: the bootloader Partition table (pratition table) occupies 64 bytes: in the filesystem allocation table partition table, each 16 bytes identifies a partition. Therefore, the primary partition and the extended partition can have up to four partitions. 2 bytes: 55AA flag, and 55AA indicates that the partition takes effect, others indicate invalid disk interface type: IDE (ATA): Speed 133 MB/s,/dev/hd SCSI: Speed 640 MB/s SATA: Speed 6 Gbps SAS: Speed 6 Gbps USB: speed: 480 MB/s hard disk device identification: names of disks with various interfaces in linux. After centos6, they are all named:/dev/sd * marked with Different Hard Disk devices: /dev/sd [a-z] Mark different partitions on the same device:/dev/sd [a-z] [1-] 1-4: name the primary or extended partition ID 5 +: Logical partition ID Device File: special file device number: major, minor major: indicates the device type minor: different devices of the same type "Block ": block, Random Device "character": character, linear device GPT: GUIDPartition Table disk management adds a new disk to the linux system. You need to partition the disk and format the partition, create available file system 3 create a mount point and mount it to the disk and directory capacity df command: list the overall disk usage of the file system report file system disk space usage Syntax: df [OPTION]... [FILE]... option:-a: List all file systems-k or-m: display the file system-h in units of KB, MB: easy to read GB, MB, display in KB or other formats-I: No need for hard disk capacity, displayed as inode quantity-T: Display partition file system type example:

# List the overall disk usage of the file system [root @ localhost ~] # DfFilesystem 1K-blocks Used Available Use % Mounted on/dev/sda3 9947976 551432 8868160 6%/devtmpfs 493016 493016 0%/devtmpfs 501580 501580 0% 501580/dev/shmtmpfs 6792 494788 2%/runtmpfs 501580 0 501580 0%/sys/fs/cgroup/dev/sda2 20027216 1112520 17874312 6%/usr/dev/sda1 194235 90696 89203 51%/boot/dev/sda5 9947976 36976 9382616 1%/home # display the format of each partition in the file system [root @ localhost ~] # Df-T Filesystem Type 1K-blocks Used Available Use % Mounted on/dev/sda3 ext4 9947976 551432 8868160 6%/devtmpfs 493016 0 493016/devtmpfs tmpfs 0% 0 501580/dev/shmtmpfs tmpfs 501580 6792 494788 2%/runtmpfs tmpfs 501580 0 501580 0%/sys/fs/cgroup/dev/sda2 ext4 20027216 1112520 17874312 6%/usr/dev/sda1 ext4 194235 90696 89203/boot /dev/sda5 ext4 9947976 36976 9382616 1%/ Home # [root @ localhost ~] # Df-ThFilesystem Type Size Used Avail Use % Mounted on/dev/sda3 ext4 9.5G 539 M 8.5G 6%/devtmpfs 482 M 0 482 M 0%/devtmpfs tmpfs 490 M 0 490 M 0%/dev/shmtmpfs tmpfs 490 M 6.7 M 484 M 2%/runtmpfs tmpfs 490 M 0 490 M 0%/sys/fs/cgroup/dev/sda2 ext4 20G 1.1G 18G 6%/usr/dev/sda1 ext4 190 M 89 M 88 M 51%/boot/dev/sda5 ext4 9.5G 37 M 9.0G 1%/home

 

Filesystem: Indicates each partition. device name Type: File System Format: 1k-blocks: 1 k indicates the unit of the following numbers: Used space Avail: available space Use %: disk usage Mounted on: disk mount point du command: Count the directory capacity du [OPTION]... [FILE]... parameter:-a: List all files and directory capacity-h: the unit of readable capacity is KB, MB, and GB.-s: list total-S: example of a total that does not contain subdirectories:
# Default analysis of the current directory without a directory or file name [root @ localhost test] # du4. /testbash28. [root @ localhost test] # du-a16. /functions4. /testbash4. /test_vim28. [root @ localhost test] # du-h4.0K. /testbash28K. [root @ localhost test] # du-sh/etc/22 M/etc/[root @ localhost test] # du-S4. /testbash24.

 

Partitioning: separates the storage space into multiple small spaces. Each space can use the file system independently. Partitioning tools: fdisk, parted, and sfdisk fdisk: A maximum of 15 partitions can be created on a hard disk. fdisk DEVICE: DEVICE indicates the DEVICE file name. Do not add a number to the back. The partition is for the entire hard disk DEVICE partition management sub-command: p: show current Partition Table n: Create new partition d: delete specified partition t: Modify partition ID l: list all supported partition types and IDs w: Save and exit q: discard modification and exit m: after obtaining help, check whether the kernel has recognized the new partition: # cat/proc/partitions has three commands to allow the kernel to re-read the disk partition table CentOS5: partprobe [DEVICE] CentOS6, 7. Command: partx kpartx partx command: partx DEVICE partx-a DEVICE registers all the partition information on a disk, as shown in figure If the partition information has been recorded, an error is reported. If the partition information on a disk is not recorded, it is completed quietly. Partx-a-n M: n device records the information of the nth to nth partitions. M reads the information of the nth partition. M: specifies the minimum value for reading the Partition Number: n: specify the maximum value of the read Partition Number. kpartx command: create a DEVICE ing from the partition table. kpartx-af DEVICE-a: Add a partition ing. Linux File System: VFS: virtual FileSystem ensures that all disk device interfaces can use Linux: ext2, ext3, ext4, reiserfs, xfs, btrfs, and swap optical disks: iso9660 Windows: fat32 (vfat), ntfs Unix: ffs, ufs, jfs, jfs2 Network File System: nfs, cifs Cluster File System: ocfs2, gfs2 Distributed File System: ceph, moosefs, mogilefs, hdfs, gfs, glusterfs (1) log File System Non-Log File System: ext2 Log File System: ext3 (2) swap: swap partition use the hard disk as the temporary memory to create a file system: to execute formatting (Advanced formatting) on a partition, you need to use a certain file system to meet two conditions: in the kernel: support for this file system user space: a file system management tool to create a tool: mkfs (make filesystem) mkfs-t type DEVICE mkfs. type DEVICE mkfs [Tab] [Tab] to view the file formats supported by mkfs. cramfs mkfs. ext3 mkfs. minix mkfs. btrfs mkfs. ext2 mkfs. ext4 mkfs. xfs ext file system dedicated management tools: mke2fs-t {ext2 | ext3 | ext4} DEVICE-B BLOCK: 1024,204 8, 4096 specify the BLOCK size; determine the block allocation size based on the size of the storage file-L 'label': Set the volume LABEL name-I #: to give more space to an inode-N #: how many inode-m are reserved for this disk partition #: the percentage of space occupied by the reserved disk space is used for later management.-c: Check disk errors. Only once-c is released, will perform a quick read Test-j: equivalent to mk2fs-t ext3; the original mke2fs is ext2, add journal to become ext3-O feature [,...] enable the specified feature has journal to enable the log function-O ^ feature [,...] disable the specified feature/etc/mke2fs. conf default feature configuration file blkid command: locate and display block device attributes locate/print block DEVICE attributes blkid device view LABEL, UUID, TYPE example:
# Check whether a new disk/dev/sdb is available [root @ localhost ~] # Fdisk-l Disk/dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectorsUnits = sectors of 1*512 = 512 bytesSector size (logical/physical ): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytesDisk label type: dosDisk identifier: 0x000c2314 Device Boot Start End Blocks Id System/dev/sda1 * 2048 411647 204800 83 Linux/dev/sda2 411648 41371647 20480000 83 Linux/dev/sda3 41371648 6 1851647 10240000 83 Linux/dev/sda4 61851648 251658239 94903296 5 Extended/dev/sda5 61855744 82335743 10240000 83 Linux/dev/sda6 82337792 86532095 2097152 82 Linux swap/Solaris/dev/sda7 61853696 61855743 1024 83 Linux/dev/sda8 86534144 107505663 10485760 83 LinuxPartition table entries are not in disk orderDisk/dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1*512 = 512 BytesSector size (logical/physical): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytes # create a new partition on the new disk [root @ localhost ~] # Fdisk/dev/sdbWelcome to fdisk (util-linux 2.23.2 ). changes will remain in memory only, until you decide to write them. be careful before using the write command. device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0x3bb13419. command (m for help): n -------------------> Create a New Partition type: p primary (0 primary, 0 extended, 4 free) ----> select create primary Partition e ext Ended ---------------------------------> Select (default p): p -----------------------------------> Create primary Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): -----> Select Start cylindrical default 2048 start Using default value 2048 Last sector, + sectors or + size {K, M, G} (2048-41943039, default 41943039 ): + 1024 MPartition 1 of type Linux and of size 1 GiB is setCommand (m for help): p ------------- ---------> Print partition table information # There are two ways to create the partition size above #1. Enter the start and end columns, determine the partition size #2 directly input + xx units to allocate the partition size Disk/dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1*512 = 512 bytesSector size (logical/physical): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytesDisk label type: dosDisk identifier: 0x3bb13419 Device Boot Start End Blocks Id System/dev/sdb1 2048 2099199 1048576 83 Li NuxCommand (m for help): nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p ): e -------------------> Create an extended Partition (up to one extended Partition can be created) Partition number (2-4, default 2): 2 First sector (2099200-41943039, default 2099200 ): using default value 2099200 Last sector, + sectors or + size {K, M, G} (2099200-41943039, default 41943039): Using default value 41943039 Partition 2 of type Extended And of size 19 GiB is setCommand (m for help): nPartition type: p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5) ---------> because the extended partition is created earlier, the logical partition Select (default p): lAdding logical partition 5 First sector (2101248-41943039, default 2101248) is available ): 512 Value out of range. first sector (2101248-41943039, default 2101248): Using default value 2101248 Last sector, + sectors or + size {K, M, G }( 2101248-41943039, default 41943039): + 512 MPartition 5 of type Linux and of size 512 MiB is setCommand (m for help): pDisk/dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1*512 = 512 bytesSector size (logical/physical): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytesDisk label type: dosDisk identifier: 0x3bb13419 Device Boot Start End Blocks Id Syst Em/dev/sdb1 2048 2099199 1048576 83 Linux/dev/sdb2 2099200 41943039 19921920 2101248 5 Extended/dev/sdb5 3149823 524288 83 LinuxCommand (m for help ): w # Do not save The input q and exit fdisk # Enter w to write The operation to The partition table has been altered! Calling ioctl () to re-read partition table. Syncing disks. # view partition information [root @ localhost ~] # Cat/proc/partitions major minor # blocks name 8 0 125829120 sda 8 1 204800 sda1 8 2 20480000 sda2 8 3 10240000 sda3 8 4 1 sda4 8 5 5 10240000 sda5 8 6 2097152 sda6 8 7 1024 sda7 8 8 10485760 sda8 8 16 20971520 sdb 8 17 1048576 sdb1 8 18 1 sdb2 8 21 524288 sdb5 11 0 651264 sr0 # reread partition information [root @ localhost ~] # Partx/dev/sdbNR start end sectors size name uuid 1 2048 2099199 2097152 1G 2 2099200 41943039 39843840 19G 5 2101248 3149823 1048576 512 M # disk formatting mkfs format the created sdb1 in xfs format [root @ localhost ~] # Mkfs-t xfs/dev/sdb1meta-data =/dev/sdb1 isize = 256 agcount = 4, agsize = 65536 blks = sectsz = 512 attr = 2, projid32bit = 1 = crc = 0 finobt = 0 data = bsize = 4096 blocks = 262144, imaxpct = 25 = sunit = 0 swidth = 0 blksnaming = version 2 bsize = 4096 ascii-ci = 0 ftype = 0log = internal log bsize = 4096 blocks = 2560, version = 2 = sectsz = 512 sunit = 0 blks, lazy-count = 1 realtime = none extsz = 4096 blocks = 0, rtextents = 0 # view the partition format [root @ loc Alhost ~] # Blkid/dev/sdb1/dev/sdb1: UUID = "a7712c0d-6264-496e-8f6b-1da5b7da5939" TYPE = "xfs" # format/dev/sdb5 as ext4 using mkfs. ext4 DEVICE [root @ localhost ~] # Mkfs. ext4/dev/sdb5mke2fs 1.42.9 (28-Dec-2013) Filesystem label = OS type: LinuxBlock size = 4096 (log = 2) Fragment size = 4096 (log = 2) Stride = 0 blocks, stripe width = 0 blocks32768 inodes, 131072 blocks6553 blocks (5.00%) reserved for the super userFirst data block = 0 Maximum filesystem blocks = 1342177284 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups store D on blocks: 32768,983 04 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: done # view the partition format [root @ localhost ~] # Blkid/dev/sdb5/dev/sdb5: UUID = "7ff064f9-49c8-466d-8d86-7f4eba5e353b" TYPE = "ext4" # ext file system dedicated management tools to create partitions [root @ localhost ~] # Mke2fs-t ext4-L 'test _ mk2fs '/dev/sdb6mke2fs 1.42.9 (28-Dec-2013) Filesystem label = test_mk2fsOS type: LinuxBlock size = 4096 (log = 2) fragment size = 4096 (log = 2) Stride = 0 blocks, Stripe width = 0 blocks32768 inodes, 131072 blocks6553 blocks (5.00%) reserved for the super userFirst data block = 0 Maximum filesystem blocks = 1342177284 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768,983 04 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: done

 


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.