Um eine Linux ext3/ext4 Partition erfolgreich zu verkleinern, muss die Größe korrekt bestimmt werden. Wie Ihr vorgehen solltet beschreibe ich in dieser Anleitung.
In dieser Anleitung gehe ich von einem Debian System mit ext4 und GPT Partitionstabelle aus. Es sollte jedoch allgemein umsetzbar sein.
Punkt 1: Installation von gdisk (GPT)
Sollte die Systempartition verkleinert werden, startet bitte zuerst ein Linux Recovery/Rescue System. Die Partition darf nicht gemountet sein!
Unter Debian installieren wir zuerst gdisk um GPT Partitionen bearbeiten zu können. Für MBR Partitionen kann dieser Schritt ausgelassen werden.
# apt-get install gdisk
Punkt 2: ext3/ext4 Journal entfernen und FSCK durchführen
Wir lassen uns zuerst die Partitionstabelle ausgeben. Es soll /dev/sda4 auf 45 GB verkleinert werden.
# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.1
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 1167966208 sectors, 556.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9FE452AC-D4A2-4A34-8D5F-74604ABD909D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1167966174
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02
2 4096 1003519 488.0 MiB EF00
3 1003520 17004543 7.6 GiB 8200
4 17004544 1167964159 548.8 GiB 0700
Um das Journal der ext3/ext4 Partition entfernen zu können, führen wir einen Filesystem Check durch.
# e2fsck -f /dev/sda4
e2fsck 1.42 (29-Nov-2011)
/dev/sda4: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (141318017, counted=141188576).
Fix<y>? yes
Free inodes count wrong (35926303, counted=35902923).
Fix<y>? yes
/dev/sda4: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda4: 68149/35971072 files (0.1% non-contiguous), 2681376/143869952 blocks
Nun entfernen wir das Journal und führen noch einmal einen Filesystem Check durch.
# tune2fs -O ^has_journal /dev/sda4
tune2fs 1.42 (29-Nov-2011)
root@ma21959:~# e2fsck -f /dev/sda4
e2fsck 1.42 (29-Nov-2011)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda4: 68149/35971072 files (0.1% non-contiguous), 2648608/143869952 blocks
Punkt 3: Verkleinern von /dev/sda4
Jetzt kann die Partition auf beispielsweise 45 GB verkleinert werden.
ACHTUNG: Achtet bitte darauf, dass die Partition nach dem Verkleinern noch genügend Speicherplatz frei hat. Die Partition darf nicht kleiner werden als sie mit Daten befüllt ist!
# resize2fs /dev/sda4 45G
resize2fs 1.42 (29-Nov-2011)
Resizing the filesystem on /dev/sda4 to 11796480 (4k) blocks.
The filesystem on /dev/sda4 is now 11796480 blocks long.
Punkt 4: Partitionstabelle verkleinern
Wir nutzen wieder gdisk (GPT) oder fdisk (MBR) um die Partition /dev/sda4 zu löschen, und mit der neuen Größe erneut anzulegen. Als Faustregel immer +1 GB dazurechnen!
ACHTUNG: Wenn die Faustregel beachtet wurde, gehen bei diesem Schritt keinerlei Daten verloren!
Öffnet die betroffene Festplatte /dev/sda mit gdisk und listet mit (p) die Tabelle auf. Wir sehen noch 548.8 GB.
# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.1
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/sda: 1167966208 sectors, 556.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9FE452AC-D4A2-4A34-8D5F-74604ABD909D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1167966174
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02
2 4096 1003519 488.0 MiB EF00
3 1003520 17004543 7.6 GiB 8200
4 17004544 1167964159 548.8 GiB 0700
Nun löschen wir Partition 4 mit den Kommandos (d) und (4), gefolgt von der Eingabe-Taste.
Command (? for help): d
Partition number (1-4): 4
Jetzt legen wir Partition 4 (/dev/sda4) mit der korrekten neuen Größe an. Geben (n) – (4) – (ENTER für Default) und (+46G) ein.
Rechnet nach der Faustregel immer mindestens 1 GB zur neuen Größe hinzu!
Command (? for help): n
Partition number (4-128, default 4):
First sector (34-1167966174, default = 17004544) or {+-}size{KMGTP}:
Last sector (17004544-1167966174, default = 1167966174) or {+-}size{KMGTP}: +46G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Wir prüfen die neu angelegte Größe (p) und speichern die Änderung ab (w). Es werden die korrekten 46 GB (45 GB + 1 GB Faustregel) ausgegeben.
Command (? for help): p
Disk /dev/sda: 1167966208 sectors, 556.9 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9FE452AC-D4A2-4A34-8D5F-74604ABD909D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1167966174
Partitions will be aligned on 2048-sector boundaries
Total free space is 1054494653 sectors (502.8 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02
2 4096 1003519 488.0 MiB EF00
3 1003520 17004543 7.6 GiB 8200
4 17004544 113473535 46.0 GiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT).
The operation has completed successfully.
Punkt 5: Inhalt prüfen und Journal aktivieren
Nun prüfen wir ob unsere Daten alle noch vorhanden sind.
# mount /dev/sda4 /mnt
# ls -lah /mnt/
total 480K
drwxr-xr-x 24 root root 4.0K Mar 7 09:48 .
drwxrwxrwt 28 root root 240 Mar 7 09:43 ..
-rw------- 1 root root 8.0K Mar 6 11:08 aquota.user
drwxr-xr-x 2 root root 4.0K Mar 6 11:08 bin
drwxr-xr-x 2 root root 4.0K Mar 6 10:37 boot
drwxr-xr-x 3 root root 4.0K Mar 6 10:37 dev
drwxr-xr-x 90 root root 4.0K Mar 7 09:35 etc
drwxr-xr-x 2 root root 4.0K Jan 28 10:53 home
lrwxrwxrwx 1 root root 30 Mar 6 10:38 initrd.img -> /boot/initrd.img-3.2.0-4-amd64
drwxr-xr-x 16 root root 4.0K Mar 6 11:08 lib
drwxr-xr-x 2 root root 4.0K Mar 6 10:37 lib64
drwx------ 2 root root 16K Mar 6 10:37 lost+found
drwxr-xr-x 2 root root 4.0K Mar 6 10:37 media
drwxr-xr-x 2 root root 4.0K Jan 28 10:53 mnt
drwxr-xr-x 2 root root 4.0K Mar 6 10:37 opt
drwxr-xr-x 2 root root 4.0K Jan 28 10:53 proc
drwx------ 5 root root 4.0K Mar 6 14:20 root
drwxr-xr-x 2 root root 4.0K Mar 6 10:41 run
drwxr-xr-x 2 root root 4.0K Mar 6 11:08 sbin
drwxr-xr-x 2 root root 4.0K Jun 10 2012 selinux
drwxr-xr-x 2 root root 4.0K Mar 6 10:37 srv
drwxr-xr-x 2 root root 4.0K Jul 14 2013 sys
drwxrwxrwt 5 root root 4.0K Mar 7 09:23 tmp
drwxr-xr-x 12 root root 4.0K Mar 6 11:08 usr
drwxr-xr-x 12 root root 4.0K Mar 6 11:03 var
lrwxrwxrwx 1 root root 26 Mar 6 10:38 vmlinuz -> boot/vmlinuz-3.2.0-4-amd64
Jetzt kann das Journal aktiviert werden und zur Sicherheit noch einmal das Dateisystem geprüft werden.
# umount /mnt/
# tune2fs -j /dev/sda4
tune2fs 1.42 (29-Nov-2011)
Creating journal inode: done
# e2fsck -f /dev/sda4
e2fsck 1.42 (29-Nov-2011)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda4: 68149/2949120 files (1.6% non-contiguous), 604352/11796480 blocks
Das Recovery/Rescue kann beendet werden, das System sollte normal starten und es ist genügend Speicherplatz frei für z.B: verschiedene LVM Devices.
Das Betreiben der Dienste, Webseite und Server machen wir gerne, kostet aber leider auch Geld.Unterstütze unsere Arbeit mit einer Spende. |
