Overwriting a VPS Default Install Using Swap

in #linux6 years ago

1000px-Tux.svg.png

The Default

I rent a few VPS from a provider and I don't like their default install image at all.

The partitions are setup in silly ways, I don't trust some of the things they've done to the image, etc.

Starting off they have a /, /boot/, and swap partition to work with.

Luckily this, plus access to the client's GRUB on startup, gives us everything we need to overwrite the system remotely.

Time to swap it back and forth


Once logged in we deactivate the swap partition so that we can use it as a landing zone.
Screenshot_2018-04-16_23-43-10.png

I format it to ext4, doesn't really matter so long as it's not swap and readable by GRUB,
image.png

Then mount it somewhere and cd to it.
image.png

We download our fresh mini.iso into the new space. I host mine myself for simplicity.
GIFrecord_2018-04-16_235459.gif

We're done with this image, time to blow this sucka' away!
I do a hard reboot in the console and go to the GRUB commandline.

We can settle this land

image.png
Using the grub commands we can load the mini.iso that we just downloaded, and tell grub where the linux and initrd are.
After that we can boot and it should take us to the mini-install.

image.png

A new installation is like slipping into a warm bath.


From here on out it should act like a normal installation. The mini.iso is loaded into memory so you don't have to keep the /dev/sda2 partition hanging around.

GIFrecord_2018-04-17_001242.gif
GIFrecord_2018-04-17_001714.gif

Obliterating the old sda partitions including our mini.iso, there's no turning back now...


GIFrecord_2018-04-17_001957.gif
GIFrecord_2018-04-17_002231.gif

Select some base packages, openssh is helpful for remote machines :)
GIFrecord_2018-04-17_003419.gif

And that's about it! By the end if all goes well through installation there should be a fresh copy of linux (ubuntu server in this case) on the machine ready for you to do some work.

image.png

Tux image from: https://commons.wikimedia.org

Sort:  

P.S. This line should let people pin the photos they use to their own ipfs node so that they can ensure robust file availability, with this page as an example,
for i in $(curl -s https://busy.org/@schrosct/overwriting-a-vps-default-install-using-swap | grep "img src" | grep -i ipfs| sed -e 's/.*ipfs///g' -e 's/".*//g') ; do ipfs pin add -r "$i" ; done