[pve-devel] [PATCH pve-container 2/2] enable emulation of containers using qemu-user-static
Wolfgang Bumiller
w.bumiller at proxmox.com
Mon Sep 17 13:53:48 CEST 2018
On Mon, Sep 17, 2018 at 01:41:38PM +0200, Dietmar Maurer wrote:
> You need to install package qemu-user-static which provides
> the emulation toolkit.
>
> - emulate arm on x86
> - emulate x86 on arm
>
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
> src/PVE/LXC/Setup.pm | 40 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
>
> diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
> index 1b89f28..7b4016b 100644
> --- a/src/PVE/LXC/Setup.pm
> +++ b/src/PVE/LXC/Setup.pm
> @@ -280,12 +280,52 @@ sub rewrite_ssh_host_keys {
> $self->protected_call($code);
> }
>
> +my $get_host_arch = sub {
> +
> + my @uname = POSIX::uname();
> + my $machine = uname[4];
Missing a $ here, perl should ... curiously be printing a "usage" error
here at runtime...
> +
> + if ($machine eq 'x86_64') {
> + return 'amd64';
> + } elsif ($machine eq 'aarch64') {
> + return 'arm64';
> + } else {
> + die "unsupported host architecture '$machine'\n";
> + }
> +};
> +
> +my $container_emulator_path = {
> + 'amd64' => '/usr/bin/qemu-x86_64-static',
> + 'arm64' => '/usr/bin/qemu-aarch64-static',
> +};
> +
> sub pre_start_hook {
> my ($self) = @_;
>
> return if !$self->{plugin}; # unmanaged
>
> + my $host_arch = $get_host_arch->();
> +
> + my $container_arch = $self->{conf}->{arch};
> +
> + $container_arch = 'amd64' if $container_arch eq 'i386'; # always use 64 bit version
> + $container_arch = 'amd64' if $container_arch eq 'armhf'; # always use 64 bit version
You used 'amd64' in both cases.
> +
> + my $emul;
> + my $emul_data;
> +
> + if ($host_arch ne $container_arch) {
> + if ($emul = $container_emulator_path->{$container_arch}) {
> + $emul_data = PVE::Tools::file_get_contents($emul, 10*1024*1024) if -f $emul;
> + }
> + }
> +
> my $code = sub {
> +
> + if ($emul && $emul_data) {
> + $self->{plugin}->ct_file_set_contents($emul, $emul_data, 0755);
> + }
> +
> # Create /fastboot to skip run fsck
> $self->{plugin}->ct_file_set_contents('/fastboot', '');
>
> --
> 2.11.0
More information about the pve-devel
mailing list