Migrate VM to AWS

最後更新: 2021-04-27

目錄

 


Linux VM

 

# Checking NIC

modinfo ena

modinfo: ERROR: Module ena not found.

OR

filename:       /lib/modules/3.10.0-1127.19.1.el7.x86_64/
                kernel/drivers/net/ethernet/amazon/ena/ena.ko.xz
version:        2.0.3K
...

# OS Support

# Ubuntu

# Ubuntu 16.04 and 18.04 ship with the Ubuntu custom kernel (linux-aws kernel package)

# The latest Ubuntu HVM AMIs include the module required for enhanced networking with ENA installed and have ENA support enabled.

apt-get update

apt-get upgrade linux-aws

reboot

apt-get purge linux-image-generic linux-image-*-generic

# CentOS

RHEL 7.4 and later come preinstalled with the module needed for enhanced networking with ENA.

 

 


Centos 7

 

1) Kernel Module

modprobe ena

echo ena > /etc/modules-load.d/ena.conf

2) NIC Name

[grub2]

/etc/default/grub

GRUB_CMDLINE_LINUX='... net.ifnames=0'

grub2-mkconfig -o /boot/grub2/grub.cfg

3) NIC DHCP

/etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

 


Ubuntu 16

 

apt-get install linux-headers-generic

apt-get install -y build-essential dkms

wget https://github.com/amzn/amzn-drivers/archive/ena_linux_2.2.11.zip

unzip ena_linux_2.2.11.zip

mv amzn-drivers-ena_linux_2.2.11 amzn-drivers-2.2.11

vim amzn-drivers-2.2.11/dkms.conf

PACKAGE_NAME="ena"
PACKAGE_VERSION="2.2.11"
CLEAN="make -C kernel/linux/ena clean"
MAKE="make -C kernel/linux/ena/ BUILD_KERNEL=${kernelver}"
BUILT_MODULE_NAME[0]="ena"
BUILT_MODULE_LOCATION="kernel/linux/ena"
DEST_MODULE_LOCATION[0]="/updates"
DEST_MODULE_NAME[0]="ena"
AUTOINSTALL="yes"

# Add the module to DKMS

dkms add -m amzn-drivers -v 2.2.11

Creating symlink /var/lib/dkms/amzn-drivers/2.2.11/source ->
                 /usr/src/amzn-drivers-2.2.11

DKMS: add completed.

# Build the module using the dkms

dkms build -m amzn-drivers -v 2.2.11

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area....
make KERNELRELEASE=4.4.0-197-generic -C kernel/linux/ena/ BUILD_KERNEL=4.4.0-197-generic.....
cleaning build area....

DKMS: build completed.

# Install the module using dkms.

dkms install -m amzn-drivers -v 2.2.11

ena:
Running module version sanity check.
 - Original module
 - Installation
   - Installing to /lib/modules/4.4.0-197-generic/updates/dkms/

# Rebuild initramfs so the correct module is loaded at boot time.

update-initramfs -u -k all

update-initramfs: Generating /boot/initrd.img-4.4.0-197-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.

# Verify the ena module is installed

modinfo ena

filename:       /lib/modules/4.4.0-197-generic/updates/dkms/ena.ko
version:        2.2.11g
license:        GPL
description:    Elastic Network Adapter (ENA)
author:         Amazon.com, Inc. or its affiliates
srcversion:     17C7CD1CEAD3F0ADB3A5E5E
...

# 改 OS 用 eth0

/etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0"

update-grub

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-197-generic
Found initrd image: /boot/initrd.img-4.4.0-197-generic
done

/etc/network/interfaces

auto eth0
iface eth0 inet dhcp

 


Centos 6

 

------------------ Step 1: compile driver

yum groupinstall -y "Development Tools"

yum install kernel-devel-$(uname -r) 

Remark

yum install kernel-devel

cd /lib/modules/2.6.32-696.3.1.el6.x86_64

ln -s /usr/src/kernels/2.6.32-696.el6.x86_64/ build

mkdir /usr/src/ena

mkdir /usr/src/ena; cd /usr/src/ena

# 788K

wget https://github.com/amzn/amzn-drivers/archive/refs/tags/ena_linux_2.4.1.zip

cd amzn-drivers-ena_linux_2.4.1/kernel/linux/ena

make -j

cp ena.ko /lib/modules/$(uname -r)/

depmod

modprobe ena

lsmod | grep ena

echo '#!/bin/sh
/sbin/modprobe ena' >> /etc/sysconfig/modules/ena.modules

chmod 755 /etc/sysconfig/modules/ena.modules

dracut -f -v                # Update initramfs

------------------ Step 2: Disable predictable network interface names

[grub1]

/boot/grub/grub.conf

kernel ... net.ifnames=0

------------------ Step 3

If your instance operating system contains an /etc/udev/rules.d/70-persistent-net.rules file,

you must delete it before creating the AMI.

原因:

This file contains the MAC address for the Ethernet adapter of the original instance.

If another instance boots with this file, the operating system will be unable to find the device and

eth0 might fail, causing boot issues.

This file is regenerated at the next boot cycle,

and any instances launched from the AMI create their own version of the file.

------------------

Configure the Dynamic Kernel Module Support (DKMS) program to make sure that the driver is included during future kernel upgrades

yum install dkms -y

...