Revision 79224631

b/.gitignore
1
# gitignore rules
2
# autotools results
3
/Makefile
4
/Makefile.in
5
/aclocal.m4
6
/autom4te.cache
7
/autotools
8
/config.log
9
/config.status
10
/configure
11

  
12
# built scripts
13
/common.sh
14

  
15
# archives
16
/ganeti-instance-debootstrap-*.tar.gz
b/COPYING
1
		    GNU GENERAL PUBLIC LICENSE
2
		       Version 2, June 1991
3

  
4
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
6
 Everyone is permitted to copy and distribute verbatim copies
7
 of this license document, but changing it is not allowed.
8

  
9
			    Preamble
10

  
11
  The licenses for most software are designed to take away your
12
freedom to share and change it.  By contrast, the GNU General Public
13
License is intended to guarantee your freedom to share and change free
14
software--to make sure the software is free for all its users.  This
15
General Public License applies to most of the Free Software
16
Foundation's software and to any other program whose authors commit to
17
using it.  (Some other Free Software Foundation software is covered by
18
the GNU Library General Public License instead.)  You can apply it to
19
your programs, too.
20

  
21
  When we speak of free software, we are referring to freedom, not
22
price.  Our General Public Licenses are designed to make sure that you
23
have the freedom to distribute copies of free software (and charge for
24
this service if you wish), that you receive source code or can get it
25
if you want it, that you can change the software or use pieces of it
26
in new free programs; and that you know you can do these things.
27

  
28
  To protect your rights, we need to make restrictions that forbid
29
anyone to deny you these rights or to ask you to surrender the rights.
30
These restrictions translate to certain responsibilities for you if you
31
distribute copies of the software, or if you modify it.
32

  
33
  For example, if you distribute copies of such a program, whether
34
gratis or for a fee, you must give the recipients all the rights that
35
you have.  You must make sure that they, too, receive or can get the
36
source code.  And you must show them these terms so they know their
37
rights.
38

  
39
  We protect your rights with two steps: (1) copyright the software, and
40
(2) offer you this license which gives you legal permission to copy,
41
distribute and/or modify the software.
42

  
43
  Also, for each author's protection and ours, we want to make certain
44
that everyone understands that there is no warranty for this free
45
software.  If the software is modified by someone else and passed on, we
46
want its recipients to know that what they have is not the original, so
47
that any problems introduced by others will not reflect on the original
48
authors' reputations.
49

  
50
  Finally, any free program is threatened constantly by software
51
patents.  We wish to avoid the danger that redistributors of a free
52
program will individually obtain patent licenses, in effect making the
53
program proprietary.  To prevent this, we have made it clear that any
54
patent must be licensed for everyone's free use or not licensed at all.
55

  
56
  The precise terms and conditions for copying, distribution and
57
modification follow.
58

59
		    GNU GENERAL PUBLIC LICENSE
60
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61

  
62
  0. This License applies to any program or other work which contains
63
a notice placed by the copyright holder saying it may be distributed
64
under the terms of this General Public License.  The "Program", below,
65
refers to any such program or work, and a "work based on the Program"
66
means either the Program or any derivative work under copyright law:
67
that is to say, a work containing the Program or a portion of it,
68
either verbatim or with modifications and/or translated into another
69
language.  (Hereinafter, translation is included without limitation in
70
the term "modification".)  Each licensee is addressed as "you".
71

  
72
Activities other than copying, distribution and modification are not
73
covered by this License; they are outside its scope.  The act of
74
running the Program is not restricted, and the output from the Program
75
is covered only if its contents constitute a work based on the
76
Program (independent of having been made by running the Program).
77
Whether that is true depends on what the Program does.
78

  
79
  1. You may copy and distribute verbatim copies of the Program's
80
source code as you receive it, in any medium, provided that you
81
conspicuously and appropriately publish on each copy an appropriate
82
copyright notice and disclaimer of warranty; keep intact all the
83
notices that refer to this License and to the absence of any warranty;
84
and give any other recipients of the Program a copy of this License
85
along with the Program.
86

  
87
You may charge a fee for the physical act of transferring a copy, and
88
you may at your option offer warranty protection in exchange for a fee.
89

  
90
  2. You may modify your copy or copies of the Program or any portion
91
of it, thus forming a work based on the Program, and copy and
92
distribute such modifications or work under the terms of Section 1
93
above, provided that you also meet all of these conditions:
94

  
95
    a) You must cause the modified files to carry prominent notices
96
    stating that you changed the files and the date of any change.
97

  
98
    b) You must cause any work that you distribute or publish, that in
99
    whole or in part contains or is derived from the Program or any
100
    part thereof, to be licensed as a whole at no charge to all third
101
    parties under the terms of this License.
102

  
103
    c) If the modified program normally reads commands interactively
104
    when run, you must cause it, when started running for such
105
    interactive use in the most ordinary way, to print or display an
106
    announcement including an appropriate copyright notice and a
107
    notice that there is no warranty (or else, saying that you provide
108
    a warranty) and that users may redistribute the program under
109
    these conditions, and telling the user how to view a copy of this
110
    License.  (Exception: if the Program itself is interactive but
111
    does not normally print such an announcement, your work based on
112
    the Program is not required to print an announcement.)
113

114
These requirements apply to the modified work as a whole.  If
115
identifiable sections of that work are not derived from the Program,
116
and can be reasonably considered independent and separate works in
117
themselves, then this License, and its terms, do not apply to those
118
sections when you distribute them as separate works.  But when you
119
distribute the same sections as part of a whole which is a work based
120
on the Program, the distribution of the whole must be on the terms of
121
this License, whose permissions for other licensees extend to the
122
entire whole, and thus to each and every part regardless of who wrote it.
123

  
124
Thus, it is not the intent of this section to claim rights or contest
125
your rights to work written entirely by you; rather, the intent is to
126
exercise the right to control the distribution of derivative or
127
collective works based on the Program.
128

  
129
In addition, mere aggregation of another work not based on the Program
130
with the Program (or with a work based on the Program) on a volume of
131
a storage or distribution medium does not bring the other work under
132
the scope of this License.
133

  
134
  3. You may copy and distribute the Program (or a work based on it,
135
under Section 2) in object code or executable form under the terms of
136
Sections 1 and 2 above provided that you also do one of the following:
137

  
138
    a) Accompany it with the complete corresponding machine-readable
139
    source code, which must be distributed under the terms of Sections
140
    1 and 2 above on a medium customarily used for software interchange; or,
