LINUX

Comando Fdisk en Linux (administrar particiones)

Fdisk es una utilidad basada en texto que se utiliza en Linux para administrar particiones de disco. Con fdisk puede ver todas las particiones del disco, crear una nueva partición, eliminar una partición del disco duro existente y ver el tamaño de la partición.

Con fdisk se le permite crear un máximo de cuatro particiones primarias y cualquier número de particiones lógicas, según el tamaño del disco. Tenga en cuenta que cualquier partición requiere un tamaño mínimo de 40 MB.

En este tutorial, aprendamos a usar el comando fdisk en Linux con algunos ejemplos.

1) Ver todas las particiones de disco existentes

Antes de crear una nueva partición o modificar una partición existente, es posible que desee ver todas las particiones disponibles en el sistema.

El comando enumerará las particiones de todos los discos duros conectados. Cuando tiene más de un disco en el sistema, la lista de particiones está ordenada por el nombre / dev del dispositivo. Por ejemplo, / dev / sda, / dev / sdb, / dev / sdc, etc.

Usar fdisk -l para ver todas las particiones disponibles de la siguiente manera:

# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 2904 1951866 83 Linux
/dev/sda7 2905 3147 1951866 83 Linux
/dev/sda8 3148 3264 939771 82 Linux swap / Solaris
/dev/sda9 3265 5283 16217586 b W95 FAT32

2) Ver particiones de un disco duro específico

Para ver todas las particiones del disco duro ‘/ dev / sda’, haga lo siguiente.

# fdisk -l /dev/sda

Ver todos los comandos de fdisk usando el comando fdisk m

Utilice el comando fdisk m, para ver todos los comandos fdisk disponibles como se muestra a continuación:

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

3) Eliminar una partición del disco duro

Supongamos que le gusta combinar varias particiones (por ejemplo, / dev / sda6, / dev / sda7 y / dev / sda8) en una sola partición de disco. Para hacer esto, primero debe eliminar todas esas particiones individuales, como se muestra a continuación.

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 2904 1951866 83 Linux
/dev/sda7 2905 3147 1951866 83 Linux
/dev/sda8 3148 3264 939771 82 Linux swap / Solaris
/dev/sda9 3265 5283 16217586 b W95 FAT32

Command (m for help): d
Partition number (1-9): 8

Command (m for help): d
Partition number (1-8): 7

Command (m for help): d
Partition number (1-7): 6

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

4) Crea una nueva partición de disco

Una vez que haya eliminado todas las particiones existentes, puede crear una nueva partición usando todo el espacio disponible como se muestra a continuación.

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (2662-5283, default 2662):
Using default value 2662
Last cylinder, +cylinders or +size{K,M,G} (2662-3264, default 3264):
Using default value 3264
In the above example, fdisk n command is used to create new partition with the specific size. While creating a new partition, it expects following two inputs.
Starting cylinder number of the partition to be create (First cylinder).
Size of the partition (or) the last cylinder number (Last cylinder, +cylinders or +size ).
Please keep in mind that you should issue the fdisk write command (w) after any modifications.
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Una vez creada la partición, formatéela con el comando mkfs como se muestra a continuación.

# mkfs.ext3 /dev/sda7

5) Ver el tamaño de una partición existente

Como se muestra abajo, fdisk -s muestra el tamaño de la partición en bloques.

En el siguiente ejemplo, muestra el tamaño ‘/ dev / sda7’ como 4900 MB.

# fdisk -s /dev/sda7
4843566

6) Alternar el indicador de arranque de una partición

El comando Fdisk muestra el indicador de inicio de cada partición. Cuando desee deshabilitar o habilitar el indicador de arranque en la partición correspondiente, haga lo siguiente.

# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help): a
Partition number (1-7): 5

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help):

Como se vio arriba, el indicador de arranque está deshabilitado en la partición ‘/ dev / sda5’.

7) Arreglar el orden de la tabla de particiones

Cuando elimina una partición lógica y la vuelve a crear, es posible que vea el problema de ‘partición fuera de servicio’. es decir, el mensaje de error «Las entradas de la tabla de particiones no están en el orden del disco».

Por ejemplo, cuando elimina tres particiones lógicas (sda6, sda7 y sda8) y crea una nueva partición, puede esperar que el nombre de la nueva partición sea sda6. Pero, es posible que el sistema haya creado la nueva partición como sda7. Esto se debe a que, después de eliminar las particiones, la partición ‘sda9’ se ha movido como sda6 y el espacio libre se ha movido al final.

Para solucionar este problema de orden de partición y asignar sda6 a la partición recién creada, ejecute el comando experto f Como se muestra abajo.

$ fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 3265 5283 16217586 b W95 FAT32
/dev/sda7 2662 3264 4843566 83 Linux

Partition table entries are not in disk order

Command (m for help): x

Expert command (m for help): f
Done.

Expert command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Una vez que se haya solucionado el orden de la tabla de particiones, ya no recibirá el mensaje de error «Las entradas de la tabla de particiones no están en el orden del disco».

# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

Device Boot Start End Blocks Id System
/dev/sda1 1 1959 15735636 c W95 FAT32 (LBA)
/dev/sda2 1960 5283 26700030 f W95 Ext'd (LBA)
/dev/sda3 5284 6528 10000462+ 7 HPFS/NTFS
/dev/sda4 6529 9729 25712032+ c W95 FAT32 (LBA)
/dev/sda5 * 1960 2661 5638752 83 Linux
/dev/sda6 2662 3264 4843566 83 Linux
/dev/sda7 3265 5283 16217586 b W95 FAT32

Conclusión

En este tutorial, aprendimos cómo usar el comando fdisk en Linux para administrar particiones. Espero que haya disfrutado de la lectura y deje su sugerencia en el cuadro de comentarios a continuación. Nota: No elimine, modifique ni agregue particiones si no sabe lo que está haciendo. Puede terminar perdiendo sus datos. Ten cuidado.

Publicaciones relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Botón volver arriba
Cerrar