Help Center> Bare Metal Server> Private Image Creation Guide> Linux> Modifying the Hardware Device Drivers That Boot the OS
Updated on 2023-07-24 GMT+08:00

Modifying the Hardware Device Drivers That Boot the OS

Scenario

This section describes how to modify the hardware device drivers that are loaded during OS startup.

Prerequisites

You have logged in to the VM.

Procedure

  1. Add or modify the configuration file.
    • For Red Hat/Oracle Linux/EulerOS/OpenEuler/SUSE 12/SUSE 15/CentOS, use the vi editor to open the /etc/dracut.conf file and change or add the value of add_drivers. In the following example, the value of add_drivers is a list of RAID drivers.
      logfile=/var/log/dracut.log
      # fileloglvl=7
      ...
      ...
      # additional kernel modules to the default
      add_drivers+="ahci megaraid_sas mpt3sas mpt2sas virtio_blk virtio_scsi virtio_net"

      If an error is reported, add a space before and after the driver list in the quotation marks and try again.

    • For Ubuntu 14.04 or Debian, use the vi editor to open the /etc/initramfs-tools/modules file and add ahci, megaraid_sas, mpt3sas, and mpt2sas drivers (the format depends on the OS).
      # List of modules that you want to include in your initramfs.
      # They will be loaded at boot time in the order below.
      #
      # Syntax:  module_name [args ...]
      #
      # You must run update-initramfs(8) to effect this change.
      #
      # Examples:
      #
      # raid1
      # sd_mod
      ahci
      megaraid_sas
      mpt3sas
      mpt2sas
      virtio_blk
      virtio_scsi
      virtio_net
    • For Ubuntu 16.04/Ubuntu 18.04, add drivers to the /etc/dracut.conf and /etc/initramfs-tools/modules files. Before editing the files, install required software.
      1. Run the following command to install dracut:

        apt-get install dracut

        After the installation is complete, add add_drivers+="ahci megaraid_sas mpt3sas mpt2sas virtio_blk virtio_scsi virtio_net" to the end of the /etc/dracut.conf file by performing operations similar to those for Red Hat and Oracle Linux 7.3.

        If an error is reported, add a space before and after the driver list in the quotation marks and try again.

      2. Run the following command to install initramfs-tools:

        apt-get install initramfs-tools

        After the installation is complete, add the ahci, megaraid_sas, mpt3sas, mpt2sas, and virtio_blk virtio_scsi virtio_net drivers to the end of the /etc/initramfs-tools/modules file by performing operations similar to those for Ubuntu 14.04.

    • For Ubuntu 16.04 ARM, run the following commands to update the kernel and drivers, and then restart the VM:

      sudo apt-get update

      sudo apt-get dist-upgrade

    • For SUSE 11 SP4, use the vi editor to open the /etc/sysconfig/kernel file, and add or change the value of INITRD_MODULES. In the following example, the value of INITRD_MODULES is a list of RAID drivers.
      ...
      #
      INITRD_MODULES="ahci megaraid_sas mpt3sas mpt2sas virtio_blk virtio_scsi virtio_net"
      ## Type:   string(yes)
      ...

    You can enter multiple RAID drivers and separate them with spaces. The RAID driver names can be obtained from the purchased hardware devices. Multiple types of drivers can be added at the same time, such as mpt3sas, mpt2sas, and megaraid_sas. If any hardware driver cannot be installed here, you can install it after the BMS is created.

  2. Update the kernel. For Ubuntu 16.04 ARM and Ubuntu 18.04 ARM, skip this step.

    For Rad Hat/Oracle Linux/EulerOS/SUSE 12/SUSE 15/Ubuntu 16.04/Ubuntu 18.04/CentOS run the dracut -f command.

    • For Rad Hat/Oracle Linux/EulerOS/OpenEuler/CentOS, run the dracut -f command. Wait for several seconds. If no command output is returned, the drivers have been loaded.
    • For SUSE 12 SP1, run the dracut -f command. Check the command output in the last few lines. If message "Some kernel modules could not be included. This is not necessarily an error:" is displayed and drivers not loaded are displayed (excluding the RAID drivers), the RAID drivers are loaded successfully.
      ...
      Some kernel modules could not be included
      This is not necessarily an error:
      pcmcia
      sdhci_acpi
      swap
    • For SUSE 12/SUSE 15, run the dracut -f command. The kernel is updated successfully if information similar to the following is displayed.

    • For Ubuntu 14.04/Ubuntu 16.04/Ubuntu 18.04/Debian, run the following command to generate initrd:

      update-initramfs -u

      Run the following commands to check whether the ahci, megaraid_sas, mpt3sas, and mpt2sas drivers have been loaded:

      lsinitramfs /boot/initrd.img-`uname -r` |grep ahci

      lsinitramfs /boot/initrd.img-`uname -r` |grep megaraid_sas

      lsinitramfs /boot/initrd.img-`uname -r` |grep mpt3sas

      lsinitramfs /boot/initrd.img-`uname -r` |grep mpt2sas

    • For SUSE 11 SP4, run the mkinitrd command to check whether the value of Kernel Modules contains the manually added drivers. If the following command output is displayed, the drivers are successfully loaded.

  3. For SUSE 11 SP4, change the virtual disks in the VM file to physical disks. For other OSs, such as Rad Hat, CentOS, Oracle Linux, SUSE 12, and EulerOS, skip this step.

    If LVM is used, perform 3.a to 3.e to change the drive letter mode.

    1. In the /boot/grub directory of the VM, run the blkid command to check whether disk partitions are normal.
      linux-a5d6:/boot/grub # blkid
      /dev/sda1: UUID="c23d47f8-ef1b-4c4e-9a3b-5ae138ef7184" TYPE="swap"
      /dev/sda2: UUID="27644978-e244-4a8c-996a-03119fdaff71" TYPE="ext3"

      If some disk partitions do not have UUIDs, check whether the VM OS is properly installed. If it is not, install it again.

    2. Use the vi editor to open the /boot/grub/menu.lst file, modify the OS boot parameters, and save the configuration.

      Original menu.lst file

      Modified menu.lst file

    3. Use the vi editor to open the /boot/grub/device.map file.

      Original device.map file

      (hd0)   /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001
      ~

      Modified device.map file

      (hd0)   /dev/sda
    4. Use the vi editor to open the /etc/fstab file.

      Original fstab file

      Modified fstab file

    5. Use the vi editor to open the /etc/mtab file, delete the line where CDROM of /dev/sr0 is located, and save the configuration.

      Modified mtab file

      If the /dev/sr0 configuration item does not exist, skip this step.

    6. Use the vi editor to open the /etc/sysconfig/bootloader file.

      Original bootloader file

      Modified bootloader file

    If SUSE 11 SP4 uses LVM, replace the virtual disks in the VM file with the actual physical disks.

    1. In the /boot/grub directory of the VM, run the blkid command to check whether disk partitions are normal.

      If some disk partitions do not have UUIDs, check whether the VM OS is properly installed. If it is not, install it again.

    2. Use the vi editor to open the /boot/grub/menu.lst file, modify the OS boot parameters, and save the configuration.

      Original menu.lst file

      Modified menu.lst file

    3. Use the vi editor to open the /boot/grub/device.map file.

      Original device.map file

      (hd0)    /dev/disk/by-id/ata-QEMU_HARDDISK_QM00001

      Modified device.map file

      (hd0)    /dev/sda
      ~
    4. Use the vi editor to open the /etc/fstab file.

      Original fstab file

      Modified fstab file

    5. Use the vi editor to open the /etc/sysconfig/bootloader file.

      Original bootloader file

      Modified bootloader file

    After the configuration is complete, run the mkinitrd command. If the value of resume is not by-uuid, run the reboot and then mkinitrd commands to ensure that the value of resume is by-uuid.

  4. For Ubuntu 18.04 and Ubuntu 16.04 ARM, modify the grub, fstab, and interfaces files.
    1. Modify parameters in the /etc/default/grub configuration file.

      Set GRUB_DISABLE_LINUX_UUID to true.

      ...
      # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to linux
      GRUB_DISABLE_LINUX_UUID=true
      
      # Uncomment to disable generation of recovery mode menu entries
      ...

      Then, run the sudo update-grub2 command.

    2. Change the UUID in the /etc/fstab file to that of /dev/sdax, which can be obtained by running the sudo blkid command.

    3. Delete all interface information except lo interface from the /etc/network/interfaces file.
      # This file describes the network interfaces available on your system
      # and how to activate them. For more information, see interfaces (5).
      
      source /etc/network/interfaces.d/*
      
      # The loopback network interface
      auto lo
      iface to inet loopback
      
      ~
      ~