Hey there, it’s been a long time since last blog post. Life happened. And I crashed my server more than a year ago. So why writing a new blog post if I can’t publish it!
I finally took the time to fix my server. So my first priority was to fix my blog to write about this salvation.
And you know what? My blog was on Gitlab Pages all along 🤦 Anyway, let’s talk about how this server was salvaged.
Contexte
So I own an OVH Kimsufi dedicated hosting service. And more than a year ago, I crashed it, like bad. I don’t even remember what I did, that’s not really relevant. The relevant part is how I salvaged it.
OVH does provide a web interface to reset the server with a brand new operating system. But there is no way to control the configuration of partitions. The partition table will just be wiped out.
The thing is, I have 2 partitions on that server, / and /home. And I have
a lot of data in /home that I would not like to lose. Sure, I could backup,
but I don’t have external disks at home anymore. I could rent disk storage
somewhere, but I don’t want to spend money on it. And where is the fun, that’s
the entire point of partitioning a disk in the first place, so that I can just
wipe the OS without worrying.
Rescue mode
First of all, OVH Kimsufi, like probably all the other similar services, provide a rescue mode. It basically allow to start a cheap machine hosted by them, that will have access to the disks of your crashed server. So I’m not completely helpless.
So, let’s choose an operating system
We are here for the fun, aren’t we? And I have been playing with
guix for quite a while now, let see if I can get
that deployed.
What is guix?
guix is a declarative operating system [1]. You describe how the system should
be in a configuration file, then you deploy it. If you want to change something
(add a user, start a Postgres service, install a new software), you change the
configuration, then you deploy again.
Sure, it’s less flexible, but you always know what is on your system. And you
can track your configuration file in a version system. And guix itself do not
erase the previous deployment, so rollback is trivial.
I have tried guix on my local desktop (in WSL2, because why make it easy).
But after a few months, I droped it for being not flexible enough. But a local
laptop and a server have very different constraints: I need more stability, more
traceability and less flexibilty on a server.
Just install guix
Yes, that is what I thought, but two problems arised that I didn’t see coming:
-
how to use
guixon a cheap rescue mode machine? -
how to install
guixon the partition?
guix on rescue mode
A year ago, I already tried some rescue operations without success. One of
the problem was that a simple guix pull (to update guix) was getting an
out of memory error. It actually lead me to a very deep rabbit hole (hey!),
where I tried to actually build the image on another machine [2], then transfer the result to the rescue
machine, then deploy. But it brought more questions, like what is the format
of the image, how do I transfer it, and, should I deploy on /dev/sda1 or the
entire disk?
Where to deploy the guix image?
I was convinced, that guix was handling the entire machine, and therefore, the
entire disk, partition table included. But I didn’t want the partition table to
be erased or replaced.
It took me a while to realize that it was not the case. Like any OS, it only
install on the / partition. Then you can configure your OS to mount other
partitions in your system. Once I understood that, I was relieved, but it
weirdly took me too long, mostly because I was not asking the right questions.
So, just install it?
In the end, pretty much yes. I now know that only /dev/sda1 will be touched.
And about the RAM problem? I decided to not update guix: I can still update
once the real server is started.
Here is the configuration.
(define-module (operating-systems tuziwo)
#:use-module (gnu)
#:use-module (guix)
#:export (tuziwo))
(use-service-modules networking ssh)
(use-package-modules ssh)
(define-public tuziwo
(operating-system
(host-name "tuziwo.info")
(timezone "Europe/Paris")
(locale "fr_FR.utf8")
;; No keyboard-layout: irrelevant over SSH, and the default is US.
(bootloader (bootloader-configuration
(bootloader grub-bootloader)
(targets '("/dev/sda"))
(timeout 0)))
;; net.ifnames=0 keeps the NIC named "eth0", as in rescue mode.
(kernel-arguments '("console=ttyS0" "console=tty0" "net.ifnames=0"))
(file-systems (cons* (file-system
(device (file-system-label "guix-root"))
(mount-point "/")
(type "btrfs")
(options "compress=zstd"))
(file-system
(device (uuid
"aa8c009c-a1ed-44fc-91dd-f42eeca749e7"))
(mount-point "/home")
(needed-for-boot? #f)
(type "btrfs")
(options "compress=zstd")) %base-file-systems))
(swap-devices (list (swap-space
(target (uuid "c8c42b4c-d3d8-4b18-ab52-e700eeda789c")))))
(users (cons (user-account
(name "woshilapin")
(group "users")
(supplementary-groups '("wheel"))
(uid 1000)) %base-user-accounts))
(services
(append (list (service static-networking-service-type
(list (static-networking (addresses (list (network-address
(device
"eth0")
(value
"37.187.7.46/24"))))
(routes (list (network-route
(destination
"default")
(gateway
"37.187.7.254"))))
(name-servers '("213.186.33.99"
"8.8.8.8")))))
(service openssh-service-type
(openssh-configuration (openssh openssh-sans-x)
(port-number 22)
(authorized-keys `(("woshilapin@osrd-laptop.2026.11" ,
(local-file
"/home/woshilapin/.ssh/id_ed25519.pub")))))))
(modify-services %base-services
(guix-service-type config =>
(guix-configuration (inherit config)
(authorized-keys (append
(list (local-file
"/etc/guix/signing-key.pub"))
%default-authorized-guix-keys)))))))
(sudoers-file (plain-file "sudoers"
(string-append (plain-file-content
%sudoers-specification)
"woshilapin ALL = NOPASSWD: ALL\n")))))
tuziwo
Then after mounting /dev/sda1 on /mnt, use guix system init tuziwo.scm mnt
/to deploy. You can then reboot the OVH server from the Kimsufi web interface.
And now what?
Let’s go a step further, and start using guix deploy. This way, I don’t have
to quit my laptop to deploy a new version of the server. The way it works: you
build the system locally, you create an archive, you send the archive to the
server, where it is extracted, then installed. All of it is done in a simple
guix deploy.
guix deploy takes a file that describes a list of machines, one in my case.
(define-module (machines tuziwo)
#:use-module (gnu machine)
#:use-module (gnu machine ssh)
#:use-module (operating-systems tuziwo)
#:use-module (guix))
(define tuziwo-machine-ssh-configuration
(machine-ssh-configuration (host-name "tuziwo.info")
(host-key
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB4CV6nerE3fDhYaypmLFJ+P9pwA6ra5fC5bfMw2HRX+")
(system "x86_64-linux")
(user "woshilapin")
(identity
"/home/woshilapin/.ssh/woshilapin@gmail.com.rsa")
(port 22)))
(define tuziwo-machine
(machine (operating-system
tuziwo)
(environment managed-host-environment-type)
(configuration tuziwo-machine-ssh-configuration)))
(list tuziwo-machine)
Then you just need to guix deploy --load-path=$PWD machines/tuziwo.scm. Note
however that this deployment doesn’t restart the machine, nor the services. You
can then guix deploy --load-path=$PWD machines/tuziwo.scm --execute — sudo
reboot --kexec to reboot the entire machine, or with herd restart ssh to only
restart a specific service.
I’m pretty happy with this new setup, compared to the old one that was docker
only, with an Apache in front.