8 ms·
Takeover.sh – Wipe and reinstall a running Linux system via SSH without reboot
- simon1573 10y agoI guess this could be really useful for installing distributions that are not available at some VPS providers.
- tomsmeding 10y agoThere is a similar script on github somewhere that does some more work and can install arch over debian on a DigitalOcean host. It's beautiful.
- tyingq 10y agoAnother trick to do that is to use the VPS's rescue mode, download qemu, and start it with the remote desktop / VNC console. Then, do the install from there. Poor man's IPMI.
- nashashmi 10y agoSomebody correct if I am wrong, but this script somehow allows the session to live in the RAM. Once the OS is running directly from the RAM, the hard drive can be wiped and a new OS can be installed. The system is then booted to run off of the hard drive.
- VoidWhisperer 10y agoI feel like this is, on one hand, an amazing thing to be able to do because it removes the necessity to have IPMI to remotely re-install a system. On the other hand, this seems like it would be an incredibly easy thing to screw up and potentially leave yourself with a corrupted or unbootable system.
- ams6110 10y agoHence the advice to only do this on machines where you have physical access, or at least can trigger a PXE boot via IPMI.
- lisivka 10y agoThis scripts creates another root, then substitutes /sbin/init using `mount --bind`, then reloads /sbin/init, which pivots into new root with fakeinit. IMHO, systemd in container mode can be used instead of fakeinit.
- dredmorbius 10y agoWhich is fundamentally how an installer works already. Look up the chroot-install method for Debian/Ubuntu, as an example of this in a user-accessible manner. The process uses debootstrap, but as I understand was originally developed via a chroot shell on a running system and either partition or ramdisk-based bootstrapping of a new system.
- gizmo 10y agoPretty cool, although I'm pretty sure I would never use something like this. What has saved my skin on a number of occasions is the ability to boot remote servers into rescue mode and chroot into the broken system. That way you can use package managers, all your diagnostic tools, and everything else the boot image doesn't provide. Basically you just mount the different partitions and then chroot just swaps /proc /sys /dev of the rescue image with the real ones, and BAM you're back in business. For details see threads like: http://superuser.com/questions/111152/whats-the-proper-way-to-prepare-chroot-to-recover-a-broken-linux-installation http://superuser.com/questions/111152/whats-the-proper-way-t... I know that for many of you this isn't rocket surgery, but for those who don't know you have to google for "chroot" when you boot into a rescue image and discover you can't do anything, you might just remember this post.
- rijoja 10y agoI like the term rocket surgery, I will steal it from you for sure.
- gizmo 10y agoIf I'm not mistaken, credit goes to Chris Rock (who is not me).
- jonathonf 10y agoPretty sure the conflation has been around ever since rocket science and brain surgery have been used as a comparison. :)
- AnkhMorporkian 10y agoI don't tend to link youtube videos on HN, particularly of the comedic type, but I'm just going to leave this here for anyone who wants a good laugh for their morning. https://www.youtube.com/watch?v=THNPmhBl-8I https://www.youtube.com/watch?v=THNPmhBl-8I
- Aissen 10y agoFYI, there's vps2arch that does the same thing with a different approach: https://github.com/drizzt/vps2arch https://github.com/drizzt/vps2arch Edit: it doesn't really do the same thing. vps2arch could be implemented on top of takeover.sh for better reliability.
- camtarn 10y agoSeeing if I understand what this is doing: this keeps running the same Linux kernel and kernel modules, but swaps out absolutely everything else up to and including the init system - is that right?
- efficax 10y agoMore precisely, what it does is start a new init system on a pseudofilesystem, starts an sshd chrooted to that new system, and lets you then login there, where you can then, if you want, umount the original root fs, wipe it, install a new os, then reboot the system.
- camtarn 10y agoThanks!
- NGTmeaty 10y agoHoly shit, that's really cool.
- dpweb 10y agoremoved. No delete on HN comments? interesting
- andruby 10y agoWhere does this takeover.sh readme mention anything about missing pg_dump files?
- cperciva 10y agoIt doesn't... but wiping and reinstalling a system would result in missing pg_dump files...
- bjacobel 10y agoI think you meant to comment on the GitLab postmortem thread.
- dpweb 10y agooops, yeah..
- rocky1138 10y agoYou can delete comments but only up until a certain amount of time has passed, I think. I've been able to do it.
- Klathmon 10y agoI believe once someone replies you can no longer delete it. And you can edit for up to 2 hours after you've made the comment.
- dredmorbius 10y agoThis is conceptually similar to the chroot installation method, which has been a documented, if not entirely standard, method on Debian for quite some time. https://www.debian.org/releases/stable/amd64/apds03.html.en https://www.debian.org/releases/stable/amd64/apds03.html.en https://wiki.debian.org/chroot https://wiki.debian.org/chroot
- yellowapple 10y agoIt's also a common installation method for the more "advanced" distros. The "SAG Trifecta" (Slackware/Arch/Gentoo) uses a lot of chrooting in its installation procedures. What's interesting about takeover.sh, though, is that it goes a step further and causes the chrooted system to actually replace an existing OS without a reboot and (theoretically) without involving additional boot media.
- predakanga 10y agoFor anyone interested in adding this to their toolkit, I would suggest reading this StackOverflow answer: http://unix.stackexchange.com/a/227318/189858 http://unix.stackexchange.com/a/227318/189858 In short, the answer details how to switch your running system to use an in-memory only root filesystem, without restarting. This allows installing a new OS, resizing the OS disks, etc. It's a risky operation, but the linked answer covers many pitfalls that you might run into - I recently used it to shrink the root partition on a remote server, very much appreciated the detail.
- aaronmdjones 10y agoI've been using this procedure to remotely replace operating systems for years. The most common scenario is a VPS provider that doesn't give you the choice of OS you want. Infact, I will be using it later today, to replace a Debian system with Gentoo, no less. The README in OPs link is spot-on here (the last few paragraphs).
- djsumdog 10y agoThis is exactly what I thought when I saw this post. I really want to use Void Linux on a provider, but no one supports it (except for those who allow custom images like Linode). It'd be great to be able to provision a standard Ubuntu or CentOS box and then replace it with the OS I actually want to run.
- drvdevd 10y agoThanks for this! Ive been doing wacky stuff like kexec which was completely unecessary when I could've just done a pivot_root...
- ce4 10y agoReminds me of Debian Takeover from more than 10 years ago :-) https://wiki.debian.org/DebianTakeover https://wiki.debian.org/DebianTakeover
- zimbatm 10y agohttps://github.com/elitak/nixos-infect https://github.com/elitak/nixos-infect is similar but doesn't require to pivot root.
- geoffmcc 10y agoI wonder if this would help me switch from Ubuntu Desktop to Ubuntu Server on my laptop that has a broken screen.
- pipo098 10y agoyou can always connect an external screen and go from there
- geoffmcc 10y agoI can connect HDMI and can get into UBUNTU, but I cannot get into BIOS to tell it to boot from USB. If I could get that figured out- I think HDMI will activate on the boot of the ISO, but Im not sure. I even tried VGA to a monitor, but that dont show me bios either. Dont wake up till Ubuntu starts to boot.
- umanwizard 10y agoCan you physically disconnect the hard drive? Maybe you'll get lucky and USB will be next in the boot order. Contrary to popular belief, you can USUALLY plug the hard drive back in while the system is running from USB without any problems.
- geoffmcc 10y agooh. You may be onto something. I am pretty sure USB is boot option 2, but if not it would be my disc drive- but I can make that work too. It's a Lenova (maybe acer) laptop with some wierd tool it seems to open it up. I can try to figure it out though. I just want to use it as an inhome server so it dont need to look pretty.
- umanwizard 10y agoKeep in mind, you might get a kernel panic when you try to hot-plug the drive back in. It's not guaranteed to work, but it's worth a try. If that doesn't work (kernel panic or whatever) you can disconnect the drive and connect it via a SATA-to-USB adapter in which case hot plugging should definitely work.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- notaplumber 10y agoThis sounds similar to the more cleverly named FreeBSD Depenguinator project which could be written over top of a remote Linux server replacing it with FreeBSD, without console. If you have remote console access, a similar thing can be done for OpenBSD by dd(1)'ing a miniroot ramdisk install image.
- Odiee 10y agoI need system linux. Send me please
- technologyvault 10y agoWish I had known about this hack before today, even if it is just experimental at this point.
- rdslw 10y agoAnother nice trick of this family (with reboots, or without with using systemd-nspawn) lies with clever btrfs usage. Long story short: * use btrfs, and create your main root filesystem as a btrfs partition subvolume and another btrfs subvolume for snapshots (also a sub of master btrfs partition) * to start any experiment (e.g. installing whole gnome and 500 different packages you MIGHT WANT TO REVERT in the future) create before the risky operation snapshot (btrfs subvolume snapshot / /.snapshots/yournameofsnap) of current filesystem * experiment in any way :) * switch between old root (snapshot you created) or the new one with (btrfs subvoulme set-default) * delete any of them (btrfs subvolume delete) btrfs copy-on-write allows all of these commands to happen instantly without (almost) any actual copying. Also booting from both volumes is possible without any additional steps as long as master btrfs partition is the one to be booted from UEFI. https://wiki.archlinux.org/index.php/Btrfs https://wiki.archlinux.org/index.php/Btrfs
- floatboth 10y agoCongratulations, you've reinvented ZFS Boot Environments :)
- LeoPanthera 10y agoOnly to a very high level. btrfs snapshots are writable, but share blocks, so you can boot directly from a snapshot. It's a better system.