Skip to content

Commit 6c648f4

Browse files
Docker-VM: Add Disk Size choice (#4241)
* Add Disk Size Choice to Advanced * Add Disk Size Choice to Advanced
1 parent 9f88b1b commit 6c648f4

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

vm/docker-vm.sh

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Copyright (c) 2021-2025 community-scripts ORG
4-
# Author: thost96 (thost96)
4+
# Author: thost96 (thost96) | Co-Author: michelroegl-brunner
55
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
66

77
source /dev/stdin <<<$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
@@ -26,7 +26,7 @@ METHOD=""
2626
NSAPP="debian12vm"
2727
var_os="debian"
2828
var_version="12"
29-
DISK_SIZE="8G"
29+
DISK_SIZE="4G"
3030

3131
YW=$(echo "\033[33m")
3232
BL=$(echo "\033[36m")
@@ -57,19 +57,19 @@ function error_handler() {
5757
}
5858

5959
function cleanup_vmid() {
60-
if qm status $VMID &>/dev/null; then
61-
qm stop $VMID &>/dev/null
62-
qm destroy $VMID &>/dev/null
60+
if qm status "$VMID" &>/dev/null; then
61+
qm stop "$VMID" &>/dev/null
62+
qm destroy "$VMID" &>/dev/null
6363
fi
6464
}
6565

6666
function cleanup() {
6767
popd >/dev/null
68-
rm -rf $TEMP_DIR
68+
rm -rf "$TEMP_DIR"
6969
}
7070

7171
TEMP_DIR=$(mktemp -d)
72-
pushd $TEMP_DIR >/dev/null
72+
pushd "$TEMP_DIR" >/dev/null
7373
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "Docker VM" --yesno "This will create a New Docker VM. Proceed?" 10 58; then
7474
:
7575
else
@@ -146,6 +146,7 @@ function default_settings() {
146146
FORMAT=",efitype=4m"
147147
MACHINE=""
148148
DISK_CACHE=""
149+
DISK_SIZE="4G"
149150
HN="docker"
150151
CPU_TYPE=""
151152
CORE_COUNT="2"
@@ -159,6 +160,7 @@ function default_settings() {
159160
echo -e "${DGN}Using Virtual Machine ID: ${BGN}${VMID}${CL}"
160161
echo -e "${DGN}Using Machine Type: ${BGN}i440fx${CL}"
161162
echo -e "${DGN}Using Disk Cache: ${BGN}None${CL}"
163+
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}$DISK_SIZE${CL}"
162164
echo -e "${DGN}Using Hostname: ${BGN}${HN}${CL}"
163165
echo -e "${DGN}Using CPU Model: ${BGN}KVM64${CL}"
164166
echo -e "${DGN}Allocated Cores: ${BGN}${CORE_COUNT}${CL}"
@@ -174,7 +176,7 @@ function default_settings() {
174176
function advanced_settings() {
175177
METHOD="advanced"
176178
while true; do
177-
if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
179+
if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
178180
if [ -z "$VMID" ]; then
179181
VMID="$NEXTID"
180182
fi
@@ -194,7 +196,7 @@ function advanced_settings() {
194196
"i440fx" "Machine i440fx" ON \
195197
"q35" "Machine q35" OFF \
196198
3>&1 1>&2 2>&3); then
197-
if [ $MACH = q35 ]; then
199+
if [ "$MACH" = q35 ]; then
198200
echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}"
199201
FORMAT=""
200202
MACHINE=" -machine q35"
@@ -207,11 +209,26 @@ function advanced_settings() {
207209
exit-script
208210
fi
209211

212+
if DISK_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Disk Size in GiB (e.g., 10, 20)" 8 58 "$DISK_SIZE" --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
213+
DISK_SIZE=$(echo "$DISK_SIZE" | tr -d ' ')
214+
if [[ "$DISK_SIZE" =~ ^[0-9]+$ ]]; then
215+
DISK_SIZE="${DISK_SIZE}G"
216+
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}$DISK_SIZE${CL}"
217+
elif [[ "$DISK_SIZE" =~ ^[0-9]+G$ ]]; then
218+
echo -e "${DISKSIZE}${BOLD}${DGN}Disk Size: ${BGN}$DISK_SIZE${CL}"
219+
else
220+
echo -e "${DISKSIZE}${BOLD}${RD}Invalid Disk Size. Please use a number (e.g., 10 or 10G).${CL}"
221+
exit-script
222+
fi
223+
else
224+
exit-script
225+
fi
226+
210227
if DISK_CACHE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISK CACHE" --radiolist "Choose" --cancel-button Exit-Script 10 58 2 \
211228
"0" "None (Default)" ON \
212229
"1" "Write Through" OFF \
213230
3>&1 1>&2 2>&3); then
214-
if [ $DISK_CACHE = "1" ]; then
231+
if [ "$DISK_CACHE" = "1" ]; then
215232
echo -e "${DGN}Using Disk Cache: ${BGN}Write Through${CL}"
216233
DISK_CACHE="cache=writethrough,"
217234
else
@@ -223,11 +240,11 @@ function advanced_settings() {
223240
fi
224241

225242
if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 docker --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
226-
if [ -z $VM_NAME ]; then
243+
if [ -z "$VM_NAME" ]; then
227244
HN="docker"
228245
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
229246
else
230-
HN=$(echo ${VM_NAME,,} | tr -d ' ')
247+
HN=$(echo "${VM_NAME,,}" | tr -d ' ')
231248
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
232249
fi
233250
else
@@ -238,7 +255,7 @@ function advanced_settings() {
238255
"0" "KVM64 (Default)" ON \
239256
"1" "Host" OFF \
240257
3>&1 1>&2 2>&3); then
241-
if [ $CPU_TYPE1 = "1" ]; then
258+
if [ "$CPU_TYPE1" = "1" ]; then
242259
echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}"
243260
CPU_TYPE=" -cpu host"
244261
else
@@ -250,7 +267,7 @@ function advanced_settings() {
250267
fi
251268

252269
if CORE_COUNT=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 2 --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
253-
if [ -z $CORE_COUNT ]; then
270+
if [ -z "$CORE_COUNT" ]; then
254271
CORE_COUNT="2"
255272
echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
256273
else
@@ -261,7 +278,7 @@ function advanced_settings() {
261278
fi
262279

263280
if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 4096 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
264-
if [ -z $RAM_SIZE ]; then
281+
if [ -z "$RAM_SIZE" ]; then
265282
RAM_SIZE="4096"
266283
echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
267284
else
@@ -272,7 +289,7 @@ function advanced_settings() {
272289
fi
273290

274291
if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
275-
if [ -z $BRG ]; then
292+
if [ -z "$BRG" ]; then
276293
BRG="vmbr0"
277294
echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
278295
else
@@ -282,8 +299,8 @@ function advanced_settings() {
282299
exit-script
283300
fi
284301

285-
if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address" 8 58 $GEN_MAC --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
286-
if [ -z $MAC1 ]; then
302+
if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address" 8 58 "$GEN_MAC" --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
303+
if [ -z "$MAC1" ]; then
287304
MAC="$GEN_MAC"
288305
echo -e "${DGN}Using MAC Address: ${BGN}$MAC${CL}"
289306
else
@@ -295,7 +312,7 @@ function advanced_settings() {
295312
fi
296313

297314
if VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
298-
if [ -z $VLAN1 ]; then
315+
if [ -z "$VLAN1" ]; then
299316
VLAN1="Default"
300317
VLAN=""
301318
echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
@@ -308,7 +325,7 @@ function advanced_settings() {
308325
fi
309326

310327
if MTU1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then
311-
if [ -z $MTU1 ]; then
328+
if [ -z "$MTU1" ]; then
312329
MTU1="Default"
313330
MTU=""
314331
echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
@@ -358,9 +375,9 @@ post_to_api_vm
358375

359376
msg_info "Validating Storage"
360377
while read -r line; do
361-
TAG=$(echo $line | awk '{print $1}')
362-
TYPE=$(echo $line | awk '{printf "%-10s", $2}')
363-
FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}')
378+
TAG=$(echo "$line" | awk '{print $1}')
379+
TYPE=$(echo "$line" | awk '{printf "%-10s", $2}')
380+
FREE=$(echo "$line" | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}')
364381
ITEM=" Type: $TYPE Free: $FREE "
365382
OFFSET=2
366383
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
@@ -390,10 +407,10 @@ sleep 2
390407
msg_ok "${CL}${BL}${URL}${CL}"
391408
curl -f#SL -o "$(basename "$URL")" "$URL"
392409
echo -en "\e[1A\e[0K"
393-
FILE=$(basename $URL)
410+
FILE=$(basename "$URL")
394411
msg_ok "Downloaded ${CL}${BL}${FILE}${CL}"
395412

396-
STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}')
413+
STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}')
397414
case $STORAGE_TYPE in
398415
nfs | dir)
399416
DISK_EXT=".qcow2"
@@ -411,8 +428,8 @@ btrfs)
411428
esac
412429
for i in {0,1}; do
413430
disk="DISK$i"
414-
eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-}
415-
eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk}
431+
eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"""${DISK_EXT:-"}"
432+
eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"""${!disk"}"
416433
done
417434
418435
msg_info "Installing Pre-Requisite libguestfs-tools onto Host"
@@ -435,10 +452,9 @@ pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
435452
qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
436453
qm set $VMID \
437454
-efidisk0 ${DISK0_REF}${FORMAT} \
438-
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=2G \
455+
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \
439456
-boot order=scsi0 \
440457
-serial0 socket >/dev/null
441-
qm resize $VMID scsi0 8G >/dev/null
442458
qm set $VMID --agent enabled=1 >/dev/null
443459
444460
DESCRIPTION=$(
@@ -473,6 +489,14 @@ EOF
473489
)
474490
qm set "$VMID" -description "$DESCRIPTION" >/dev/null
475491
492+
if [ -n "$DISK_SIZE" ]; then
493+
msg_info "Resizing disk to $DISK_SIZE GB"
494+
qm resize $VMID scsi0 ${DISK_SIZE} >/dev/null
495+
else
496+
msg_info "Using default disk size of $DEFAULT_DISK_SIZE GB"
497+
qm resize $VMID scsi0 ${DEFAULT_DISK_SIZE} >/dev/null
498+
fi
499+
476500
msg_ok "Created a Docker VM ${CL}${BL}(${HN})"
477501
if [ "$START_VM" == "yes" ]; then
478502
msg_info "Starting Docker VM"

0 commit comments

Comments
 (0)