How to install Alibaba Cloud Linux locally-Alibaba Cloud Developer Community

1. Why do I need to install Alibaba Cloud Linux locally?

It is said that the official website of CentOS officially announced that it would stop maintaining CentOS Linux and invest more funds and manpower into CentOS Stream. CentOS Linux 8 will stop maintenance by the end of 2021, and CentOS Linux 7 will stop maintenance by the end of June 2024 (https://access.redhat.com/announcements/5634831).

Many projects tested in the local CentOS system will eventually go online to Alibaba Cloud. Although Alibaba Cloud images have several versions of CentOS and several versions of Alibaba Cloud Linux that have performance advantages and are compatible with the former, there are minor differences in operating systems and sources between the online and offline operating systems, it still brings some confusion to O & M. As CentOS may be unreliable in the future, it is a good choice to install Alibaba Cloud Linux that Alibaba officially supports maintenance for a long time.

2. Alibaba Cloud Linux resources

Alibaba Cloud Linux the product page, Alibaba Cloud Linux 2 and Alibaba Cloud Linux 3. These rich official documents describe their product advantages and functions, application scenarios, product trends, documents and tools, however, the official only provides the localization steps for the KVM: Use the Alibaba Cloud Linux 2 image locally and use the Alibaba Cloud Linux 3 image locally. The following describes how to install Alibaba Cloud Linux on a local physical machine. Appropriate modifications to this method can also be used for various versions of virtual machines.

First, https://mirrors.aliyun.com/alinux/image/下载Alibaba the image in the Cloud Linux. Select **, which is the basic image of Alibaba Cloud long-term support edition. This article was written at 20210726.

3. Install Alibaba Cloud Linux locally

1) installed on physical machines

note: package the image to a ready-made linux live cd or rescue cd, and use dd to restore the target disk in the rescue mode, just like ghost or win WIM.

1. Alibaba Cloud official Image qcow2 format conversion

you can use qemu-img. I am the Win workbench and the download address is https://cloudbase.it/qemu-img-windows /.. Linux or macOS can be installed online. Conversion command:

qemu-img convert -f qcow2 aliyun_2_1903_x64_20G_nocloud_alibase_20210726.qcow2 -O raw aliyun_2_1903_x64_20G_nocloud_alibase_20210726.raw

the format is dd if/.

2. Make installation disk

aliyun_2_1903_x64_20G_nocloud_alibase_20210726.raw with 20G. Pack the 20g file into the installation disk. If you don't use the U disk but burn the disk, the disk capacity is not enough. Even if the capacity is not a problem, it is not conducive to distribution. Therefore, the file should be shrink without damage.

I have tried three possibilities, or failure or other reasons to give up (mention these for the reference of interested parties):

compression and dd:

gzip -dv aliyun_2_1903_x64_20G_nocloud_alibase_20210726.raw.gz | dd of=/dev/sda bs=256M

gzip requires 20GB of space to completely decompress, and the installation disk, whether U disk, CD or mount. iso, is a simulated CDROM, after boot tmpfs only supports 2GB .

②The after the installation disk is integrated with qemu-img, the image and write disk are converted:

qemu-img convert aliyun_2_1903_x64_20G_nocloud_alibase_20210726.qcow2 -O raw /dev/sda

the existing linux live or rescue environments generally lack qemu-img and its runtime library, and the integration process is complicated and abandoned.

resize2fs aliyun_2_1903_x64_20G_nocloud_alibase_20210726.raw 2.41G

in the raw file, the system only occupies 2.41GB, and the rest is the sparse space filled with 00 or random. The system and sparse are not distinct continuous storage, but the Shard status, as shown in the following figure:

however, resize2fs will be truncated according to the parameters given by the command line, which will undoubtedly cause system data loss.

If the system and sparse are defragmented, data may not be lost after resize2fs is truncated. I did not verify.

Successful methods :

use a disk tool to adjust the partition.

That is defragmentation make r the process of system and sparse separation in aw files. I use Diskgenius. GParted is available in linux.

Red Box: The system only occupies 2.41GB.

Blue Box: **this version, the sector limit after lossless adjustment is 5058007. This value is available later.

Green frame: partition front space 992K don't to otherwise, the system cannot boot after the disk is restored.

Note: the raw file is still 20GB. Because raw is a mounted virtual disk at this time, the parameter of the virtual disk is modified. The slice ends to 5058007, which does not affect the file size.

