diff --git a/LICENSE b/LICENSE index 2071b23..b3ade84 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) +Copyright (c) 2023 | Patrick Asmus - ScriptOS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/Linux_Containers_logo.svg b/Linux_Containers_logo.svg new file mode 100644 index 0000000..0e8e118 --- /dev/null +++ b/Linux_Containers_logo.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 7a06fa3..438ab73 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,75 @@ -# proxmox-lxc-size-changer +# Größe der LXC Container mit einem Script ändern + +![Linux_Containers_logo.svg](Linux_Containers_logo.svg?raw=true "Linux_Containers_logo.svg") + +Das Skript `proxmox-lxc-size-changer.v1.sh` ermöglicht die Änderung der Größe eines LXC-Containers auf die gewünschte Gesamtgröße der Container-Disk. Das Skript kann verwendet werden, um die Größe der Disk eines LXC-Containers anzupassen. + +## Anwendungsbeschreibung +Um das Skript zu verwenden, folgen Sie den nachstehenden Schritten: + +1. Laden Sie das Skript `proxmox-lxc-size-changer.v1.sh` auf dem Proxmox-Server herunter. +2. Öffnen Sie die Bash-Shell auf dem Proxmox-Server und navigieren Sie zum Speicherort des Skripts. +3. Stellen Sie sicher, dass das Skript ausführbar ist, indem Sie den Befehl `chmod +x proxmox-lxc-size-changer.v1.sh` ausführen. +4. Öffnen Sie das Skript in einem Texteditor und passen Sie die Konfigurationsvariablen an: +- `lxcPath`: Der Storage, in dem der Container gemountet ist (Proxmox-Webinterface -> Rechenzentrum -> Storage) +- `fullLxcPath`: Der Pfad zum LXC-Container im Proxmox-Dateisystem +- `containerID`: Die ID des LXC-Containers, dessen Größe geändert werden soll. +- `diskFilename`: Der Dateiname der Disk des Containers. +- `newSize`: Die gewünschte neue Größe für die Container-Disk. +- `storage`: Der Name des Proxmox-Speichers, in dem das Backup gespeichert wird. +5. Speichern Sie das Skript und schließen Sie den Texteditor. +6. Öffnen Sie eine Bash-Shell und navigieren Sie zum Speicherort des Skripts. +7. Führen Sie den Befehl `bash ./proxmox-lxc-size-changer.v1.sh` aus, um das Skript auszuführen. +8. Das Skript stoppt den Container, erstellt ein Backup, führt eine Dateisystemprüfung durch, passt die Größe der Disk an, passt die Konfiguration an und startet den Container wieder. + +Hinweis: Stellen Sie sicher, dass Sie über die erforderlichen Berechtigungen und Kenntnisse verfügen, um die Größe eines LXC-Containers zu ändern. Ausserdem muss im Vorfeld geprüft werden, inwiefern der Container vergrößert oder verkleinert werden kann. (!) + +## Ich übernehme keine Verantwortung für Schäden an Ihrem System! + +So könnte das ganze dann aussehen, wenn das Script erfolgreich gelaufen ist: +```bash +➜ root: bash proxmox-lxc-size-changer.v1.sh +INFO: starting new backup job: vzdump 9100 --notes-template 'Backup vor Größenänderung durch Script' --remove 0 --storage nas02 --mode stop +INFO: Starting Backup of VM 9100 (lxc) +INFO: Backup started at 2023-07-16 17:57:17 +INFO: status = stopped +INFO: backup mode: stop +INFO: ionice priority: 7 +INFO: CT Name: dev-sv01-ubuntu +INFO: including mount point rootfs ('/') in backup +INFO: creating Proxmox Backup Server archive 'ct/9100/2023-07-16T15:57:17Z' +INFO: run: lxc-usernsexec -m u:0:100000:65536 -m g:0:100000:65536 -- /usr/bin/proxmox-backup-client backup --crypt-mode=none pct.conf:/nas/nas02/backup-pool/vhost01/proxmox-backup/tmp_backup/vzdumptmp1248981_9100//etc/vzdump/pct.conf root.pxar:/mnt/vzsnap0 --include-dev /mnt/vzsnap0/./ --skip-lost-and-found --exclude=/tmp/?* --exclude=/var/tmp/?* --exclude=/var/run/?*.pid --backup-type ct --backup-id 9100 --backup-time 1689523037 --repository root@pam!vhost01@192.168.20.122:nas02 +INFO: Starting backup: ct/9100/2023-07-16T15:57:17Z +INFO: Client name: vhost01 +INFO: Starting backup protocol: Sun Jul 16 17:57:18 2023 +INFO: Downloading previous manifest (Sun Jul 16 17:10:15 2023) +INFO: Upload config file '/nas/nas02/tmp_backup/vzdumptmp1248981_9100//etc/vzdump/pct.conf' to 'root@pam!vhost01@192.168.20.122:8007:nas02' as pct.conf.blob +INFO: Upload directory '/mnt/vzsnap0' to 'root@pam!vhost01@192.168.20.122:8007:nas02' as root.pxar.didx +INFO: root.pxar: had to backup 119.804 MiB of 2.704 GiB (compressed 26.377 MiB) in 5.13s +INFO: root.pxar: average backup speed: 23.34 MiB/s +INFO: root.pxar: backup was done incrementally, reused 2.587 GiB (95.7%) +INFO: Uploaded backup catalog (1.726 MiB) +INFO: Duration: 5.25s +INFO: End Time: Sun Jul 16 17:57:23 2023 +INFO: adding notes to backup +INFO: Finished Backup of VM 9100 (00:00:06) +INFO: Backup finished at 2023-07-16 17:57:23 +INFO: Backup job finished successfully +e2fsck 1.46.5 (30-Dec-2021) +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 +/volumes/appdata2/images/9100/vm-9100-disk-0.raw: 84327/786432 files (0.5% non-contiguous), 829602/3145728 blocks +resize2fs 1.46.5 (30-Dec-2021) +Resizing the filesystem on /volumes/appdata2/images/9100/vm-9100-disk-0.raw to 3670016 (4k) blocks. +The filesystem on /volumes/appdata2/images/9100/vm-9100-disk-0.raw is now 3670016 (4k) blocks long. + +➜ root: pct enter 9100 +➜ / df -h +Filesystem Size Used Avail Use% Mounted on +/dev/loop28 14G 2.9G 11G 23% / +... +``` -Ändert bei Bedarf die Größe des LXC Containers. \ No newline at end of file diff --git a/proxmox-lxc-size-changer.v1.sh b/proxmox-lxc-size-changer.v1.sh new file mode 100644 index 0000000..bf96ca3 --- /dev/null +++ b/proxmox-lxc-size-changer.v1.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Script Name: proxmox-lxc-size-changer.v1.sh +# Beschreibung: Ändert die Größe des LXC Containers auf die gewünschte Gesamtgröße der Disk des Containers +# Dies gilt primär erstmal nur für die Disk mit der ID 0 +# Aufruf: bash ./proxmox-lxc-size-changer.v1.sh +# Autor: Patrick Asmus +# Web: https://www.media-techport.de +# Git-Reposit.: https://git.media-techport.de/scriptos/proxmox-lxc-size-changer +# Version: 1.0 +# Datum: 16.07.2023 +# Modifikation: Ersterstellung +##################################################### + +# Variablen +lxcPath="appdata2" +fullLxcPath="/volumes/${lxcPath}" +containerID="9100" +diskFilename="vm-${containerID}-disk-0.raw" +newSize="12G" +storage="nas02" + +# Container stoppen +pct stop $containerID + +# Backup erstellen +vzdump $containerID --remove 0 --mode stop --notes-template 'Backup vor Größenänderung durch Script' --storage $storage + +# Dateisystemprüfung +e2fsck -fy "${fullLxcPath}/images/${containerID}/${diskFilename}" + +# Größe des LXC anpassen +resize2fs "${fullLxcPath}/images/${containerID}/${diskFilename}" $newSize + +# Konfiguration anpassen +configFile="/etc/pve/lxc/${containerID}.conf" +sed -i "s|rootfs: ${lxcPath}:${containerID}/${diskFilename},size=.*|rootfs: ${lxcPath}:${containerID}/${diskFilename},size=${newSize}|" $configFile + +# Container starten +pct start $containerID \ No newline at end of file