Ok, let's assume that you have rented a very cheap VPS, or in general that you want to install Gentoo on a machine where another Linux is already installed, and you cannot access the machine locally, or the machine has no USB or CDROM or network boot available at all. This is actually common on very cheap VPS where you might only have an emergency console access, but limited disk space and no external attachable media.
The overall idea is to remote access your VPS via SSH and start performing a Gentoo installation then, when you would be ready to reboot it, hot-replace your existing linux with the Gentoo installation.
NOTE: this is not for the faint of heart and having a snapshot/backup is STRONGLY recommended, as well as having a recovery console/KVM that you can access remotely.
I assume the following:
Login as root then follow the standard Gentoo installation guide (you can also refer to my quick notes here).
I will assume the Gentoo chroot is located at /mnt/gentoo.
Get to the point where you would be rebooting.
At this point, i suggest you install the Gentoo kernel alongside the original Linux kernel and boot the original linux with Gentoo kernel. If this is successful, it will be much better for the following. This is not mandatory anyway, just strongly suggested.
Ok, do a reboot to ensure your OLD linux still boots, and now is a good time to backup it or/and create a snapshot in case something goes wrong in the following.
Have you created the snapshot? Good, let's move to the critical part.
What we will do is to get into the Gentoo chroot, leverage that we can now break the original Linux install, and replace it with Gentoo. Consider that Gentoo currently lives under /mnt/gentoo while the old linux lives under /. After the next steps, the old linux will be gone and Gentoo will live under / instead of the old linux.
So, remount the usual dev/proc/sys/… stuff and go back into the Gentoo chroot. Mind you, you will not be able to get out of the chroot, so after the next step is complete you will need to hard-reset or manually power off/on your machine.
Good, now, inside the Gentoo chroot, mount the root partition as /mnt. Please note, this is actually /mnt/gentoo/mnt in terms of the root partition, as Gentoo is installed in /mnt/gentoo, but inside the chroot we see it as /. Also note, we do not bind-mount, but directly mount.
So:
[chroot] cd / [chroot] mount /dev/sda2 mnt [chroot] ls mnt bin boot dev etc home initrd.img initrd.img.old lib lib64 lost+found media mnt opt proc root run sbin srv swap sys tmp usr var vmlinuz vmlinuz.old
What you see is the original Linux, the one we want to replace, stored on the root partition. Now, let's make this clear: when we are inside the chroot (and i put [chroot] in the code snippets to make this clear), / refers to the Gentoo root (which is sda2:/mnt/gentoo) and /mnt now refers to the original Linux root (which is sda2:/).
Well, ready? After this point, the damage is irreversible.
Remove the old linux:
[chroot ]for i in bin etc home lib lib64 media opt root sbin usr srv var [chroot] do [chroot] rm -rf mnt/$i [chroot] done
Note that you must not touch the special folders boot, dev, proc, run, sys, tmp as they are not real folders and must stay there. Also, do not remove the mnt folder, that's where the Gentoo chroot is located… I have removed the srv folder as it's not needed by Gentoo on OpenRC. Of course, the boot folder doesn't need to be removed as well.
Cool! Now, your VPS is without an operating system. Sweating already? Let's fix that!
Time to copy the Gentoo chroot in place of the original Linux that we deleted:
[chroot ]for i in bin etc home lib lib64 media opt root sbin usr var [chroot] do [chroot] cp -a /$i mnt/ [chroot] done
This command will copy the entire Gentoo installation from the chroot to the real root. Note that, again, we skipped to copy the special folders for which there is no need to copy. This step will take longer, but you cannot move the files, you must copy, otherwise the chroot will stop working and… you will be in deep troubles midway.
Did the copy ended without errors? If not, fix and retry. The copy must be complete and flawless before you exit from the chroot, otherwise you need to restore your snapshot/backup.
Now, exit the chroot (exit or CTRL+D) and… well, you are now in a mixed situation, with a working Gentoo, but booted on a now-deleted original Linux. This is a dangerous situation from which you have no exit strategy but a hard physical shutdown or a hard reboot.
Do not attempt to type reboot / reset or poweroff! That will break your Gentoo installation, instead, do a hard reboot at this point.
As a final note, if you are not already running the Gentoo kernel (as suggested in step 1), you need now to run grub-mkconfig (or whatever) to ensure your Gentoo kernel will start at next reboot.
If all went well, you should now be reboot into Gentoo!