[GUIDE] DEBOOTSTRAP: Installing Debian into a folder in a running system

    • Official Post

    is utility that can be used to install a Debian base OS system into a directory. This can be useful in some cases where the current installation kernel does not recognize some hardware (like a network card or hard disk drive).

    For the wheezy base distribution is well known that the current default kernel lacks some hardware drivers that are present in the backport 3.16.

    Related ASUS H170I-PLUS D3 intel I219-V card and the qualcom atheros 8171 are not supported under default kernel 3.2

    This guide covers how to perform a minimal Debian install into a mounted disk with a current running networked system.

    What you need

    • Any recent running linux distribution (Debian jessie or testing, ubuntu, fedora, systemrescuecd) with network working. If debootstrap is not installed use your package manager utility to install it.
    • An empty drive that's gonna be the target disk for install

    is worth to mention that the debootstrap utility comes bundled in many distros including systemRescueCD, so you can grab that or a live ubuntu or any other that's available with recent kernel.

    The full installation into a drive from running system requires three main steps:

    • Run debootstrap into a directory (mounted drive). This will download all the base files for Debian into a directory. These base files exclude kernel
    • Edit /etc/fstab to add the entries for the new filesystem in the base install directory and install a kernel
    • Install grub loader into the new disk.

    First we will assume the target disk has been already partitioned with one partition for rootfs and one for swap. The partitioning procedure is not covered here and is targeted at disks using msdos partition type (MBR) not GPT which is needed for UEFI

    Let's create our filesystem in the first partition and swap for the logical one.

    mkfs.ext4 /dev/sdb1
    mkfs.swap /dev/sdb5

    Now we run blkid and take note of our UUID of sdb1 and sdb5 for the fstab of the target directory.

    blkid | grep -i sdb

    /dev/sdb1: UUID="4d8976e1-9e95-4285-a459-a938f6178fab" TYPE="ext4"
    /dev/sdb5: UUID="ab7960a7-be74-4086-8fc1-ebf9d4eea0a4" TYPE="swap"

    Mount the first partition of the disk into our target destination path

    mkdir /target
    mount /dev/sdb1 /target

    Step 1: Debootstrapping

    Let's install Debian into /target directory

    debootstrap --arch=amd64 wheezy /target http://httpredir.debian.org/debian/

    Command instructs to treat /target folder as base root filesystem directory and put wheezy base OS files for amd64 architecture. You'll see the command connecting to Debian servers and retrieving a good amount of packages.

    Once the command is finished you can go to /target an examine the contents of the directory and you'll see a standard linux root filesystem tree inside. Look in detail there are no /lib/modules dir or symlinks to vmlinuz, means there is no kernel there.

    Step 2: Editing fstab
    Before doing a chroot into the /target dir we first need to bind /dev /dev/pts /proc /sys to the /target dir. This is necessary for the grub later to find the target block device.

    mount -o bind /dev/pts /target/dev/pts
    mount -o bind /proc /target/proc
    mount -o bind /sys /target/sys
    mount -o bind /dev /target/dev

    Now let's chroot into that folder. This will allow us to perform commands as we are actually inside that new system.

    chroot /target /bin/bash

    Now we are in our new install system, every command in here is executed inside this environment

    • Assign root password type passwd, enter new root password two times
    • Edit fstab with nano /etc/fstab

    Put the following inside

    UUID=4d8976e1-9e95-4285-a459-a938f6178fab /    ext4 errors=remount-ro 0       0
    UUID=ab7960a7-be74-4086-8fc1-ebf9d4eea0a4 none  swap    sw              0       0

    Note: In your setup change the uuid's accordingly

    • Edit the sources.list so you can fetch necessary packages. Replace the existing contents of /etc/apt/sources.list with this

    deb http://ftp.us.debian.org/debian wheezy main contrib non-free
    deb http://ftp.debian.org/debian/ wheezy-updates main contrib non-free
    deb http://security.debian.org/ wheezy/updates main contrib non-free

    Add the backport repository

    echo 'deb http://ftp.debian.org/debian wheezy-backports main contrib non-free' > /etc/apt/sources.list.d/backports.list

    Generate the apt-get index with apt-get update

    Step 3: Install the grub loader and the kernel

    First we install openssh-server and initramfs-tools. The first is necessary to access remotely from the network when we boot the new system, the second is for installing kernel

    apt-get install openssh-server initramfs-tools/wheezy-backports

    Now the kernel apt-get install linux-image-3.16.0-0.bpo.4-amd64
    this command will generate a series of errors like reading the mounting table, etc. Should be ok to ignore.

    With a kernel present now we proceed to install grub:

    apt-get install grub2

    You can choose from the menu to install to /dev/sdb (not sdb1) or ignore and use CLI

    grub-install /dev/sdb

    This should end with "Installation finished. No error reported."

    Check the file /boot/grub/grub.cfg is present and has the menu entries with the proper UUID for the rootfs.

    Final tweak, we want the machine to gain network as soon as it boots so we adjust the necessary files

    nano /etc/network/interfaces

    At the end of the file we place the following directives (If your interface is not eth0 then change it to the proper one)

    # eth0 network interface
    auto eth0
    allow-hotplug eth0
    iface eth0 inet dhcp

    That's it, you have your system ready to boot. Type exit to leave the chroot environment, reboot your currently running system and select the new boot disk in BIOS.­

    Once you boot your new debian install with bpo kernel, you can install OMV on top following this steps

    Howto install OpenMediaVault on Debian 7.x (Wheezy)

    Questions / Problems / Discussions
    Click Here

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!