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:
  1. Flash your live CD ISO to a USB device. You may use DD, Etcher or Rufus to do this.
  2. In your UEFI, select the Ubuntu live CD boot option and click ‘e’ when the GRUB screen loads, to edit the boot options
  3. Look for the line that starts with ‘linux’, and write ‘recovery’ after the three hyphens (obviously leaving a space)
  4. Press Ctrl+x or F10 to boot
  5. Click on the ‘network’ option and agree to everything (you must be connected through Ethernet)
  6. Click on the ‘root’ option and press [Enter]
  7. Congrats! Now you are in a root shell and you’re now ready to start the installation
  8. First, you should upgrade all the LiveCD packages. The easiest way to do this is to run apt update and apt full-upgrade. This may take some minutes.
  9. 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 fdisk
    • g to create a GPT disklabel
    • n, 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, then 1 to select the EFI partition and write uefi 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.
  10. Format the partitions. The first one needs to be in FAT32, but the main one can be in EXT4 or BTRFS
  11. Mount the partitions.
    • mount [MAIN_SYSTEM_PARTITION] /mnt to mount the main system partition
    • cd /mnt to access the mounted part.
    • mkdir boot to create the boot dir.
    • mkdir boot/efi to create the EFI part mount folder
    • mount [EFI_SYSTEM_PARTITION] /mnt/boot/efi to mount the EFI partition
  12. 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.
  13. Now you need to install the following packages: debootstrap, arch-install-scripts. Run apt install debootstrap arch-install-scripts to obtain them.
  14. 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 ran debootstrap --arch=amd64 hirsute /mnt http://archive.ubuntu.com/ubuntu to install Ubuntu 21.04.
  15. Now you need to ‘mount’ some folders:
    • mount -B /dev /mnt/dev
    • mount -B /sys /mnt/sys
    • mount -B /proc /mnt/proc
  16. Generate the /etc/fstab file with genfstab -U /mnt > /mnt/etc/fstab
  17. Finally, run chroot /mnt to CHROOT to the new basic installation environment.
  18. 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!

Categories: Tutorials

Lumito

A junior open-source developer on GitHub (github.com/LumitoLuma) and owner of this website (www.lumito.net). His favorite programming language is C++, followed by C, C# and Java.

0 Comments

Leave a Reply

Avatar placeholder