磁盘分区20191017
程序员文章站
2022-05-09 11:10:06
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分区工具。