If you use Server Migration Center (SMC) to migrate a Linux source server running on an early kernel version (such as CentOS 5 and Debian 7), the version of the built-in system boot program GRUB is earlier than v1.99, and the "Do Grub Failed" error message appears in the log file, you must upgrade GRUB to v1.99 or later.

Background information

This topic uses GRUB v1.99 or v2.02 as an example to describe how to install GRUB on a Linux server. The procedure to install GRUB of other versions is similar. The difference is that you need to install the source code package corresponding to the GRUB version. For more information, visit Index of /gnu/grub.

Procedure

  1. Log on to the Linux source server.
  2. Run the following commands to view the original grub, grub-install, and grub-mkconfig paths:
    # which grub
    # which grub-install
    # which grub-mkconfig
  3. Run the mv command to rename the old versions of grub, grub-install, and grub-mkconfig to back up these files.
    After you use SMC to migrate the server, you can reinstate the original files by changing their names back to the original ones.
    # mv /sbin/grub /sbin/grub-old
    # mv /sbin/grub-install /sbin/grub-install-old
    # mv /sbin/grub-mkconfig /sbin/grub-mkconfig-old
  4. Install the GRUB dependencies including bison, gcc, and make.
    # yum install -y bison gcc make
  5. Run the following commands to install flex:
    # test -d /root/tools || mkdir -p /root/tools
    # cd /root/tools
    # wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
    # tar xzf flex-2.6.4.tar.gz
    # cd flex-2.6.4
    # mkdir -p build
    # cd build
    # ../configure
    # make && make install
    # ln -s /usr/local/bin/flex /usr/bin/flex
  6. Run the following commands to install GRUB and the corresponding dependencies:
    • Upgrade GRUB to v1.9 or later in the operating systems of early versions such as CentOS 5, Red Hat Enterprise Linux 2, or Debian 7.
      # test -d /root/tools || mkdir -p /root/tools
      # cd /root/tools
      # wget https://alpha.gnu.org/gnu/grub/grub-1.99~rc1.tar.gz
      # tar xzf grub-1.99~rc1.tar.gz
      # cd grub-1.99~rc1
      # mkdir -p build
      # cd build
      # ../configure
      # sed -i -e "s/-Werror//" ./grub-core/Makefile
      # sed -i -e "s/-Werror//" . /Makefile
      # make && make install
      # ln -s /usr/local/sbin/grub-install /sbin/grub-install
      # ln -s /usr/local/sbin/grub-mkconfig /sbin/grub-mkconfig
    • Upgrade GRUB to v2.02 or later in Amazon Linux operating systems.
      # test -d /root/tools || mkdir -p /root/tools
      # cd /root/tools
      # wget https://alpha.gnu.org/gnu/grub/grub-2.02~rc1.tar.gz
      # tar xzf grub-2.02~rc1.tar.gz
      # cd grub-2.02~rc1
      # mkdir -p build
      # cd build
      # ../configure
      # sed -i -e "s/-Werror//" ./grub-core/Makefile
      # sed -i -e "s/-Werror//" . /Makefile
      # make && make install
      # ln -s /usr/local/sbin/grub-install /sbin/grub-install
      # ln -s /usr/local/sbin/grub-mkconfig /sbin/grub-mkconfig
    Note If the -Werror error is reported during compilation, find the error in the makefile file, remove the -Werror option, and then try again.
  7. Run the grub-install --version command to check whether the GRUB version is updated.

What to do next

  • After you have upgraded GRUB, you can use SMC to migrate the server to Alibaba Cloud. For more information, see the Migration process topic in SMC documentation .
  • Optional. After the migration is complete, run the following commands to restore GRUB to the original version:
    # rm /sbin/grub-install
    # rm /sbin/grub-mkconfig
    # rm /boot/grub/grub.cfg
    # mv /sbin/grub-old /sbin/grub
    # mv /sbin/grub-install-old /sbin/grub-install