1、磁碟存儲 磁碟分區主流2種: MBR最大分區不超過2T,1塊硬碟最多4個主分區,也可以3(主)+1(擴展下N個邏輯分區);GPT支持128個分區,全是主分區; 2、創建磁碟: 查看磁碟分區表信息 [root@localhost ~]#hexdump -C -n 512 /dev/sdb 0000 ...
1、磁碟存儲 磁碟分區主流2種: MBR最大分區不超過2T,1塊硬碟最多4個主分區,也可以3(主)+1(擴展下N個邏輯分區);GPT支持128個分區,全是主分區; 2、創建磁碟: 查看磁碟分區表信息 [root@localhost ~]#hexdump -C -n 512 /dev/sdb 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000200 1.1、MBR或GPT,命令: [root@localhost ~]# parted /dev/sdb mklabel gpt #命令命令最後選擇分區類型GPT或msdos Information: You may need to update /etc/fstab. 2、查詢創建結果: [root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: B49D2C14-D087-486B-8ABF-72D3809D82E3 3、查看當前分區有哪些 [root@localhost ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags:
Number Start End Size File system Name Flags 4、分區:選擇主分區,100M,起始1M,終止101M,primary表示主分區。 [root@localhost ~]#parted /dev/sdb mkpart primary 1 101 [root@localhost ~]#parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags:
Number Start End Size File system Name Flags 1 1049kB 101MB 99.6MB primary 5、查看硬碟分區情況: [root@localhost ~]#lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 100G 0 part / ├─sda3 8:3 0 50G 0 part /data ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP] sdb 8:16 0 10G 0 disk └─sdb1 8:17 0 95M 0 part sdc 8:32 0 5G 0 disk sr0 11:0 1 6.7G 0 rom 6、刪除分區 [root@localhost ~]#parted /dev/sdb rm 1 [root@localhost ~]#lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 100G 0 part / ├─sda3 8:3 0 50G 0 part /data ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP] sdb 8:16 0 10G 0 disk └─sdb2 8:18 0 97M 0 part sdc 8:32 0 5G 0 disk sr0 11:0 1 6.7G 0 rom 7、分區必須是連續的,無法跨越,如第一個分區是1-100M,第二個是101-202M, 如果刪除1-100M,,再重新建立分區,如1-300M,實際是100M 8、刪[root@localhost ~]#dd if=/dev/zero of=/dev/sdb bs=1 count=512 [root@localhost ~]#dd if=/dev/zero of=/dev/sdb bs=1 count=512 512+0 records in 512+0 records out 512 bytes copied, 0.00275154 s, 186 kB/s [root@localhost ~]#fdisk -l /dev/sdb Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes 2.1 fdisk工具創建分區 [root@localhost ~]#fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1). 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 table. Created a new DOS disklabel with disk identifier 0x1de77d65.
Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-20971519, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +5G
CreateCommand (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. d a new partition 1 of type 'Linux' and of size 5 GiB. PS:centos8分區直接w存檔退出, centos7 w存檔退出後,分區同步:partprobe centos6 w存檔退出後,增加分區同步:partx -a /dev/sdb ;刪除分區同步 partx -d --nr 6-8 /dev/sdb (6-8刪除分區編號)(柱面單位,1個柱面:255*63*512=8M) 2.刪除分區 [root@localhost ~]#fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): d Partition number (1,2,5, default 5): 5
Partition 5 has been deleted.
Command (m for help): p Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x1de77d65
Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 10487807 10485760 5G 83 Linux /dev/sdb2 10487808 14682111 4194304 2G 5 Extended
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. PS:分區編號自動遞增,如分區編號是:12345,刪除3,則結果:1234. 分區掛載配置最好寫分區UUID,唯一不變,寫分區號,刪除分區影響掛載配置文件。 PS:刪除擴張分區,直接就刪除邏輯分區 增加分區後,磁碟分區表 [root@localhost ~]#hexdump -C -n 512 /dev/sdb 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000001b0 00 00 00 00 00 00 00 00 65 7d e7 1d 00 00 00 20 |........e}..... | 000001c0 21 00 83 d5 89 8c 00 08 00 00 00 00 a0 00 00 d5 |!...............| 000001d0 8a 8c 05 ea d9 91 00 08 a0 00 00 00 40 00 00 00 |............@...| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.| 00000200
3.修改分區類型 [root@localhost ~]#fdisk /dev/sdb Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT 10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/ 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto 1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep 1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT Hex code (type L to list all codes): 2.2 fdisk分區常見命令: fdisk /dev/sdb 命令參數 p 分區列表 t 更改分區類型 n 創建新分區 d 刪除分區 v 校驗分區 u 轉換單位 w 保存並退出 q 不保存並退出 2.3 gdisk分區工具同等於fdisk分區工具。