141

  
142
    b) Accompany it with a written offer, valid for at least three
143
    years, to give any third party, for a charge no more than your
144
    cost of physically performing source distribution, a complete
145
    machine-readable copy of the corresponding source code, to be
146
    distributed under the terms of Sections 1 and 2 above on a medium
147
    customarily used for software interchange; or,
148

  
149
    c) Accompany it with the information you received as to the offer
150
    to distribute corresponding source code.  (This alternative is
151
    allowed only for noncommercial distribution and only if you
152
    received the program in object code or executable form with such
153
    an offer, in accord with Subsection b above.)
154

  
155
The source code for a work means the preferred form of the work for
156
making modifications to it.  For an executable work, complete source
157
code means all the source code for all modules it contains, plus any
158
associated interface definition files, plus the scripts used to
159
control compilation and installation of the executable.  However, as a
160
special exception, the source code distributed need not include
161
anything that is normally distributed (in either source or binary
162
form) with the major components (compiler, kernel, and so on) of the
163
operating system on which the executable runs, unless that component
164
itself accompanies the executable.
165

  
166
If distribution of executable or object code is made by offering
167
access to copy from a designated place, then offering equivalent
168
access to copy the source code from the same place counts as
169
distribution of the source code, even though third parties are not
170
compelled to copy the source along with the object code.
171

172
  4. You may not copy, modify, sublicense, or distribute the Program
173
except as expressly provided under this License.  Any attempt
174
otherwise to copy, modify, sublicense or distribute the Program is
175
void, and will automatically terminate your rights under this License.
176
However, parties who have received copies, or rights, from you under
177
this License will not have their licenses terminated so long as such
178
parties remain in full compliance.
179

  
180
  5. You are not required to accept this License, since you have not
181
signed it.  However, nothing else grants you permission to modify or
182
distribute the Program or its derivative works.  These actions are
183
prohibited by law if you do not accept this License.  Therefore, by
184
modifying or distributing the Program (or any work based on the
185
Program), you indicate your acceptance of this License to do so, and
186
all its terms and conditions for copying, distributing or modifying
187
the Program or works based on it.
188

  
189
  6. Each time you redistribute the Program (or any work based on the
190
Program), the recipient automatically receives a license from the
191
original licensor to copy, distribute or modify the Program subject to
192
these terms and conditions.  You may not impose any further
193
restrictions on the recipients' exercise of the rights granted herein.
194
You are not responsible for enforcing compliance by third parties to
195
this License.
196

  
197
  7. If, as a consequence of a court judgment or allegation of patent
198
infringement or for any other reason (not limited to patent issues),
199
conditions are imposed on you (whether by court order, agreement or
200
otherwise) that contradict the conditions of this License, they do not
201
excuse you from the conditions of this License.  If you cannot
202
distribute so as to satisfy simultaneously your obligations under this
203
License and any other pertinent obligations, then as a consequence you
204
may not distribute the Program at all.  For example, if a patent
205
license would not permit royalty-free redistribution of the Program by
206
all those who receive copies directly or indirectly through you, then
207
the only way you could satisfy both it and this License would be to
208
refrain entirely from distribution of the Program.
209

  
210
If any portion of this section is held invalid or unenforceable under
211
any particular circumstance, the balance of the section is intended to
212
apply and the section as a whole is intended to apply in other
213
circumstances.
214

  
215
It is not the purpose of this section to induce you to infringe any
216
patents or other property right claims or to contest validity of any
217
such claims; this section has the sole purpose of protecting the
218
integrity of the free software distribution system, which is
219
implemented by public license practices.  Many people have made
220
generous contributions to the wide range of software distributed
221
through that system in reliance on consistent application of that
222
system; it is up to the author/donor to decide if he or she is willing
223
to distribute software through any other system and a licensee cannot
224
impose that choice.
225

  
226
This section is intended to make thoroughly clear what is believed to
227
be a consequence of the rest of this License.
228

229
  8. If the distribution and/or use of the Program is restricted in
230
certain countries either by patents or by copyrighted interfaces, the
231
original copyright holder who places the Program under this License
232
may add an explicit geographical distribution limitation excluding
233
those countries, so that distribution is permitted only in or among
234
countries not thus excluded.  In such case, this License incorporates
235
the limitation as if written in the body of this License.
236

  
237
  9. The Free Software Foundation may publish revised and/or new versions
238
of the General Public License from time to time.  Such new versions will
239
be similar in spirit to the present version, but may differ in detail to
240
address new problems or concerns.
241

  
242
Each version is given a distinguishing version number.  If the Program
243
specifies a version number of this License which applies to it and "any
244
later version", you have the option of following the terms and conditions
245
either of that version or of any later version published by the Free
246
Software Foundation.  If the Program does not specify a version number of
247
this License, you may choose any version ever published by the Free Software
248
Foundation.
249

  
250
  10. If you wish to incorporate parts of the Program into other free
251
programs whose distribution conditions are different, write to the author
252
to ask for permission.  For software which is copyrighted by the Free
253
Software Foundation, write to the Free Software Foundation; we sometimes
254
make exceptions for this.  Our decision will be guided by the two goals
255
of preserving the free status of all derivatives of our free software and
256
of promoting the sharing and reuse of software generally.
257

  
258
			    NO WARRANTY
259

  
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
262
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
266
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
267
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
REPAIR OR CORRECTION.
269

  
270
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
POSSIBILITY OF SUCH DAMAGES.
279

  
280
		     END OF TERMS AND CONDITIONS
281

282
	    How to Apply These Terms to Your New Programs
283

  
284
  If you develop a new program, and you want it to be of the greatest
285
possible use to the public, the best way to achieve this is to make it
286
free software which everyone can redistribute and change under these terms.
287

  
288
  To do so, attach the following notices to the program.  It is safest
289
to attach them to the start of each source file to most effectively
290
convey the exclusion of warranty; and each file should have at least
291
the "copyright" line and a pointer to where the full notice is found.
292

  
293
    <one line to give the program's name and a brief idea of what it does.>
294
    Copyright (C) <year>  <name of author>
295

  
296
    This program is free software; you can redistribute it and/or modify
297
    it under the terms of the GNU General Public License as published by
298
    the Free Software Foundation; either version 2 of the License, or
299
    (at your option) any later version.
300

  
301
    This program is distributed in the hope that it will be useful,
302
    but WITHOUT ANY WARRANTY; without even the implied warranty of
303
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
304
    GNU General Public License for more details.
305

  
306
    You should have received a copy of the GNU General Public License
