GNU/Linux >> LINUX-Kenntnisse >  >> Linux

Fdisk-Befehl in Linux (Partitionen verwalten)

Fdisk ist ein textbasiertes Dienstprogramm, das in Linux zum Verwalten von Festplattenpartitionen verwendet wird. Mit fdisk können Sie alle Festplattenpartitionen anzeigen, eine neue Partition erstellen, eine vorhandene Festplattenpartition löschen und die Größe der Partition anzeigen.

Mit fdisk können Sie maximal vier primäre Partitionen und je nach Größe der Festplatte eine beliebige Anzahl logischer Partitionen erstellen. Beachten Sie, dass jede einzelne Partition eine Mindestgröße von 40 MB benötigt.

Lassen Sie uns in diesem Tutorial anhand einiger Beispiele lernen, wie der Befehl fdisk unter Linux verwendet wird.

1) Alle vorhandenen Festplattenpartitionen anzeigen

Bevor Sie eine neue Partition erstellen oder eine vorhandene Partition ändern, möchten Sie vielleicht alle verfügbaren Partitionen im System anzeigen.

Der Befehl listet Partitionen von allen angeschlossenen Festplatten auf. Wenn Sie mehr als eine Festplatte im System haben, ist die Partitionsliste nach dem /dev-Namen des Geräts geordnet. Zum Beispiel /dev/sda, /dev/sdb, /dev/sdc und so weiter.

Verwenden Sie fdisk -l um alle verfügbaren Partitionen wie folgt anzuzeigen:

# 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) Partitionen einer bestimmten Festplatte anzeigen

Gehen Sie wie folgt vor, um alle Partitionen der Festplatte „/dev/sda“ anzuzeigen.

# fdisk -l /dev/sda

Alle fdisk-Befehle mit dem fdisk-Befehl m

anzeigen

Verwenden Sie den fdisk-Befehl m , um alle verfügbaren fdisk-Befehle wie unten gezeigt anzuzeigen:

# 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) Löschen Sie eine Festplattenpartition

Nehmen wir an, Sie möchten mehrere Partitionen (z. B. /dev/sda6, /dev/sda7 und /dev/sda8) zu einer einzigen Festplattenpartition zusammenfassen. Dazu sollten Sie zunächst alle diese einzelnen Partitionen löschen, wie unten gezeigt.

# 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) Erstellen Sie eine neue Festplattenpartition

Sobald Sie alle vorhandenen Partitionen gelöscht haben, können Sie eine neue Partition erstellen, die den gesamten verfügbaren Speicherplatz wie unten gezeigt verwendet.

# 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.

Nachdem die Partition erstellt wurde, formatieren Sie sie mit dem mkfs-Befehl wie unten gezeigt.

# mkfs.ext3 /dev/sda7

5) Anzeigen der Größe einer vorhandenen Partition

Wie unten gezeigt, fdisk -s zeigt die Größe der Partition in Blöcken an.

Im folgenden Beispiel wird die Größe „/dev/sda7“ mit 4900 MB angezeigt.

# fdisk -s /dev/sda7
4843566

6) Schaltet das Boot-Flag einer Partition um

Der Befehl Fdisk zeigt das Boot-Flag jeder Partition an. Wenn Sie das Boot-Flag auf der entsprechenden Partition deaktivieren oder aktivieren möchten, gehen Sie wie folgt vor.

# 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):

Wie oben zu sehen, ist das Boot-Flag auf der Partition „/dev/sda5“ deaktiviert.

7) Reihenfolge der Partitionstabellen korrigieren

Wenn Sie eine logische Partition löschen und erneut erstellen, wird möglicherweise das Problem „Partition außer Betrieb“ angezeigt. d.h. Fehlermeldung 'Partitionstabelleneinträge sind nicht in Festplattenreihenfolge'.

Wenn Sie beispielsweise drei logische Partitionen (sda6, sda7 und sda8) löschen und eine neue Partition erstellen, erwarten Sie möglicherweise, dass der neue Partitionsname sda6 lautet. Möglicherweise hat das System die neue Partition jedoch als sda7 erstellt. Dies liegt daran, dass nach dem Löschen der Partitionen die Partition 'sda9' als sda6 verschoben wurde und der freie Speicherplatz an das Ende verschoben wurde.

Um dieses Problem mit der Partitionsreihenfolge zu beheben und der neu erstellten Partition sda6 zuzuweisen, führen Sie den Expertenbefehl f aus wie unten gezeigt.

$ 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.

Sobald die Reihenfolge der Partitionstabelle festgelegt ist, erhalten Sie die Fehlermeldung „Die Einträge der Partitionstabelle sind nicht in der Festplattenreihenfolge“ nicht mehr.

# 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

Schlussfolgerung

In diesem Tutorial haben wir gelernt, wie man den Befehl fdisk in Linux verwendet, um Partitionen zu verwalten. Ich hoffe, Sie hatten Spaß beim Lesen und hinterlassen Sie bitte Ihren Vorschlag im Kommentarfeld unten. Hinweis:Löschen, ändern oder fügen Sie keine Partition hinzu, wenn Sie nicht wissen, was Sie tun. Sie können am Ende Ihre Daten verlieren. Seien Sie vorsichtig.


Linux
  1. So partitionieren Sie eine Festplatte unter Linux

  2. So löschen Sie eine Partition unter Linux

  3. So erstellen Sie Partitionen unter Linux

  4. So sichern oder klonen Sie Linux-Partitionen mit dem Befehl „cat“.

  5. So verwenden Sie fdisk zum Partitionieren einer Festplatte unter Linux

So listen Sie Festplattenpartitionen unter Linux auf

So erstellen und verwalten Sie Linux-Partitionen mit Parted

So erstellen Sie Festplattenpartitionen unter Linux

15 Linux sfdisk-Befehlsbeispiele zum Verwalten von Festplattenpartitionen

So zeigen Sie Linux-Festplattenpartitionen an (Partitionstabelle)

fdisk-Befehlsbeispiele unter Linux