VM – Root LVM vergrößern

Um einen Root Partition auf einem VM zu vergrößern, müssen wir erstmal den Logical Volume auf dem Host vergrößern. Man kann den Befehl ausführen während der VM Läuft bzw. Logical Volume eingehängt ist.

lvextend -L +10G /dev/vgroup/VM2

somit erhöhen wir den Logical Volume VM2 um 10GB mehr, nach dem wir den LV auf dem Host vergrößert haben, müssen wir die Partition Table innerhalb die VM neu lesen oder die VM runterfahren dann nochmal neu starten.

jetzt innerhalb der VM kann man mit Hilfe von fdsik die partition vergrößern oder bzw. mit VNC und gparted.

hier werden wir die Partition mit fdisk innerhalb der VM vergrößern:

root@gitlab ~ # fdisk /dev/vda 

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2,5, default 5): 

Partition 5 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 

Partition 2 has been deleted.

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000c2678



Command (m for help): n
Partition type
 p primary (0 primary, 0 extended, 4 free)
 e extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-62914559, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-62914559, default 62914559): +29,1G

Created a new partition 1 of type 'Linux' and of size 29,1 GiB.

Command (m for help): p
Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000c2678

Device Boot Start End Sectors Size Id Type
/dev/vda1 2048 61024255 61022208 29,1G 83 Linux


Command (m for help): n
Partition type
 p primary (1 primary, 0 extended, 3 free)
 e extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 
First sector (61024256-62914559, default 61024256): 
Last sector, +sectors or +size{K,M,G,T,P} (61024256-62914559, default 62914559): 

Created a new partition 2 of type 'Extended' and of size 923 MiB.

Command (m for help): p
Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000c2678

Device Boot Start End Sectors Size Id Type
/dev/vda1 2048 61024255 61022208 29,1G 83 Linux
/dev/vda2 61024256 62914559 1890304 923M 5 Extended


Command (m for help): n
Partition type
 p primary (1 primary, 1 extended, 2 free)
 l logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (81997824-83886079, default 81997824): 
Last sector, +sectors or +size{K,M,G,T,P} (81997824-83886079, default 83886079): 

Created a new partition 5 of type 'Linux' and of size 922 MiB.

Command (m for help): p
Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000c2678

Device Boot Start End Sectors Size Id Type
/dev/vda1 2048 61024255 61022208 29,1G 83 Linux
/dev/vda2 61024256 62914559 1890304 923M 5 Extended
/dev/vda5 61026304 62869503 1843200 900M 83 Linux

Command (m for help): t
Partition number (1,2,5, default 5): 
Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): p
Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000c2678

Device Boot Start End Sectors Size Id Type
/dev/vda1 2048 61024255 61022208 29,1G 83 Linux
/dev/vda2 61024256 62914559 1890304 923M 5 Extended
/dev/vda5 61026304 62869503 1843200 900M 82 Linux swap / Solaris

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Das Gerät oder die Ressource ist belegt

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

VM neu starten. Jetzt müssen wir noch das Filesystem Ändern:

resize2fs /dev/vda1 

und [nochmals VM neu starten,] fertig.

Leave a Reply

Your email address will not be published. Required fields are marked *

Default top bar text