Install Custom Operating System in Light-weight Application Server
Nowadays many cloud service providers like Tencent Cloud have provided a kind of special VPS called ‘Light-weight Application Server’. Targeted at students and small enterprises, this kind of VPS are usually more or less cheaper than so-called ‘Cloud VPS’. However, even though they are also a kind of VPS, providers usually limits 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 #
- You have full VNC access to your VPS. You can see the whole process of booting, from BIOS screen, GRUB options to login screen.
- Your VM disk is large enough to contain the installation ISO and the installed system.
Idea #
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.
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.
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:
- Put mfsLinux’s
initrd
andvmlinuz
files in some place (e.g./root/
). - Reboot to GRUB command line, load mfsLinux into memory and boot.
- In mfsLinux, we use
fdisk
and other tools to shrink original system’s root partition, and create a new partition in the free space. - In mfsLinux or reboot into original system, we download / upload our custom ISO and may extract its
initrd
andvmlinuz
for loading. - Reboot to GRUB command line, load custom ISO, boot and install (never touch the little partition where ISO is).
- 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 #
- Install a provided system, like CentOS.
- Download / upload mfsLinux’s ISO, and extract the
isolinux
folder out. Remember the path. - 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
- Login with password
mfsroot
directly or using SSH. - Use
fdisk
and other tools (likeresize2fs
) to cut a little partition at the end of your virtual disk, which is large enough to contain your ISO. - Reboot to original system. (Optional. mfsLinux has SSH enabled, you can also stay in it to do the following step)
- Download / upload your ISO to the new partition.
- 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 should be able to enter the installation.