]>
git.proxmox.com Git - pve-container.git/blob - src/lxc-pve
12 use PVE
::RPCEnvironment
;
13 use PVE
::JSONSchema
qw(get_standard_option);
19 use base
qw(PVE::CLIHandler);
21 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
25 die "please run as root\n" if $> != 0;
28 PVE
::INotify
::inotify_init
();
30 my $rpcenv = PVE
::RPCEnvironment-
>init('cli');
31 $rpcenv->set_language($ENV{LANG
});
32 $rpcenv->set_user('root@pam');
34 my $nodename = PVE
::INotify
::nodename
();
36 __PACKAGE__-
>register_method ({
40 description
=> "Create a new container root directory.",
42 additionalProperties
=> 0,
44 name
=> get_standard_option
('pve-vmid'),
46 description
=> "The path to the container configuration directory (LXC internal argument - do not pass manually!).",
50 description
=> "The path to the container's rootfs (LXC internal argument - do not pass manually!)",
53 storage
=> get_standard_option
('pve-storage-id'),
55 description
=> " A uid map (user namespaces - LXC internal argument - do not pass manually!)",
60 description
=> " A gid map (user namespaces - LXC internal argument - do not pass manually!)",
66 returns
=> { type
=> 'null' },
71 # check that we have all variables we need
72 if (!(defined($ENV{LXC_NAME
}) && defined($ENV{LXC_PATH
}) && defined($ENV{LXC_ROOTFS
}))) {
73 die "ERROR: Not running through LXC.\n"
76 # only orinial user can access /etc/pve
77 $< = $param->{'mapped-uid'} if defined($param->{'mapped-uid'});
78 $( = $param->{'mapped-gid'} if defined($param->{'mapped-gid'});
80 my $userns = defined($param->{'mapped-uid'}) ?
1 : 0;
82 my $private = $param->{rootfs
};
84 die "got strange path '$param->{path}'\n"
85 if $param->{path
} !~ m!^/etc/pve/lxc/$param->{name}/?$!;
87 # print "TEST $< $(\n";
89 $rpcenv->init_request();
93 my $conf = PVE
::LXC
::load_config
($param->{name
});
96 my $storage_cfg = PVE
::Cluster
::cfs_read_file
("storage.cfg");
98 my $ostemplate = "local:vztmpl/debian-7.0-standard_7.0-2_i386.tar.gz";
99 print "Template: $ostemplate\n";
101 my $archive = PVE
::Storage
::abs_filesystem_path
($storage_cfg, $ostemplate);
103 #$< = $( = 0; # switch back to container root
104 #print "TEST $< $(\n";
106 my $cmd = ['tar', 'xpf', $archive, '--numeric-owner', '--totals', '--sparse', '-C', $private];
107 push @$cmd, '--anchored';
108 push @$cmd, '--exclude' , '/dev/*';
109 # push @$cmd, '--exclude' , '/dev/loop*';
110 # push @$cmd, '--exclude' , '/dev/ram*';
111 # push @$cmd, '--exclude' , '/dev/pty*';
112 # push @$cmd, '--exclude' , '/dev/tty*';
113 # push @$cmd, '--exclude' , '/dev/pty*';
114 # push @$cmd, '--exclude' , '/dev/null';
115 # push @$cmd, '--exclude' , '/dev/random';
116 # push @$cmd, '--exclude' , '/dev/urandom';
117 # push @$cmd, '--exclude' , '/dev/console';
118 # push @$cmd, '--exclude' , '/dev/zero';
119 # push @$cmd, '--exclude' , '/dev/ptmx';
120 # push @$cmd, '--exclude' , '/dev/port';
121 # push @$cmd, '--exclude' , '/dev/mem';
122 # push @$cmd, '--exclude' , '/dev/kmem';
123 # push @$cmd, '--exclude' , '/dev/full';
125 print "extracting archive '$archive' to '$private'\n";
126 PVE
::Tools
::run_command
($cmd);
128 File
::Path
::make_path
("$private/dev/pts");
130 # template/OS specific configuration
131 $conf->{'lxc.arch'} = 'i386'; # || x86_64
133 $conf->{'lxc.include'} = "/usr/share/lxc/config/debian.common.conf";
136 die "also include me";
137 $conf->{'lxc.include'} = "/usr/share/lxc/config/debian.userns.conf";
140 PVE
::LXC
::write_config
($param->{name
}, $conf);
145 my $cmddef = [ __PACKAGE__
, 'lxc-pve' ];
147 push @ARGV, 'help' if !scalar(@ARGV);
149 PVE
::CLIHandler
::handle_simple_cmd
($cmddef, \
@ARGV, undef, $0);
157 lxc-pve - create containers from Proxmox VE templates
165 This script creates containers from Proxmox VE templates. This is always
166 called from within lxc-create, so please do not try to use this directly.
173 =include pve_copyright