Skip to content

Instantly share code, notes, and snippets.

@jellium
Forked from joedborg/launch_vm.sh
Created November 9, 2023 22:10
Show Gist options
  • Save jellium/a477730c96c958297c6712050bd7d57f to your computer and use it in GitHub Desktop.
Save jellium/a477730c96c958297c6712050bd7d57f to your computer and use it in GitHub Desktop.
LXD Ubuntu VM launch and disk resize
#!/bin/env bash
set -e
readonly VM="banana"
readonly CPU="8"
readonly MEM="8GB"
readonly DSK="120GB"
lxc init images:ubuntu/focal ${VM} -p default -p vm --vm
lxc config set ${VM} limits.cpu ${CPU}
lxc config set ${VM} limits.memory ${MEM}
lxc config device override ${VM} root size=${DISK}
lxc start ${VM}
sleep 10 # `lxc start` needs a `--wait`.
lxc exec ${VM} -- apt update
lxc exec ${VM} -- apt install cloud-initramfs-growroot -y
lxc exec ${VM} -- growpart /dev/sda 2
lxc exec ${VM} -- resize2fs /dev/sda2
config:
user.user-data: |
apt_mirror: http://us.archive.ubuntu.com/ubuntu/
ssh_pwauth: yes
users:
- name: ubuntu
passwd: "\$6\$s.wXDkoGmU5md\$d.vxMQSvtcs1I7wUG4SLgUhmarY7BR.5lusJq1D9U9EnHK2LJx18x90ipsg0g3Jcomfp0EoGAZYfgvT22qGFl/"
lock_passwd: false
groups: lxd
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
growpart:
mode: auto
devices:
- '/'
- '/dev/sda'
- '/dev/sda2'
ignore_growroot_disabled: false
description: VN profile
devices:
config:
source: cloud-init:config
type: disk
eth0:
nictype: bridged
parent: lxdbr0
type: nic
root:
path: /
pool: default
size: 100GB
type: disk
name: vm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment