aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2020-12-05 18:48:34 +0100
committerneodarz <neodarz@neodarz.net>2020-12-05 18:49:05 +0100
commit086115e10524a83f7804b7252a34eeaf85500abb (patch)
treebe7b3ed9dd10f9b2688139fb426ad71a0ee0ab36
parent2cd86cd7f08febd057eb30a8d88f795e613f4a89 (diff)
downloadwebsite-086115e10524a83f7804b7252a34eeaf85500abb.tar.xz
website-086115e10524a83f7804b7252a34eeaf85500abb.zip
Add article 2020-12-05 first playing with libvirt and cloudinit
-rw-r--r--src/blog/2020-12-05-first_playing_with_libvirt_and_cloudinit.rst121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/blog/2020-12-05-first_playing_with_libvirt_and_cloudinit.rst b/src/blog/2020-12-05-first_playing_with_libvirt_and_cloudinit.rst
new file mode 100644
index 0000000..83a9737
--- /dev/null
+++ b/src/blog/2020-12-05-first_playing_with_libvirt_and_cloudinit.rst
@@ -0,0 +1,121 @@
+.. post:: Dec 05, 2020
+ :tags: system
+ :language: en
+ :author: neodarz
+
+First playing with libvirt and cloudinit
+========================================
+
+Exactly one year earlier I :doc:`write an article </blog/2019-05-12-mysteredesportsusb>`
+(fr) about understanding some shit I've done with my system. Here we go again...
+
+This time it's about trying a new tool for hosting some virtual machines and
+containers, thanks to my friend `droper <https://analphabet.me/>`_ to help me
+understanding it. I will say some obvious thing when you know it but yes some
+times is better to repeat this obvious things.
+
+So, I've had some good feedback about libvirt for hosting vm and also
+want to have a simple way to configure user on it. I first looked at
+cloudinit and it's seems to be a good thing. Well... I've had some
+difficulty to understand it and the doc about cloudinit it's... how to say...
+not complete enough for my taste. But whatever, I'm here to try it, starting
+with creating a new virtual machine.
+
+For my tests I mainly use the cloundinit documentation
+`nocloud datasource <https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html>`_.
+
+So first thing to do is to grab some virtual image, like the debian's cloud
+image of the day.
+
+.. code::
+
+ wget https://cdimage.debian.org/cdimage/cloud/buster/daily/20200512-261/debian-10-generic-amd64-daily-20200512-261.qcow2
+
+Since I just want to test cloudinit I will juste simply make a copy of the
+image that I just downloaded and use this copied image as my main vm disk.
+
+.. code::
+
+ cp debian-10-generic-amd64-daily-20200512-261.qcow2 myvm.qcow2
+
+.. admonition:: Hint - Wait, why don't just use the image without copying it ???
+ :class: hint
+
+ Since I will use the debian cloud image for various tests I don't want
+ cloudinit "flag it" and starts the installation procedure only once.
+ Yes with my first attempts I didn't copy it and I dind't understand why
+ cloudinit didn't want to apply the configuration, very frustrating.
+
+
+For the next step I will simply create a new user with a plain text password
+for some quick tests. For that I create a :samp:`user-data` file based on some
+`examples <https://cloudinit.readthedocs.io/en/latest/topics/examples.html>`_
+in cloudinit documentation. Here is what my :samp:`user-data`
+config file looks like:
+
+.. code::
+
+ #cloud-config
+
+ users:
+ - name: toot
+ plain_text_passwd: 'toot'
+ lock_passwd: false
+
+For the :samp:`meta-data` file I will just make an empty one for the next of our
+journey.
+
+.. code::
+
+ touch meta-data
+
+Now we have all the necessary configuration files we need to generate a new
+image who will contains our :samp:`meta-data` and :samp:`user-data` files and
+who will be consumed by cloudinit when booting the virtual machine.
+
+.. code::
+
+ sudo genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data
+
+The final step is to launch the :samp:`virt-install` command for create our new
+virtual machine.
+
+.. code::
+
+ virt-install --name myvm \
+ --import \
+ --os-variant debian10 \
+ --memory 4096 \
+ --memorybacking hugepages=on \
+ --vcpu 2 \
+ --network user \
+ --graphics none \
+ --disk disk.qcow2 \
+ --disk seed.iso,readonly=on \
+ --qemu-commandline='-smbios type=1,serial=ds=nocloud;' \
+ --noreboot \
+ --autostart \
+ --noautoconsole
+
+.. hint::
+
+ Keep attention to the command line option :samp:`qemu-commandline`, I noticed
+ that it's mandatory for Debian but not for Ubuntu. It's a detail but It took
+ me some time to notice this... I don't know for other distribution yet but I
+ think it's usefull to keep that in mind and don't forget to use it each time
+ you want to create an virtual machine based on cloudinit.
+
+Now we can starting it and then try to connect to it in console mode.
+
+.. code::
+
+ virsh start --console myvm
+
+For the network part, I will try it later since my network configuration on my
+Archlinux desktop is actually a mess (I'm not going to talk about the mess on
+my Archlinux laptop either).
+
+Yes, I could make a fresh install of both of my systems but this is the easy
+way. I prefer to waste more time and have more fun to repair my mess.
+(I don't do this for work and servers obviously, all is documented but maybe
+it's better to have a home lab and trying things on it...)