5.1.1 Disk Structure and Partitioning

structure of the disk

    Because of the old saying in linux that "everything is a file", so for a file. Read and write, open and close all need corresponding functions: open(), read(), write(), close(). Devices are also considered files by Linux: block device: block, access unit "block", disk

                                                                                                 Character devices: char, access unit "character", keyboard

You can view all device files that come with the system under /dev. Device files have major and minor device numbers

brw-rw----. 1 root disk 8, 1 Mar 31 06:03 /dev/sda1
crw-rw-rw-. 1 root root 1, 5 Mar 31 06:03 /dev/zero

Common disk interfaces are: SATA: 6Gbps, SAS: 6Gbps, USB: 480MB/s

    Starting from CentOS6, all interface types of hard disks are named sd[a..z][number], and virtual disks are named vb.

    In CentOS6, the newly added hard disk will be named as the first hard disk (sda), and in CentOS7, it will be named as the last hard disk.

Common types of disks are: mechanical hard drives and solid state drives.

    Compared with HDD, SSD has obvious advantages in shock resistance, drop resistance, transfer rate, power consumption, weight, and noise. The transfer rate performance of SSD is twice that of HDD.

    Compared with SSD, HDD has absolute advantages in price, capacity and service life


hard drive storage terms

    head : head, track : track, cylinder : cylinder, sector : sector (512bytes)

    Magnetic head = disk surface = disk * 2, number of tracks = number of cylinders

Because the sector with a small track number is large, and the sector with a large track number is small, the current mechanical hard disk uses ZBR (Zoned Bit Recording)


Disk addressing methods are: CHS and LBA addressing

CHS
    uses 24bit bit addressing
    where the first 10 bits represent the cylinder, the middle 8 bits represent the head, and the last 6 bits represent the sector
    ’s maximum addressing space of 8GB
LBA (logical block addressing)
    LBA uses 48 bits to address
    the maximum addressing space of 128PB

partition of the disk

    Partitioning

MBR : Master Boot Record (Master Boot Record) uses 32 bits to indicate the number of sectors, and the partition does not exceed2T. According to the sector partition,in the 512 bytes of the 0 track 0 sector ofthe disk, the MBR of the hard disk is stored, and the details are written in thefile system foundation.

[root@CentOS6 ~]#hexdump -C /dev/sda -n 512
00000000  eb 48 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.H..............|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 03 02  |.........|...t..|
00000040  80 00 00 80 70 13 05 00  00 08 fa 90 90 f6 c2 80  |....p...........|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|<.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |[email protected]........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |[email protected]..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}<.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|`......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..<.u...........|
000001b0  00 00 00 00 00 00 00 00  89 1d 0b 00 00 00 80 20  |............... |
000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 aa |! ... (....... ... |
000001d0 29 82 83 fe ff ff 00 08 20 00 00 00 40 06 00 fe |)....... ...@...|
000001e0 ff ff 83 fe ff 00 08 60 06 00 00 60 00 00 fe | ........ `...` ... |
000001f0  ff ff 05 fe ff ff 00 08  c0 06 00 f8 bf 05 55 aa  |..............U.|
00000200


GPT : GUID (Globals Unique Identifiers) partition tablesupports 128 partitions, uses 64 bits to represent the number of sectors, and supports a maximum partition of 8Z (512Byte/block) or 64Z (4096Byte/block). Use 128-bit UUID (Universally Unique Identifier) ​​to indicate that the disk and partition GPT partition table is automatically backed up in two copies at the head and tail, and has a CRC check bit.


Disks using GPT partitions are divided into: EFI information area (GPT header), partition table, GPT partition, and backup area.

    Manage partitions

    The lsblk command lists information about all available block devices and displays their dependencies, but it does not list information about RAM disks.

    Syntax : lsblk [options] [device]

[root@CentOS6 ~]# lsblk --fs
NAME   FSTYPE  LABEL UUID                                 MOUNTPOINT
sr0    iso9660 CDROM                                      /media/CDROM
sth                                                       
├─sda1 ext4          056668aa-7ecd-4235-8351-c8fb02372e3b /boot
├─sda2 ext4 481fa90c-b9f1-459b-ba67-f4f4c8d7942b /
├─sda3 ext4          b98328eb-21c7-4114-b3d5-93cd4aec6bc8 /data
├─sda4                                                    
├─sda5 swap          5a1eda5a-2e54-4d0c-b8ea-ef99b9ac3417 [SWAP]
└─sda6 ext4    /home 6caa3a45-0781-49bf-a167-9bfac5fa7fb5

    Options :

-a, --all Display all devices.
-f, Display file system information.
-m Display permission information.

-l, --list Display in list format.

    fdisk is used to create and maintain MBR partition table; gdisk is used to create and maintain GPT partition table. The configuration does not take effect immediately, it takes effect after saving.

    Syntax : fdisk [-l] [disk]

    When using fdisk to manage MBR partitions on CentOS6, you need to use the -c option.

[root@CentOS6 ~]#fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b1d89

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6658    52428800   83  Linux
/dev/sda3 6658 7050 3145728 83 Linux
/dev/sda4            7050       13055    48233472    5  Extended
/dev/sda5            7050        7311     2097152   82  Linux swap / Solaris
/dev/sda6            7311        7572     2098730+  83  Linux
[root@CentOS6 ~]#fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help):

    Subcommand :

p partition list
t change partition type
n create new partition
d delete partition
v verify partition
u convert unit
w save and exit

q do not save and exit

    The parted command is an advanced disk maintenance tool that can manage and maintain MBR and GPT partitioned disks. Entering "parted disk" directly will enter the interactive mode, and the operation result of the parted command willtake effect immediately.

    Syntax : parted [disk] [command]

[root@CentOS6 ~]#parted /dev/sda rm 6
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after
reboot.
Information: You may need to update /etc/fstab.                           

    Subcommand :

mklabel: create a new partition type (partition table) 
mkfs: create a file system for the partition with the specified label 
mkpart: create a partition 
mkpartfs: create a partition with a file system 
name: name the partition with the specified number 
print: print the partition table, Or partition 
quit: quit the program  

rm: delete the partition with the specified number 

    Sync partitions

View the partitions recognized by the current kernel:

[root@CentOS6 ~]#cat /proc/partitions
major minor  #blocks  name

   8 0 104857600 sda
   8 1 1048576 sda1
   8 2 52428800 sda2
   8 3 3145728 sda3
   8 4 1 sda4
   8 5 2097152 sda5
[root@CentOS6 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  5.8G  0 rom  /media/CDROM
sda      8:0    0  100G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   50G  0 part /
├─sda3   8:3    0    3G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
[root @ CentOS6 ~] #ls / dev / sda *
/ dev / sda / dev / sda1 / dev / sda2 / dev / sda3 / dev / sda4 / dev / sda5
View existing partitions on the current disk:
[root@CentOS6 ~]#fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b1d89

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6658    52428800   83  Linux
/dev/sda3 6658 7050 3145728 83 Linux
/dev/sda4            7050       13055    48233472    5  Extended
/dev/sda5            7050        7311     2097152   82  Linux swap / Solaris
/dev/sda6            7311        7572     2098730+  83  Linux

Most of the reasons for the out-of-sync is that the hard disk has been used for a period of time.

    CentOS 6 can use the partx command to synchronize the partition table in memory with the hard disk.

    Syntax : partx option disk

[root@CentOS6 ~]#partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5

    Options :

-a: Extra partition

-d --nr NM: reduce partitions

     CentOS 7 can be synced using the partprobe command.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324825822&siteId=291194637