Do you use let's encrypt?

5847 votes ~ 21 comments


DebianInstaller Remotely with Multiple Network Interfaces

Posted by otrojake on Wed 22 Sep 2010 at 11:33

I'm going to detail a process I've used recently at my work to install Debian on a computer already running Linux that was located hundreds of miles away from our location. The distance and cost of having a tech at the facility where the server was located necessitated using a method where we could install Debian without having anyone physically touch the machine.

Most of what I'm going to detail has been gleaned from the DebianInstaller wiki on remote installation. Many thanks to the author for providing a groundwork for this article. That article, however, does not mention what to do if there are multiple interfaces on the remote machine. As one does not have physical access to the remote machine, it is imperative that the remote computer has the correct address bound to the correct interface.

Some Caveats
As noted in the above link, this process is not to be taken lightly. You are most likely looking at this article because you need to install on a machine that you have no access to. If improperly configured, the kernel will either fail to boot on the remote machine or fail to bring up the network resulting in physical intervention being needed on the target computer. Triple-check your set up and test, test, test before deploying. .

The process
1. You'll need a running Debian system somewhere to compile the installer kernel. I used a virtual machine and it made the process much easier.

2. Get the source for the debian-installer package:

# apt-get source debian-installer

3. Get the build dependencies:

# apt-get build-dep debian-installer

4. Install nameif through the net-tools package if not already installed:

# aptitude install net-tools

5. Change into the debian-installer directory and insert the following line at the beginning of build/pkg-lists/netboot/i386.cfg.

#include "network-console"

6. Create a preseed file with--at the very least--the following, changing values as needed and placing it somewhere you can remember:

d-i preseed/early_command /bin/nameif
d-i debian-installer/locale string en_US
d-i debconf/priority select critical
d-i auto-install/enabled boolean true
d-i netcfg/choose_interface select installer0
d-i netcfg/disable_dhcp boolean true
d-i netcfg/get_nameservers string
d-i netcfg/get_ipaddress string
d-i netcfg/get_netmask string
d-i netcfg/get_gateway string
d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string myserver
d-i netcfg/get_domain string myhome.none
d-i network-console/password password password
d-i network-console/password-again password password

7. Add the following to build/config/local:


8. Create build/sources.list.udeb.local containing:

deb stable main/debian-installer
deb testing main/debian-installer

9. Once you are sure of your configuration, you can build the netboot image:

fakeroot make rebuild_netboot

10. Normally, this is where we would be done, but we need to make some modifications to the initrd we just created. (You can make these changes in the Make file if you feel so inclined. I found it much easier to make minor changes to the initrd rather than recompiling each time I need to make a change.):

cd tmp/netboot
mkdir initrd
cp initrd.gz initrd/
cd initrd/
gunzip initrd.gz
cpio -i --no-absolute-filenames < initrd #IMPORTANT! Without the --no-absolute-filenames option this will extract into root "/"

11. We've now extracted what is contained in the initrd. We've got to do some editing to make sure the correct interface is assigned the correct IP address. Take a look at the MAC addresses on the remote system. For this example we'll assume that we want installer0 to be our main interface and to be bound to 00:00:00:00:00:01 with another interface with a MAC address of 00:00:00:00:00:02.

cp /sbin/nameif bin/nameif
echo -e "installer0 00:00:00:00:00:01\n\ninstaller1 00:00:00:00:00:02" > etc/mactab

12. Now that we've got the system in place to bring up the correct interface for installer we can get the initrd ready for boot again:

find . | cpio -o -H newc > initrd
gzip -c initrd > initrd.gz

13. You'll probably want to copy the kernel and initrd to some place convenient:

cp initrd.gz ~/debian-installer-rd.gz
#cd back to the build/tmp/netboot directory
cp vmlinuz ~/debian-installer-vmlinuz

14. Now we need to configure the bootloader on the target system.

If grub1, add the following to the top of the /boot/grub/menu.lst:

title debian installer
        root (hd0,0)
        kernel /boot/debian-installer-vmlinuz rw ramdisk_size=24000 root=/dev/rd/0
        initrd /boot/debian-installer-rd.gz

AND copy debian-installer-vmlinuz and debian-installer-rd.gz to the boot folder on the target system.

If grub2, rename the kernel image and initrd to include a kernel version. For example vmlinuz-2.6.32-5-686-installer and initrd.img-2.6.32-5-686-installer and copy those files to the boot folder on the target system. Then run:

# update-grub

If lilo, NOTE: I have not tested this under lilo. If this is incorrect, comment and let me know. The source article used this configuration to boot the installer kernel and initrd. I imagine since there hasn't been any major revisions to lilo lately that this will still hold true.


15. Now for the moment of truth. Check everything again to make sure that your interface is correctly configured in the preseed file. Also check your mactab again to make sure that you entered the MAC addresses correctly. If any of these values are wrong, the installer kernel will boot an fail to bring up the interfaces, leaving you with an unreachable machine. This is where a virtual machine pays off. You'll be able to boot the installer kernel and make sure there are no errors. I highly recommend using a virtual machine for this purpose.

16. After you are absolutely sure everything is configured correctly, reboot the remote system.

17. SSH into the remote system:


18. Run through the installer process. Do NOT finish the installation without performing this step, or the new installation will not be guaranteed to bring up the interfaces with the correct interface names. Before selecting "Finish the installation" select "Execute a shell" and run the following commands (assuming /dev/sda1 is the device name of your newly created root partition--check this with fdisk -l):

mkdir /mnt/newinstall
mount /dev/sda1 /mnt/newinstall
rm /lib/udev/rules.d/75-persistent-net-generator.rules
rm /mnt/newinstall/lib/udev/rules.d/75-persistent-net-generator.rules

Now edit /mnt/newinstall/etc/udev/rules.d/70-persistent-net.rules to make sure that the MAC addresses line up with the interface names. For example, change the line

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:00:00:00:00:01", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"


SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:00:00:00:00:01", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="installer0"

19. Once those commands have been executed run exit to drop back to the installer screen. Now you can finish the installation.

20. If you've done everything right, your remote computer will now boot into the newly installed Debian system. A couple of housecleaning items once booted into the new system:

Change the interfaces from installer0,installer1 back to eth0,eth1:

Edit /etc/network/interfaces, changing all instances of installer0 to eth0 and also edit /etc/udev/rules.d/70-persistent-net.rules, also replacing instances of installer0 or installer1 to eth0 or eth1.

21. Reboot one last time to make those changes final and configure your system however you see fit! And congratulations on installing a new OS without ever touching the machine!



Re: DebianInstaller Remotely with Multiple Network Interfaces
Posted by Anonymous (110.233.xx.xx) on Wed 29 Sep 2010 at 04:43
Perhaps a patch is required:

-aptitude install nameif
+aptitude install net-tools


[ Parent | Reply to this comment ]

Re: DebianInstaller Remotely with Multiple Network Interfaces
Posted by otrojake (72.24.xx.xx) on Wed 29 Sep 2010 at 15:54
Changed. Thanks.

[ Parent | Reply to this comment ]

wide lines
Posted by Anonymous (85.127.xx.xx) on Wed 11 Apr 2012 at 18:59
This page is wider than my firefox window, so I have to scroll left-right to read each line. Can you change the layout?

[ Parent | Reply to this comment ]