②The truncate the raw file after lossless contraction.

Transfer the partition-adjusted raw file to the available linux system and run truncation:

truncate --size=$[(5058007+1)*512] aliyun_2_1903_x64_20G_nocloud_alibase_20210726.raw

+1 is because the number of sectors starts from 0; 512 is because each sector has 512 bytes.

It is said that the win system api has the fileapi.h SetEndOfFile function, which can also be truncated. I did not try.

will package raw files (2.41GB) after lossless contraction to linux live or rescue cd.

I chose CentOS-7-x86_64-NetInstall-2009.iso because CentOS7 has the best compatibility with Alibaba Cloud Linux. After packaging, the final installation disk file is 3.03GB. There are many tools for packaging. iso.

3. Use this installation disk to install the system

whether to burn USB flash drive or CD, as you wish. The following describes how to use virtual machines to simulate physical machines. The operations in the real environment are the same.

create a virtual machine with an empty hard disk and mount it on a cd centOS-7-x86_64-NetInstall-2009-aliyun20210726.iso, select cd for BIOS start.

②The borrow CentOS7 installation disk function, from the Troubleshooting to the Rescue mode.

select a shell that is not mounted to the hard disk. 3

mount the installation disk to restore the system. Run

mkdir /mnt/cdrom

mount /dev/cdrom /mnt/cdrom

dd if=/mnt/cdrom/aliyun_2_1903_x64_20G_nocloud_alibase_20210726.raw of=/dev/sda bs=256M

output: sda is not sda1, because raw is a disk image rather than a partition Image. 256MB can be adjusted according to the host memory size, which is 2GB. The recovery speed and time are shown in the figure.

expand the sda1 partition where the system is located to the actual available space of the host hard disk. Otherwise, the sda1 partition will be 2.4GB of raw.

You can use the fdisk deletion method:

fdisk /dev/sda, in sequence d, n, press enter 4 times to select default, w.

(I don't have a hard disk of 4 TB or above. It is estimated that gdisk is used in GPT partitions, or general parted. Similarly delete built operation )

e2fsck -f /dev/sda1

resize2fs /dev/sda1

restart the system to make the preceding changes take effect.

select the shell where the hard disk is mounted to the directory, that 1

switch root: chroot /mnt/sysimage

create under/boot initramfs file:

cd boot

dracut -f initramfs-4.19.91-24.1.al7.x86_64.img 4.19.91-24.1.al7.x86_64

modify the root logon password: passwd root, enter the no echo password twice;

enable the user to log on with a password: sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config

restart and use the local hard disk to boot.

Note:

the Alibaba Cloud Linux system is designed to generate metadata based on the information (such as the machine name, password, cpu, and memory) submitted when you purchase an ECS instance on the Alibaba Cloud platform, and initialize the operating system environment through cloud-init-local and dracut-initqueue. We do not need these metadata, so do the above operation, manual create initramfs file, generate the root password, and enable it to log on. Knowing its purpose, these operations can also be changed as you wish.

For example ⑤ restart directly after completion, as follows,

rw init=/bin/bash crashkernel=auto

this allows you to access the system.

4. Optimize the system

after entering the system, the operation is the same as CentOS or Alibaba Cloud Linux. Configure the network

vi /etc/sysconfig/network-scripts/ifcfg-eth0

BOOTPROTO = static

IPADDR =

GATEWAY =

NETMASK =

DNS1 =

systemctl restart network

systemctl restart sshdafter remote.

There is no error in the floppy drive. Disable it:

echo "blacklist floppy" | tee /etc/modprobe.d/blacklist-floppy.conf

in addition, online search to disable and delete cloud services are available:

/usr/local/share/assist-daemon/assist_daemon --stop

/usr/local/share/assist-daemon/assist_daemon --delete

rm -rf /usr/local/share/assist-daemon

wget http://update.aegis.aliyun.com/download/uninstall.sh

chmod +x uninstall.sh

./uninstall.sh

wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh

chmod +x quartz_uninstall.sh

./quartz_uninstall.sh

pkill aliyun-service

rm -fr /etc/init.d/agentwatch /usr/sbin/aliyun-service

rm -rf /usr/local/aegis*

sudo systemctl stop aegis.service

sudo systemctl disable aegis.service

sudo rm /lib/systemd/system/aegis.service

sudo systemctl stop aliyun.service

sudo systemctl disable aliyun.service

sudo rm /lib/systemd/system/aliyun.service

sudo systemctl stop agentwatch.service

sudo systemctl disable agentwatch.service

sudo rm /lib/systemd/system/agentwatch.service

sudo systemctl stop accounts-daemon.service

sudo systemctl disable accounts-daemon.service

sudo rm /lib/systemd/system/accounts-daemon.service

sudo systemctl stop aliyun-util.service

sudo systemctl disable aliyun-util.service

sudo rm /etc/systemd/system/aliyun-util.service

sudo systemctl stop cloud-config.service

sudo systemctl disable cloud-config.service

sudo rm /lib/systemd/system/cloud-config.service

sudo systemctl stop cloud-final.service

sudo systemctl disable cloud-final.service

sudo rm /lib/systemd/system/cloud-final.service

sudo systemctl stop cloud-init-local.service

sudo systemctl disable cloud-init-local.service

sudo rm /lib/systemd/system/cloud-init-local.service

sudo systemctl stop cloud-init-upgrade.service

sudo systemctl disable cloud-init-upgrade.service

sudo rm /lib/systemd/system/cloud-init-upgrade.service

sudo systemctl stop cloud-init.service

sudo systemctl disable cloud-init.service

sudo rm /lib/systemd/system/cloud-init.service

sudo systemctl stop kdump.service

sudo systemctl disable kdump.service

systemctl daemon-reload

systemctl reset-failed

after the restart, systemd-analyze blamesee the effect.

2) install on a virtual machine

