Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -aeux
- # createContainer.sh - Script to create a proxmox lxc container
- VMID="${1:-1000}"
- CNAME="${2:-testreposerver}"
- TMPL="/var/lib/vz/template/cache/oracle_8_x86_64_20250827.tar.xz"
- PUBKEY="/root/.ssh/id_rsa.pub"
- function cleanup {
- echo "Removing $CLIST"
- rm -f "$CLIST"
- }
- trap cleanup EXIT
- if ! test -f "${TMPL}"; then
- echo "Template ${TMPL} not found"
- exit 1
- fi
- if ! test -f "${PUBKEY}"; then
- echo "Public key ${PUBKEY} not found"
- exit 1
- fi
- CLIST=$(mktemp)
- if ! pct list > "$CLIST" 2> /dev/null; then
- echo "Failed to get container list"
- exit 1
- fi
- if grep -w "${VMID}" "$CLIST" ; then
- echo "VMID ${VMID} already exists"
- exit 1
- elif grep -w "${CNAME}" "$CLIST" ; then
- echo "Container already exists with name ${CNAME}"
- exit 1
- fi
- pct create "${VMID}" "${TMPL}" \
- --ostype centos \
- --hostname "${CNAME}" \
- --cores 2 \
- --memory 512 \
- --swap 512 \
- --rootfs local-lvm:8 \
- --net0 name=eth0,bridge=vmbr0,ip=dhcp \
- --password Debbie_Loves_Ian_1993 \
- --unprivileged 0 \
- --onboot 1 \
- --start 0 \
- --features mount=nfs \
- --timezone host \
- --ssh-public-keys "${PUBKEY}" \
Advertisement
Add Comment
Please, Sign In to add comment