We can always start the container when LXD starts on boot. All you have to do is set boot.autostart to true. You can define the order to start the containers in (starting with highest first) using boot.autostart.priority (the default value is 0) option. Next we can define the number of seconds to wait after the container started before starting the next one using the boot.autostart.delay option. This page explains how to auto start an LXD container at boot time using the lxc command.
Syntax to auto start LXD containers VM using the lxc command
Above discussed keys can be set using the lxc tool with the following syntax:
$ lxc config set {vm-name} {key} {value}
$ lxc config set {vm-name} boot.autostart {true|false}
$ lxc config set {vm-name} boot.autostart.priority integer
$ lxc config set {vm-name} boot.autostart.delay integer
How do I set an LXD container to start on boot in Ubuntu Linux 16.10?
Type the following command:
$ lxc config set {vm-name} boot.autostart true
Set an LXD container name ‘nginx-vm’ to start on boot
$ lxc config set nginx-vm boot.autostart true
You can verify setting using the following syntax:
$ lxc config get {vm-name} boot.autostart
$ lxc config get nginx-vm boot.autostart
Sample outputs:
true
You can the 10 seconds to wait after the container started before starting the next one using the following syntax:
$ lxc config set nginx-vm boot.autostart.delay 10
Finally, define the order to start the containers in by setting with highest value. Make sure db_vm container start first and next start nginx_vm
$ lxc config set db_vm boot.autostart.priority 100
$ lxc config set nginx_vm boot.autostart.priority 99
Use the following bash for loop on Linux to view all values:
#!/bin/bash echo 'The current values of each vm boot parameters:' for c in db_vm nginx_vm memcache_vm do echo "*** VM: $c ***" for v in boot.autostart boot.autostart.priority boot.autostart.delay do echo "Key: $v => $(lxc config get $c $v)" done echo "" done
Sample outputs:
Fig.01: Get autostarting LXD containers values using a bash shell script
Another way is to grab all lxd VMs using
#!/bin/bash x=$(lxc list -c n | awk '{ print $2}' | sed -e '/^$/d' -e '/^NAME/d') echo 'The current values of each vm boot parameters:' for c in $x do echo "*** VM: $c ***" for v in boot.autostart boot.autostart.priority boot.autostart.delay do echo "Key: $v => $(lxc config get $c $v)" done echo "" done
Conclusion
You learned how to auto start an LXD container in Linux using the lxc command.
- Install LXD container hypervisor on Ubuntu 16.04 LTS
- How to install and setup LXC (Linux Container) on Fedora Linux 26
- Set up LXD container under KVM or Xen virtual machine
- List VM images in LXD (Linux Containers)
- Upgrade LXD containers powered by Ubuntu/Debian or CentOS Linux
- Auto start LXD containers at boot time in Linux
- Command to rename LXD / LXC container
- Run commands on Linux Container (LXD) instance at provision launch time
- Use LXD (Linux containers) in a shell script to create VM when the cloud instance launches
- Move/migrate LXD VM to another host on Linux
- Fedora install and set up LXD
- CentOS 7.x install and set up LXD server
- Install LXD pure-container hypervisor on Ubuntu 18.04 LTS
- Create snapshots with lxc command for LXD
- Set up and install LXD on CentOS/RHEL 8
- Ubuntu 20.04 LTS install and set up LXD
- Full backup and restore LXD containers
- Disable firewall and NAT rules on the LXD bridge
- Delete or remove LXD container using the lxc
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 1 comment... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
for c in `lxc list -c n|grep "| [a-zA-Z]"|sed -e "s/[\|\ ]//g"`