Ubuntu系统分区信息查看:fdisk /dev/vda
1
2
3
4
5
6
7
8
9
10
11Command (m for help): p
Disk /dev/vda: 60 GiB, 64424509440 bytes, 125829120 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: 0x630fdccb
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 1953791 1951744 953M 83 Linux
/dev/vda2 1953792 125829119 123875328 59.1G 83 Linux
Sart、End、Sectors单位都是扇区, 1扇区=512bytes,那么2扇区就是1KB 通常称为一个block块,那么就有了2sectors=1KB=1 block
,可以通过blockdev --getsz /dev/vda
得到整块盘扇区数像上面1953791-2048+1=1951744
扇,953M=1951744/2/1024KB
CentOS差别可能就是 Blocks数显示,上面说了1Block=1KB1
2
3
4
5
6
7
8
9
10Disk /dev/vda: 64.4 GB, 64424509440 bytes, 125829120 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
Disk label type: dos
Disk identifier: 0x000afe6d
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 4196351 2097152 83 Linux
/dev/vda2 4196352 125829119 60816384 83 Linux
我来验证一下1
4196351-2048+1得到扇区数,(4196351-2048+1)/2=2097152刚好等于Blocks数,也就是2097152KB=2048MB=2GB
我们再来学习下dd命令1
2
3
4bs参数代表逻辑块大小,默认单位是扇区,bs=512代表一个扇区,也就是512bytes
count参数代表逻辑块的个数或扇区数,那么处理的存储大小就是bs*count
skip 表示跳过if 设备的扇区数开始读数据,skip=200代表200个扇区,也就是100KB
seek表示跳过of设备的扇区数开始写数据,seek=400代表400个扇区,也就是200KB
那么学了这些有什么用呢?
一个裸盘有硬件raid卡信息是不能正常被格式化的,这个raid信息会存在硬盘的最后63个扇区的地方,我们可以用dd复盖掉1
2snumber=$(($(blockdev --getsz /dev/sda)-63))
dd if=/dev/zero of=/dev/sda bs=512 count=63 seek=$snumber
总结:
- 一个扇区512bytes , 1Block=1KB=2扇区
- dd参数的skip针对if设备,seek针对of设备(跳过多少扇区再处理)