307
    along with this program; if not, write to the Free Software
308
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
309

  
310

  
311
Also add information on how to contact you by electronic and paper mail.
312

  
313
If the program is interactive, make it output a short notice like this
314
when it starts in an interactive mode:
315

  
316
    Gnomovision version 69, Copyright (C) year  name of author
317
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
    This is free software, and you are welcome to redistribute it
319
    under certain conditions; type `show c' for details.
320

  
321
The hypothetical commands `show w' and `show c' should show the appropriate
322
parts of the General Public License.  Of course, the commands you use may
323
be called something other than `show w' and `show c'; they could even be
324
mouse-clicks or menu items--whatever suits your program.
325

  
326
You should also get your employer (if you work as a programmer) or your
327
school, if any, to sign a "copyright disclaimer" for the program, if
328
necessary.  Here is a sample; alter the names:
329

  
330
  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
  `Gnomovision' (which makes passes at compilers) written by James Hacker.
332

  
333
  <signature of Ty Coon>, 1 April 1989
334
  Ty Coon, President of Vice
335

  
336
This General Public License does not permit incorporating your program into
337
proprietary programs.  If your program is a subroutine library, you may
338
consider it more useful to permit linking proprietary applications with the
339
library.  If this is what you want to do, use the GNU Library General
340
Public License instead of this License.
b/Makefile.am
1
osname=$(subst ganeti-instance-,,$(PACKAGE))
2

  
3
osdir=$(OS_DIR)/$(osname)
4
variantsdir="$(DESTDIR)${sysconfdir}/ganeti/instance-debootstrap/variants"
5

  
6
dist_os_SCRIPTS = create import export rename
7
dist_os_DATA = ganeti_api_version variants.list
8
os_DATA = common.sh
9

  
10
dist_doc_DATA = COPYING NEWS README
11

  
12
EXTRA_DIST = common.sh.in defaults
13

  
14
do_subst = sed \
15
	-e 's,[@]sysconfdir[@],$(sysconfdir),g' \
16
	-e 's,[@]localstatedir[@],$(localstatedir),g'
17

  
18
common.sh: common.sh.in Makefile
19
	$(do_subst) < $< > $@
20
	chmod +x $@
21

  
22
install-exec-local:
23
	@mkdir_p@ "$(variantsdir)"
24
	touch "$(variantsdir)/default.conf"
25

  
26
CLEANFILES = common.sh
b/NEWS
1
Version 0.7
2
-----------
3

  
4
Fix Ganeti 1.2 compatibility (0.6 was broken) and force the scripts to be
5
executed under /bin/bash (rather than /bin/sh). This fixes compatibility with
6
distributions where /bin/sh is not bash.
7

  
8
Support 'msdos' partition style, in which the instance disk gets a partition
9
table, and one big partition, rather than creating the filesytem directly on
10
the block device. This requires kpartx to be installed, and is the default when
11
installing under Ganeti 2.0.
12

  
13
Added the possibility to customize the installation without having to patch the
14
os directly, by executing the scripts in CUSTOMIZE_DIR and giving them a chance
15
to change the instance filesystem. As an example a script that sets the first
16
nic to request a dhcp address is provided.
17

  
18
Version 0.6
19
-----------
20

  
21
Support for Ganeti 2.0 (os api 10)
22

  
23
The instance's fstab is now generated with volumes' UUIDs rather than paths.
24
This makes it more resilient to changes and use under different
25
hypervisors/drivers.
26

  
27
Init is configured to listen on /dev/console rather than /dev/tty1
28

  
29
Version 0.5
30
-----------
31

  
32
Most of the settings of the script have been moved to a configuration
33
file.  Depending on the ./configure options, the location of this file
34
might be /etc/default/ganeti-instance-debootstrap or
35
/usr/local/etc/default/ganeti-instance-debootstrap.
36

  
37
The cache generation and cleaning variables can be modified as follows:
38

  
39
- to enable generating the cache, modify the config file and set
40
  GENERATE_CACHE to "yes"
41
- to disable cleaning the cache, set CLEAN_CACHE to ""; or
42
  alternatively, you can customize with this variable the number of days
43
  after which to clear the cache
44

  
45
Note that the cache file is no longer stored in the same directory as
46
the OS definition files, but (again depending on ./configure options)
47
usually under /var/cache/ganeti-instance-debootstrap.
48

  
49
There are many other customuizable settings added in this version, for
50
example the actual OS to be installed (no longer always installing
51
Debian Etch), whether to use a proxy or not, etc. See the README and the
52
'defaults' files.
53

  
54
Version 0.4
55
-----------
56

  
57
This version fixes the problem of interface renaming at instance import
58
time, by removing the saved udev hotplug rules (if any).
59

  
60
Version 0.3
61
-----------
62

  
63
The OS will cache the image of the first instance it installs using the
64
name "cache-$arch.tar" (where $arch is what dpkg --print-architecture
65
returns) on a node-by-node basis. This cache will be then used on the
66
future installs, speeding them greatly (even with a fast mirror). Feel
67
free to remove the cache at any time, or to copy it to all nodes. The
68
cache will be kept for two weeks, after which the first install will
69
recreate the cache (in order not to use old packages). If you don't care
70
about package age, remove the user write permission (chmod u-w) from the
71
cache and ganeti will continue to use the same file without refreshing
72
it.
73

  
74
If you don't have enough space and don't want cache creation, just touch
75
the file 'no_cache' - this will prevent the creation, but the script
76
will continue to use a cache if it exists (but it will remove an
77
existing one after two weeks).
78

  
79
Also note that if the image file is there, the script does not need
80
network access at all.
b/README
1
ganeti-instance-debootstrap
2
===========================
3

  
4
This is a guest OS definition for Ganeti (http://code.google.com/p/ganeti).
5
It will install a minimal version of Debian or Ubuntu via debootstrap (thus it
6
requires network access). This only works if you have a Debian-based node or
7
you have debootstrap installed by hand on another distribution.
8

  
9
Installation
10
------------
11

  
12
In order to install this package from source, you need to determine what
13
options ganeti itself has been configured with. If ganeti was built
14
directly from source, then the only place it looks for OS definitions is
15
``/srv/ganeti/os``, and you need to install the OS under it::
16

  
17
  ./configure --prefix=/usr --localstatedir=/var \
18
    --sysconfdir=/etc \
19
    --with-os-dir=/srv/ganeti/os
20
  make && make install
21

  
22
If ganeti was installed from a package, its default OS path should
23
already include /usr/share/ganeti/os, so you can just run::
24

  
25
  ./configure -prefix=/usr --localstatedir=/var \
26
    --sysconfdir=/etc
27
  make && make install
28

  
29
Note that you need to repeat this procedure on all nodes of the cluster.
30

  
31
The actual path that ganeti has been installed with can be determined by
32
looking for a file named _autoconf.py under a ganeti directory in the
33
python modules tree (e.g.
34
``/usr/lib/python2.4/site-packages/ganeti/_autoconf.py``). In this file,
35
a variable named OS_SEARCH_PATH will list all the directories in which
36
ganeti will look for OS definitions.
37

  
38
Configuration of instance creation
39
----------------------------------
40

  
41
The kind of instance created can be customized via a settings file. This
42
file is not installed by default, as the instance creation will work
43
without it. The creation scripts will look for it in
44
``$sysconfdir/default/ganeti-instance-debootstrap``, so if you have run
45
configure with the parameter ``--sysconfdir=/etc``, the final filename
46
will be ``/etc/default/ganeti-instance-debootstrap``.
47

  
48
The following settings will be examined in this file (see also the file
49
named 'defaults' in the source distribution for more details):
50

  
51
- PROXY: http proxy to use for non-cached installs
52
- MIRROR: the mirror to use if not the default one
53
- ARCH: either i386 or amd64, otherwise your current architecture will
54
  be used
55
- SUITE: the actual OS to be installed; the current default is Debian
56
  *lenny*, and you can choose any of the OSes supported deboostrap (on
57
  Debian, look into /usr/share/deboostrap/scripts)
58
- EXTRAPKGS: most OSes will need some extra packages installed to make
59
  them work nicely under Xen; the example file containts a few
60
  suggestions
61
- CUSTOMIZE_DIR: a directory containing customization script for the instance.
62
  (by default $sysconfdir/ganeti/instance-debootstrap.d) See "Customization of
63
  the instance" below.
64
- GENERATE_CACHE: if 'yes' (the default), the installation process will
65
  save and reuse a cache file to speed reinstalls (located under
66
  $localstatedir/cache/ganeti-instance-debootstrap)
67
- CLEAN_CACHE: if empty, the cached files will never be cleaned and thus
68
  the installation will definitely need to be updated after install;
69
  otherwise, the value of this variable will be taken as the number of
70
  days after which to remove the cache file; the default is 14 (two
71
  weeks)
72
- PARTITION_STYLE: if 'none' the device will be formatted directly, if 'msdos'
73
  a partition table will be installed on it. You need to have kpartx installed
74
  to use the 'msdos' option. The default is 'msdos' from Ganeti 2.0 onwards,
75
  but still 'none' if installing under Ganeti 1.2
76

  
77
Note that the settings file is important on the node that the instance
78
is installed on, not the cluster master. This is indeed not a very good
79
model of using this OS but currently the OS interface in ganeti is
80
limiting.
81

  
82
Customization of the instance
83
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84

  
85
If run-parts is in the os create script, and the CUSTOMIZE_DIR (by default
86
$sysconfdir/ganeti/instance-debootstrap.d, /etc/ganeti/instance-debootstrap.d
87
if you configured the os with --sysconfdir=/etc) directory exists any
88
executable whose name matches the run-parts execution rules (quoting
89
run-parts(8): the  names  must consist entirely of upper and lower case
90
letters, digits, underscores, and hyphens) is executed to allow further
91
personalization of the installation. The following environment variables are
92
passed, in addition to the ones ganeti passes to the OS scripts:
93

  
94
TARGET: directory in which the filesystem is mounted
95
SUITE: suite installed by debootstrap (eg: lenny)
96
ARCH: target architecture
97
PARTITION_STYLE: style of the disk partitioning (see above)
98
EXTRA_PKGS: extra packages installed by debootstrap
99
BLOCKDEV: ganeti block device
100
FSYSDEV: device in which the filesystem resides (the one mounted in TARGET)
101

  
102
The scripts in CUSTOMIZE_DIR can exit with an error code to signal an error in
103
the instance creation, should they fail.
104

  
105
The scripts in CUSTOMIZE_DIR should not start any long-term processes or
106
daemons using this directory, otherwise the installation will fail because it
107
won't be able to umount the filesystem from the directory, and hand the
108
instance back to Ganeti.
109

  
110

  
111
Caching
112
~~~~~~~
113

  
114
As described above, the install process uses a cache file in order to
115
speed up repeated installs. If you only rarely do installs, this will
116
not matter to you, but if you want to install 10 instances in a row, the
117
difference will be visible.
118

  
119
The default settings are to generate a cache, and to clean it up after
120
two weeks.
121

  
122
Note that the cache will use one file per architecture per suite, so if
123
you install multiple suites there might be a non-trivial amount of space
124
used in the cache directory. It is safe to remove manually the files.
125

  
126
It is also possible, if done with care, to modify and regenerate the
127
cache file (which is simply a tar archive) in order to preseed your
128
installs with site-specific customizations.
129

  
130
Instance notes
131
--------------
132

  
133
The instance is a minimal install:
134

  
135
 - it has no password for root; simply login at the console
136
 - it has no network interfaces defined (besides lo); add your own
137
   definitions to /etc/network/interfaces
138
 - after configuring the network, it is recommended to run ``apt-get
139
   update`` so that signatures for the release files are picked up
b/autogen.sh
1
#!/bin/sh
2

  
3
if test ! -f configure.ac ; then
4
  echo "You must execute this script from the top level directory."
5
  exit 1
6
fi
7

  
8
set -e
9

  
10
rm -rf config.cache autom4te.cache
11
mkdir -p autotools
12

  
13
${ACLOCAL:-aclocal} -I autotools
14
${AUTOCONF:-autoconf}
15
${AUTOMAKE:-automake} --add-missing
16

  
17
rm -rf autom4te.cache
b/common.sh.in
1
#
2

  
3
# Copyright (C) 2007, 2008, 2009 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

  
20
CLEANUP=( )
21

  
22
log_error() {
23
  echo "$@" >&2
24
}
25

  
26
get_api5_arguments() {
27
  GETOPT_RESULT=$*
28
  # Note the quotes around `$TEMP': they are essential!
