Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
lpi1:partitionierung [2018/07/09 09:48] 127.0.0.1 Externe Bearbeitung |
lpi1:partitionierung [2022/03/18 00:44] |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== Blockdevices anzeigen ====== | ||
- | lsblk | ||
- | |||
- | ===== Kernel Partitionsliste aktualisieren ===== | ||
- | Nach Änderungen an einem Boot-Datenträger. (Im Paket parted) | ||
- | partprobe | ||
- | ====== Format der Partitionstabelle ====== | ||
- | 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. | ||
- | |||
- | ====== Übung: default-Werte für Mount-Optionen herausfinden ====== | ||
- | Test-Image erstellen und mounten: | ||
- | dd if=/dev/zero of=/tmp/zero.img bs=1M count=500 | ||
- | mkfs.ext4 /tmp/zero.img | ||
- | mkdir /mnt/img | ||
- | mount /tmp/zero.img /mnt/img | ||
- | |||
- | ''exec'': | ||
- | cp -a /usr/bin/tail /mnt/img | ||
- | Ist ''/mnt/img/tail'' ausführbar? | ||
- | |||
- | ''suid'': | ||
- | chmod u+s /mnt/img/tail | ||
- | Als Nutzer: | ||
- | /mnt/img/tail /etc/shadow | ||
- | Ist das SUID-Bit wirksam? | ||
- | |||
- | ''dev'': | ||
- | 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: ''qemu-img'' | ||
- | * Debian 8: ''qemu-utils'' | ||
- | * openSUSE 42.2: ''qemu-tools'' | ||
- | |||
- | ===== 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]] Swap-Partition anlegen: | ||
- | mkpart linux-swap 1MiB 100MiB | ||
- | |||
- | Daten-Partition anlegen: | ||
- | mkpart ext4 100MiB 100% | ||
- | |||
- | ''parted'' verlassen: | ||
- | quit | ||
- | |||
- | === 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 --root /mnt/loop -ihv 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 systemd passwd yum procps-ng iproute tmux grub | ||
- | grub2-install --root-directory=./ /dev/loop0 | ||
- | |||
- | | ||
- | TODO: formatieren, vergrößern | ||
- | |||
- | ====== Partitionstabelle sichern und wiederherstellen ====== | ||
- | ==== sfdisk ==== | ||
- | für MBR-partitionierte Blockgeräte | ||
- | === sichern === | ||
- | sfdisk -d /dev/sda > part-table.txt | ||
- | === wiederherstellen === | ||
- | sfdisk /dev/sda < part-table.txt | ||
- | |||
- | ==== sgdisk ==== | ||
- | 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 | ||
- | |||
- | Leere Partitionstabelle erstellen: | ||
- | parted /dev/sda mklabel | ||
- | msdos | ||
- | oder | ||
- | gpt | ||
- | Partitionierung [[partitionierung#beispielneue_partition_anlegen| von Hand anlegen]] | ||
- | |||
- | ====== Partitionierung ====== | ||
- | ===== fdisk/gdisk ===== | ||
- | fdisk - ausschließlich MBR-Partitionierte Blockgeräte\\ | ||
- | gdisk - GPT Blockgeräte | ||
- | ==== Benötigte Pakete ==== | ||
- | Debian: | ||
- | util-linux | ||
- | === Wichtige fdisk Befehle === | ||
- | | m | Hilfe | | ||
- | | d | Partition löschen | | ||
- | | n | neue Partition erstellen | | ||
- | | t | Typ der Partition setzen | | ||
- | | p | Partitionstabelle anzeigen | | ||
- | | w | geänderte Partitionstabelle speichern | | ||
- | | q | fdisk verlassen ohne zu speichern | | ||
- | |||
- | ==== Beispiel: neue Partition anlegen ==== | ||
- | 2100 MByte große Partition auf Festplatte ''/dev/sda'' anlegen: | ||
- | fdisk /dev/sda | ||
- | Neue Partition erstellen: | ||
- | n | ||
- | Partition als logische Partition erstellen: | ||
- | l | ||
- | 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 virtuellen Maschinen kann man hier auch 0 angeben.// | ||
- | |||
- | Größe angeben: | ||
- | +2100M | ||
- | geänderte Partitionstabelle speichern: | ||
- | w | ||
- | Alte Kerneltabelle ansehen: | ||
- | cat /proc/partitions | ||
- | Kernel Partitionstabelle neu einlesen lassen: | ||
- | partprobe | ||
- | ((oder | ||
- | blockdev --rereadpt /dev/sda | ||
- | )) | ||
- | |||
- | Neue Kerneltabelle prüfen: | ||
- | cat /proc/partitions | ||
- | |||
- | ===== Mit parted ===== | ||
- | ==== Benötigte Pakete ==== | ||
- | Debian: | ||
- | parted | ||
- | |||
- | === Wichtige parted Befehle === | ||
- | | help | Hilfe | | ||
- | | rm | Partition löschen | | ||
- | | mklabel | neue Partitionstabelle erstellen | | ||
- | | mkpart | neue Partition erstellen | | ||
- | | set | Typ der Partition setzen | | ||
- | | print | Partitionstabelle anzeigen | | ||
- | | quit | fdisk verlassen ohne zu speichern | | ||
- | |||
- | ==== Beispiel: neue Partition anlegen ==== | ||
- | 2100 MByte große Partition auf Festplatte ''/dev/sda'' anlegen: | ||
- | parted /dev/sda | ||
- | Aktuelle Partitionierung ausgeben: | ||
- | |||
- | Neue Partition erstellen: | ||
- | mkpart | ||
- | Partition type? primary/logical? | ||
- | l | ||
- | File system type? | ||
- | ext3 | ||
- | Start? | ||
- | 16500 | ||
- | End? | ||
- | 19077 | ||
- | Parted verlassen: | ||
- | quit | ||
- | |||
- | === Fehlermeldung: The resulting partition is not properly aligned for best performance === | ||
- | Lösung: http://support.hp.com/us-en/document/c03479326 | ||
- | |||
- | ==== Beispiel: Partition im laufenden Betrieb anlegen ==== | ||
- | Partition anlegen: | ||
- | parted /dev/sda | ||
- | |||
- | mkpart | ||
- | 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 | ||
- | |||