90cf460fdc97426491fcbfc3fcf14370ce34ce07
[snf-image-creator] / docs / usage.rst
1 Usage
2 ^^^^^
3
4 snf-image-creator comes in 2 variants:
5  * snf-image-creator: A non-interactive command line program
6  * snf-mkimage: A user-friendly dialog-based program
7
8 Non-interactive version
9 =======================
10
11 snf-image-creator receives the following options:
12
13 .. code-block:: console
14
15  $ snf-image-creator --help
16
17  Usage: snf-image-creator [options] <input_media>
18
19  Options:
20   --version             show program's version number and exit
21   -h, --help            show this help message and exit
22   -o FILE, --outfile=FILE
23                         dump image to FILE
24   -f, --force           overwrite output files if they exist
25   -s, --silent          silent mode, only output errors
26   -u FILENAME, --upload=FILENAME
27                         upload the image to pithos with name FILENAME
28   -r IMAGENAME, --register=IMAGENAME
29                         register the image with ~okeanos as IMAGENAME
30   -a ACCOUNT, --account=ACCOUNT
31                         Use this ACCOUNT when uploading/registering images
32                         [Default: None]
33   -m KEY=VALUE, --metadata=KEY=VALUE
34                         Add custom KEY=VALUE metadata to the image
35   -t TOKEN, --token=TOKEN
36                         Use this token when uploading/registering images
37                         [Default: None]
38   --print-sysprep       print the enabled and disabled system preparation
39                         operations for this input media
40   --enable-sysprep=SYSPREP
41                         run SYSPREP operation on the input media
42   --disable-sysprep=SYSPREP
43                         prevent SYSPREP operation from running on the input
44                         media
45   --no-sysprep          don't perform system preparation
46   --no-shrink           don't shrink any partition
47
48
49 Most input options are self-describing. If you want to save a local copy for
50 the image you create, you specify *-o* option. To upload the image to
51 *pithos+*, you specify valid credentials with *-a* and *-t* options and a
52 filename using *-u*. If you want to register the image with *~okeanos*,
53 in addition to *-u* specify a registration name using *-r*.
54
55 By default snf-image-creator will perform a number of system preparation
56 operations on the snapshot of the media and will shrink the last partition
57 found, before extracting the image. Both can be disabled by specifying
58 *--no-sysprep* and *--no-shrink* respectively.
59
60 If *--print-sysprep* is defined, the program will exit after outputing a
61 list of enabled and disabled system preparation operation appliable to this
62 media source. The user can enable or disable specific *syspreps* when creating
63 an image, using *-{enable,disable}-sysprep* options. You can specify those
64 options multiple times to enable or disable multiple *syspreps*.
65
66 Running *snf-image-creator* with *--print-sysprep* on a raw file that hosts a
67 debian system, we get the following output:
68
69 .. _sysprep:
70
71 .. code-block:: console
72
73    $ snf-image-creator --print-sysprep debian_desktop.img
74
75    snf-image-creator 0.1
76    =====================
77    Examining source media `debian_desktop.img'... looks like an image file
78    Snapshotting media source... done
79    Enabling recovery proc
80    Launching helper VM... done
81    Inspecting Operating System... found a(n) debian system
82    Mounting the media read-only... done
83
84    Enabled system preparation operations:
85        cleanup-cache:
86         Remove all regular files under /var/cache
87
88        cleanup-log:
89         Empty all files under /var/log
90
91        cleanup-passwords:
92         Remove all passwords and lock all user accounts
93
94        cleanup-tmp:
95         Remove all files under /tmp and /var/tmp
96
97        cleanup-userdata:
98         Delete sensitive userdata
99
100        fix-acpid:
101         Replace acpid powerdown action scripts to immediately shutdown the
102         system without checking if a GUI is running.
103
104        remove-persistent-net-rules:
105         Remove udev rules that will keep network interface names persistent
106         after hardware changes and reboots. Those rules will be created again
107         the next time the image runs.
108
109        remove-swap-entry:
110         Remove swap entry from /etc/fstab. If swap is the last partition
111         then the partition will be removed when shrinking is performed. If the
112         swap partition is not the last partition in the disk or if you are not
113         going to shrink the image you should probably disable this.
114
115        use-persistent-block-device-names:
116         Scan fstab & grub configuration files and replace all non-persistent
117         device references with UUIDs.
118
119    Disabled system preparation operations:
120        cleanup-mail:
121         Remove all files under /var/mail and /var/spool/mail
122
123        remove-user-accounts:
124         Remove all user accounts with id greater than 1000
125
126
127    cleaning up...
128
129 If we want the image to have all normal user accounts and all mail files
130 removed, we can create it specifying *--enable-sysprep* option like this:
131
132 .. code-block:: console
133
134    $ snf-image-creator --enable-sysprep cleanup-mail --enable-sysprep remove-user-accounts ...
135
136 Dialog-based version
137 ====================
138
139 *snf-mkimage* receives the following options:
140
141 .. code-block:: console
142
143    $ Usage: snf-mkimage [options] [<input_media>]
144
145    Options:
146      --version             show program's version number and exit
147      -h, --help            show this help message and exit
148      -l FILE, --logfile=FILE
149                             log all messages to FILE
150
151 If the input media is not specified in the command line, in the first dialog
152 box the user will be asked to specify it. After the input media is examined and
153 the program is initialized, the user will be given the choice to run
154 *snf-mkimage* in *wizard* or *expert* mode.
155
156 Wizard mode
157 -----------
158
159 When *snf-mkimage* runs in *wizard* mode, the user is just asked to provide the
160 following basic information:
161
162  * Name: A short name for the image (ex. "Slackware")
163  * Description: An one-line description for the image (ex. "Slackware Linux 14.0 with KDE")
164  * Account: An *~okeanos* account email
165  * Token: A token corresponding to the account defined previously
166
167 After confirming, the image will be extracted, uploaded to *pithos+* and
168 registered to *~okeanos*. The user will also be given the choice to keep a local
169 copy of it. For most users the functionality this mode provides should be
170 sufficient.
171
172 Expert mode
173 -----------
174
175 Expert mode allows the user to have better control on the image creation
176 process. In the picture below the main menu can be seen:
177
178 .. image:: /snapshots/main_menu.png
179
180 In the *Customize* sub-menu the user can control:
181
182  * The system preparation operations that will be applied on the media
183  * Whether the image will be shrunk or not
184  * The properties associated with the image
185  * The configuration tasks that will run during image deployment
186
187 In the *Register* sub-menu the user can provide:
188
189  * The credentials to login to *~okeanos*
190  * A pithos filename for the uploaded *diskdump* image
191  * A name for the image to be registered to *~okeanos* with
192
193 By choosing the *Extract* menu entry the user can dump the image to the local
194 file system and finally, if the user selects *Reset*, the system will ignore
195 all changes made so far and will start the image creation process again.
196
197 Usage example
198 =============
199
200 Supposing you have snf-image-creator installed on a machine (hereafter referred
201 to as your **host machine**), you can follow the next steps to upload and
202 register an image of an OS of your preference (hereafter referred to as your
203 **guest OS**) to your synnefo deployment.
204
205  * `Step 1: Install the guest OS`_
206  * `Step 2: Create and upload an image of the guest OS`_
207  * `Step 3: Create your VM`_
208
209
210 Step 1: Install the guest OS
211 -----------------------------
212
213 The guest OS has to be installed on a media such as a block device or a regular
214 raw file, that can be **accessible** by your host machine.
215
216 But why is accessible empasized? Well, because you don't need to do the
217 installation of the guest OS on your host machine. You can just as well install
218 it on a raw file, upload it on Pithos+, download it on your host machine and
219 use it for Step 2.
220
221 *Note: If you have a guest OS already installed, you may want to skip the
222 next step. However, be sure to check out the* `Caveats`_ *section, where
223 some requirements about the guest OS are presented.*
224
225 Installation example
226 """"""""""""""""""""
227
228 To simplify things a bit, we will install the guest OS on the host machine
229 where snf-image-creator is installed. We will assume that the host machine is
230 an Ubuntu 12.04 ~okeanos VM, built with max specifications (4 CPUs, 2GB of
231 ram, 40GB of disk space at the time of writing this).
232
233 *Note: Since the installation of the guest OS will take place on your host
234 VM, you must be able to connect to it graphically. This is covered by our*
235 `connection guide <https://okeanos.grnet.gr/support/user-guide/cyclades-how-do-
236 i-connect-to-a-vm/#windows-linux-host-to-linux-guest-graphical>`_.
237
238 For our guest OS, we will choose, Linux Mint, which is the most hyped Linux
239 OS according to Distrowatch. A new version has just been released, so
240 this seems like a fine choice. ::
241
242    Warning: The installation might take a long time (~1 hour) and a bit of
243    lagginess due to nested virtualization is to be expected.
244
245 Fire up your terminal, go to your home directory and type the following to
246 download the Linux Mint live cd::
247
248    $ wget http://ftp.ntua.gr/pub/linux/linuxmint//stable/14/linuxmint-14-mate-dvd-64 bit.iso
249
250 Verify that it has been downloaded correctly. If the following command
251 prints "OK". then you are good to go::
252
253    $ echo 'b370ac59d1ac6362f1662cfcc22a489c linuxmint-14-mate-dvd-64bit.iso' > check.md5
254    $ md5sum -c check.md5
255
256 Allocate a few gigs of space to create a sparse file::
257
258    $ truncate -s 7G linuxmint.raw
259
260 Use `kvm` to boot the Live CD::
261
262    $ sudo kvm -m 1200 -smp 4 -boot d -drive \
263      file=linuxmint.raw,format=raw,cache=none,if=virtio \
264      -cdrom linuxmint-14-mate-dvd-64bit.iso
265
266    At a glance, let's see what the above options do:
267      -m 1200:               Use 1200MB of RAM for the guest OS. You should
268                             allocate as much as possible
269      -smp 4:                Simulate an SMP system with 4 CPUs for the
270                             guest OS to use.
271      -boot d:               Place cdrom first in the boot order
272      file=opensuse.raw      Use this raw file as the "hard disk" for the
273                             installation
274      if=virtio:             Inform the OS that it should preload the
275                             VirtIO drivers (more on that on `Caveats`_
276                             section)
277      -cdrom linuxmint-14-mate-dvd-64bit.iso:
278                             "Insert" Linux Mint's live cd in the cdrom
279                             drive
280
281 Wait a few seconds and then a new screen with the Linux Mint logo should
282 appear. You don't have to press any key since it will boot automatically to
283 Linux Mint's live desktop after a few minutes.
284
285 |qemu-live|
286
287 Choose "Install Linux Mint". The installation process should be pretty
288 straightforward. Just keep two things in mind:
289
290 * The username you choose will also be used later on, when you create a VM
291   from this OS image. The password, however, will be removed and you will
292   be given a new one.
293 * The installed OS must have no more than one primary partition and
294   optionally a swap partition. You can read more in the `Caveats`_
295   section below. You don't have to worry about it in this installation
296   however, since the default option takes care of that.
297
298   |qemu-partition|
299
300 After the installation is complete, you can close the QEMU window. You
301 will be able to boot your installed OS and make any changes you want to it
302 using the following command::
303
304    $ sudo kvm -m 1200 -smp 4 -boot d -drive \
305    file=linuxmint.raw,format=raw,cache=none,if=virtio
306
307 At the very least, you should install OpenSSH server to connect to your VM
308 properly. You can install OpenSSH server using the following command::
309
310    $ sudo apt-get install openssh-server
311
312 Bear in mind that once the OS image has been uploaded to your synnefo
313 deployment, you will not be able to make changes to it. Since you can only
314 apply changes to your raw file, you are advised to do so now and then proceed
315 to Step 2.
316
317 Caveats
318 """""""
319 This is a list of restrictions you must have in mind while installing the
320 guest OS:
321
322 **Partitions**
323
324 The installation must consist of no more than one primary partition. It
325 can have a swap partition though, which should ideally - but not
326 necessarily - be located at the end of the media. In this case, the
327 uploaded image will be much smaller and the VM deployment process much
328 faster.
329
330 **VirtIO drivers**
331
332 Depending on your synnefo-deployment, you may need to use para-virtualized
333 drivers for your storage and network needs.
334
335 ~okeanos uses the VirtIO framework which is essential for the ~okeanos VMs
336 to work properly since their disk I/O controller and Ethernet cards are
337 para-virtualized.
338
339 Fortunately, you will not need to deal with the installation of VirtIO drivers
340 directly, since they are included in Linux kernel since version 2.6.25 and
341 shipped with all the modern Linux distributions. However, if the VirtIO drivers
342 are built as a module (and most modern OSes do so), they need to be preloaded
343 using an initial ramdisk (initramfs), otherwise the VM you create from this OS
344 image will not be able to boot.
345
346 Debian derivatives will create an initial ramdisk with VirtIO included if
347 they are connected during the installation on a para-virtualized interface
348 (the "if=virtio" option in the Linux Mint example).
349
350 In many other distros though, this is not the case. In Arch Linux for
351 example, the user needs to manually add virtio_blk and virtio_pci drivers
352 in /etc/mkinitcpio.conf and rebuild the initial ramdisk to make the
353 virtio drivers get preloaded during boot. You can read more in the `Arch
354 Linux wiki <https://wiki.archlinux.org/index.php/KVM#Paravirtualized_
355 guests_.28virtio.29>`_ on how to do it.
356
357 For now, snf-image-creator cannot resolve this kind of problems and it's
358 left to the user to do it.
359
360 Step 2: Create and upload an image of the guest OS
361 --------------------------------------------------
362
363 This is the step on which we use snf-image-creator. There are actually two
364 variants of snf-image-creator, `snf-image-creator`_ and `snf-mkimage`_, both
365 achieving the same results but suited for different needs. Their scope is
366 documented at the start of the `Usage`_ section of this document.
367
368 *Note: Both tools take a snapshot of the installed OS on the media
369 provided to them. So, any changes they apply do not affect the OS
370 installed on the original media.*
371
372 Let's see both tools in action. We will use them to create an image of the
373 Linux Mint 14 OS we installed in Step 2.
374
375 snf-mkimage
376 """""""""""
377
378 In order to use snf-mkimage, simply type::
379
380    $ sudo snf-mkimage linuxmint.raw
381
382 snf-mkimage will initially check if the media is indeed a single disk
383 partition or a raw file representing a hard disk. Then, it will use
384 heuristics to understand which OS has been installed on the media. After
385 that, you will be asked which mode you prefer.
386
387 |mkimage-wizard|
388
389 * Wizard mode is intuitive and consists of 4 simple steps.
390 * Expert mode has an abundance of options but requires a bit of knowledge
391   of the inner workings of Cyclades from your part. You can learn more on the
392   `Expert Mode`_ section of snf-mkimage.
393
394 For our tutorial, we will use Wizard mode. So, choose "Wizard" and then provide
395 a name for the image.
396
397 |mkimage1|
398
399 This name will appear on Pithos+ and on the Public Images section of Cyclades.
400
401 Then, provide a description for the image.
402
403 |mkimage2|
404
405 This will appear under the chosen image name on the Public Images section of
406 cyclades.
407
408 Next, add your account e-mail
409
410 |mkimage3|
411
412 ... your account token...
413
414 |mkimage4|
415
416 ...and you're done! A list operations will appear on your console.
417
418 |mkimage-results|
419
420 We will briefly comment on the above output.
421
422 * **Sysprep:** Operations from 1/9 to 9/9 are part of the system
423   preparation operations and are best explained in the snf-image-creator's
424   `sysprep`_ section.
425 * **Shrinking:** When shrinking the image, we check if a swap partition
426   exists at the end of the media. If this is the case, it will be removed
427   and re-inserted upon the deployment process of the VM. Alternatively, if
428   the swap partition lies at the start of the media, it will be left
429   untouched. On both cases, the primary partition will be shrunken as much
430   as possible. On this example, we can see that the final size is 3.5GB,
431   whereas the orginal size was 7GB. This means that the image was reduced
432   by half, a pretty impressive feat.
433 * **MD5SUM:** The md5sum of the image is used later on to verify that the
434   image has been uploaded successfully.
435 * **Uploading:** Everytime you upload an OS image, every block is hashed,
436   checked against existing blocks in Pithos+ and finally uploaded, if no
437   other block has the same hash.
438
439   *Consider this example: You have just uploaded a Gentoo Linux image but
440   had forgotten to install a necessary package. In this case, you would
441   probably edit the OS in the raw file and then use snf-mkimage to upload
442   the new image. However, since there is an almost identical image already
443   uploaded on Pithos+, you can just as well upload only the blocks that
444   differentiate those two images. This is both time and space efficient.*
445
446 Finally, after the image has been uploaded successfully, you will be asked
447 whether you want to save a local copy of the **shrunken** image. This is
448 just a copy of the diskdump that has been uploaded to Pithos+ and, in case
449 you are confused, the original OS installed on the media (linuxmint.raw in
450 our example) remains intact.
451
452 snf-image-creator
453 """""""""""""""""
454
455 snf-image-creator is the command-line equivalent of snf-mkimage. All the
456 info provided in the steps above are given now as options, which makes it
457 ideal for scripting purposes. The full set of options can be found in the
458 `Usage section <#non-interactive-version>`_ of snf-image-creator's
459 documentation.
460
461 This tool is most commonly used with the following set of options::
462
463    $ sudo snf-image-creator linuxmint.raw -a user@email.com \
464    -t hUudl4DEIlomlnvWnv7Rlw== -u linuxmint.diskdump -r "Linux Mint 14 Nadia"
465
466 As you can see, these options are exactly what snf-mkimage's steps
467 translate to. You can also see that the output is nearly identical:
468
469 |image-creator|
470
471 Step 3: Create your VM
472 ----------------------
473
474 Creating a VM out of an uploaded custom image is a fairly simple task.
475 Just select "New Machine", go to "My Images" section and select your
476 image.
477
478 |custom-vm|
479
480 Alternatively, if you want to create a VM from another user's custom
481 image, you can go to the "Public Images" section.
482
483 .. |qemu-live| image:: /snapshots/qemu-live.png
484
485 .. |qemu-partition| image:: /snapshots/qemu-partition.png
486
487 .. |mkimage-wizard| image:: /snapshots/mkimage-wizard.png
488
489 .. |mkimage1| image:: /snapshots/mkimage1.png
490
491 .. |mkimage2| image:: /snapshots/mkimage2.png
492
493 .. |mkimage3| image:: /snapshots/mkimage3.png
494
495 .. |mkimage4| image:: /snapshots/mkimage4.png
496
497 .. |mkimage-fin| image:: /snapshots/mkimage-fin.png
498
499 .. |mkimage-results| image:: /snapshots/mkimage-results.png
500
501 .. |image-creator| image:: /snapshots/image-creator.png
502
503 .. |custom-vm| image:: /snapshots/custom-vm.png
504