Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
|
admin_grundlagen:partitionierung [2017/01/25 11:21] ingo_wichmann |
admin_grundlagen:partitionierung [2025/09/27 06:22] (aktuell) ingo_wichmann [Format der Partitionstabelle] |
||
|---|---|---|---|
| Zeile 2: | Zeile 2: | ||
| lsblk | lsblk | ||
| - | ====== Format der Partitionstabelle ====== | + | ====== Partitionierung ====== |
| - | Das lange unter Linux gebräuchliche MSDOS oder [[wpde>Master Boot Record|MBR]] Format sollte man nur bei Festplatten unter 2TB verwenden. Für größere Festplatten, und wenn man wie bei aktuellen Rechnern üblich eine [[wpde>Unified Extensible Firmware Interface|UEFI]] Firmware an Stelle des [[wpde>BIOS]] vorfindet, sollte man für die Partitionstabelle [[wpde>GUID Partition Table|GPT]] verwenden. | + | ===== Format der Partitionstabelle ===== |
| + | Das lange unter Linux gebräuchliche [[wpde>Master Boot Record|MSDOS oder MBR]] Format kann man nur bei Festplatten unter 2TB verwenden. Es ist komplizierter zu benutzen(( zumindest wenn man mehr als 4 Partitionen anlegen will)). Wenn man (wie bei aktuellen Rechnern üblich) eine [[wpde>Unified Extensible Firmware Interface|UEFI]] Firmware an Stelle des [[wpde>BIOS]] vorfindet, muss man zum Booten [[wpde>GUID Partition Table|GPT]] verwenden. Labels sind nützlich, wenn man mehrere Festplatten eingebaut hat - die gibt es nicht bei MBR Partitionen. | ||
| - | ====== Partitionstabelle sichern und wiederherstellen ====== | + | Tools: |
| - | ==== sfdisk ==== | + | * ''fdisk'' - MBR und GPT Partitionstabellen |
| - | === sichern (nur MBR) === | + | * ''gdisk'' - Spezialist für GPT Partitionstabellen |
| - | sfdisk -d /dev/sda > part-table.txt | + | * ''parted'' - MBR und GPT Partitionstabellen |
| - | === wiederherstellen === | + | |
| - | sfdisk /dev/sda < part-table.txt | + | |
| - | ==== dd ==== | + | |
| - | geht nur bei identischer Festplatte | + | |
| - | === sichern === | + | |
| - | dd if=/dev/sda of=part-table.img bs=1 count=512 | + | |
| - | === wiederherstellen === | + | |
| - | dd if=part-table.img of=/dev/sda bs=1 count=64 skip=446 seek=446 | + | |
| - | ==== fdisk ==== | + | |
| - | === sichern === | + | |
| - | fdisk -l > partitionierung.txt | + | |
| - | === wiederherstellen === | + | |
| - | geht nur von Hand | + | |
| - | ==== parted ==== | + | ===== Beispiel: neue Partition anlegen ===== |
| - | === sichern === | + | ==== mit gdisk ==== |
| - | parted /dev/sda print > partitionierung.txt | + | ++++ Wichtige gdisk Befehle | |
| - | === wiederherstellen === | + | | ? | Hilfe | |
| - | geht nur von Hand | + | | d | Partition löschen | |
| + | | n | neue Partition erstellen | | ||
| + | | t | Typ der Partition setzen | | ||
| + | | c | Name/Label der Partition setzen | | ||
| + | | p | Partitionstabelle anzeigen | | ||
| + | | w | geänderte Partitionstabelle speichern | | ||
| + | | q | gdisk verlassen ohne zu speichern | | ||
| + | ++++ | ||
| + | === Benötigte Pakete === | ||
| + | * Debian: ''gdisk'' | ||
| - | Leere Partitionstabelle erstellen: | + | === Partition erstellen === |
| - | parted /dev/sda mklabel | + | [[wpde>Byte#Vergleich|2 Gigibyte]] große Partition auf Festplatte ''/dev/sda'' anlegen: |
| - | msdos | + | gdisk /dev/sda |
| - | oder | + | Aktuelle Partitionstabelle anzeigen: |
| - | gpt | + | p |
| - | Partitionierung [[partitionierung#beispielneue_partition_anlegen| von Hand anlegen]] | + | Neue Partition erstellen: |
| + | n | ||
| + | Startblock auswählen: //Bei der ersten Partition sollte hier Sektor 2048 oder ein Vielfaches davon stehen// | ||
| - | ====== Partitionierung ====== | + | Größe angeben: |
| - | ===== fdisk ===== | + | +2G |
| - | ==== Benötigte Pakete ==== | + | Label ändern: |
| - | Debian: | + | c |
| - | util-linux | + | Name eingeben: ((Wenn in dem Computer viele Festplatten eingebaut sind, dann wird man wahrscheinlich nur eine Partition anlegen und den Platz mit [[LVM]], [[RAID]], [[lpi2:btrfs]] oder [[ZFS]] verwalten. Dann ist ein Namensschema nützlich, z.B. f/b für Front/Back,r0 für Reihe 0 von oben und c0 für Spalte 0 von links)) |
| - | === Wichtige fdisk Befehle === | + | fr0c0 |
| + | geänderte Partitionstabelle speichern: | ||
| + | w | ||
| + | |||
| + | === Prüfen, ob der Kernel die geänderte Partitionstabelle kennt == | ||
| + | cat /proc/partitions | ||
| + | Wenn nicht, Kernel Partitionstabelle neu einlesen lassen: | ||
| + | blockdev --rereadpt /dev/sda | ||
| + | ((oder | ||
| + | partprobe | ||
| + | )) | ||
| + | ==== mit fdisk ==== | ||
| + | ++++ Wichtige fdisk Befehle | | ||
| | m | Hilfe | | | m | Hilfe | | ||
| | d | Partition löschen | | | d | Partition löschen | | ||
| Zeile 49: | Zeile 60: | ||
| | w | geänderte Partitionstabelle speichern | | | w | geänderte Partitionstabelle speichern | | ||
| | q | fdisk verlassen ohne zu speichern | | | q | fdisk verlassen ohne zu speichern | | ||
| - | + | ++++ | |
| - | ==== Beispiel: neue Partition anlegen ==== | + | === Benötigte Pakete === |
| - | 2100 MByte große Partition auf Festplatte ''/dev/sda'' anlegen: | + | * Debian: ''util-linux'' |
| + | === Partition erstellen === | ||
| + | [[wpde>Byte#Vergleich|2 Gigibyte]] große Partition auf Festplatte ''/dev/sda'' anlegen: | ||
| fdisk /dev/sda | fdisk /dev/sda | ||
| + | Aktuelle Partitionstabelle anzeigen: | ||
| + | p | ||
| Neue Partition erstellen: | Neue Partition erstellen: | ||
| n | n | ||
| - | Partition als logische Partition erstellen: | + | Partition als logische Partition erstellen (//nur bei MSDOS/MBR//): |
| l | l | ||
| - | Startblock auswählen: | + | Startblock auswählen: //Bei der ersten Partition sollte hier Sektor 2048 oder ein Vielfaches davon stehen. Wenn die Sektorgröße 512 Bytes ist, dann liegt der Partitionsbeginn bei 1048576 Bytes ([[wpde>Mebibyte|=1 MiB]]).// |
| - | + | ||
| - | //Bei der ersten Partition sollte hier Sektor 2048 oder ein Vielfaches davon stehen. Wenn die Sektorgröße 512 Bytes ist, dann liegt der Partitionsbeginn bei 1048576 Bytes ([[wpde>Mebibyte|=1 MiB]]). Bei virtuellen Maschinen kann man hier auch 0 angeben.// | + | |
| Größe angeben: | Größe angeben: | ||
| - | +2100M | + | +2G |
| geänderte Partitionstabelle speichern: | geänderte Partitionstabelle speichern: | ||
| w | w | ||
| - | Alte Kerneltabelle ansehen: | + | |
| + | === Prüfen, ob der Kernel die geänderte Partitionstabelle kennt == | ||
| cat /proc/partitions | cat /proc/partitions | ||
| - | Kernel Partitionstabelle neu einlesen lassen: | + | Wenn nicht, Kernel Partitionstabelle neu einlesen lassen: |
| + | blockdev --rereadpt /dev/sda | ||
| + | ((oder | ||
| partprobe | partprobe | ||
| - | ((oder | ||
| - | blockdev --rereadpt /dev/sda | ||
| )) | )) | ||
| - | Neue Kerneltabelle prüfen: | + | ==== mit parted ==== |
| - | cat /proc/partitions | + | ++++ Wichtige parted Befehle | |
| - | + | ||
| - | ===== Mit parted ===== | + | |
| - | ==== Benötigte Pakete ==== | + | |
| - | Debian: | + | |
| - | parted | + | |
| - | + | ||
| - | === Wichtige parted Befehle === | + | |
| | help | Hilfe | | | help | Hilfe | | ||
| | rm | Partition löschen | | | rm | Partition löschen | | ||
| Zeile 89: | Zeile 96: | ||
| | print | Partitionstabelle anzeigen | | | print | Partitionstabelle anzeigen | | ||
| | quit | fdisk verlassen ohne zu speichern | | | quit | fdisk verlassen ohne zu speichern | | ||
| + | ++++ | ||
| + | === Benötigte Pakete === | ||
| + | * Debian: ''parted'' | ||
| - | ==== Beispiel: neue Partition anlegen ==== | + | === Partition erstellen === |
| - | 2100 MByte große Partition auf Festplatte ''/dev/sda'' anlegen: | + | 2 Gibibyte große Partition auf Festplatte ''/dev/sda'' anlegen: |
| parted /dev/sda | parted /dev/sda | ||
| Aktuelle Partitionierung ausgeben: | Aktuelle Partitionierung ausgeben: | ||
| Zeile 102: | Zeile 112: | ||
| ext3 | ext3 | ||
| Start? | Start? | ||
| - | 16500 | + | xxx |
| End? | End? | ||
| - | 19077 | + | xxx |
| Parted verlassen: | Parted verlassen: | ||
| quit | quit | ||
| - | === Fehlermeldung: The resulting partition is not properly aligned for best performance === | + | ====== Partitionstabelle sichern und wiederherstellen ====== |
| - | Lösung: http://support.hp.com/us-en/document/c03479326 | + | ==== sfdisk ==== |
| + | === sichern === | ||
| + | sfdisk -d /dev/sda > part-table.txt | ||
| + | === wiederherstellen === | ||
| + | sfdisk /dev/sda < part-table.txt | ||
| - | ==== Beispiel: Partition im laufenden Betrieb anlegen ==== | + | ==== sgdisk ==== |
| - | Partition anlegen: | + | nur für GPT Partitionen |
| - | parted /dev/sda | + | === sichern === |
| - | + | sgdisk --backup=sda.gpt.bkup /dev/sda | |
| - | mkpart | + | === wiederherstellen === |
| + | sgdisk --load-backup=sda.gpt.bkup /dev/sda | ||
| + | |||
| + | ==== dd ==== | ||
| + | geht nur bei identischer Festplatte | ||
| + | === sichern === | ||
| + | dd if=/dev/sda of=part-table.img bs=1 count=512 | ||
| + | === wiederherstellen === | ||
| + | dd if=part-table.img of=/dev/sda bs=1 count=64 skip=446 seek=446 | ||
| + | |||
| + | ==== fdisk ==== | ||
| + | === sichern === | ||
| + | fdisk -l > partitionierung.txt | ||
| + | === wiederherstellen === | ||
| + | geht nur von Hand | ||
| + | |||
| + | ==== gdisk ==== | ||
| + | === sichern === | ||
| + | gdisk -l > partitionierung.txt | ||
| + | === wiederherstellen === | ||
| + | geht nur von Hand | ||
| + | |||
| + | ==== parted ==== | ||
| + | === sichern === | ||
| + | parted /dev/sda print > partitionierung.txt | ||
| + | === wiederherstellen === | ||
| + | geht nur von Hand | ||
| + | |||
| + | ====== Übung: default-Werte für mount-Optionen herausfinden ====== | ||
| + | Test-Image erstellen und mounten: | ||
| + | fallocate -l 500M /tmp/zero.img | ||
| + | (( | ||
| + | oder | ||
| + | dd if=/dev/zero of=/tmp/zero.img bs=1M seek=500 count=0 | ||
| + | oder | ||
| + | dd if=/dev/zero of=/tmp/zero.img bs=1M 500 | ||
| + | )) | ||
| + | mkfs.ext4 /tmp/zero.img | ||
| + | mkdir /mnt/img | ||
| + | mount /tmp/zero.img /mnt/img | ||
| + | |||
| + | === Ist die mount-Option suid aktiv? === | ||
| + | cp -a /usr/bin/tail /mnt/img | ||
| + | chmod u+s /mnt/img/tail | ||
| + | Als Nutzer: | ||
| + | /mnt/img/tail /etc/shadow | ||
| + | Ist das SUID-Bit wirksam? | ||
| + | |||
| + | === Ist die mount-Option exec aktiv? === | ||
| + | cp -a /usr/bin/tail /mnt/img | ||
| + | /mnt/img/tail /etc/passwd | ||
| + | Ist ''/mnt/img/tail'' ausführbar? | ||
| + | |||
| + | === Ist die mount-Option dev aktiv? === | ||
| + | mknod /mnt/img/sda b 8 0 | ||
| + | fdisk -l /mnt/img/sda | ||
| + | Ist der Zugriff auf das Device ''/mnt/img/sda'' möglich? | ||
| + | |||
| + | ====== Übung: virtuelle Festplatte partitionieren ====== | ||
| + | Erstellen einer virtuellen Festplatte und vorbereiten für den Einsatz in einer VM | ||
| + | |||
| + | Pakete installieren: | ||
| + | * CentOS 7: ''parted qemu-img'' | ||
| + | * Debian 8: ''parted qemu-utils'' | ||
| + | * openSUSE 42.2: ''parted qemu-tools'' | ||
| + | |||
| + | ===== Beispiel: Loop-Devices mit Sparse-Files ===== | ||
| + | Nicht in der Praxis ;-) | ||
| + | |||
| + | == Sparse-File erzeugen == | ||
| + | dd if=/dev/zero of=disc1 bs=1K count=0 seek=200M | ||
| + | ls -lsh disc* | ||
| + | losetup -f disc1 --show | ||
| + | losetup -a | ||
| + | |||
| + | == Loop-Devices partitionieren == | ||
| + | lsblk | ||
| + | {fdisk,gdisk,parted} /dev/loopxx | ||
| + | |||
| + | == Partitionen sichtbar machen == | ||
| + | partprobe | ||
| + | partprobe /dev/loopxx | ||
| + | |||
| + | ===== Beispiel: GPT mit parted ===== | ||
| + | |||
| + | Virtuelle Festplatte erstellen: | ||
| + | qemu-img create /srv/vmdisk1.img 2G | ||
| + | |||
| + | === Partitionieren: === | ||
| + | parted /srv/vmdisk1.img | ||
| + | |||
| + | GPT-Partitionstabelle anlegen: (In der ''parted'' Kommandozeile) | ||
| + | mklabel gpt | ||
| + | |||
| + | [[wpde>Mebibyte|100 MiB - 1MiB]] (parted arbeitet mit festen Endwerten) Swap-Partition anlegen: | ||
| + | mkpart linux-swap 1MiB 100MiB | ||
| + | |||
| + | Daten-Partition anlegen: | ||
| + | mkpart ext4 100MiB 100% | ||
| + | |||
| + | GRUB BIOS Partition aktivieren: | ||
| + | set 1 bios_grub on | ||
| + | |||
| + | ''parted'' verlassen: | ||
| quit | quit | ||
| - | Mountpoint anlegen und temporär mounten | ||
| - | mkfs.ext3 /dev/sda6 | ||
| - | mkdir /mnt/sda6 | ||
| - | mount /dev/sda6 /mnt/sda6 | ||
| - | Daten in die neue Partition kopieren: | ||
| - | cp -a /usr/bin/. /mnt/sda6 | ||
| - | Kopie überprüfen: | ||
| - | ( cd /usr/bin; tar c . ) | ( cd /mnt/sda6; tar d . ) | ||
| - | Partition wieder aushängen | ||
| - | umount /mnt/sda6 | ||
| - | Partition endgültig mounten: | ||
| - | mount /dev/sda6 /usr/bin | ||
| - | tail -n 1 /etc/mtab >> /etc/fstab | ||
| - | Daten auf Orginalpartition löschen: | ||
| - | mkdir /mnt/original | ||
| - | mount --bind / /mnt/original | ||
| - | shopt -s dotglob | ||
| - | rm /mnt/original/usr/bin/* | ||
| - | ls -la /mnt/original/usr/bin | ||
| - | umount /mnt/original | ||
| + | === formatieren === | ||
| + | Partitionen aus der Image-Datei im System sichtbar machen: | ||
| + | losetup --show -f -P /srv/vmdisk1.img | ||
| + | |||
| + | Swap-Partition formatieren: | ||
| + | mkswap /dev/loop0p1 | ||
| + | |||
| + | System/Datenpartition mit XFS für VM mit 2 vCPUs formatieren: | ||
| + | mkfs.xfs -d agcount=2 /dev/loop0p2 | ||
| + | |||
| + | ==== CentOS 7 ins Image installieren ==== | ||
| + | yumdownloader centos-release.x86_64 | ||
| + | rpm -ihv --nodeps --root /mnt/loop centos-release-7-*.rpm | ||
| + | install -b --suffix=.orig /etc/yum.repos.d/CentOS-Base.repo /mnt/loop/etc/yum.repos.d/CentOS-Base.repo | ||
| + | yum -y --nogpg --releasever=7 --installroot=/mnt/loop install grub2 iproute tmux passwd procps-ng systemd yum | ||
| + | grub2-install --root-directory=./ /dev/loop0 | ||
| + | |||
| + | | ||
| + | TODO: formatieren, vergrößern | ||