<div dir="ltr">Done<div><br></div><div><div>diff --git a/PVE/API2/OpenVZ.pm b/PVE/API2/OpenVZ.pm</div><div>index 06fe60b..eeba1a2 100644</div><div>--- a/PVE/API2/OpenVZ.pm</div><div>+++ b/PVE/API2/OpenVZ.pm</div><div>@@ -413,7 +413,7 @@ __PACKAGE__->register_method({</div>
<div> <span class="" style="white-space:pre"> </span></div><div> <span class="" style="white-space:pre"> </span># hack: vzctl '--userpasswd' starts the CT, but we want </div><div> <span class="" style="white-space:pre"> </span># to avoid that for create</div>
<div>-<span class="" style="white-space:pre"> </span>PVE::OpenVZ::set_rootpasswd($private, $password) </div><div>+<span class="" style="white-space:pre"> </span>PVE::OpenVZ::set_rootpasswd($private, $password, $vmid) </div>
<div> <span class="" style="white-space:pre"> </span> if defined($password);</div><div> <span class="" style="white-space:pre"> </span> }</div><div> </div></div><div><br></div><div><br></div><div><div>diff --git a/PVE/OpenVZ.pm b/PVE/OpenVZ.pm</div>
<div>index a16d4fc..ea0717f 100644</div><div>--- a/PVE/OpenVZ.pm</div><div>+++ b/PVE/OpenVZ.pm</div><div>@@ -1243,24 +1243,55 @@ sub replacepw {</div><div> }<span class="" style="white-space:pre"> </span></div><div> }</div>
<div> </div><div>+sub ploop_mount {</div><div>+ my ($rootdisk, $vmid) = @_;</div><div>+<span class="" style="white-space:pre"> </span>my $fstype = "ext4";</div><div>+<span class="" style="white-space:pre"> </span>my $tmpdir = "/tmp/$vmid";</div>
<div>+ if (-f $rootdisk) {</div><div>+ #create tmp dir</div><div>+ mkdir $tmpdir;</div><div>+<span class="" style="white-space:pre"> </span>#mount image to tmpdir</div><div>+ my $cmd = ['/usr/sbin/ploop', 'mount', '-t', $fstype, '-m', $tmpdir, $rootdisk];</div>
<div>+ eval { PVE::Tools::run_command($cmd); };</div><div>+ my $err = $?;</div><div>+ die "cannot mount $rootdisk" if ($err ne 0);</div><div>+ return $tmpdir;</div><div>+ }</div><div>
+}</div><div>+</div><div>+sub ploop_umount {</div><div>+ my $ploopdisk = shift;</div><div>+ my $cmd = ['/usr/sbin/ploop', 'umount', $ploopdisk];</div><div>+ eval { PVE::Tools::run_command($cmd); };</div>
<div>+ my $err = $?;</div><div>+ die "cannot umount $ploopdisk" if ($err ne 0);</div><div>+}</div><div>+</div><div> sub set_rootpasswd {</div><div>- my ($privatedir, $opt_rootpasswd) = @_;</div>
<div>+ my ($privatedir, $opt_rootpasswd, $vmid) = @_;</div><div>+</div><div>+ my $rootdisk = "$privatedir/root.hdd/root.hdd";</div><div>+ my ($pwfile, $shadow, $tmpdir);</div><div> </div><div>- my $pwfile = "$privatedir/etc/passwd";</div>
<div>+ $tmpdir = ploop_mount($rootdisk, $vmid) if (-f $rootdisk);</div><div>+ $privatedir = $tmpdir if defined($tmpdir);</div><div>+</div><div>+ $pwfile = "$privatedir/etc/passwd";</div><div> </div><div>
return if ! -f $pwfile;</div><div> </div><div>- my $shadow = "$privatedir/etc/shadow";</div><div>+ $shadow = "$privatedir/etc/shadow";</div><div> </div><div> if ($opt_rootpasswd !~ m/^\$/) {</div>
<div>-<span class="" style="white-space:pre"> </span>my $time = substr (Digest::SHA::sha1_base64 (time), 0, 8);</div><div>-<span class="" style="white-space:pre"> </span>$opt_rootpasswd = crypt(encode("utf8", $opt_rootpasswd), "\$1\$$time\$");</div>
<div>+ my $time = substr (Digest::SHA::sha1_base64 (time), 0, 8);</div><div>+ $opt_rootpasswd = crypt(encode("utf8", $opt_rootpasswd), "\$1\$$time\$");</div><div> };</div>
<div> </div><div> if (-f $shadow) {</div><div>-<span class="" style="white-space:pre"> </span>replacepw ($shadow, $opt_rootpasswd);</div><div>-<span class="" style="white-space:pre"> </span>replacepw ($pwfile, 'x');</div>
<div>+ replacepw ($shadow, $opt_rootpasswd);</div><div>+ replacepw ($pwfile, 'x');</div><div> } else {</div><div>-<span class="" style="white-space:pre"> </span>replacepw ($pwfile, $opt_rootpasswd);</div>
<div>+ replacepw ($pwfile, $opt_rootpasswd);</div><div> }</div><div>-}</div><div>+ ploop_umount($rootdisk) if (-f $rootdisk);</div><div>+}</div><div>\ No newline at end of file</div></div><div><br></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 25, 2013 at 11:44 AM, Dietmar Maurer <span dir="ltr"><<a href="mailto:dietmar@proxmox.com" target="_blank">dietmar@proxmox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">> Previous solution work only with simfs.<br>
> If we use ploop, we need to mount VM image and then change password.<br>
><br>
> Why we can't solve this with simple, built-in solution?<br>
<br>
</div>Because that made many troubles. Starting a container at create stage<br>
is really unexpected and not what we want to do (for example many prebuild<br>
appliances do special things a first boot).<br>
<br>
But maybe you can find another solution, i.e. mount ploop first?<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>С уважением, Шестаков Игорь<br>Сеть дата-центров "Селектел"
</div>