29
  eval set -- "$GETOPT_RESULT"
30
  while true; do
31
    case "$1" in
32
      -i|-n) instance=$2; shift 2;;
33

  
34
      -o) old_name=$2; shift 2;;
35

  
36
      -b) blockdev=$2; shift 2;;
37

  
38
      -s) swapdev=$2; shift 2;;
39

  
40
      --) shift; break;;
41

  
42
      *)  log_error "Internal error!" >&2; exit 1;;
43
    esac
44
  done
45
  if [ -z "$instance" -o -z "$blockdev" ]; then
46
    log_error "Missing OS API Argument (-i, -n, or -b)"
47
    exit 1
48
  fi
49
  if [ "$SCRIPT_NAME" != "export" -a -z "$swapdev"  ]; then
50
    log_error "Missing OS API Argument -s (swapdev)"
51
    exit 1
52
  fi
53
  if [ "$SCRIPT_NAME" = "rename" -a -z "$old_name"  ]; then
54
    log_error "Missing OS API Argument -o (old_name)"
55
    exit 1
56
  fi
57
}
58

  
59
get_api10_arguments() {
60
  if [ -z "$INSTANCE_NAME" -o -z "$HYPERVISOR" -o -z "$DISK_COUNT" ]; then
61
    log_error "Missing OS API Variable:"
62
    log_error "(INSTANCE_NAME HYPERVISOR or DISK_COUNT)"
63
    exit 1
64
  fi
65
  instance=$INSTANCE_NAME
66
  if [ $DISK_COUNT -lt 1 -o -z "$DISK_0_PATH" ]; then
67
    log_error "At least one disk is needed"
68
    exit 1
69
  fi
70
  if [ "$SCRIPT_NAME" = "export" ]; then
71
    if [ -z "$EXPORT_DEVICE" ]; then
72
      log_error "Missing OS API Variable EXPORT_DEVICE"
73
    fi
74
    blockdev=$EXPORT_DEVICE
75
  elif [ "$SCRIPT_NAME" = "import" ]; then
76
    if [ -z "$IMPORT_DEVICE" ]; then
77
       log_error "Missing OS API Variable IMPORT_DEVICE"
78
    fi
79
    blockdev=$IMPORT_DEVICE
80
  else
81
    blockdev=$DISK_0_PATH
82
  fi
83
  if [ "$SCRIPT_NAME" = "rename" -a -z "$OLD_INSTANCE_NAME" ]; then
84
    log_error "Missing OS API Variable OLD_INSTANCE_NAME"
85
  fi
86
  old_name=$OLD_INSTANCE_NAME
87
}
88

  
89
format_disk0() {
90
  # Create one big partition, and make it bootable
91
  # some versions of sfdisk need manual specification of 
92
  # head/sectors for devices such as drbd which don't 
93
  # report geometry
94
  sfdisk -H 255 -S 63 --quiet --Linux "$1" <<EOF
95
0,,L,*
96
EOF
97
}
98

  
99
map_disk0() {
100
  blockdev="$1"
101
  filesystem_dev_base=`kpartx -l -p- $blockdev | \
102
                       grep -m 1 -- "-1.*$blockdev" | \
103
                       awk '{print $1}'`
104
  if [ -z "$filesystem_dev_base" ]; then
105
    log_error "Cannot interpret kpartx output and get partition mapping"
106
    exit 1
107
  fi
108
  kpartx -a -p- $blockdev > /dev/null
109
  filesystem_dev="/dev/mapper/$filesystem_dev_base"
110
  if [ ! -b "$filesystem_dev" ]; then
111
    log_error "Can't find kpartx mapped partition: $filesystem_dev"
112
    exit 1
113
  fi
114
  echo "$filesystem_dev"
115
}
116

  
117
unmap_disk0() {
118
  kpartx -d -p- $1
119
}
120

  
121
cleanup() {
122
  if [ ${#CLEANUP[*]} -gt 0 ]; then
123
    LAST_ELEMENT=$((${#CLEANUP[*]}-1))
124
    REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0)
125
    for i in $REVERSE_INDEXES; do
126
      ${CLEANUP[$i]}
127
    done
128
  fi
129
}
130

  
131
trap cleanup EXIT
132

  
133
DEFAULT_FILE="@sysconfdir@/default/ganeti-instance-debootstrap"
134
if [ -f "$DEFAULT_FILE" ]; then
135
    . "$DEFAULT_FILE"
136
fi
137

  
138
# note: we don't set a default mirror since debian and ubuntu have
139
# different defaults, and it's better to use the default
140

  
141
# only if the user want to specify a mirror in the defaults file we
142
# will use it, this declaration is to make sure the variable is set
143
: ${MIRROR:=""}
144
: ${PROXY:=""}
145
: ${SUITE:="lenny"}
146
: ${ARCH:=""}
147
: ${EXTRA_PKGS:=""}
148
: ${CUSTOMIZE_DIR:="@sysconfdir@/ganeti/instance-debootstrap.d"}
149
: ${VARIANTS_DIR:="@sysconfdir@/ganeti/instance-debootstrap/variants"}
150
: ${GENERATE_CACHE:="yes"}
151
: ${CLEAN_CACHE:="14"} # number of days to keep a cache file
152
if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
153
  DEFAULT_PARTITION_STYLE="none"
154
else
155
  DEFAULT_PARTITION_STYLE="msdos"
156
fi
157
: ${PARTITION_STYLE:=$DEFAULT_PARTITION_STYLE} # disk partition style
158

  
159
CACHE_DIR="@localstatedir@/cache/ganeti-instance-debootstrap"
160

  
161
SCRIPT_NAME=$(basename $0)
162

  
163
if [ -f /sbin/blkid -a -x /sbin/blkid ]; then
164
  VOL_ID="/sbin/blkid -o value -s UUID"
165
  VOL_TYPE="/sbin/blkid -o value -s TYPE"
166
else
167
  for dir in /lib/udev /sbin; do
168
    if [ -f $dir/vol_id -a -x $dir/vol_id ]; then
169
      VOL_ID="$dir/vol_id -u"
170
      VOL_TYPE="$dir/vol_id -t"
171
    fi
172
  done
173
fi
174

  
175
if [ -z "$VOL_ID" ]; then
176
  log_error "vol_id or blkid not found, please install udev or util-linux"
177
  exit 1
178
fi
179

  
180
if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
181
  OS_API_VERSION=5
182
  GETOPT_RESULT=`getopt -o o:n:i:b:s: -n '$0' -- "$@"`
183
  if [ $? != 0 ] ; then log_error "Terminating..."; exit 1 ; fi
184
  get_api5_arguments $GETOPT_RESULT
185
elif [ "$OS_API_VERSION" = "10" -o "$OS_API_VERSION" = "15" ]; then
186
  get_api10_arguments
187
else
188
  log_error "Unknown OS API VERSION $OS_API_VERSION"
189
  exit 1
190
fi
191

  
192
if [ -n "$OS_VARIANT" ]; then
193
  if [ ! -d "$VARIANTS_DIR" ]; then
194
    log_error "OS Variants directory $VARIANTS_DIR doesn't exist"
195
    exit 1
196
  fi
197
  VARIANT_CONFIG="$VARIANTS_DIR/$OS_VARIANT.conf"
198
  if [ -f "$VARIANT_CONFIG" ]; then
199
    . "$VARIANT_CONFIG"
200
  else
201
    if grep -qxF "$OS_VARIANT" variants.list; then
202
      log_error "ERROR: instance-debootstrap configuration error"
203
      log_error "  Published variant $OS_VARIANT is missing its config file"
204
      log_error "  Please create $VARIANT_CONFIG or unpublish the variant"
205
      log_error "  (by removing $OS_VARIANT from variants.list)"
206
    else
207
      log_error "Unofficial variant $OS_VARIANT is unsupported"
208
      log_error "Most probably this is a user error, forcing a wrong name"
209
      log_error "To support this variant please create file $VARIANT_CONFIG"
210
    fi
211
    exit 1
212
  fi
213
fi
214

  
b/configure.ac
1
AC_PREREQ(2.59)
2
AC_INIT(ganeti-instance-debootstrap, 0.7, ganeti@googlegroups.com)
3

  
4
AC_CONFIG_AUX_DIR(autotools)
5
AC_CONFIG_SRCDIR(configure)
6

  
7
AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability])
8

  
9
# --with-os-dir=...
10
AC_ARG_WITH([os-dir],
11
  [AS_HELP_STRING([--with-os-dir=DIR],
12
    [top-level OS directory under which to install]
13
    [ (default is $datadir/ganeti/os)]
14
  )],
15
  [os_dir="$withval"],
16
  [os_dir="$datadir/ganeti/os"])
17
AC_SUBST(OS_DIR, $os_dir)
18

  
19
# Check common programs
20
AC_PROG_INSTALL
21
AC_PROG_LN_S
22

  
23
AC_CONFIG_FILES([ Makefile ])
24

  
25
AC_OUTPUT
b/create
1
#!/bin/bash
2

  
3
# Copyright (C) 2007, 2008, 2009 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

  
20
set -e
21

  
22
. common.sh
23

  
24
if [ "$GENERATE_CACHE" = "yes" -a ! -d "$CACHE_DIR" ]; then
25
  mkdir -p "$CACHE_DIR"
26
fi
27

  
28
DPKG_ARCH=${ARCH:-`dpkg --print-architecture`}
29
CACHE_FILE="$CACHE_DIR/cache-${SUITE}-${DPKG_ARCH}.tar"
30

  
31
# If the target device is not a real block device we'll first losetup it.
32
# This is needed for file disks.
33
if [ ! -b $blockdev ]; then
34
  ORIGINAL_BLOCKDEV=$blockdev
35
  blockdev=$(losetup -sf $blockdev)
36
  CLEANUP+=("losetup -d $blockdev")
37
fi
38

  
39
if [ "$PARTITION_STYLE" = "none" ]; then
40
  filesystem_dev=$blockdev
41
elif [ "$PARTITION_STYLE" = "msdos" ]; then
42
  # Create one big partition, and make it bootable
43
  format_disk0 $blockdev
44
  filesystem_dev=$(map_disk0 $blockdev)
45
  CLEANUP+=("unmap_disk0 $blockdev")
46
else
47
  echo "Unknown partition style $PARTITION_STYLE"
48
  exit 1
49
fi
50

  
51
mke2fs -Fjq $filesystem_dev
52
root_uuid=$($VOL_ID $filesystem_dev )
53

  
54
if [ -n "$swapdev" ]; then
55
  mkswap $swapdev
56
  swap_uuid=$($VOL_ID $swapdev || true )
57
fi
58

  
59
TMPDIR=`mktemp -d` || exit 1
60
CLEANUP+=("rmdir $TMPDIR")
61

  
62
mount $filesystem_dev $TMPDIR
63
CLEANUP+=("umount $TMPDIR")
64

  
65
# remove the cache file if it's old (> 2 weeks) and writable by the owner (the
66
# default due to the standard umask)
67
if [ "$CLEAN_CACHE" -a -d "$CACHE_DIR" ]; then
68
  find "$CACHE_DIR" -name 'cache-*.tar' -type f \
69
    -daystart -mtime "+${CLEAN_CACHE}" -print0 | \
70
    xargs -r0 rm -f
71
fi
72

  
73
if [ -f "$CACHE_FILE" ]; then
74
  tar xf "$CACHE_FILE" -C $TMPDIR
75
else
76
  if [ "$PROXY" ]; then
77
    export http_proxy="$PROXY"
78
  fi
79
  # INCLUDE will be empty if EXTRA_PKGS is null/empty, otherwise we
80
  # build the full parameter format from it
81
  INCLUDE=${EXTRA_PKGS:+"--include=$EXTRA_PKGS"}
82
  debootstrap \
83
    --arch "$DPKG_ARCH" \
84
    $INCLUDE \
85
    "$SUITE" $TMPDIR $MIRROR
86

  
87
  # remove the downloaded debs, as they are no longer needed
88
  find "$TMPDIR/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
89
    xargs -r0 rm -f
90

  
91
  # remove the persistent-net rules, otherwise it will remember the node's
92
  # interfaces as eth0, eth1, ...
93
  rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules"
94

  
95
  if [ "$GENERATE_CACHE" = "yes" ]; then
96
    TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"`
97
    tar cf "$TMP_CACHE" -C $TMPDIR .
98
    mv -f "$TMP_CACHE" "$CACHE_FILE"
99
  fi
100
fi
101

  
102
cp -p /etc/hosts $TMPDIR/etc/hosts
103
cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf
104
echo $instance > $TMPDIR/etc/hostname
105
echo $instance > $TMPDIR/etc/mailname
106

  
107
cat > $TMPDIR/etc/fstab <<EOF
108
# /etc/fstab: static file system information.
109
#
110
# <file system>   <mount point>   <type>  <options>       <dump>  <pass>
111
UUID=$root_uuid   /               ext3    defaults        0       1
112
proc              /proc           proc    defaults        0       0
113
EOF
114

  
115
[ -n "$swapdev" -a -n "$swap_uuid" ] && cat >> $TMPDIR/etc/fstab <<EOF
116
UUID=$swap_uuid   swap            swap    defaults        0       0
117
EOF
118

  
119
cat > $TMPDIR/etc/network/interfaces <<EOF
120
auto lo
121
iface lo inet loopback
122
EOF
123

  
124
if [ -e $TMPDIR/etc/inittab ]; then
125
  cat $TMPDIR/etc/inittab | sed -re 's/\stty1$/ console/' \
126
    > $TMPDIR/etc/inittab.new
127
  mv $TMPDIR/etc/inittab.new $TMPDIR/etc/inittab
128
elif [ -e $TMPDIR/etc/event.d/tty1 ]; then
129
  cat $TMPDIR/etc/event.d/tty1 | sed -re 's/tty1/console/' \
130
    > $TMPDIR/etc/event.d/console
131
  rm $TMPDIR/etc/event.d/tty1
132
fi
133

  
134
RUN_PARTS=`which run-parts`
135

  
136
if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
137
  TARGET=$TMPDIR
138
  BLOCKDEV=$blockdev
139
  FSYSDEV=$filesystem_dev
140
  export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV FSYSDEV
141
  $RUN_PARTS $CUSTOMIZE_DIR
142
fi
143

  
144
# execute cleanups
145
cleanup
146
trap - EXIT
147

  
148
exit 0
b/defaults
1
# ganeti-instance-debootstrap defaults file
2

  
3
# if you want to change from the default of installing debian stable
4
# on the next instance, customize this file before the instance
5
# installation
6

  
7
# PROXY: if non-null, use this as an http-proxy in order to speed up
8
# non-cached installs; not that if not set, debootstrap might still
9
# use a system-wide proxy setting if it is exported in the
10
# ganeti-noded daemon environment
11
# PROXY="http://proxy.example.com:3128/"
12

  
13
# MIRROR: do not customize MIRROR if you want to be able to install
14
# both debian and ubuntu, since they have different defaults; or
15
# customize it before each install
16
# MIRROR="http://ftp.debian.org/debian"
17

  
18
# ARCH: define ARCH only if you want a different architecture than the
19
# current one; the known use case is to install a 32-bit instance on a
20
# 64-bit node; choose either "i386" or "amd64":
21
# ARCH="i386"
22

  
23
# SUITE: change suite to any of the ones supported by deboostrap; this
24
# could be unstable, etch, etc.:
25
# SUITE="lenny"
26

  
27
# EXTRA_PKGS: depending on the suite and architecture you are using, different
28
# extra packages are needed for different hypervisors. For example:
29
#
30
# Xen, for etch/lenny i386:
31
# EXTRA_PKGS="linux-image-xen-686,libc6-xen"
32
# Xen, for etch/lenny amd64:
33
# EXTRA_PKGS="linux-image-xen-amd64"
34
# KVM, for lenny i386:
35
# EXTRA_PKGS="acpi-support-base,console-tools,udev,linux-image-686"
36
# KVM, for lenny amd64:
37
# EXTRA_PKGS="acpi-support-base,console-tools,udev,linux-image-amd64"
38
#
39

  
40
# CUSTOMIZE_DIR: a directory containing scripts to customize the installation.
41
# The scripts are executed using run-parts
42
# By default /etc/ganeti/instance-debootstrap.d
43
# CUSTOMIZE_DIR="/etc/ganeti/instance-debootstrap.d"
44

  
45
# GENERATE_CACHE: if set to yes (the default), create new cache files;
46
# any other value will disable the generation of cache files (but they
47
# will still be used if they exist)
48
GENERATE_CACHE="yes"
49

  
50
# CLEAN_CACHE: should be set to the number of days after which to
51
# clean the cache; the default is 14 (two weeks); to disable cache
52
# cleaning, set it to an empty value ("")
53
CLEAN_CACHE="14"
54

  
55
# PARTITION_STYLE: whether and how the target device should be partitioned.
56
# Allowed values:
57
# 'none': just format the device, but don't partition it
58
# 'msdos': install an msdos partition table on the device, with a single
59
#          partition on it
60
# (more styles may be added in the future)
61
# The default is "msdos" from ganeti 2.0 onwards, but none if installing under
62
# Ganeti 1.2 (os api version 5)
63
# PARTITION_STYLE="none"
b/devel/upload
1
#!/bin/bash
2

  
3
# Copyright (C) 2006, 2007 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

  
20
# This is a test script to ease development and testing on test clusters.
21
# It should not be used to update production environments.
22

  
23
# Usage: upload node-{1,2,3}
24

  
25
set -e
26

  
27
hosts=
28
while [ "$#" -gt 0 ]; do
29
  opt="$1"
30
  case "$opt" in
31
    -h|--help)
32
      echo "Usage: $0 hosts..."
33
      exit 0
34
      ;;
35
    -*)
