You may’ve heard about building your own PC, but not about building you own OS. In this tutorial I’m going to explain how to install your Linux distro (in this case, Ubuntu) from Scratch, as you may do with Arch. Note: things between [ ] need to be changed depending on your PC/setup. Note 2: This only works with Debian-based distros.
Requirements:
- A PC
- Ubuntu live CD
Procedure:
- Flash your live CD ISO to a USB device. You may use DD, Etcher or Rufus to do this.
- In your UEFI, select the Ubuntu live CD boot option and click ‘e’ when the GRUB screen loads, to edit the boot options
- Look for the line that starts with ‘linux’, and write ‘recovery’ after the three hyphens (obviously leaving a space)
- Press Ctrl+x or F10 to boot
- Click on the ‘network’ option and agree to everything (you must be connected through Ethernet)
- Click on the ‘root’ option and press [Enter]
- Congrats! Now you are in a root shell and you’re now ready to start the installation
- First, you should upgrade all the LiveCD packages. The easiest way to do this is to run
apt update
andapt full-upgrade
. This may take some minutes. - After that, you need to format the installation drive. I use
fdisk
to do this, since it’s pretty simple. Run:fdisk [installation_drive]
to enter fdiskg
to create a GPT disklabeln
, press [Enter] two times and write+128M
to set the EFI partition size to 128 MiB.n
again and press [Enter] three times to allocate the rest of the drive space. NOTE: I’m not going to create a swap partition. If you want one, please search online to find how to do it.t
to change a partition type, then1
to select the EFI partition and writeuefi
to specify that it’s an EFI-type partition.- Finally, write
w
to write the changes to the disk. BE SURE THAT YOU DON’T HAVE ANYTHING IMPORTANT ON THE DRIVE, SINCE THIS IS NOT REVERSIBLE.
- Format the partitions. The first one needs to be in FAT32, but the main one can be in EXT4 or BTRFS
- Mount the partitions.
mount [MAIN_SYSTEM_PARTITION] /mnt
to mount the main system partitioncd /mnt
to access the mounted part.mkdir boot
to create the boot dir.mkdir boot/efi
to create the EFI part mount foldermount [EFI_SYSTEM_PARTITION] /mnt/boot/efi
to mount the EFI partition
- Edit the /etc/apt/sources.list and write ‘universe’ at the end of the base repo, in the case of ubuntu, to enable the Universe repository.
- Now you need to install the following packages: debootstrap, arch-install-scripts. Run
apt install debootstrap arch-install-scripts
to obtain them. - Prepare the basic chroot environment. Run
debootstrap --arch=[COMPUTER_ARCH] [DISTRO_RELEASE_CODENAME] /mnt http://archive.ubuntu.com/ubuntu
to do it. In my case, I’ve randebootstrap --arch=amd64 hirsute /mnt http://archive.ubuntu.com/ubuntu
to install Ubuntu 21.04. - Now you need to ‘mount’ some folders:
mount -B /dev /mnt/dev
mount -B /sys /mnt/sys
mount -B /proc /mnt/proc
- Generate the /etc/fstab file with
genfstab -U /mnt > /mnt/etc/fstab
- Finally, run
chroot /mnt
to CHROOT to the new basic installation environment. - Now you are free to do what you want! Install all the packages that you like, change the locales to your own ones and enjoy! But don’t forget to install the Linux kernel, network-manager, grub and a few other things (like copy /etc/resolv.conf) if the desktop environment doesn’t do that for you.
And… that’s all! I hope that this tutorial was useful and please share it with others if you liked it by clicking on the buttons below. Thanks!