All Products
Search
Document Center

Elastic Compute Service:Create a virtual machine and install a Linux operating system

Last Updated:May 24, 2024

VirtualBox is a free open source cross-platform virtual machine software. You can create a Linux image file in the Virtual Hard Disk (VHD) format based on the Linux operating system provided by VirtualBox. This topic describes how to create a virtual machine by using VirtualBox and install a Linux operating system on the virtual machine.

Prerequisites

  • VirtualBox is installed. If VirtualBox is not installed, click VirtualBox to download VirtualBox.

  • An ISO image file is prepared. Example: CentOS-7-x86_64-Minimal-2009.iso. You can visit the Alibaba Cloud Official Image Site to download ISO image files.

  • Network connectivity is good.

Procedure

The procedure to install an operating system on a virtual machine may vary based on the operating system. In this topic, VirtualBox 7.0.2 is used to create a virtual machine and the CentOS 7.9 operating system is installed. Perform the following steps:

Step 1: Create a virtual machine

  1. Start Oracle VM VirtualBox Manager and click New to create a virtual machine.

  2. Create a virtual machine.

    1. Configure the following parameters:

      • Name: Enter a name for the virtual machine. Example: centos VM.

      • Machine Folder: Specify a folder on your computer where you want to store the virtual machine.

      • Type: Select Linux.

      • Version: Select an operating system version.

      • Memory size: Select a memory size based on the configuration of the virtual machine that you want to create and the requirements of the Linux operating system that you want to install. The default memory size is 1,024 MB. In this example, the memory size is set to 1,024 MB.

      • Hard disk: Select Create a virtual hard disk now.

    2. Click Create.

  3. Create a virtual hard disk.

    1. Configure the following parameters:

      • File location: Specify a folder where you want to store the image file.

      • File size: Specify the size of the image file in the virtual hard disk. In this example, 20 GB is used.

      • Hard disk file type: Select VHD (Virtual Hard Disk).

        Note

        Only image files in the RAW, VHD, and QCOW2 formats can be imported to Elastic Compute Service (ECS). If you select a different format here, you must convert the created image to a supported format before you can import the image to ECS. For more information, see Convert the format of an image.

      • Storage on physical hard disk: Select Dynamically allocated.

    2. Click Create.

Step 2: Install a Linux operating system

Method 1: Install a Linux operating system in BIOS mode

  1. Start Oracle VM VirtualBox Manager and select the new virtual machine. Example: centos VM.

  2. Click Settings.

  3. In the Settings window, select Storage in the left-side navigation pane. In the storage device list, select Empty. Then, in the Attributes section on the right side, click the 盘片 icon and select Choose a disk file, select the CentOS 7 image file. Select the CentOS-7-x86_64-Minimal-2009.iso file and click OK.

  4. Select the new virtual machine and click Start to start the virtual machine.

  5. Go to the operating system installation page and install the operating system as instructed.

    1. Select a system language and click Continue.

    2. On the INSTALLATION SUMMARY page, click INSTALLATION DESTINATION.

    3. On the INSTALLATION DESTINATION page, select Local Standard Disks for Device Selection, select I will configure partitioning for Partitioning, and then click Done.

    4. On the MANUAL PARTITIONING page, click the 添加 icon. On the right side, set Mount Point to /, Device Type to Standard Partition, and File System to ext4. Then, click Done.

    5. On the INSTALLATION SUMMARY page, click NETWORK & HOST NAME.

    6. On the NETWORK & HOST NAME page, select Ethernet, click the On button on the right side, and then click Done.

    7. On the INSTALLATION SUMMARY page, click Begin Installation.

    8. After the operating system is installed, set a password for the root user. Then, click FINISH CONFIGURATION.

      You must use the password for authentication when you log on to the virtual machine. Keep the password confidential.

  6. After the operating system is installed, log on to the virtual machine and run the following command to make sure that the root partition is mounted as the very last step in the boot process. If the root partition is not mounted as the very last step in the boot process, the instance cannot start or the disk cannot be resized.

    lsblk

    A command output similar to the following one is returned.确认分区

Method 2: Install a Linux operating system in UEFI mode

  1. Start Oracle VM VirtualBox Manager and select the new virtual machine. Example: centos VM.

  2. Click Settings.

  3. In the Settings window, select Storage in the left-side navigation pane. In the storage device list, select Empty. Then, in the Attributes section on the right side, click the 盘片 icon and select Choose a disk file, select the CentOS 7 image file. Select the CentOS-7-x86_64-Minimal-2009.iso file and click OK.

  4. Click Settings.

  5. In the Settings window, select System in the left-side navigation pane. On the Motherboard tab, select Enable EFI (special OSes only) for Extended Features and click OK.

  6. Go to the operating system installation page and install the operating system as instructed.

    1. You must first mount the /boot/efi partition, select Standard Partition for Device Type, and then select EFI System Partition for File System.

    2. Mount the / root partition, select Standard Partition for Device Type, and then select ext4 for File System.

      Important

      The system disk can have only the root partition. If the system disk has other partitions, the instance cannot start or the disk cannot be resized. Therefore, you must configure the root partition to be mounted as the very last step in the boot process.

  7. After the operating system is installed, log on to the virtual machine and run the following command to make sure that the root partition is mounted as the very last step in the boot process. If the root partition is not mounted as the very last step in the boot process, the instance cannot start or the disk cannot be resized.

    lsblk

    A command output similar to the following one is returned.确认分区

What to do next

After you create a virtual machine and install a Linux operating system on the virtual machine, you can perform the following operations:

  • To ensure that ECS instances created from an image can be initialized, install cloud-init in the image. For more information, see Install cloud-init.

  • To ensure that ECS instances created from an image can start, install the virtio driver on the virtual machine from which the image is created. For more information, see Install the virtio driver.

  • Optional. If you select Customized Linux when you import a custom image, the image cannot be recognized by Alibaba Cloud. To ensure that ECS instances created from the image can be automatically configured, add a parsing script to the custom image before the import. For more information, see Customize Linux images.

  • Use an image compliance tool to check whether an image can be imported. For more information, see Check whether an image meets the import requirements.