Install Ubuntu in UEFI mode with debootstrap

作者 古振浩 日期 2017-11-03
Install Ubuntu in UEFI mode with debootstrap

在 UEFI 模式下想要安裝 Ubuntu 卻總是失敗:

Ubuntu boot failed

於是決定改採用全手動安裝的方式。

Installation

Boot your PC/server from Ubuntu live CD

Boot your PC/server from Ubuntu live CD, configure network to connect to Internet.

Prepare the partition

Create partitions on the system disk, the first one is for EFI system; the other is for system.

1
2
3
4
5
6
7
8
9
10
sudo parted /dev/sda
(parted) mklabel gpt
(parted) mkpart ESP fat32 1MiB 128MiB
(parted) mkpart primary xfs 128MiB 100%
(parted) set 1 boot on
(parted) quit

sudo partprobe /dev/sda
sudo mkfs.vfat -F 32 /dev/sda1
sudo mkfs.xfs -f /dev/sda2

Mount root file system:

1
sudo mount /dev/sda2 /mnt

Install Ubuntu core with debootstrap

First, you need to install debootstrap:

1
sudo apt install debootstrap

Then, you can install ubuntu to the /mnt with debootstrap command:

1
sudo debootstrap --arch amd64 xenial /mnt http://tw.archive.ubuntu.com/ubuntu

Copy the apt repository configuration to new file system:

1
sudo cp /etc/apt/sources.list /mnt/etc/apt/sources.list

Mount other file system

1
2
3
4
5
6
7
sudo mkdir -p /mnt/boot/efi
sudo mount /dev/sda1 /mnt/boot/efi
sudo mount --bind /dev /mnt/dev
sudo mount -t devpts /dev/pts /mnt/dev/pts
sudo mount -t proc proc /mnt/proc
sudo mount -t sysfs sysfs /mnt/sys
sudo mount -t tmpfs tmpfs /mnt/tmp

Then, chroot to /mnt:

1
2
sudo chroot /mnt /bin/bash
export HOME=/root

Install Linux kernel, grub and other packages

1
2
apt update
apt install linux-image-generic linux-headers-generic grub-efi

Configure grub

1
2
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --debug
update-grub

The reboot system.

Reference

  1. GNU Parted - ArchWiki
  2. GRUB - ArchWiki#UEFI.E7.B3.BB.E7.B5.B1.28UEFI_systems.29)