a56j3w
Last Updated: March 08, 2016
·
20.4K
· liquid
D0e7a53bc25c2827451d9f5b14561e05

Memory efficient Ubuntu VMs

15 Responses
Add your response

8066
245fe21

Great, I'll try it!

Useful and well documented tip. +1.

over 1 year ago ·
8120

Or just use linux-image-virtual minimal kernel.

over 1 year ago ·
8122
32fc08ee80cf129f6b1e8593eccb9a03

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 ·
8125
D0e7a53bc25c2827451d9f5b14561e05

@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 ·
8126
Orig

"sudo cat >> …" won't work; the input redirection takes place in your non-root shell.

Try "sudo tee -a … > /dev/null" instead.

over 1 year ago ·
8137
94e6c47b2f9a76cd39f5c7b7c8ad3a36

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

over 1 year ago ·
8145
Default profile 6 normal

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 ·
8147
D0e7a53bc25c2827451d9f5b14561e05

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

over 1 year ago ·
8148
D0e7a53bc25c2827451d9f5b14561e05

@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 ·
8149
D0e7a53bc25c2827451d9f5b14561e05

@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 ·
8150
D0e7a53bc25c2827451d9f5b14561e05

@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 ·
8156

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 ·
8246
Ed481abca20f07ae118262da5e4e5210

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 ·
8298
D0e7a53bc25c2827451d9f5b14561e05

@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 ·
13683
2e83c483adaab94fb02c1e05fa6f646b

Now that's what I call a pro tip!

over 1 year ago ·