Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Nächste Überarbeitung | Vorherige Überarbeitung | ||
admin_grundlagen:partitionierung [2010/07/08 14:56] 127.0.0.1 Externe Bearbeitung |
admin_grundlagen:partitionierung [2024/05/21 06:59] (aktuell) ingo_wichmann |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== Partitionstabelle sichern und wiederherstellen ====== | + | ====== Blockdevices anzeigen ====== |
- | ==== sfdisk ==== | + | lsblk |
- | === sichern === | + | |
- | sfdisk -d /dev/sda > part-table.txt | + | |
- | === 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 ==== | + | ====== Partitionierung ====== |
- | === sichern === | + | ===== Format der Partitionstabelle ===== |
- | parted /dev/sda print > partitionierung.txt | + | Das lange unter Linux gebräuchliche MSDOS oder [[wpde>Master Boot Record|MBR]] Format kann man nur bei Festplatten unter 2TB verwenden. Für größere Datenträger, oder 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. |
- | === wiederherstellen === | + | |
- | Leere Partitionstabelle erstellen: | + | |
- | parted /dev/sda mklabel | + | |
- | msdos | + | |
- | oder | + | |
- | gpt | + | |
- | Partitionierung [[partitionierung#beispielneue_partition_anlegen| von Hand anlegen]] | + | |
- | ==== ==== | + | Tools: |
+ | * fdisk - MBR und GPT Partitionstabellen | ||
+ | * gdisk - Spezialist für GPT Partitionstabellen | ||
+ | * parted - MBR und GPT Partitionstabellen | ||
- | ====== Partitionierung ====== | + | ===== Beispiel: neue Partition anlegen ===== |
- | ===== fdisk ===== | + | ==== mit fdisk ==== |
- | ==== Benötigte Pakete ==== | + | === Benötigte Pakete === |
- | Debian: | + | * Debian: ''util-linux'' |
- | util-linux | + | |
=== Wichtige fdisk Befehle === | === Wichtige fdisk Befehle === | ||
| m | Hilfe | | | m | Hilfe | | ||
Zeile 44: | Zeile 24: | ||
| q | fdisk verlassen ohne zu speichern | | | q | fdisk verlassen ohne zu speichern | | ||
- | ==== Beispiel: neue Partition anlegen ==== | + | === Partition erstellen === |
- | 2100 MByte große Partition auf Festplatte ''/dev/sda'' anlegen: | + | 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]]).// |
- | + | ||
- | ( Vorgabe einfach mit Enter bestätigen ) | + | |
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: |
partprobe | partprobe | ||
- | oder | + | ((oder |
- | blockdev --rereadpt /dev/diskname | + | blockdev --rereadpt /dev/sda |
- | Neue Kerneltabelle prüfen: | + | )) |
- | cat /proc/partitions | + | |
- | ===== Mit parted ===== | + | ==== Mit parted ==== |
- | ==== Benötigte Pakete ==== | + | === Benötigte Pakete === |
- | Debian: | + | * Debian: ''parted'' |
- | parted | + | |
=== Wichtige parted Befehle === | === Wichtige parted Befehle === | ||
Zeile 82: | Zeile 61: | ||
| quit | fdisk verlassen ohne zu speichern | | | quit | fdisk verlassen ohne zu speichern | | ||
- | ==== 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 94: | Zeile 73: | ||
ext3 | ext3 | ||
Start? | Start? | ||
- | 16500 | + | xxx |
End? | End? | ||
- | 19077 | + | xxx |
Parted verlassen: | Parted verlassen: | ||
quit | quit | ||
- | ==== Beispiel: Partition im laufenden Betrieb anlegen ==== | + | ====== Partitionstabelle sichern und wiederherstellen ====== |
- | Partition anlegen: | + | ==== sfdisk ==== |
- | parted /dev/sda | + | === sichern === |
- | + | sfdisk -d /dev/sda > part-table.txt | |
- | mkpart | + | === wiederherstellen === |
+ | sfdisk /dev/sda < part-table.txt | ||
+ | |||
+ | ==== sgdisk ==== | ||
+ | nur für GPT Partitionen | ||
+ | === sichern === | ||
+ | sgdisk --backup=sda.gpt.bkup /dev/sda | ||
+ | === 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 entgü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 | ||
- | ====== einfache Performance Tests ====== | + | === formatieren === |
- | hdparm -t -T /dev/sda | + | Partitionen aus der Image-Datei im System sichtbar machen: |
+ | losetup --show -f -P /srv/vmdisk1.img | ||
+ | |||
+ | Swap-Partition formatieren: | ||
+ | mkswap /dev/loop0p1 | ||
- | <file> | + | System/Datenpartition mit XFS für VM mit 2 vCPUs formatieren: |
- | /dev/sda: | + | mkfs.xfs -d agcount=2 /dev/loop0p2 |
- | Timing cached reads: 2900 MB in 2.00 seconds = 1448.77 MB/sec | + | |
- | Timing buffered disk reads: 82 MB in 3.13 seconds = 26.22 MB/sec | + | |
- | </file> | + | |
- | ====== Zusätzlichen Swap-Speicher in einer Datei anlegen ====== | + | ==== CentOS 7 ins Image installieren ==== |
- | Datei mit 500 MByte Größe anlegen: | + | yumdownloader centos-release.x86_64 |
- | dd if=/dev/zero of=/var/tmp/swap bs=1M count=500 | + | rpm -ihv --nodeps --root /mnt/loop centos-release-7-*.rpm |
- | Datei als swap formatieren: | + | install -b --suffix=.orig /etc/yum.repos.d/CentOS-Base.repo /mnt/loop/etc/yum.repos.d/CentOS-Base.repo |
- | mkswap /var/tmp/swap | + | yum -y --nogpg --releasever=7 --installroot=/mnt/loop install grub2 iproute tmux passwd procps-ng systemd yum |
- | Swap Datei einbinden: | + | grub2-install --root-directory=./ /dev/loop0 |
- | swapon /var/tmp/swap | + | |
- | Überprüfen: | + | |
- | free -m | + | |
- | swapon -s | + | |
- | ====== Dokumentation ====== | + | |
- | ===== swap ===== | + | TODO: formatieren, vergrößern |
- | * http://www.thomashertweck.de/linuxram.html | + | |