Packer EBS构建器的KernelId

时间:2017-04-28 00:07:15

标签: amazon-ecs packer

有没有办法设置内核ID以用于Packer EBS构建器?

我正在尝试为安装了NVIDIA驱动程序的ECS(弹性容器服务)构建AMI(亚马逊机器映像),以便我可以在容器内运行GPU任务。

这是我的Packer文件:

{
  "variables": {
    "aws_access_key": "",
    "aws_secret_key": "",
    "region": "us-west-2",

    "ami": "ami-62d35c02",
    "ami_arch": "x86_64",

    "nvidia_release": "367.57"
  },
  "builders": [
    {
      "type": "amazon-ebs",
      "access_key": "{{ user `aws_access_key` }}",
      "secret_key": "{{ user `aws_secret_key` }}",
      "region": "{{ user `region` }}",
      "source_ami": "{{ user `ami` }}",
      "instance_type": "g2.2xlarge",
      "ssh_username": "ec2-user",
      "ami_name": "ecs-machine-image",
      "user_data": "#cloud-config\nrepo_releasever: 2016.09"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "sudo yum update -y",
        "sudo yum groupinstall -y \"Development Tools\"",
        "sudo yum install -y kernel-devel-$(uname -r)",
        "cd /tmp",
        "curl -L -O http://us.download.nvidia.com/XFree86/Linux-{{ user `ami_arch` }}/{{ user `nvidia_release` }}/NVIDIA-Linux-{{ user `ami_arch` }}-{{ user `nvidia_release` }}.run",
        "chmod +x NVIDIA-Linux-{{ user `ami_arch` }}-{{ user `nvidia_release` }}.run",
        "echo `uname -a`",
        "sudo sh -c \"./NVIDIA-Linux-{{ user `ami_arch` }}-{{ user `nvidia_release` }}.run -silent\""
      ]
    }
  ]
}

这构建很好,但是回显内核版本的行(即uname -r)表明打包器构建器正在运行内核为4.4.51-40.58的计算机。但是,当我使用此AMI通过AWS控制台启动实例时,我看到该实例正在运行内核4.9.20-11.31,因此无法找到内核模块nvidia,如果我运行find 1}}存在于/lib/modules/4.4.51-40.58/...内。

我尝试让Packer使用以下内容暂存/boot/grub/menu.lst文件:

# created by imagebuilder
default=0
timeout=0
hiddenmenu

title Amazon Linux 2016.09 (4.4.51-40.58.amzn1.x86_64)
root (hd0,0)
kernel /boot/vmlinuz-4.4.51-40.58.amzn1.x86_64 root=LABEL=/ 
console=tty1 console=ttyS0
initrd /boot/initramfs-4.4.51-40.58.amzn1.x86_64.img

通过此更改,我再次启动一个实例,但它正在运行4.4.51-40.60,而不是4.4.51-40.58,并且menu.lst中有一个我没有指定的相应额外条目

将内核模块构建为Packer EBS映像,因为我正在尝试反模式,或者我错过了什么?

1 个答案:

答案 0 :(得分:1)

g2.2xlarge HVM 内核ID 仅对 PV 实例有效。

相反,问题在于:

sudo yum update -y

将安装将在下次启动时使用的新内核。但是,然后为当前运行的内核安装Nvidia驱动程序。

curl -L -O http://us.download.nvidia.com/XFree86/Linux-{{ user `ami_arch` }}/{{ user `nvidia_release` }}/NVIDIA-Linux-{{ user `ami_arch` }}-{{ user `nvidia_release` }}.run
chmod +x NVIDIA-Linux-{{ user `ami_arch` }}-{{ user `nvidia_release` }}.run
echo `uname -a`
sudo sh -c "./NVIDIA-Linux-{{ user `ami_arch` }}-{{ user `nvidia_release` }}.run -silent"

如果您不更新内核,或者为新内核显式构建模块,我希望它能正常工作。