Before using a KVM ECS to create a private image, you need to install native KVM drivers on the ECS. If the drivers have been installed, skip this section.
If you do not install KVM drivers, NICs of the ECS may not be detected and the ECS cannot communicate with other resources.
If the root filesystem is mounted by initramfs, run the following command:
lsinitrd /boot/initramfs-`uname -r`.img | grep virtio
If the root filesystem is mounted by initrd, run the following command:
lsinitrd /boot/initrd-`uname -r` | grep virtio
lsinitramfs /boot/initrd.img-`uname -r` |grep virtio
lsinitrd /boot/initrd-`uname -r` | grep virtio
If the root filesystem is mounted by initramfs, run the following command:
lsinitrd /boot/initramfs-`uname -r`.img | grep virtio
If the root filesystem is mounted by initrd, run the following command:
lsinitrd /boot/initrd-`uname -r` | grep virtio
If VirtIO drivers have been installed, skip this section.

If VirtIO drivers have not been installed, install them as instructed in this section.
Modify the configuration file based on the OS version.
OS | Configuration | Reference |
|---|---|---|
CentOS/EulerOS | Take CentOS 7.0 as an example.
| |
Ubuntu/Debian |
| |
SUSE and openSUSE | If the OS version is earlier than SUSE 12 SP1 or openSUSE 13:
| |
If the OS version is SUSE 12 SP1:
| ||
If the OS version is later than SUSE 12 SP1 or openSUSE 13:
|
vi /etc/dracut.conf
[root@CTU10000xxxxx ~]# vi /etc/dracut.conf# additional kernel modules to the defaultadd_drivers+="add_drivers+="virtio_blkvirtio_blk virtio_scsivirtio_scsi virtio_netvirtio_net virtio_pcivirtio_pci virtio_ring virtio"virtio_ring virtio"....
dracut -f /boot/initramfs-2.6.32-573.8.1.el6.x86_64.img
If the virtual file system is not the default initramfs, run the dracut -f Name of the initramfs or initrd file actually used command. The actual initramfs or initrd file name can be obtained from the grub.cfg file, which can be /boot/grub/grub.cfg, /boot/grub2/grub.cfg, or /boot/grub/grub.conf depending on the OS.
lsinitrd /boot/initramfs-`uname -r`.img | grep virtio
If the virtual file system is initrd, run the following command to check whether native KVM drivers have been installed:
lsinitrd /boot/initrd-`uname -r` | grep virtio
Assume that the virtual file system is initramfs. The following command output will be displayed:
[root@CTU10000xxxxx home]# lsinitrd /boot/initramfs-`uname -r`.img | grep virtio-rwxr--r-- 1 root root 23448 Jul 16 17:53 lib/modules/2.6.32-573.8.1.el6.x86_64/kernel/drivers/block/virtio_blk.kovirtio_blk.ko-rwxr--r-- 1 root root 50704 Jul 16 17:53 lib/modules/2.6.32-573.8.1.el6.x86_64/kernel/drivers/net/virtio_net.kovirtio_net.ko-rwxr--r-- 1 root root 28424 Jul 16 17:53 lib/modules/2.6.32-573.8.1.el6.x86_64/kernel/drivers/scsi/virtio_scsi.kovirtio_scsi.kodrwxr-xr-x 2 root root 0 Jul 16 17:53 lib/modules/2.6.32-573.8.1.el6.x86_64/kernel/drivers/virtiovirtio-rwxr--r-- 1 root root 14544 Jul 16 17:53 lib/modules/2.6.32-573.8.1.el6.x86_64/kernel/drivers/virtio/virtio.kovirtio.ko-rwxr--r-- 1 root root 21040 Jul 16 17:53 lib/modules/2.6.32-573.8.1.el6.x86_64/kernel/drivers/virtio/virtio_pci.kovirtio_pci.ko-rwxr--r-- 1 root root 18016 Jul 16 17:53 lib/modules/2.6.32-573.8.1.el6.x86_64/kernel/drivers/virtio/virtio_ring.kovirtio_ring.ko
If you add built-in drivers to the initrd or initramfs file, the ECS will not be affected. This makes it easy to modify the drivers. However, you cannot check the drivers by running the lsinitrd command. You can run the following command to check whether the drivers are built-in ones in the kernel:
cat /boot/config-`uname -r` | grep CONFIG_VIRTIO | grep y
vi /etc/initramfs-tools/modules
[root@CTU10000xxxxx ~]#vi /etc/initramfs-tools/modules...# Examples:## raid1# sd_mOdvirtio_blkvirtio_blkvirtio_scsivirtio_scsivirtio_netvirtio_netvirtio_pcivirtio_pcivirtio_ringvirtio_ringvirtiovirtio
update-initramfs -u
lsinitramfs /boot/initrd.img-`uname -r` |grep virtio
[root@ CTU10000xxxxx home]# lsinitramfs /boot/initrd.img-`uname -r` |grep virtiolib/modules/3.5.0-23-generic/kernel/drivers/scsi/virtio_scsi.kovirtio_scsi.ko
If you add built-in drivers to the initrd or initramfs file, the ECS will not be affected. This makes it easy to modify the drivers. However, you cannot check the drivers by running the lsinitrd command. You can run the following command to check whether the drivers are built-in ones in the kernel:
[root@ CTU10000xxxxx home]## catcat /boot/config-`uname/boot/config-`uname -r`-r` || grepgrep CONFIG_VIRTIOCONFIG_VIRTIO || grepgrep yyCONFIG_VIRTIO_BLK=yCONFIG_VIRTIO_NET=yCONFIG_VIRTIO=yCONFIG_VIRTIO_RING=yCONFIG_VIRTIO_PCI=yCONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
Modify the /etc/sysconfig/kernel file.
vi /etc/sysconfig/kernel
SIA10000xxxxx:~ # vi /etc/sysconfig/kernel# (like drivers for scsi-controllers, for lvm or reiserfs)#INITRD_MODULES="ata_piixINITRD_MODULES="ata_piix ata_genericata_generic virtio_blkvirtio_blk virtio_scsivirtio_scsi virtio_netvirtio_net virtio_pcivirtio_pci virtio_ringvirtio_ring virtio"virtio"
If the virtual file system is not the default initramfs or initrd, run the dracut -f Name of the initramfs or initrd file actually used command. The actual initramfs or initrd file name can be obtained from the menu.lst or grub.cfg file (/boot/grub/menu.lst, /boot/grub/grub.cfg, or /boot/grub2/grub.cfg).
The following is an example initrd file of SUSE 11 SP4:
default 0timeout 10gfxmenu (hd0,0)/boot/messagetitle sles11sp4_001_[_VMX_]root (hd0,0)kernel /boot/linux.vmx vga=0x314 splash=silent console=ttyS0,115200n8 console=tty0 net.ifnames=0 NON_PERSISTENT_DEVICE_NAMES=1 showoptsinitrd /boot/initrd.vmx/boot/initrd.vmxtitle Failsafe_sles11sp4_001_[_VMX_]root (hd0,0)kernel /boot/linux.vmx vga=0x314 splash=silent ide=nodma apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max+cstate=1 nomodeset x11failsafe console=ttyS0,115200n8 console=tty0 net.ifnames=0 NON_PERSISTENT_DEVICE_NAMES=1 showoptsinitrd /boot/initrd.vmx
/boot/initrd.vmx in the initrd line is the initrd file actually used. Run the dracut -f /boot/initrd.vmx command. If the initrd file does not contain the /boot directory, such as /initramfs-xxx, run the dracut -f /boot/initramfs-xxx command.
lsinitrd /boot/initrd-`uname -r` | grep virtio
SIA10000xxxxx:~ # lsinitrd /boot/initrd-`uname -r` | grep virtio-rwxr--r-- 1 root root 19248 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/scsi/virtio_scsi.kovirtio_scsi.ko-rwxr--r-- 1 root root 23856 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/block/virtio_blk.kovirtio_blk.kodrwxr-xr-x 2 root root 0 Jul 12 14:53 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtiovirtio-rwxr--r-- 1 root root 15848 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtio/virtio_ring.kovirtio_ring.ko-rwxr--r-- 1 root root 20008 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtio/virtio_pci.kovirtio_pci.ko-rwxr--r-- 1 root root 12272 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtio/virtio.kovirtio.ko-rwxr--r-- 1 root root 38208 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/virtio_net.kovirtio_net.ko
lsinitrd /boot/initrd-`uname -r` | grep virtio
SIA10000xxxxx:~ # lsinitrd /boot/initrd-`uname -r` | grep virtio-rwxr--r-- 1 root root 19248 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/scsi/virtio_scsi.kovirtio_scsi.ko-rwxr--r-- 1 root root 23856 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/block/virtio_blk.kovirtio_blk.kodrwxr-xr-x 2 root root 0 Jul 12 14:53 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtiovirtio-rwxr--r-- 1 root root 15848 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtio/virtio_ring.kovirtio_ring.ko-rwxr--r-- 1 root root 20008 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtio/virtio_pci.kovirtio_pci.ko-rwxr--r-- 1 root root 12272 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/virtio/virtio.kovirtio.ko-rwxr--r-- 1 root root 38208 Jun 22 2012 lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/virtio_net.kovirtio_net.ko
If you add built-in drivers to the initrd or initramfs file, the ECS will not be affected. This makes it easy to modify the drivers. However, you cannot check the drivers by running the lsinitrd command. You can run the following command to check whether the drivers are built-in ones in the kernel:
cat /boot/config-`uname -r` | grep CONFIG_VIRTIO | grep y
Modify the /etc/dracut.conf file.
vi /etc/dracut.conf
[root@CTU10000xxxxx ~]# vi /etc/dracut.conf# additional kernel modules to the defaultadd_drivers+="ata_piix"ata_piix ata_genericata_generic virtio_blkvirtio_blk virtio_scsivirtio_scsi virtio_netvirtio_net virtio_pcivirtio_pci virtio_ringvirtio_ring virtio"virtio"
dracut -f /boot/initramfs-File name
If the virtual file system is not the default initramfs, run the dracut -f Name of the initramfs or initrd file actually used command. The actual initramfs or initrd file name can be obtained from the grub.cfg file, which can be /boot/grub/grub.cfg, /boot/grub2/grub.cfg, or /boot/grub/grub.conf depending on the OS.
lsinitrd /boot/initramfs-`uname -r`.img | grep virtio
If the virtual file system is initrd, run the following command to check whether native KVM drivers have been installed:
lsinitrd /boot/initrd-`uname -r` | grep virtio
Modify the /etc/dracut.conf file.
Take SUSE Linux Enterprise Server 12 SP2 (x86_64) as an example.
vi /etc/dracut.conf
[root@CTU10000xxxxx ~]# vi /etc/dracut.conf# additional kernel modules to the defaultadd_drivers+="add_drivers+="ata_piixata_piix ata_genericata_generic virtio_blkvirtio_blk virtio_scsivirtio_scsi virtio_netvirtio_net virtio_pcivirtio_pci virtio_ringvirtio_ring virtio"virtio"
dracut -f /boot/initramfs-File name
If the virtual file system is not the default initramfs, run the dracut -f Name of the initramfs or initrd file actually used command. The actual initramfs or initrd file name can be obtained from the grub.cfg file, which can be /boot/grub/grub.cfg, /boot/grub2/grub.cfg, or /boot/grub/grub.conf depending on the OS.
lsinitrd /boot/initramfs-`uname -r`.img | grep virtio
If the virtual file system is initrd, run the following command to check whether native KVM drivers have been installed:
lsinitrd /boot/initrd-`uname -r` | grep virtio
Assume that the virtual file system is initrd. The following command output will be displayed:
sluo-ecs-30dc:~ # lsinitrd /boot/initrd-`uname -r` | grep virtio-rw-r--r-- 1 root root 29335 Oct 26 2016 lib/modules/4.4.21-69-default/kernel/drivers/block/virtio_blk.kovirtio_blk.ko-rw-r--r-- 1 root root 57007 Oct 26 2016 lib/modules/4.4.21-69-default/kernel/drivers/net/virtio_net.kovirtio_net.ko-rw-r--r-- 1 root root 32415 Oct 26 2016 lib/modules/4.4.21-69-default/kernel/drivers/scsi/virtio_scsi.kovirtio_scsi.kodrwxr-xr-x 2 root root 0 Sep 28 10:21 lib/modules/4.4.21-69-default/kernel/drivers/virtio-rw-r--r-- 1 root root 19623 Oct 26 2016 lib/modules/4.4.21-69-default/kernel/drivers/virtio/virtio.kovirtio.ko-rw-r--r-- 1 root root 38943 Oct 26 2016 lib/modules/4.4.21-69-default/kernel/drivers/virtio/virtio_pci.kovirtio_pci.ko-rw-r--r-- 1 root root 24431 Oct 26 2016 lib/modules/4.4.21-69-default/kernel/drivers/virtio/virtio_ring.kovirtio_ring.ko
If you add built-in drivers to the initrd or initramfs file, the ECS will not be affected. This makes it easy to modify the drivers. However, you cannot check the drivers by running the lsinitrd command. You can run the following command to check whether the drivers are built-in ones in the kernel:
cat /boot/config-`uname -r` | grep CONFIG_VIRTIO | grep y
Delete log files, historical records, and other data.
echo > /$path/$to/$root/.ssh/authorized_keys
Example: echo > /root/.ssh/authorized_keys
echo > /$path/$to/$none-root/.ssh/authorized_keys
Example: echo > /home/linux/.ssh/authorized_keys
rm -rf /var/log/*
Before deleting log files, back up log directories and log files required by application startup. For example, if the default Nginx log directory /var/log/nginx is deleted, Nginx may fail to be started.
echo > /root/.bash_history
history -c