Create a virtual machine and install Linux

更新时间:
复制 MD 格式

VirtualBox is a free, open-source, and cross-platform virtualization software. You can use it to create Linux image files in VHD format. This topic describes how to create a virtual machine and install a Linux operating system using VirtualBox.

Prerequisites

Procedure

Installation steps may vary depending on the operating system. Follow the prompts in the installation wizard. This topic uses VirtualBox 7.1.10 and CentOS 7.9 as an example.

Step 1: Create a virtual machine

  1. Open Oracle VM VirtualBox Manager. In the toolbar, click Preferences, select the Expert tab, and then click OK.

    Note

    In this version of VirtualBox, you must select the Expert tab to enable expert mode. This allows you to select a virtual disk file type when you create a virtual machine. Otherwise, the format defaults to VDI.

  2. In the toolbar, click New Resources.

  3. Create the virtual machine.

    1. In the Name and Operating System section, set the name and operating system type for the virtual machine.

      • Name: Enter a name for the virtual machine, such as centosVM.

      • Folder: Select a path to save the virtual machine.

      • ISO image: Select the prepared ISO image.

      • Version and Disk Category: VirtualBox automatically fills in the operating system version and type based on the ISO image.

      • Skip Unattended Installation: By default, VirtualBox automatically installs the selected operating system. Select Skip Unattended Installation.

    2. In the Hardware section, configure the hardware for the virtual machine.

      • Base Memory: Specify the amount of memory to allocate to the virtual machine.

      • Processor: Specify the number of virtual CPUs to allocate.

      • Enable EFI (special OSes only): To boot the virtual machine in UEFI mode, select this option. Otherwise, the virtual machine boots in BIOS mode.

    3. In the Virtual hard disk section, select Create A Virtual Hard Disk Now.

      • Select a storage location and disk size for the virtual hard disk file.

      • Select a Hard Disk File Type.

        Note

        ECS supports only images in RAW, VHD, QCOW2, and VMDK formats. If you select another format, you must convert the image format before you import it.

  4. Click Completed and wait for the virtual machine to be created.

Step 2: Install the OS

You can install the operating system in either Basic Input/Output System (BIOS) or Unified Extensible Firmware Interface (UEFI) mode. This choice determines the boot mode of the system disk for the ECS instance that you later create from this image. For more information about boot modes, see Instance boot modes.

BIOS

  1. Select the new virtual machine and click Start in the toolbar to start the virtual machine.

  2. After the operating system installation interface appears, follow the wizard to install the operating system.

    1. Select a system language and click Continue.

    2. On the INSTALLATION SUMMARY page, click Installation Location.

    3. On the INSTALLATION DESTINATION page, set Device Selection to Local Standard Disks and Partition to I Will Configure Partitioning. Then, click Completed.

    4. On the Manual partitioning page, click 添加, set Mounting Point to /, Device Type to standard partition, and File System to ext4. Then, click Completed.

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

    6. On the NETWORK & HOST NAME page, select Ethernet, click the On toggle on the right, and then click Completed.

    7. On the INSTALLATION SUMMARY page, click Install.

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

      You will need this password to log on to the virtual machine. Keep it in a secure place.

  3. After the operating system is installed, restart the system.

  4. Log on to the virtual machine and run the following command to ensure that the root partition is mounted last. Otherwise, the instance may fail to start or disk expansion may fail.

    lsblk

    The output is similar to the following:

    [root@xxx ~]# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0   20G  0 disk
    sda1     8:1    0   19G  0 part /
    sr0     11:0    1 1024M  0 rom

UEFI

  1. Select the new virtual machine and click Start in the toolbar to start the virtual machine.

  2. After the operating system installation interface appears, follow the wizard to install the operating system.

    1. Select a system language and click Continue.

    2. On the INSTALLATION SUMMARY page, click Installation Location.

    3. On the INSTALLATION DESTINATION page, set Device Selection to Local Standard Disks and Partition to I Will Configure Partitioning. Then, click Completed.

    4. On the Manual partitioning page, click 添加, configure the Mounting Point, Device Type, and File System, and then click Completed.

      1. First, mount /boot/efi. Set Device Type to Standard Partition and File System to EFI System Partition.

      2. Then, mount the root partition /. Set Device Type to standard partition and File System to ext4.

        Important

        Do not create any partitions after the root partition on the system disk. Otherwise, the instance may fail to start or disk expansion may fail.

    5. On the INSTALLATION SUMMARY page, click Install.

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

      You will need this password to log on to the virtual machine. Keep it in a secure place.

  3. After the operating system is installed, restart the system.

  4. Log on to the virtual machine and run the following command to ensure that the root partition is mounted last. Otherwise, the instance may fail to start or disk expansion may fail.

    lsblk

    The output is similar to the following:

    [root@xxx]# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0   20G  0 disk
    ├─sda1   8:1    0   95M  0 part /boot/efi
    └─sda2   8:2    0 18.6G  0 part /
    sr0     11:0    1 1024M  0 rom
    [root@xxx]# _

Next steps

You can perform the following tasks as needed:

  • Install cloud-init: This ensures that the ECS instance created from the image can complete initialization.

  • Install the virtio driver: After you import a custom image, the resulting virtual machine may fail to start if the virtio driver is missing. Before you import an image, check whether the virtio driver must be installed on the source server.

  • (Optional) Customize a Linux image: Alibaba Cloud identifies customized Linux images as unrecognized operating systems. Before you import the image, add a parsing script to it. This enables automated instance configuration on first boot.

  • Check and fix an image: Use the Image Compliance Tool to check if an imported image file is valid.