/usr/bin/xen-create-nfs is in xen-tools 4.4-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | #!/usr/bin/perl -w
=encoding utf8
=head1 NAME
xen-create-nfs - Create a Xen configuration file for an NFS-root guest.
=head1 SYNOPSIS
xen-create-nfs [options]
Help Options:
--help Show help information.
--manual Read the manual for this script.
--version Show the version information and exit.
--verbose Show diagnostic output.
Networking Options:
--broadcast The broadcast address to use when configured with a static IP.
--dhcp Configure the guest to use DHCP for IP allocation.
--gateway The gateway address to use when configured with a static IP.
--hostname The hostname to configure for the guest.
--ip The IP address to use when configured with a static IP.
--netmask The netmask to use when configured with a static IP.
--nameserver The nameserver to use when configured with a static IP.
General options:
--admins Specify which users should be setup as xen-shell admins.
--force Force the overwriting of an existing configuration file.
--initrd Specify the initial ramdisk for the guest.
--kernel Specify the kernel to use for the guest.
--memory Specify the memory to allocate for this guest.
--mac Specify the MAC address to use for the guest.
--template Specify an alternative template file to use.
NFS options:
--nfs_server Specify the NFS server to mount the root partition from.
--nfs_root Specify the path, upon the NFS server, to mount.
=head1 OPTIONS
=over 8
=item B<--help>
Show help information.
=item B<--hostname>
Specify the hostname to delete.
=item B<--manual>
Read the manual for this script.
=item B<--version>
Show the version number and exit.
=back
=head1 DESCRIPTION
xen-create-nfs is a simple script which allows you to easily create
a single configuration file for a Xen guest which will mount its remote
filesystem over an NFS root.
It doesn't create any images to use for local storage, and it doesn't
support more than the minimal number of options to completement the
existing xen-create-image script, however it is hopefully useful.
=head1 REFERENCE
For more details on what you'll need to support NFS-root Xen guests
the following article, written by the author, might be useful:
http://www.debian-administration.org/articles/505
=head1 AUTHORS
Steve Kemp, http://www.steve.org.uk/
Stéphane Jourdois
=head1 LICENSE
Copyright (c) 2005-2009 by Steve Kemp, (c) 2010 by The Xen-Tools
Development Team. All rights reserved.
This module is free software;
you can redistribute it and/or modify it under
the same terms as Perl itself.
The LICENSE file contains the full text of the license.
=cut
use strict;
use English;
use Env;
use Getopt::Long;
use Pod::Usage;
use Text::Template;
use Xen::Tools::Common;
#
# Configuration values read from the command line.
#
# We do not need to read any configuration file.
#
my %CONFIG;
#
# Default options
#
$CONFIG{ 'template' } = '/etc/xen-tools/xm-nfs.tmpl';
#
# Release number.
#
my $RELEASE = '4.4';
# store version number away.
$CONFIG{ 'xen_tools_version' } = $RELEASE;
#
# Read the global configuration file.
#
readConfigurationFile("/etc/xen-tools/xen-tools.conf", \%CONFIG);
#
# Parse the command line arguments.
#
parseCommandLineArguments();
#
# Validate our arguments.
#
testArguments();
#
# Create the image.
#
if ( -e "/etc/xen/$CONFIG{'hostname'}.cfg" )
{
die "Configuration file for $CONFIG{'hostname'} already exists"
unless ( $CONFIG{ 'force' } );
}
#
# If we've been given any administrators then set them up.
#
if ( $CONFIG{ 'admins' } )
{
setupAdminUsers(\%CONFIG);
}
#
# Now create the NFS configuration file.
#
createNewConfigurationFile();
#
# All done.
#
exit;
=begin doc
Parse the command line arguments this script was given.
=end doc
=cut
sub parseCommandLineArguments
{
my $HELP = 0;
my $MANUAL = 0;
my $VERSION = 0;
#
# Parse options.
#
GetOptions(
# Networking options
"dhcp", \$CONFIG{ 'dhcp' },
"gateway=s", \$CONFIG{ 'gateway' },
"broadcast=s", \$CONFIG{ 'broadcast' },
"ip=s", \$CONFIG{ 'ip' },
"netmask=s", \$CONFIG{ 'netmask' },
"nameserver=s", \$CONFIG{ 'nameserver' },
"hostname=s", \$CONFIG{ 'hostname' },
"memory=s", \$CONFIG{ 'memory' },
"mac=s", \$CONFIG{ 'mac' },
# NFS options.
"nfs_server=s", \$CONFIG{ 'nfs_server' },
"nfs_root=s", \$CONFIG{ 'nfs_root' },
# Misc. options
"admins=s", \$CONFIG{ 'admins' },
"kernel=s", \$CONFIG{ 'kernel' },
"initrd=s", \$CONFIG{ 'initrd' },
"force", \$CONFIG{ 'force' },
"template=s", \$CONFIG{ 'template' },
# Help options
"help", \$HELP,
"manual", \$MANUAL,
"verbose", \$CONFIG{ 'verbose' },
"version", \$VERSION
);
pod2usage(1) if $HELP;
pod2usage( -verbose => 2 ) if $MANUAL;
if ($VERSION)
{
logprint("xen-create-nfs release $RELEASE\n");
exit;
}
}
=begin doc
Test that our arguments make sense.
=end doc
=cut
sub testArguments
{
#
# Hostname is mandatory
#
die "No hostname" unless ( $CONFIG{ 'hostname' } );
my @network = qw/ ip gateway netmask /;
#
# If DHCP then all the other options aren't needed
#
if ( $CONFIG{ 'dhcp' } )
{
foreach my $f (@network)
{
delete( $CONFIG{ $f } );
}
}
else
{
foreach my $f (@network)
{
die "Missing --$f" unless ( $CONFIG{ $f } );
}
}
#
# We need an NFS server + root
#
die "Missing NFS server." unless ( $CONFIG{ 'nfs_server' } );
die "Missing NFS root." unless ( $CONFIG{ 'nfs_root' } );
# Shorthack to fix http://bugs.debian.org/648814 -- xen-create-nfs
# should better use xt-create-xen-config instead. Guess from where
# this code is borrowed for now...
if ( exists($CONFIG{ 'memory' }) and
defined($CONFIG{ 'memory' }) ) {
#
# The memory size: Convert Gb -> Mb.
#
if ( $CONFIG{ 'memory' } =~ /^(\d+)Gb.*$/i )
{
$CONFIG{ 'memory' } = $1 * 1024;
}
#
# Remove any trailing Mb.
#
if ( $CONFIG{ 'memory' } =~ /^(\d+)Mb.*$/i )
{
$CONFIG{ 'memory' } = $1;
}
}
# All OK.
}
=begin doc
Create the Xen configuration file for our new Xen guest.
=end doc
=cut
sub createNewConfigurationFile
{
die "Template file missing: $CONFIG{'template'}"
unless ( -e $CONFIG{ 'template' } );
#
# Load the template.
#
my $template = new Text::Template( TYPE => 'FILE',
SOURCE => $CONFIG{ 'template' } );
my $result = $template->fill_in( HASH => \%CONFIG );
#
# The file we'll write to.
#
my $file = "/etc/xen/$CONFIG{'hostname'}.cfg";
#
# Output the configuration file.
#
open( FILE, ">", $file ) or die "Failed to write to $file - $!";
print FILE $result;
close(FILE);
}
|