Just Imagine! If I tell you that your Linux System will get wiped out and in the another moment it will be reinstalled and you don’t even need to reboot.
Seems Weird..! But now it’s possible, I will show you how it all goes around.
Recently, a new script named takeover.sh has taken the market by storm, the script makes it possible to Wipe and Reinstall a running Linux system via SSH.
Everything seems easy as using the script you can remotely take over your running Linux system and you can log into an in-memory rescue environment, as well as do all your task like unmounting original root file system, replace one distro with another without any interruption and all these can be done without even rebooting.
But to come over with the script you must have to know about the script a bit more deeply:
To try takeover.sh in your system you must be aware of its compatibility and for which system it is designed. As per the information from the team, it is designed for systems using sysvinit that support the telinit u command to reload /sbin/init.
Now, the important note comes forward, if your system uses something else or is not designed as per the compatibility, you will have to adapt it, or as it is not your cup of tea. Being a bit straightforward, it might not work at all for your Linux system.
Learn More About:
If you want to test this you can try this in a VM first. Just collect a group of files together and combine them as one and then extract it into a VM image.
Now that was for those whose system was not supporting the takeover.sh script but if your system is compatible with the commands then you can go for it, let’s learn how:
How to use takeover.sh to Wipe and Re-Install Linux Via SSH?
Using takeover.sh is not a big or tough task to overcome with. Just give a try, a bit risky but it will fun giving a try to wipe out all your content and reinstall the complete Linux system without rebooting. Seems exciting..!
Let’s see the usage of takeover.sh:
Step 1: Create a custom directory /takeover on your target system and mount a tmpfs on it.
Step 2: Extract your rescue environment there but you have to make sure that the rescue environment works fine, you can check out by chrooting into it and running a few commands. Make sure you do not bork filesystem permissions. Exit the chroot.
Step 3: Grab a recent copy of busybox (statically linked) and put it in /takeover/busybox. You can find binaries here. Make sure it works by trying something like /takeover/busybox sh.
Step 4: Copy the contents of this repository into /takeover.
Step 5: Compile fakeinit.c. Compile fakeinit.c in such a way that it can properly work inside the takeover environment.
Note: If your rescue environment has gcc, you can just compile it inside the chroot: chroot /takeover gcc /fakeinit.c -o /fakeinit. Otherwise, you might want to statically link it.
Step 6: It is recommended to shut down as many services as you can on your host. takeover.sh will by default set up an SSHd listening on port 80, though you may edit this in the script.
Step 7: Run sh /takeover/takeover.sh and follow the prompts.
That was awesome… Just take a long breath and spend a few seconds relaxing.
Now cross your fingers and if you have done everything perfectly then you can now be glad to get introduced to the new script.
After all this, you can use your new SSH session to kill any remaining old daemons (kill -9 is recommended to make sure they don’t try to do anything silly during shutdown), and then unmount all filesystems under /old_root, including /old_root itself. You may want to first copy /old_root/lib/modules into your new tmpfs in case you need any old kernel modules.
This is also not the end…
You may still have to clean up LVM volumes (dmsetup is your friend) and similar before you can safely repartition your disk and install Gentoo Linux.
Now here comes the final step: Unmount all filesystems, then reboot -f or echo b > /proc/sysrq-trigger.
Last but not the least:
Warning to All:
Takeover.sh is on experiment and if you’re not at all aware of what is going on then it is a prior request of not using this script on any of your systems. The above commands are not just to see and copy paste, all commands need proper understanding and experience in the Linux system. So please do not try if you are new to Linux.
For more information and detailed explanation, you can refer here.