Skip to content

Instantly share code, notes, and snippets.

@zenlord
Forked from joedborg/launch_vm.sh
Last active August 12, 2023 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zenlord/169b0fae297bd706c9a3d11d06a4e572 to your computer and use it in GitHub Desktop.
Save zenlord/169b0fae297bd706c9a3d11d06a4e572 to your computer and use it in GitHub Desktop.
LXD launch Debian VM and set disk size
config:
boot.autostart: true
user.user-data: |
package_update: true
package_upgrade: true
package_reboot_if_required: true
apt_mirror: http://deb.debian.org/debian
ssh_pwauth: yes
users:
- name: root
passwd: "$6$11223344SALT$2btHorFfWS/iqMWVv9zRUjtjxLSsJoL.8k2OzXMF/OPYVm06K.viV/AvLTGy3ALtMtn2maHnYvxxjgG9YqDig."
lock_passwd: false
groups: lxd
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
apt:
packages:
runcmd:
- [cloud-init, schema, --system]
description: VM profile
devices:
config:
source: cloud-init:config
type: disk
eth0:
nictype: bridged
parent: lxdbr0
type: nic
root:
path: /
pool: default
size: 50GiB
type: disk
name: vm
#!/bin/env bash
## Set root password in config.yaml
## $ mkpasswd -m sha-512 l33tp4sswd -S "11223344SALT"
## Replace the passwd in config.yaml
set -e
export EDITOR=nano
readonly VM="banana"
readonly CPU="2"
readonly MEM="2GiB"
readonly DSK="50GiB"
lxc network create ${VM}br0
lxc profile create ${VM}vm
lxc profile edit ${VM}vm
lxc launch \
images:debian/bookworm/cloud \
${VM} \
-p default -p ${VM}vm \
--vm \
-c limits.cpu ${CPU} \
-c limits.memory ${MEM} \
-d root,size=${DSK} \
< config-debian-vm.yaml
sleep 10 # `lxc start` needs a `--wait`.
lxc shell ${VM}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment