Installing Ubuntu MATE using debootstrap

The below guide allows one to install latest Ubuntu MATE into disk image and then optionally copy this image file to the external drive.

This method maybe used for testing purposes or as alternative for the installation from now obsolete netboot/mini.iso.

Prepare Ubuntu MATE disk file

Install necessary tools:

sudo apt-get install debootstrap kpartx qemu-kvm

Allocate 16 Gb of space for virtual disk file:

fallocate -l 16G ~/mate-debootstrap.raw

Create partitions on this disk file with any software. Below is fdisk method:

echo n # new partition
echo p # it is primary
echo   # and first
echo   # starts at default
echo   # ends at end
echo w # write changes
) | fdisk ~/mate-debootstrap.raw

Create loop-devices for ~/mate-debootstrap.raw file using kpartx:

sudo kpartx -a -v ~/mate-debootstrap.raw

and format its first partition (check exact device name with losetup) with label:

sudo mkfs.ext4 /dev/mapper/loop11p1 -L MATE

then mount it

sudo mkdir /mnt/dbs-target
sudo mount /dev/mapper/loop11p1 /mnt/dbs-target

Run debootrap inside the newly created file-system

  • without proxy

    sudo debootstrap --variant=minbase --arch=amd64 hirsute /mnt/dbs-target
  • with specified proxy

    sudo env http_proxy= debootstrap --variant=minbase --arch=amd64 hirsute /mnt/dbs-target

Mount necessary file-systems:

sudo mount --bind /dev /mnt/dbs-target/dev
sudo mount --bind /proc /mnt/dbs-target/proc
sudo mount --bind /sys /mnt/dbs-target/sys

Chroot to the target file-system

Chroot to the target file-system:

sudo chroot /mnt/dbs-target
export PS1="(debootstrap) $PS1"
export DEBIAN_FRONTEND=noninteractive

Create neccessary list of repositories:

cat << EOF > /etc/apt/sources.list
deb hirsute main restricted universe multiverse 
deb hirsute-security main restricted universe multiverse 
deb hirsute-updates main restricted universe multiverse

Optionally specify proxy for the APT:

echo 'Acquire::http::Proxy "";' > /etc/apt/apt.conf.d/99proxy

Update package lists and install upgrades:

apt-get update
apt-get dist-upgrade

Create fstab file with declaration of file-systems:

echo "LABEL=MATE  /  ext4  noatime  0  1" > /etc/fstab

Install kernel and bootloader packages:

apt-get install linux-image-generic grub2

Place bootloader to the disk (consult about exact name using findmnt /):

grub-install /dev/loop11

Install useful software:

apt-get install bash-completion htop mc

Install Ubuntu MATE desktop as task:

apt-get install ubuntu-mate-desktop^

Configure Network Manager to manage all devices:

cat << EOF > /etc/NetworkManager/conf.d/01-nm-manage.conf

Final steps

Create user named user (rename to needed):

useradd -m -G adm,cdrom,sudo,dip,plugdev,lpadmin -s /bin/bash user
passwd user

Set hostname:

echo ubuntu > /etc/hostname

Optionally remove proxy configuration file:

rm /etc/apt/apt.conf.d/99proxy

Exit from chroot and umount file-systems:

sudo umount /mnt/dbs-target/{dev,proc,sys,}
sudo kpartx -d -v ~/mate-debootstrap.raw

Boot freshly installed system

Here we have three options to boot:

  • using QEMU-KVM:

    kvm -m 2048 -drive file=~/mate-debootstrap.raw,format=raw
  • using VirtualBox

    VBoxManage internalcommands createrawvmdk -filename ~/mate-debootstrap.vmdk -rawdisk ~/mate-debootstrap.raw

    and then attach this disk to the virtual machine.

  • by copying to physical drive to boot using legacy BIOS mode.

Sources and references:


This looks great I think I will try this. Do you think it is possible to get the oem first time user set up with it? If you are not familiar oem-configure it can help setup a user at first run like a wizard.

Hey cool in your notes links I see it can be done this is pretty groovy

@Norbert_X, when I do sudo kpartx -a -v ~/ubuntu.raw, I see output as

add map loop20p1 (253:0): 0 1048576 linear 7:20 2048
add map loop20p2 (253:1): 0 30406623 linear 7:20 1050624

but if I do losetup, it only lists /dev/loop20 not loop20p1 and loop20p2. So, I am not able to proceed with formatting as given in the next step. I get following error.

mkfs.fat 4.1 (2017-01-24)
mkfs.vfat: unable to open /dev/loop20p1: No such file or directory

What am I missing? My plan is to create 512M for EFI and rest for /.

EDIT: Please discard the query. Will keep the post so that other who may do same oversite as me would know.

I was supposed to use /dev/mapper/loop20p1 not /dev/loop20p1.

@Norbert_X, thank you for the tutorial. Tried and worked like a charm (for legacy BIOS).

Does this not work for UEFI? I used this guide but created efi partition, did all needed mounting and used grub-efi-amd64 but when I run kvm it just hangs at booting from disk.


What does this line do?

How do we copy? Just normal copy-paste or using dd command?

1 Like

Thanks for testing this guide, @saivinob :slight_smile:

Original GItHub gist suggests UEFI installation, I did not test it. Maybe will do this later.
I do not have UEFI system to test. Maybe I'll try to adapt the guide with VirtualBox EFI or QEMU EFI.

This line sets corresponding environment variable to run installation in non-interactive way, this means without user interaction. For possible values see Debian manual at 5.3.2 or part of Debian administrator's handbook (example 6.5 with full set of options).
Non-interactive package installation is also useful for scripting and Docker images creation.

It depends on skills and user habits.
Sometimes I use plain dd, for bigger images I use ddrescue (it shows the speed and progress while copying), for user-friendly and data-safe operation I use GNOME Disks application.

1 Like