计算机技术学习札记

Install Custom Operating System on Lighthouse Application Server

Nowadays many cloud service providers like Tencent Cloud have provided a kind of special VPS called 'Lighthouse Application Server'. Targeted at students and small enterprises, this kind of VPS are usually more or less cheaper than so-called 'Cloud VM'. However, even though they are also a kind of VPS, providers usually limit the ability for us to install custom operating system on them, which means we can only use the given systems (like CentOS and Ubuntu).

Nevertheless, in fact, as long as the providers have given us the access to VNC connection on our virtual machines, there're still ways for 'hacking' a custom operating system on the light-weight application server. And this article is about how to install RHEL on Tencent Cloud light-weight application server, which is not a officially given choice of operating system.

Prerequisite

  1. You have full VNC access to your VPS. You can see the whole process of booting, from BIOS screen, GRUB options to login screen.

  2. Your VM disk is large enough to contain the installation ISO and the installed system.

Idea and Thoughts

Given that it's impossible for us to 'plug' a USB-disk into our VPS to install new system, we need to install operating system from a local ISO file. There's an interesting logic loop that if we store the ISO file on our virtual disk, It will be wiped out since during the installation the hard disk will be re-partitioned and formatted, and the installation cannot be finished.

Obviously, to prevent this loop we need to cut out a partition at the end of our virtual disk, store our ISO file there, and use GRUB to boot from that file.

BUT, there's another problem that, our VPS is always pre-installed with a given system (and we need it for providing GRUB), and usually this system's root partition occupies all the virtual disk. It's not an easy thing for us to shrink its root partition online (especially without LVM), so we need use some little hacks.

More detailed, we use a special 'mfsLinux' to help us. This special Linux is tiny (~30 MB) but with many tools (like fdisk, resize2fs) and network support. And it can be directedly loaded into memory using its vmlinuz and initrd images by GRUB. With the help of mfsLinux, we have this way to install our custom ISO:

  1. Put mfsLinux's initrd and vmlinuz files in some place (e.g. /root/).

  2. Reboot to GRUB command line, load mfsLinux into memory and boot.

  3. In mfsLinux, we use fdisk and other tools to shrink original system's root partition, and create a new partition in the free space.

  4. In mfsLinux or reboot into original system, we download / upload our custom ISO and may extract its initrd and vmlinuz for loading.

  5. Reboot to GRUB command line, load custom ISO, boot and install (never touch the little partition where ISO is).

  6. Reboot, you will have a brand-new system.

After that we can also use mfsLinux to wiped out the partition to store our ISO file, and extend our new system.

Steps

  1. Install a provided system, like CentOS.

  2. Download / upload mfsLinux's ISO, and extract the isolinux folder out. Remember the path.

  3. Reboot and press C when GRUB screen shows. Replace (hd0,msdos1) to your real partition and execute:

    linux (hd0,msdos1)/path/to/isolinux/vmlinuz
    initrd (hd0,msdos1)/path/to/initramfs.igz
    boot
    
  4. Login with password mfsroot directly or using SSH. Believe it or not, the tiny memory-inside mfsLinux supports SSH.

  5. Use fdisk and other tools (like resize2fs) to cut a little partition at the end of your virtual disk, which is large enough to contain your ISO.

  6. Reboot to original system. (Optional. mfsLinux has SSH enabled, you can also stay in it to do the following step)

  7. Download / upload your ISO to the new partition.

  8. Reboot to GRUB command line. Load the ISO manually. For RHEL 8 it's like: (ref: https://unix.stackexchange.com/a/298311)

    set root='hd0,msdos4' # Change to the partition you store your ISO file.
    set isofile='/your-iso.iso'
    loopback loop $isofile
    linux (loop)/isolinux/vmlinuz noeject inst.stage2=hd:/dev/vda4:$isofile # Change `/dev/vda4` too.
    initrd (loop)/isolinux/initrd.img
    boot
    

    Wait, and you should be able to enter the installation.