<div dir="ltr">Yes, it is. But later we can use ploop_mount for other purposes. Such as: changing fs type, create partition etc.<div>And if we use "vzctl mount", we must pass "VE_ROOT" to function.</div>
<div><br></div><div>Of course, we can use "vzctl mount", but then functionset_rootpasswd must be rewrited to use "vzctl mount" for simfs too.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Oct 25, 2013 at 7:25 PM, 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">
Sorry if this is a stupid question, but does 'vzctl mount' does not work with ploop?<br>
<div class="HOEnZb"><div class="h5"><br>
> -----Original Message-----<br>
> From: ้วฯาุ ๛ลำิมหฯื [mailto:<a href="mailto:shine@selectel.ru">shine@selectel.ru</a>]<br>
> Sent: Freitag, 25. Oktober 2013 15:37<br>
> To: Dietmar Maurer<br>
> Cc: pve-devel<br>
> Subject: Re: [pve-devel] [PATCH][pve-manager] Changes set_userpasswd<br>
> method<br>
><br>
> Done<br>
><br>
> diff --git a/PVE/API2/OpenVZ.pm b/PVE/API2/OpenVZ.pm<br>
> index 06fe60b..eeba1a2 100644<br>
> --- a/PVE/API2/OpenVZ.pm<br>
> +++ b/PVE/API2/OpenVZ.pm<br>
> @@ -413,7 +413,7 @@ __PACKAGE__->register_method({<br>
><br>
> # hack: vzctl '--userpasswd' starts the CT, but we want<br>
> # to avoid that for create<br>
> - PVE::OpenVZ::set_rootpasswd($private, $password)<br>
> + PVE::OpenVZ::set_rootpasswd($private, $password, $vmid)<br>
> if defined($password);<br>
> }<br>
><br>
><br>
><br>
> diff --git a/PVE/OpenVZ.pm b/PVE/OpenVZ.pm<br>
> index a16d4fc..ea0717f 100644<br>
> --- a/PVE/OpenVZ.pm<br>
> +++ b/PVE/OpenVZ.pm<br>
> @@ -1243,24 +1243,55 @@ sub replacepw {<br>
> }<br>
> }<br>
><br>
> +sub ploop_mount {<br>
> + my ($rootdisk, $vmid) = @_;<br>
> + my $fstype = "ext4";<br>
> + my $tmpdir = "/tmp/$vmid";<br>
> + if (-f $rootdisk) {<br>
> + #create tmp dir<br>
> + mkdir $tmpdir;<br>
> + #mount image to tmpdir<br>
> + my $cmd = ['/usr/sbin/ploop', 'mount', '-t', $fstype, '-m', $tmpdir,<br>
> $rootdisk];<br>
> + eval { PVE::Tools::run_command($cmd); };<br>
> + my $err = $?;<br>
> + die "cannot mount $rootdisk" if ($err ne 0);<br>
> + return $tmpdir;<br>
> + }<br>
> +}<br>
> +<br>
> +sub ploop_umount {<br>
> + my $ploopdisk = shift;<br>
> + my $cmd = ['/usr/sbin/ploop', 'umount', $ploopdisk];<br>
> + eval { PVE::Tools::run_command($cmd); };<br>
> + my $err = $?;<br>
> + die "cannot umount $ploopdisk" if ($err ne 0);<br>
> +}<br>
> +<br>
> sub set_rootpasswd {<br>
> - my ($privatedir, $opt_rootpasswd) = @_;<br>
> + my ($privatedir, $opt_rootpasswd, $vmid) = @_;<br>
> +<br>
> + my $rootdisk = "$privatedir/root.hdd/root.hdd";<br>
> + my ($pwfile, $shadow, $tmpdir);<br>
><br>
> - my $pwfile = "$privatedir/etc/passwd";<br>
> + $tmpdir = ploop_mount($rootdisk, $vmid) if (-f $rootdisk);<br>
> + $privatedir = $tmpdir if defined($tmpdir);<br>
> +<br>
> + $pwfile = "$privatedir/etc/passwd";<br>
><br>
> return if ! -f $pwfile;<br>
><br>
> - my $shadow = "$privatedir/etc/shadow";<br>
> + $shadow = "$privatedir/etc/shadow";<br>
><br>
> if ($opt_rootpasswd !~ m/^\$/) {<br>
> - my $time = substr (Digest::SHA::sha1_base64 (time), 0, 8);<br>
> - $opt_rootpasswd = crypt(encode("utf8", $opt_rootpasswd),<br>
> "\$1\$$time\$");<br>
> + my $time = substr (Digest::SHA::sha1_base64 (time), 0, 8);<br>
> + $opt_rootpasswd = crypt(encode("utf8", $opt_rootpasswd),<br>
> "\$1\$$time\$");<br>
> };<br>
><br>
> if (-f $shadow) {<br>
> - replacepw ($shadow, $opt_rootpasswd);<br>
> - replacepw ($pwfile, 'x');<br>
> + replacepw ($shadow, $opt_rootpasswd);<br>
> + replacepw ($pwfile, 'x');<br>
> } else {<br>
> - replacepw ($pwfile, $opt_rootpasswd);<br>
> + replacepw ($pwfile, $opt_rootpasswd);<br>
> }<br>
> -}<br>
> + ploop_umount($rootdisk) if (-f $rootdisk);<br>
> +}<br>
> \ No newline at end of file<br>
><br>
><br>
> On Fri, Oct 25, 2013 at 11:44 AM, Dietmar Maurer <<a href="mailto:dietmar@proxmox.com">dietmar@proxmox.com</a>><br>
> wrote:<br>
> > 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>
> 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>
><br>
><br>
><br>
> --<br>
> ๓ ีืมึลฮษลอ, ๛ลำิมหฯื ้วฯาุ<br>
> ๓ลิุ ฤมิม-รลฮิาฯื "๓ลฬลหิลฬ"<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>๓ ีืมึลฮษลอ, ๛ลำิมหฯื ้วฯาุ<br>๓ลิุ ฤมิม-รลฮิาฯื "๓ลฬลหิลฬ"
</div>