Rephrase overview and install section in docs
[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 applicable 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 Creating a new image
198 ====================
199
200 Suppose you want to create a new Ubuntu server image. Download the installation
201 disk from the Internet:
202
203 .. code-block:: console
204
205    $ wget http://ubuntureleases.tsl.gr/12.04.1/ubuntu-12.04.1-server-amd64.iso
206
207 Verify that it has been downloaded correctly:
208
209 .. code-block:: console
210
211    $ echo 'a8c667e871f48f3a662f3fbf1c3ddb17  ubuntu-12.04.1-server-amd64.iso' > check.md5
212    $ md5sum -c check.md5
213
214 Create a 2G sparse file to host the new system:
215
216 .. code-block:: console
217
218    $ truncate -s 2G ubuntu_hd.raw
219
220 And install the Ubuntu system on this file:
221
222 .. code-block:: console
223
224    $ sudo kvm -boot d -drive file=ubuntu_hd.raw,format=raw,cache=none,if=virtio \
225      -m 1000 -cdrom ubuntu-12.04.1-server-amd64.iso
226
227 .. note::
228
229    During the installation, you will be asked about the partition scheme. Since
230    snf-image-creator does not support LVM partitions, you are advised to create
231    regular partitions.
232
233 When the installation is complete, you can close the QEMU window. You
234 will be able to boot your installed OS and make any changes you want to it
235 (e.g. install openssh-server) using the following command::
236
237    $ sudo kvm -boot d -drive file=ubuntu_hd.raw,format=raw,cache=none,if=virtio
238
239 After you're done, become root, activate the virtual environment you have
240 installed snf-image-creator in, and use *snf-mkimage* to create and upload the
241 image:
242
243 .. code-block:: console
244
245    $ sudo -s
246    $ source /path/to/snf-image-env/bin/activate
247    $ snf-mkimage ubuntu_hd.raw
248
249 In the first screen you will be asked to choose if you want to run the program
250 in *Wizard* or *Expert* mode. Choose *Wizard*.
251
252 .. image:: /snapshots/01_wizard.png
253
254 Then you will be asked to provide a name, a description, an *~okeanos* account
255 and the token corresponding to this account. After that you will be asked to
256 confirm the provided data.
257
258 .. image:: /snapshots/06_confirm.png
259
260 Choosing *YES* will create the image and upload it to your *~okeanos* account.
261
262 Some caveats on image creation
263 ==============================
264
265 Para-virtualized drivers
266 ------------------------
267
268 *~Okeanos* uses the *VirtIO* framework. The disk I/O controller and the
269 Ethernet cards on the VM instances are para-virtualized and need special
270 *VirtIO* drivers. Those drivers are included in the Linux Kernel mainline since
271 version 2.6.25 and are shipped with all the popular Linux distributions. The
272 problem is that if the driver for the para-virtualized disk I/O controller is
273 built as module, it needs to be preloaded using an initial ramdisk, otherwise
274 the VM will not be able to boot.
275
276 In the image creation demonstration above, we initially installed the Ubuntu
277 system on a hard disk (*ubuntu_hd.raw*) that was connected on a
278 para-virtualized interface (pay attention to the *if=virtio* option of the kvm
279 line). Ubuntu and Debian create a generic initial ramdisk file that contains
280 many different modules, including the VirtIO drivers. In many distros this is
281 not the case. In Arch Linux for example, the user needs to manually add
282 *virtio_blk* and *virtio_pci* drivers in */etc/mkinitcpio.conf* and rebuild the
283 initial ramdisk [#f1]_ to make the virtio drivers get preloaded during boot.
284 For now, *snf-image-creator* cannot resolve this kind of problems and it's left
285 to the user to do it.
286
287 Swap partitions
288 ---------------
289
290 If you want your image to have a swap partition, make sure this is the last
291 partition on the disk. If snf-image-creator detects a swap partition in the end
292 of the input media, it will remove the partition when shrinking and will save
293 enough information to be able to recreate it during image deployment. This will
294 make the image smaller and will speed up the deployment process.
295
296 .. rubric:: Footnotes
297
298 .. [#f1] https://wiki.archlinux.org/index.php/KVM#Paravirtualized_guests_.28virtio.29