Recientemente, debido a las necesidades del trabajo, se ha estudiado inicialmente la implementación de fastboot en uboot. Estudiar fastboot inevitablemente requiere conocimiento sobre la partición del disco.Bajo Linux, puede usar el comando fdisk para realizar la partición del disco. Bien, vayamos al grano.
1. Ver información de ayuda (fdisk --help)
linux@linux-System-Product-Name:~$ fdisk --help
Usage:
fdisk [options] <disk> change partition table
fdisk [options] -l [<disk>] list partition table(s)
Display or manipulate a disk partition table.
Options:
-b, --sector-size <size> physical and logical sector size
-B, --protect-boot don't erase bootbits when creating a new label
-c, --compatibility[=<mode>] mode is 'dos' or 'nondos' (default)
-L, --color[=<when>] colorize output (auto, always or never)
colors are enabled by default
-l, --list display partitions and exit
-o, --output <list> output columns
-t, --type <type> recognize specified partition table type only
......
2. Ver particiones de disco
Puede ver la partición detallada del disco a través del comando sudo fdisk -l
, como se muestra a continuación, actualmente hay dos discos en mi computadora: sda y sdb (donde sda es un disco duro de estado sólido de 240G, que es el disco del sistema y sdb es una tarjeta SD de disco de estado sólido de 16G).
linux@linux-System-Product-Name:~$ sudo fdisk -l
[sudo] password for linux:
Disk /dev/sda: 232.9 GiB, 250059350016 bytes, 488397168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: DE19ADF1-DDE6-4899-BC1B-C6B608AD5C31
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 488396799 487346176 232.4G Linux filesystem
Disk /dev/sdb: 14.6 GiB, 15646851072 bytes, 30560256 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: 0x9b9208de
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
linux@linux-System-Product-Name:~$
Tomando sdb como ejemplo, la descripción detallada es la siguiente:
- La capacidad del disco es de 14,6 GiB, un total de 15646851072 bytes, y el tamaño de cada "sector" es de 512 bytes, un total de 30560256 sectores;
- Tamaño del sector (físico/lógico): 512 bytes/512 bytes
- Tamaño de E/S (mín./típ.): 512 bytes/512 bytes
- Tipo de etiqueta de disco: dos (el tipo de etiqueta de disco de sda es gpt)
- Identificador de disco: 0x9b9208de
- El disco se divide en una "partición", el nombre de la partición es sdb1, el número de sector inicial de la partición es 2048, el número de sector final es 2099199, un total de 2097152 sectores (sector), el tamaño es 1GiB y la partición ID es 0x83 (partición nativa de Linux), el tipo es Linux
3. Partición de disco
Ejemplos de requisitos:
- Divida el disco sdb en 4 áreas, de las cuales 1, 2 y 3 son las particiones principales y 4 es la partición extendida;
- El tamaño de la partición 1 es de 512 MB, el tamaño de la partición 2 es de 2 GB, el tamaño de la partición 3 es de 4 GB y el tamaño de la partición 4 es el espacio restante en el disco;
- Crear una tabla de particiones tipo DOS (MBR)
Paso 1 : Ejecute el comando sudo fdisk /dev/sdb
, ingrese m
para obtener información de ayuda, de la siguiente manera:
linux@linux-System-Product-Name:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help):
Paso 2 : ingrese p
para ver la tabla de particiones actual del disco
Command (m for help): p
Disk /dev/sdb: 14.6 GiB, 15646851072 bytes, 30560256 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: 0x9b9208de
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
El disco actual está dividido en una "partición", el nombre de la partición es sdb1, el número de sector inicial de esta partición es 2048, el número de sector final es 2099199, un total de 2097152 sectores (sectores), el tamaño es 1GiB y el el ID de la partición es 0x83 (partición nativa de Linux), el tipo es Linux
Paso 3 : ingrese o
, cree una nueva tabla de partición GPT
Command (m for help): o
Created a new DOS disklabel with disk identifier 0x6ade9f76.
The old dos signature will be removed by a write command.
Paso 4 : ingrese n
, agregue una nueva partición (agregue nuestra primera partición con un tamaño de 512M)
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-30560255, default 2048): // 直接按“回车”即可
Last sector, +sectors or +size{
K,M,G,T,P} (2048-30560255, default 30560255): +512M // 分配的空间大小为512M
Created a new partition 1 of type 'Linux' and of size 512 MiB.
Command (m for help): p // 查询分区表
Disk /dev/sdb: 14.6 GiB, 15646851072 bytes, 30560256 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: 0x6ade9f76
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 1050623 1048576 512M 83 Linux
Paso 5 : Ingrese n
, agregue 2, 3, 4 particiones a su vez
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): // 创建第2个分区
First sector (1050624-30560255, default 1050624):
Last sector, +sectors or +size{
K,M,G,T,P} (1050624-30560255, default 30560255): +2G // 分区大小为2G
Created a new partition 2 of type 'Linux' and of size 2 GiB.
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): // 创建第3个分区
First sector (5244928-30560255, default 5244928):
Last sector, +sectors or +size{
K,M,G,T,P} (5244928-30560255, default 30560255): +4G // 分区大小为4G
Created a new partition 3 of type 'Linux' and of size 4 GiB.
Command (m for help): n
Partition type
p primary (3 primary, 0 extended, 1 free)
e extended (container for logical partitions)
Select (default e): e // 创建扩展分区
Selected partition 4 // 创建第3个分区,MBR最多只能创建4个分区
First sector (13633536-30560255, default 13633536):
Last sector, +sectors or +size{
K,M,G,T,P} (13633536-30560255, default 30560255):
Created a new partition 4 of type 'Extended' and of size 8.1 GiB. // 分区大小为“磁盘剩余空间”
Command (m for help): p
Disk /dev/sdb: 14.6 GiB, 15646851072 bytes, 30560256 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: 0x6ade9f76
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 1050623 1048576 512M 83 Linux
/dev/sdb2 1050624 5244927 4194304 2G 83 Linux
/dev/sdb3 5244928 13633535 8388608 4G 83 Linux
/dev/sdb4 13633536 30560255 16926720 8.1G 5 Extended
Paso 6 : Ingrese w
, escriba la tabla de particiones en el disco y la partición del disco estará completa.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
linux@linux-System-Product-Name:~$ // 退出了磁盘的命令模式
Paso 7 : Confirme nuevamente si la "tabla de particiones del disco" está realmente escrita en el disco
linux@linux-System-Product-Name:~$ sudo fdisk /dev/sdb
[sudo] password for linux:
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sdb: 14.6 GiB, 15646851072 bytes, 30560256 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: 0x6ade9f76
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 1050623 1048576 512M 83 Linux
/dev/sdb2 1050624 5244927 4194304 2G 83 Linux
/dev/sdb3 5244928 13633535 8388608 4G 83 Linux
/dev/sdb4 13633536 30560255 16926720 8.1G 5 Extended
Command (m for help):
Como arriba, es consistente con nuestra expectativa, y la partición del disco es exitosa.
4. Otros comandos
Primero ejecuta el comando:
sudo fdisk /dev/sdb
4.1 Cambiar el tipo de partición
Cambie el tipo de partición 1 de "Linux" a "W95 FAT32 (LBA)".