Add ARGUMENTS variable

Add ARGUMENTS variable
This commit is contained in:
Kroese 2023-07-03 13:20:55 +02:00 committed by GitHub
commit 74db7b1fb8
3 changed files with 30 additions and 19 deletions

View file

@ -69,6 +69,8 @@ docker run -it --rm -e "BOOT=http://www.example.com/image.iso" --device=/dev/kvm
DISK_SIZE: "256G" DISK_SIZE: "256G"
``` ```
This can also be used to resize the existing disk to a larger capacity without data loss.
* ### How do I change the location of the data disk? * ### How do I change the location of the data disk?
To change the data disk's location from the default Docker volume, include the following bind mount in your compose file: To change the data disk's location from the default Docker volume, include the following bind mount in your compose file:
@ -80,17 +82,6 @@ docker run -it --rm -e "BOOT=http://www.example.com/image.iso" --device=/dev/kvm
Replace the example path `/home/user/data` with the desired storage folder. Replace the example path `/home/user/data` with the desired storage folder.
* ### How do I change the space reserved by the data disk?
By default, the entire disk space is reserved in advance. To create a growable disk that only reserves the space that is actually used, add the following environment variable:
```yaml
environment:
ALLOCATE: "N"
```
Keep in mind that this will not affect any of your existing disks, it only applies to newly created disks.
* ### How do I increase the amount of CPU or RAM? * ### How do I increase the amount of CPU or RAM?
By default, a single core and 512 MB of RAM are allocated to the container. To increase this, add the following environment variables: By default, a single core and 512 MB of RAM are allocated to the container. To increase this, add the following environment variables:
@ -112,6 +103,15 @@ docker run -it --rm -e "BOOT=http://www.example.com/image.iso" --device=/dev/kvm
If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check your BIOS settings. If you receive an error from `kvm-ok` indicating that KVM acceleration can't be used, check your BIOS settings.
* ### How do I provide extra arguments to QEMU?
You can create the `ARGUMENTS` environment variable to provide additional arguments to QEMU at runtime:
```yaml
environment:
ARGUMENTS: "-drive file=/seed.iso,format=raw,if=virtio"
```
* ### How do I assign an individual IP address to the container? * ### How do I assign an individual IP address to the container?
By default, the container uses bridge networking, which shares the IP address with the host. By default, the container uses bridge networking, which shares the IP address with the host.

View file

@ -26,7 +26,9 @@ if [ -f "${DATA}" ]; then
if [[ "${ALLOCATE}" == [Nn]* ]]; then if [[ "${ALLOCATE}" == [Nn]* ]]; then
# Resize file by changing its length # Resize file by changing its length
truncate -s "${DATA_SIZE}" "${DATA}"; if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
error "Could not resize the file for the data disk." && exit 85
fi
else else
@ -42,7 +44,9 @@ if [ -f "${DATA}" ]; then
# Resize file by allocating more space # Resize file by allocating more space
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
error "Could not allocate a file for the data disk." && exit 85 if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
error "Could not resize the file for the data disk." && exit 85
fi
fi fi
if [[ "${ALLOCATE}" == [Zz]* ]]; then if [[ "${ALLOCATE}" == [Zz]* ]]; then
@ -71,7 +75,10 @@ if [ ! -f "${DATA}" ]; then
if [[ "${ALLOCATE}" == [Nn]* ]]; then if [[ "${ALLOCATE}" == [Nn]* ]]; then
# Create an empty file # Create an empty file
truncate -s "${DATA_SIZE}" "${DATA}" if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
rm -f "${DATA}"
error "Could not create a file for the data disk." && exit 87
fi
else else
@ -85,8 +92,10 @@ if [ ! -f "${DATA}" ]; then
# Create an empty file # Create an empty file
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
rm -f "${DATA}" if ! truncate -s "${DATA_SIZE}" "${DATA}"; then
error "Could not allocate a file for the data disk." && exit 87 rm -f "${DATA}"
error "Could not create a file for the data disk." && exit 87
fi
fi fi
if [[ "${ALLOCATE}" == [Zz]* ]]; then if [[ "${ALLOCATE}" == [Zz]* ]]; then

View file

@ -6,6 +6,7 @@ set -Eeuo pipefail
: ${BOOT:=''} # URL of the ISO file : ${BOOT:=''} # URL of the ISO file
: ${DEBUG:='N'} # Enable debug mode : ${DEBUG:='N'} # Enable debug mode
: ${ALLOCATE:='Y'} # Preallocate diskspace : ${ALLOCATE:='Y'} # Preallocate diskspace
: ${ARGUMENTS:=''} # Extra QEMU parameters
: ${CPU_CORES:='1'} # Amount of CPU cores : ${CPU_CORES:='1'} # Amount of CPU cores
: ${DISK_SIZE:='16G'} # Initial data disk size : ${DISK_SIZE:='16G'} # Initial data disk size
: ${RAM_SIZE:='512M'} # Maximum RAM amount : ${RAM_SIZE:='512M'} # Maximum RAM amount
@ -21,6 +22,7 @@ trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
STORAGE="/storage" STORAGE="/storage"
KERNEL=$(uname -r | cut -b 1) KERNEL=$(uname -r | cut -b 1)
MINOR=$(uname -r | cut -d '.' -f2)
ARCH=$(dpkg --print-architecture) ARCH=$(dpkg --print-architecture)
VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1) VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1)
@ -66,7 +68,7 @@ MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
SERIAL_OPTS="-serial mon:stdio -device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3" SERIAL_OPTS="-serial mon:stdio -device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3"
EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0 -object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0" EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0 -object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0"
ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${MAC_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS}" ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${MAC_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS} ${ARGUMENTS}"
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
trap - ERR trap - ERR
@ -79,7 +81,7 @@ set -m
) )
set +m set +m
if (( KERNEL > 4 )); then if (( KERNEL > 5 )) || ( (( KERNEL == 5 )) && (( MINOR > 2 )) ); then
pidwait -F "${_QEMU_PID}" & wait $! pidwait -F "${_QEMU_PID}" & wait $!
else else
tail --pid "$(cat "${_QEMU_PID}")" --follow /dev/null & wait $! tail --pid "$(cat "${_QEMU_PID}")" --follow /dev/null & wait $!