Last Updated: October 07, 2020
·
21.97K
· liquid

Memory efficient Ubuntu VMs

14 Responses
Add your response

Great, I'll try it!

Useful and well documented tip. +1.

over 1 year ago ·

Or just use linux-image-virtual minimal kernel.

over 1 year ago ·

Would be nice to see what effect blacklisting those modules had on your memory usage and if there are any other tricks to get memory usage down even further.

over 1 year ago ·

@carlzulauf:

Good point! This article was supposed to be an intro to the main steps towards memory optimisation but I guess I could profile individual kernel modules as well and update the article with the findings. I'll get some time to do it.

Other aspects of memory consumption that I was thinking of are mainly around common services on Ubuntu servers. For example using Nginx instead of Apache to lower the memory footprint, however these would be specific to individual use cases. (Not everybody is using a HTTP server, although it's quite common).

over 1 year ago ·

Would you be willing to turn the resulting VM into a Vagrant box?

over 1 year ago ·

A script as a gist to modify a new ubuntu box would be even better because it would be repeatable. This type of approach is far better than some unreferenced article with no code. Show me the code or it didn't happen.

https://gist.github.com/steakknife/6086608

Boom.

over 1 year ago ·

@honza: Yes! That was my intention since the beginning. I'll update the post when it's available.

over 1 year ago ·

@steakknife: The purpose of this post is not to just spit some shell code into peoples' faces but to explain and help understanding what is going on.

On the other hand I obviously understand the benefits of having a repeatable script, as well. If you have one, please post it. Your current one does a little too much maybe. (Not everybody needs git for example)

over 1 year ago ·

@firefishy1: Thank you, good point. I was expecting the installer to do exactly that, however it turns out that the minimal virtual install still sticks to the generic kernel (which I find interesting.)

over 1 year ago ·

@unnali: Nicely spotted! Thank you for letting me know. Originally I was doing the whole configuration in interactive root shell. I've modified the post. \o/

over 1 year ago ·

Let's go a little bit further.
Let's go a little bit further.

Disable redundant TTYs.

# for i in $(seq 2 6); do echo 'manual' > /etc/init/tty${i}.override; done 

Replace openssh with by a lighter weight SSH Dropbear

# apt-get install dropbear 
# sed -i s'/\(NO_START\)=.*/\1=0/' /etc/default/dropbear
# echo 'manual' > /etc/init/ssh.override

Reboot

Steps above have saved about 6Mb extra on my VM.

over 1 year ago ·

Lots of great comments around this post. I'm inclined to automate and spawn this off as a repeatable project as suggested by honza. Perhaps go a step further and create a JEOS template for veewee.
https://github.com/jedi4ever/veewee/issues/169

In the meantime, steakknife's script will have to do.

over 1 year ago ·

@hostmaster:

Yes I have looked into drop bear and it mostly works. Unfortunately the Official Ubuntu Package does not come with the scp command so you won't be able to securely copy files from within the guest machine to another host.

Please see the relevant issue on Launchpad:
https://bugs.launchpad.net/ubuntu/+source/dropbear/+bug/472264

This is might sound like a minor issue, however when you turn the virtual machine into a Vagrant Box, Vagrant will complain that the guest OS does not have SCP capabilities and will cancel the provisioning. Having said that, I'd rather prefer the OpenSSH server package over Dropbear for the reasons above, at least until Dropbear will support SCP as well.

over 1 year ago ·

Now that's what I call a pro tip!

over 1 year ago ·