Optimizing the VM
To ensure that ECSs created using a private image support both Xen and KVM virtualization, you must optimize the private image before its creation.
This section describes how to optimize a Linux VM that runs Ubuntu 14.04. For the optimization operations of other OSs, see Optimization Process (Linux).
Installing Native Xen and KVM Drivers
- Run the following command to open the modules file:
vi /etc/initramfs-tools/modules
- Press i to enter editing mode and add the native Xen (xen-pv) and KVM drivers (virtio drivers) to the /etc/initramfs-tools/modules file (the format depends on the OS requirements).
[root@CTU10000xxxxx ~]#vi /etc/initramfs-tools/modules ... # Examples: # # raid1 # sd_mOd xen-blkfront xen-netfront virtio_blk virtio_scsi virtio_net virtio_pci virtio_ring virtio
- Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.
- Run the following command to generate initramfs again:
- Run the following commands to check whether native Xen and KVM drivers have been installed:
lsinitramfs /boot/initrd.img-`uname -r` |grep xen
lsinitramfs /boot/initrd.img-`uname -r` |grep virtio
[root@ CTU10000xxxxx home]# lsinitramfs /boot/initrd.img-`uname -r` |grep xen lib/modules/3.5.0-23-generic/kernel/drivers/net/ethernet/qlogic/netxen lib/modules/3.5.0-23-generic/kernel/drivers/net/ethernet/qlogic/netxen/netxen_nic.ko lib/modules/3.5.0-23-generic/kernel/drivers/net/xen-netback lib/modules/3.5.0-23-generic/kernel/drivers/net/xen-netback/xen-netback.ko lib/modules/3.5.0-23-generic/kernel/drivers/block/xen-blkback lib/modules/3.5.0-23-generic/kernel/drivers/block/xen-blkback/xen-blkback.ko [root@ CTU10000xxxxx home]# lsinitramfs /boot/initrd.img-`uname -r` |grep virtio lib/modules/3.5.0-23-generic/kernel/drivers/scsi/virtio_scsi.ko
If you add built-in drivers to the initrd or initramfs file, VM running 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 commands to check whether the drivers are built-in ones in the kernel:
[root@ CTU10000xxxxx home]# cat /boot/config-`uname -r` | grep CONFIG_VIRTIO | grep y CONFIG_VIRTIO_BLK=y CONFIG_VIRTIO_NET=y CONFIG_VIRTIO=y CONFIG_VIRTIO_RING=y CONFIG_VIRTIO_PCI=y CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y [root@ CTU10000xxxxx home]# cat /boot/config-`uname -r` | grep CONFIG_XEN | grep y CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_NETDEV_FRONTEND=y
Changing the Disk Identifier in the GRUB Configuration File to UUID
- Log in to the newly created VM as user root.
- Run the following command to query all types of mounted file systems and the device UUIDs:
The following information is displayed:
/dev/xvda1: UUID="ec51d860-34bf-4374-ad46-a0c3e337fd34" TYPE="ext3" /dev/xvda5: UUID="7a44a9ce-9281-4740-b95f-c8de33ae5c11" TYPE="swap"
- Run the following command to query the grub.cfg file:
cat /boot/grub/grub.cfg
The following information is displayed:
......menuentry 'Ubuntu Linux, with Linux 3.13.0-24-generic' --class ubuntu --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.13.0-24-generic-advanced-ec51d860-34bf-4374-ad46-a0c3e337fd34' { recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34 else search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34 fi echo 'Loading Linux 3.13.0-24-generic ...' linux /boot/vmlinuz-3.13.0-24-generic root=/dev/xvda1 ro echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.13.0-24-generic }
- Search for root=/dev/xvda1 or root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34 is contained in the /boot/grub/grub.cfg configuration file.
- If root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34 exists in the configuration file, the root partition is in the UUID format and requires no change.
- If root=/dev/xvda1 exists in the configuration file, the root partition is in the device name format. Go to step 5.
- Obtain the UUID of the root partition based on root=/dev/xvda1 and information obtained by running the blkid command.
- Run the following command to open the grub.cfg file:
vi /boot/grub/grub.cfg
- Press i to enter editing mode. Use UUID to represent the root partition. For example, change root=/dev/xvda1 to root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34.
- Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.
- Run the following command to verify the change:
The change is successful if information similar to the following is displayed:
......menuentry 'Ubuntu Linux, with Linux 3.13.0-24-generic' --class ubuntu --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.13.0-24-generic-advanced-ec51d860-34bf-4374-ad46-a0c3e337fd34' { recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34 else search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34 fi echo 'Loading Linux 3.13.0-24-generic ...' linux /boot/vmlinuz-3.13.0-24-generic root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34 ro echo 'Loading initial ramdisk ...' initrd /boot/initrd.img-3.13.0-24-generic }
Changing the Disk Identifier in the fstab File to UUID
Take Ubuntu 14.04 for example. Run blkid to obtain the UUIDs of all partitions. Modify the /etc/fstab file and use the partition UUIDs to configure automatic partition mounting.
- Run the following command to query all types of mounted file systems and the device UUIDs:
The following information is displayed:
/dev/xvda2: UUID="4eb40294-4c6f-4384-bbb6-b8795bbb1130" TYPE="xfs" /dev/xvda1: UUID="2de37c6b-2648-43b4-a4f5-40162154e135" TYPE="swap"
- Run the following command to query the fstab file:
cat /etc/fstab
The following information is displayed:
[root@CTU1000028010 ~]# cat /etc/fstab /dev/xvda2 / xfs defaults 0 0 /dev/xvda1 swap swap defaults 0 0
- Check whether the disk identifier in the fstab file is the device name.
- If the disk is represented by UUID, no further operation is required.
- If the disk is represented by the device name, go to step 4.
- Run the following command to open the fstab file:
vi /etc/fstab
- Press i to enter editing mode and change the disk identifier to UUID.
- Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.
