If the GRand Unified Bootloader (GRUB) system boot program is not installed on a Linux server when you use Server Migration Center (SMC) to migrate the server to Alibaba Cloud, you must install GRUB v2.02 or later on the server. If the server runs an early Linux distribution such as CentOS 5 or Debian 7, the GRUB version is earlier than 2.02, or the "Do Grub Failed" error message is displayed in the log file, upgrade GRUB to v2.02 or later.
Background information
This topic describes how to install GRUB on a Linux server. In this example, GRUB v2.02 is used. The procedure for installing different GRUB versions is the same. However, the source code package may vary based on the GRUB version. For more information, visit Index of /gnu/grub.
Procedure
Log on to the Linux server.
Run the following commands in sequence to check the paths of the grub, grub-install, and grub-mkconfig files of the current GRUB version:
which grub which grub-install which grub-mkconfig
If the outputs of the preceding commands indicate that one or more of the file paths do not exist, GRUB is not installed on the server or the corresponding files are missing. You can perform operations in the following steps to install GRUB.
If you find the paths of all the files, run the following commands to back up the grub, grub-install, and grub-mkconfig files by renaming the files. When you install a new GRUB version, the new version overwrites the current version.
mv /sbin/grub /sbin/grub-old mv /sbin/grub-install /sbin/grub-install-old mv /sbin/grub-mkconfig /sbin/grub-mkconfig-old
NoteAfter you use SMC to migrate the server, you can restore the files by renaming the files to their original names.
Run the following command to install GRUB dependencies, including bison, gcc, and make:
yum install -y bison gcc make
Perform the following operations to install flex:
Check whether the tools folder exists. If the folder does not exist, create the folder.
test -d /home/testuser/tools || mkdir -p /home/testuser/tools
Go to the tools folder and download the flex installation package.
cd /home/testuser/tools wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
Decompress the flex installation package.
tar xzf flex-2.6.4.tar.gz
Go to the directory to which the flex installation package is decompressed and create a folder named build.
cd flex-2.6.4 mkdir -p build
Go to the build folder and compile and install flex.
cd build ../configure
make && make install
Create a symbolic link.
ln -s /usr/local/bin/flex /usr/bin/flex
Perform the following operations to install GRUB.
Use GRUB v2.02 or later for earlier distributions of Linux operating systems, such as CentOS 5, Red Hat Enterprise Linux 5, Debian 7, Amazon Linux, and Oracle Linux.
Check whether the tools folder exists. If the folder does not exist, create the folder.
test -d /home/testuser/tools || mkdir -p /home/testuser/tools
Go to the tools folder and download the GRUB v2.02 installation package.
cd /home/testuser/tools wget https://alpha.gnu.org/gnu/grub/grub-2.02~rc1.tar.gz
Decompress the GRUB v2.02 installation package.
tar xzf grub-2.02~rc1.tar.gz
Go to the directory to which the GRUB v2.02 installation package is decompressed and create a folder named build.
cd grub-2.02~rc1 mkdir -p build
Go to the build folder and compile and install GRUB.
cd build ../configure
sed -i -e "s/-Werror//" ./grub-core/Makefile sed -i -e "s/-Werror//" ./Makefile make && make install
Create a symbolic link.
ln -s /usr/local/sbin/grub-install /sbin/grub-install ln -s /usr/local/sbin/grub-mkconfig /sbin/grub-mkconfig
NoteIf the
-Werror
error is reported during the compilation process, find the makefile compile file, remove the-Werror
option from the file, and then recompile GRUB.Run the following command to check whether GRUB v2.02 is installed or GRUB is upgraded to v2.02:
grub-install --version
What to do next
If GRUB v2.02 is installed or GRUB is upgraded to v2.02, use Server Migration Center (SMC) to migrate the server to Alibaba Cloud. For more information, see Migration process.
(Optional) If you want to use the previous version of GRUB on the server after the server is migrated, run the following commands to restore GRUB to the previous version on the server:
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