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分区工具。