Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

fdisk

Create, delete and change partitions on MBR and GPT disks with a menu.

Niveau
RHCSA-examen
Groep
Schijven en bestandssystemen
Root nodig
Ja
Pakket
util-linux

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

fdisk DEVICE opens a menu. Changes are kept in memory until you press w (write); q quits without saving. fdisk -l lists the partition tables of disks.

It handles both MBR (DOS) and GPT tables: o creates a new MBR table, g a new GPT table. After writing, the kernel normally reads the new table; if the disk is in use, run partprobe.

Zo schrijf je het

fdisk [OPTION]... DEVICE
fdisk -l [DEVICE]...

Belangrijkste delen

m
Help.
p
Print the partition table.
n
New partition.
d
Delete a partition.
t
Change the partition type (alias like swap, lvm, linux, raid, uefi).
l
List known types.
o / g
Create a new empty MBR / GPT table.
a
Toggle the bootable flag (MBR).
x
Expert menu.
v
Verify the table.
i
Information about a partition.
F
Show free space.
w
Write the table and quit.
q
Quit without saving.

Opties 17

Meest gebruikt

-l, --list
List the partition tables and exit.
-x, --list-details
List with more details.
-o, --output LIST
Columns for -l.
-t, --type TYPE
Only recognize this table type (dos, gpt …).
-w, --wipe auto|never|always
Wipe old file system signatures from the disk.
-W, --wipe-partitions auto|never|always
Wipe signatures from new partitions.
-n, --noauto-pt
Do not create a default table on an empty disk.
-B, --protect-boot
Do not wipe the first sector with a new table.
-b, --sector-size SIZE
Sector size (512, 1024, 2048, 4096).
-u, --units[=cylinders|sectors]
Units for the table.
-c, --compatibility[=dos|nondos]
DOS compatibility mode.
-C, --cylinders N, -H, --heads N, -S, --sectors N
Old geometry settings.
-s, --getsz
Print the size in 512-byte sectors (old).
-L, --color[=WHEN]
Colors.
--lock[=MODE]
Lock the device while working.
-h, --help
Show help.
-V, --version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1List the partition tables

    fdisk -l /dev/vdb
    Disk /dev/vdb: 10 GiB, 10737418240 bytes, 20971520 sectors
    Disklabel type: gpt

    Check the disk before changing it.

  2. 2Create a GPT table and a partition

    fdisk /dev/vdb
    Command (m for help): g
    Command (m for help): n
    Partition number (1-128, default 1): <Enter>
    First sector (2048-20971486, default 2048): <Enter>
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971486, default 20969471): +2G
    Command (m for help): w

    Sizes like +2G are GiB.

  3. 3MBR primary partition

    fdisk /dev/vdc
    Command (m for help): o
    Command (m for help): n
    Select (default p): p
    Command (m for help): w

    MBR: up to 4 primary partitions.

  4. 4Change the type to swap or LVM

    fdisk /dev/vdb
    Command (m for help): t
    Partition number (1-3, default 3): 2
    Partition type or alias (type L to list all): lvm

    Aliases: linux, swap, lvm, raid, uefi.

  5. 5Delete a partition

    fdisk /dev/vdb
    Command (m for help): d
    Partition number (1-3, default 3): 3

    Nothing changes on disk until w.

  6. 6Show free space

    fdisk /dev/vdb
    Command (m for help): F

    Where new partitions can go.

  7. 7Script a partition (no menu)

    printf 'g\nn\n\n\n+1G\nw\n' | fdisk /dev/vdb

    For labs; for real scripts prefer parted -s or sfdisk.

  8. 8Make the kernel read the new table

    partprobe /dev/vdb; lsblk /dev/vdb

    Needed when the disk was in use.

  9. 9Back up and restore a partition table

    sfdisk -d /dev/vdb > /root/vdb-table.txt
    sfdisk /dev/vdb < /root/vdb-table.txt

    sfdisk is the script companion of fdisk.

  10. 10Check details of all disks

    fdisk -x

    Shows UUIDs and attributes of GPT partitions.

Let op

  • Double check the device name. w on the wrong disk can destroy a system.
  • Deleting a partition does not wipe data, but the file system becomes unreachable.

Exitcodes

0 :: Done. 1 :: Error.