36
      echo "Unknown option: $opt" >&2
37
      exit 1
38
    ;;
39
    *)
40
      hosts="$hosts $opt"
41
    ;;
42
  esac
43
  shift
44
done
45

  
46
set ${hosts}
47

  
48
TXD=`mktemp -d`
49
trap 'rm -rf $TXD' EXIT
50

  
51
# install the os as a real tree
52
make install DESTDIR="$TXD"
53

  
54
echo ---
55

  
56
( cd "$TXD" && find; )
57

  
58
echo ---
59

  
60
for host; do
61
  echo Uploading code to ${host}...
62
  rsync -v -rlDc ${TXD}/* root@${host}:/ &
63
done
64
wait
65

  
b/example/instance-debootstrap.d/grub
1
#!/bin/bash
2
#
3
# This is an example script that install and configure grub after installation.
4
# To use it put it in your CUSTOMIZE_DIR, make it executable, and edit EXTRAPKGS
5
# of your $sysconfdir/default/ganeti-instance-debootstrap.
6
#
7
# Xen, for etch/lenny i386:
8
#   EXTRA_PKGS="linux-image-xen-686,libc6-xen"
9
# Xen, for etch/lenny amd64:
10
#   EXTRA_PKGS="linux-image-xen-amd64"
11
# KVM:
12
#   no extra packages needed besides the normal suggested ones
13
#
14
# Do not include grub in EXTRA_PKGS because it will cause error of debootstrap.
15

  
16
set -e
17

  
18
. common.sh
19

  
20
CLEANUP=( )
21

  
22
trap cleanup EXIT
23

  
24
if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
25
  echo "Missing target directory"
26
  exit 1
27
fi
28

  
29
# install grub
30
LANG=C
31
chroot "$TARGET" apt-get -y --force-yes install grub grub-common
32

  
33
# make /dev/sda
34
mknod $TARGET/dev/sda b $(stat -L -c "0x%t 0x%T" $BLOCKDEV)
35
CLEANUP+=("rm -f $TARGET/dev/sda")
36

  
37
# make /dev/sda1
38
mknod $TARGET/dev/sda1 b $(stat -L -c "0x%t 0x%T" $FSYSDEV)
39
CLEANUP+=("rm -f $TARGET/dev/sda1")
40

  
41
# create grub directory
42
mkdir -p "$TARGET/boot/grub"
43

  
44
# create device.map
45
cat > "$TARGET/boot/grub/device.map" <<EOF
46
(hd0) /dev/sda
47
EOF
48

  
49
# execute update-grub
50
chroot "$TARGET" update-grub
51

  
52
# install grub to the block device
53
grub-install --no-floppy --root-directory="$TARGET" "$BLOCKDEV"
54

  
55
# execute cleanups
56
cleanup
57
trap - EXIT
58

  
59
exit 0
b/example/instance-debootstrap.d/interfaces
1
#!/bin/bash
2

  
3
# Copyright (C) 2009 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

  
20
# This is an example script that configures you /etc/network/interfaces after
21
# installation.  By default its sets up the system to use dhcp. To use it just
22
# put it in your CUSTOMIZE_DIR and make it executable.
23

  
24
if [ -z "$TARGET" -o ! -d "$TARGET" ]; then
25
  echo "Missing target directory"
26
  exit 1
27
fi
28

  
29
if [ ! -d "$TARGET/etc/network" ]; then
30
  echo "Missing target network directory"
31
  exit 1
32
fi
33

  
34
if [ -z "$NIC_COUNT" ]; then
35
  echo "Missing NIC COUNT"
36
  exit 1
37
fi
38

  
39
if [ "$NIC_COUNT" -gt 0 ]; then
40

  
41
  cat > $TARGET/etc/network/interfaces <<EOF
42
# This file describes the network interfaces available on your system
43
# and how to activate them. For more information, see interfaces(5).
44

  
45
auto lo
46
iface lo inet loopback
47

  
48
auto eth0
49
iface eth0 inet dhcp
50

  
51
EOF
52

  
53
fi
b/export
1
#!/bin/bash
2

  
3
# Copyright (C) 2007, 2008, 2009 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

  
20
set -e
21

  
22
. common.sh
23

  
24
# If the target device is not a real block device we'll first losetup it.
25
# This is needed for file disks.
26
if [ ! -b $blockdev ]; then
27
  ORIGINAL_BLOCKDEV=$blockdev
28
  blockdev=$(losetup -sf $blockdev)
29
  CLEANUP+=("losetup -d $blockdev")
30
fi
31

  
32
if [ "$PARTITION_STYLE" = "none" ]; then
33
  filesystem_dev=$blockdev
34
elif [ "$PARTITION_STYLE" = "msdos" ]; then
35
  filesystem_dev=$(map_disk0 $blockdev)
36
  CLEANUP+=("unmap_disk0 $blockdev")
37
else
38
  echo "Unknown partition style $PARTITION_STYLE"
39
  exit 1
40
fi
41

  
42
vol_type=$($VOL_TYPE $filesystem_dev)
43

  
44
if [ "$vol_type" = "ext3" -o "$vol_type" = "ext2" ]; then
45
  dump -0 -q -f - "$filesystem_dev"
46
fi
47

  
48
# execute cleanups
49
cleanup
50
trap - EXIT
51

  
52
exit 0
b/ganeti_api_version
1
5
2
10
3
15
b/import
1
#!/bin/bash
2

  
3
# Copyright (C) 2007, 2008, 2009 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

  
20
set -e
21

  
22
. common.sh
23

  
24
# If the target device is not a real block device we'll first losetup it.
25
# This is needed for file disks.
26
if [ ! -b $blockdev ]; then
27
  ORIGINAL_BLOCKDEV=$blockdev
28
  blockdev=$(losetup -sf $blockdev)
29
  CLEANUP+=("losetup -d $blockdev")
30
fi
31

  
32
if [ "$PARTITION_STYLE" = "none" ]; then
33
  filesystem_dev=$blockdev
34
elif [ "$PARTITION_STYLE" = "msdos" ]; then
35
  # Create one big partition, and make it bootable
36
  format_disk0 $blockdev
37
  filesystem_dev=$(map_disk0 $blockdev)
38
  CLEANUP+=("unmap_disk0 $blockdev")
39
else
40
  echo "Unknown partition style $PARTITION_STYLE"
41
  exit 1
42
fi
43

  
44
mke2fs -Fjq $filesystem_dev
45
root_uuid=$($VOL_ID $filesystem_dev )
46

  
47
if [ -n "$swapdev" ]; then
48
  mkswap $swapdev
49
  swap_uuid=$($VOL_ID $swapdev || true )
50
fi
51

  
52
TMPDIR=`mktemp -d` || exit 1
53
CLEANUP+=("rmdir $TMPDIR")
54

  
55
mount $filesystem_dev $TMPDIR
56
CLEANUP+=("umount $TMPDIR")
57

  
58
( cd $TMPDIR; restore -r -y -f - )
59
rm -f $TMPDIR/etc/udev/rules.d/z*_persistent-net.rules
60

  
61
# Fix /etc/fstab with the new volumes' UUIDs
62
if [ -e $TMPDIR/etc/fstab ]; then
63
  ROOT_LINE="UUID=$root_uuid  /     ext3  defaults  0  1"
64
  if [ -n "$swapdev" -a -n "$swap_uuid" ]; then
65
    SWAP_LINE="UUID=$swap_uuid  swap  swap  defaults  0  0"
66
    cat $TMPDIR/etc/fstab | \
67
      sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
68
          -e "s#^(/dev/sdb|UUID=[a-f0-9-]+)\s+swap\s+.*\$#$SWAP_LINE#" \
69
      > $TMPDIR/etc/fstab.new
70
  else
71
    cat $TMPDIR/etc/fstab | \
72
      sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
73
      > $TMPDIR/etc/fstab.new
74
  fi
75
  mv $TMPDIR/etc/fstab.new  $TMPDIR/etc/fstab
76
fi
77

  
78
# execute cleanups
79
cleanup
80
trap - EXIT
81

  
82
exit 0
b/rename
1
#!/bin/bash
2

  
3
# Copyright (C) 2007, 2008, 2009 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff