fdisk

Используя fdisk, можно создать новый раздел, удалить или изменить существующий раздел, сменить его тип. При помощи этой утилиты вы можете создать максимум четыре первичных раздела, и любое количество логических разделов, в зависимости от размера диска.

Основная таблица разделов MBR может содержать не более 4 первичных разделов, поэтому был изобретён Расширенный раздел (англ. extended partition). Это первичный раздел, который не содержит собственной файловой системы, а содержит другие логические разделы. Количество логических разделов ограничено только размером диска.

lsblk – вывод доступных блочных устройств (дисков)

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 12.3G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 11.3G 0 part
  ├─centos-root 253:0 0 10G 0 lvm /
  └─centos-swap 253:1 0 1.2G 0 lvm [SWAP]
sdb 8:16 0 8G 0 disk
sr0 11:0 1 1024M 0 rom

Новый диск sdb, разобьем его на три раздела партиции (по 100, 110 и 200 мегабайт)

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): +100M
Partition 1 of type Linux and of size 100 MiB is set

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (206848-16777215, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-16777215, default 16777215): +110M
Partition 2 of type Linux and of size 110 MiB is set

Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (432128-16777215, default 432128):
Using default value 432128
Last sector, +sectors or +size{K,M,G} (432128-16777215, default 16777215): +200M
Partition 3 of type Linux and of size 200 MiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.

Calling ioctl() to re-read partition table.
Syncing disks.
[root@cen758 /]#

Сменим тип раздела, например, на втором на swap

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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-3, default 3): 2

Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 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: 0x675b982b

Device Boot Start End Blocks Id System
/dev/sdb1 2048 206847 102400 83 Linux
/dev/sdb2 206848 432127 112640 82 Linux swap / Solaris
/dev/sdb3 432128 841727 204800 83 Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.

Удалим 1-й раздел

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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-3, default 3): 1
Partition 1 is deleted

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

Calling ioctl() to re-read partition table.
Syncing disks.

[root@cen758 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 12.3G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 11.3G 0 part
  ├─centos-root 253:0 0 10G 0 lvm /
  └─centos-swap 253:1 0 1.2G 0 lvm [SWAP]
sdb 8:16 0 8G 0 disk
├─sdb2 8:18 0 110M 0 part
└─sdb3 8:19 0 200M 0 part
sr0 11:0 1 1024M 0 rom

Перечитать таблицу

# partprobe
image_pdfimage_print

Leave a Reply

Your email address will not be published. Required fields are marked *