A few days ago I stumbled upon my old HP DataVault X312 that I haven't used for years. Unfortunately it doesn't have any video outputs, which makes it kind of hard to install anything on it (except of the original Windows Home Server OS it was shipped with). Not willing to spend anything on the overpriced custom made VGA adaptors, I was looking for a different solution...

Attempt #1: PXE

Except of buying the mentioned adaptor and just plugging in a display and keyboard, the X312 supports PXE out of the box. That's actually the way Windows Home Server is restored, if necessary.

So I spent a few hours on preparing a Debian netboot image, setting up a DHCP and TFTP server on my MacBook and trying to get it to boot over PXE.

Long story short: it didn't work. At least not as excepted. The network LED switched from orange to green, indicating that GbE is up. It receiced an IP, but I couldn't even ping it. And without a display it's hard to figure out if the X312 just takes forever to boot over PXE or it just doesn't work.

There must be another way...

### Attempt #2: debootstrap

Reading through blogs where people either describe how to set the X312 up using the adaptor (come on...) or PXE, I stumbled upon a comment mentioning debootstrap. That's it. No further clarification - he just managed to do it using debootstrap. Well, great!?

Looking through the docs, this reminded  me pretty much of the process of installing Arch Linux. Basically, you install Debian in a chroot environment on your own machine and then just plug it into the target. Seems to resolve the issue with not having a video output.

First of all, we need a machine running Debian. So I quickly created a virtual machine, booted it and fowarded a USB stick to it. Following a gist by tr3buchet, I managed to debootstrap the USB stick:

# install dependencies
sudo apt install debootstrap coreutils util-linux e2fsprogs

# find the mounted usb stick
# should be listed as something like /dev/sdb1
df -h

# unmount the stick
sudo umount /dev/sdb1

# create a new partition table with a single partition
sudo fdisk /dev/sdb
o # create a new partition table
n # add a new partition (use defaults)
a # toggle bootable flag on partition 1
w # write and exit

# create a filesystem on the new partition
sudo mkfs.ext2 /dev/sdb1

# mount the stick in the filesystem
mkdir ~/usb
sudo mount /deb/sdb1 ~/usb

# install Debian base system
# replace "stretch" with the latest release, at the time of writing, the latest was Debian 9.6 "Stretch"
sudo debootstrap --arch amd64 stretch /home/grumpy/tmp/usbstick http://ftp.debian.org/debian/

# enter chroot
sudo mount -t proc none ~/usb/proc
sudo mount --bind /sys ~/usb/sys
sudo mount --bind /dev ~/usb/dev
sudo cp /etc/resolv.conf ~/usb/etc/resolv.conf
sudo chroot ~/usb

The base system is now installed inside the ~/usb and we entered the chroot environment. Now let's set up Debian to be used inside the X312:

# udpate /etc/apt/sources.list to contain the following line
deb http://ftp.de.debian.org/debian/ stretch main contrib non-free
apt-get update

# install utils
install sudo vim locales ntp openssh-client openssh-server

# add your ssh key to be able to access the machine later
mkdir ~/.ssh
vim ~/.ssh/authorized_keys
  # paste your key into the file, save and close it
chmod 600 ~/.ssh/authorized_keys

# optional: add a root password
# might be useful for debugging (see troubleshooting section)
passwd

# setup locales
dpkg-reconfigure tzdata
dpkg-reconfigure locales

# setup networking (/etc/network/interfaces)
auto enp2s0
iface enp2s0 inet dhcp

# setup ntp
dpkg-reconfigure ntp

# install grub
# when the "Configuring grub-pc" menu pops up, select "/dev/sdb"
aptitude install grub-pc linux-base linux-image-amd64

# setup /etc/fstab
sudo blkid /dev/sdb1 -o value | head -1 > /etc/fstab

# make sure fstab looks like this:
# <file system>                           <mount point> <type> <options>                                    <dump> <pass>
UUID=769728ac-2c37-435f-a688-152ebe3018b3 /             ext4   noatime,nodiratime,errors=remount-ro         0       1

# exit chroot and unmount everything
exit
sudo umount ~/usb/sys
sudo umount ~/usb/dev
sudo umount ~/usb/proc
sudo umount ~/usb

Making sure the debootstrapped stick works

Before plugging in the debootstrapped stick into the X312 make sure that it works as expected. For this, simply create a new virtual machine without any OS or drives, change the boot order to allow booting from external devices and attach the USB stick to it:

empty virtual machine configuration
Boot order for empty virtual machine in Parallels

The virtual machine should boot and display the Debian login prompt.

Booting Debian on the X312

Make sure, there's no hard disk installed and plug in the USB stick into the lower usb port on the back. Power on the X312 and wait for it to boot. The network light should be orange at first but firmly turn off after ~20 seconds and eventually switch to green. Now the X312 should be available in your network and your router should display a new device with its assigned IP.

From here on, you can ssh into it and for example install OpenMediaVault as I did.

Troubleshooting

To make sure that debian is booting at all, have a look at /var/log/syslog and see if Debian at least logged something.

If you can see logs from Debian trying to boot on the X312, you should be able to spot the issue using those.

My X312 had an issue with not beeing able to start the network. The issue was related to the network device having a different name as I assumed. I used eth0 in the first place, though the device on my X312 was called enp2s0.

To get the names of the available network devices, I simply logged them to a file at boot:

# create a rc.local
eco 'ip addr >> /root/debug_log' >> /etc/rc.local
chmod +x /etc/rc.local

Just make sure to not write it to /tmp, since the folder gets wiped after each boot.