Playing with LXD containers

Lately I have been playing around with LXD containers, and its actually pretty cool.

Lets create a new container:

lxc-create -t download -n TestCont

This will download the default Ubuntu image from the official repository and create a container named TestCont.

Fire it up with “lxc-start -n TestCont”, connect to it with “lxc-attach -n TestCont”. Now you are in the shell of your new container.

Install dnsmasq, configure it for DHCP and DNS and assign IP’s to your containers based on Name or MAC address. The entry in the dnsmasq conf file should look something like this:


Lets create 10 new containers, have them set to autostart, fire them up, and watch the process go along:

for i in `seq 1 10`; do lxc-copy -n TestCont -N TestCont$i;echo “ = 1” | tee -a .local/share/lxc/TestCont$i/config;lxc-start -n TestCont$i; done; watch -n 5 lxc-ls -f

Maybe we can also configure the dnsmasq at the same time:

for i in `seq 1 10`; do echo “dhcp-host=Cont$i,10.0.0.$i” | tee -a /etc/dnsmasq.d/static-hosts.conf;lxc-copy -n TestCont -N TestCont$i;echo “ = 1” | tee -a .local/share/lxc/TestCont$i/config;lxc-start -n TestCont$i; done; watch -n 5 lxc-ls -f

As you can see my dnsmasq conf file is called static-hosts.conf. Now i got 10 new containers with fixed IP addresses in 5 minutes – thats cool 🙂

Before copying the original container I have some tips on what to install in it:


You could do it like this:

lxc-execute -n TextCont apt install ssh vim bash-completion -y

Now you got a nice base image with ssh for remote access, vim for file editing and bash completion. This image will have a ~420 MB footprint.
Another option is to put your public SSH key in the base image, now where getting somewhere 🙂



Push adbkey to device.

When flashing mobile devices with custom ROMs, I have often experienced that the initial screen resolution when booting the new image the first time is terrible wrong. When this happens I usually change the screen resolution with the following commands (this is for my Xiaomi Mi Note Pro, find your setting on or another phone site)

adb shell wm size 1440×2560
adb shell wm density 560

This will fix the resolution, but i still have bad resolution in the boot process, I haven’t figured out how to change that yet. If you know please leave a comment.

Sometimes the resolution is so bad that i cant even push the accept button on the USB debug prompt, this means that I cannot use adb to change the screen resolution. If this happens you have to reboot into the recovery (I prefer TWRP) and copy your to the /data/misc/adb/adb_keys file. You can do it like this:

adb push /data/misc/adb/adb_keys

Reboot your device and you are now able to use adb to change the screen resolution.