All Products
Search
Document Center

:Install GRUB on a Linux server

Last Updated:Apr 21, 2026

Install or upgrade GRUB to v2.02+ for Server Migration Center (SMC) migration to Alibaba Cloud.

Background

SMC requires GRUB v2.02 or later on the source server. Install or upgrade GRUB in the following situations:

  • GRUB is not installed.

  • The server runs an early Linux distribution, such as CentOS 5 or Debian 7.

  • The installed GRUB version is earlier than v2.02.

  • The "Do Grub Failed" error appears in the log file.

This procedure uses GRUB v2.02 as an example. The steps are the same for other versions, but the source code package differs. Download other versions from Index of /gnu/grub.

Procedure

Check the GRUB version

  1. Log on to the Linux server as the root user.

  2. Check the file paths of GRUB and related tools:

    which grub
    which grub-install
    which grub-mkconfig
    • If any path does not exist, GRUB is not installed or the files are missing. Proceed to install GRUB.

    • If all paths exist, back up the files by renaming them, then install the new version:

      mv /sbin/grub /sbin/grub-old
      mv /sbin/grub-install /sbin/grub-install-old
      mv /sbin/grub-mkconfig /sbin/grub-mkconfig-old
      Note

      After SMC migration, restore the files by renaming them back to their original names.

Install dependencies

Install GRUB dependencies (bison, gcc, make, and flex) based on your operating system.

CentOS or Red Hat Enterprise Linux

yum install -y bison gcc make flex

Debian or Ubuntu

apt-get update && apt-get install -y bison gcc make flex

Install flex

  1. Create the tools folder if it does not exist.

    test -d /home/testuser/tools || mkdir -p /home/testuser/tools
  2. Navigate to the tools folder and download the flex package.

    cd /home/testuser/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
  3. Compile and install flex, then create a symbolic link.

    cd flex-2.6.4
    mkdir -p build
    cd build
    ../configure
    make && make install
    ln -s /usr/local/bin/flex /usr/bin/flex

Install GRUB

  1. Download and decompress the GRUB v2.02 package.

    cd /home/testuser/tools
    wget https://alpha.gnu.org/gnu/grub/grub-2.02~rc1.tar.gz
    tar xzf grub-2.02~rc1.tar.gz
  2. Compile and install GRUB, then create symbolic links.

    cd grub-2.02~rc1
    mkdir -p build
    cd build
    ../configure
    # If the -Werror error is reported, modify the Makefile file and remove the -Werror option from the file. 
    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

Verify the installation

Verify that GRUB v2.02 is installed:

grub-install --version

Next steps

  • After GRUB v2.02 is installed, use SMC to migrate the server to Alibaba Cloud. See Server migration guide.

  • (Optional) To restore the previous GRUB version after migration, run the following commands:

    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