A virtual machine is used to simulate a physical machine. Now it is also a virtual machine. The difference lies in the mode of creating a hard disk. The former is a blank hard disk or a bare metal boot installation disk; The latter is a system hard disk that converts an Alibaba cloud image into a virtual machine hard disk format.

1, vm workstation

qemu-img.exe convert -f qcow2 aliyun_2_1903_x64_20G_nocloud_alibase_20210726.qcow2 -O vmdk aliyun_2_1903_x64_20G_nocloud_alibase_20210726.vmdk

when creating a virtual machine, use this file as a ready-to-use hard disk to start the machine.

2, qemu-kvm

alibaba Cloud images are released in the qemu-kvm format. You can directly start the machine.

​qemu-system-x86_64 -accel hax -name alinux -m 2048M -smp 1 -hda aliyun_2_1903_x64_20G_nocloud_alibase_20210726.qcow2 -cdrom CentOS-7-x86_64-NetInstall-2009.iso -boot c -vga std -net nic -nic tap,ifname=tap0

Note: -accel haxit is the accelerator for qemu on win platform. For more information, see https://github.com/intel/haxm其他系统无此参数 。.

3, Hyper-V

it should be qemu-img convert -f qcow2 aliyun_2_1903_x64_20G_nocloud_alibase_20210726.qcow2 -O vhdx aliyun_2_1903_x64_20G_nocloud_alibase_20210726.vhdx

or

qemu-img convert -f qcow2 aliyun_2_1903_x64_20G_nocloud_alibase_20210726.qcow2 -O vpc aliyun_2_1903_x64_20G_nocloud_alibase_20210726.vhd

after the conversion is successful, the virtual machine is created using this file as a ready-to-use hard disk to start the machine. The solution is as follows: 4. ESXi

4. ESXi

the vmdk converted from qemu-img failed to be started on esxi. The vmdk converted from normal start on vm workstation is compatible with esxi, but failed to be started on. Later I found StarWind V2V Converter

first, press "1. vm workstation" to convert the vmdk converted from qcow2. Select this vmdk as shown in "Local file" in the preceding figure, and then press the software operation wizard to directly deploy and generate virtual machines to remote ESXi or Hyper-V.

This software also supports Azure and AWS, which I have not tested.

5, virtualbox, parallels...

Not tested. Virtual machines have many options. Each virtual machine has many versions and supports different virtual hard disk formats. There are also modes called growable or thin, this involves the problem of file size transmission time during remote deployment...... All these are the problems of converting the original Alibaba Cloud qcow2 file with appropriate tools and software. For more information, see the above examples.

BTW, under my win platform, Hyper-V has the best performance.

6. After the virtual machine is generated

the procedure is the same as 3-1)-3-⑥ and 4.

IV. End

Selected, One-Stop Store for Enterprise Applications
Support various scenarios to meet companies' needs at different stages of development

Start Building Today with a Free Trial to 50+ Products

Learn and experience the power of Alibaba Cloud.

Sign Up Now