Skip to content

Commit

Permalink
Add image based approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Cornelicorn committed Dec 15, 2023
1 parent ddbf748 commit 54b6546
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/image
/image.tar
/mkosi.cache
/mkosi.rootpw
/mkosi.output
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Reimage any VPS without KVM access
# Reimage any VPS without KVM access

This repo conceptually shows how you can use systemctl soft-reboot to switch
to a tmpfs root filesystem, which allows you to reformat and reinstall the
OS preinstalled on your VPS with a different OS.

## Tar based

```bash
mkosi build
rsync -zP image.tar root@ip:/root/
mkosi --image=debian-tar build
rsync -zP mkosi.output/debian-tar.tar root@ip:/root/
ssh root@<ip>
mkdir -p /run/nextroot
cd /run/nextroot
Expand All @@ -13,3 +19,19 @@ ssh root@<ip>
cryptsetup close root # Close old root cryptsetup mapper if you have that
# Repartition hard drive and install your system
```

## Image based

```bash
mkosi --image=debian-image build
rsync -zP mkosi.output/debian-image.raw root@ip:/root/image.raw
ssh root@<ip>
mount -o remount,size=1700M /run
cp image.raw /run/image.raw
systemd-dissect -M /run/image.raw /run/nextroot
cp /etc/ssh/ssh_host_* /run/nextroot/etc/ssh/
systemctl soft-reboot
ssh root@<ip>
dmsetup remove root # Close old root cryptsetup mapper if you have that
systemd-repart --copy-from --dry-run=no --empty=force /run/image.raw /dev/vda
```
15 changes: 15 additions & 0 deletions mkosi.images/arch-image.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Distribution]
Distribution=arch

[Content]
Timezone=UTC
Bootable=yes
Packages=
linux
systemd
bash
pacman
openssh

[Output]
Format=disk
20 changes: 20 additions & 0 deletions mkosi.images/debian-image.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Distribution]
Distribution=debian
Release=sid

[Content]
Timezone=UTC
Bootable=yes
Packages=
linux-image-amd64
systemd
systemd-boot
dbus
udev
bash
apt
openssh-server
systemd-resolved

[Output]
Format=disk
1 change: 0 additions & 1 deletion mkosi.conf → mkosi.images/debian-tar.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Packages=
fdisk
cryptsetup
mkosi


[Output]
@Format=tar
Empty file added mkosi.output/.gitkeep
Empty file.

0 comments on commit 54b6546

Please sign in to comment.