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.
- A PC
- Ubuntu live CD
- 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 full-upgrade. This may take some minutes.
- After that, you need to format the installation drive. I use
fdiskto do this, since it’s pretty simple. Run:
fdisk [installation_drive]to enter fdisk
gto create a GPT disklabel
n, press [Enter] two times and write
+128Mto set the EFI partition size to 128 MiB.
nagain 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.
tto change a partition type, then
1to select the EFI partition and write
uefito specify that it’s an EFI-type partition.
- Finally, write
wto 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] /mntto mount the main system partition
cd /mntto access the mounted part.
mkdir bootto create the boot dir.
mkdir boot/efito create the EFI part mount folder
mount [EFI_SYSTEM_PARTITION] /mnt/boot/efito 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-scriptsto obtain them.
- Prepare the basic chroot environment. Run
debootstrap --arch=[COMPUTER_ARCH] [DISTRO_RELEASE_CODENAME] /mnt http://archive.ubuntu.com/ubuntuto do it. In my case, I’ve ran
debootstrap --arch=amd64 hirsute /mnt http://archive.ubuntu.com/ubuntuto 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 /mntto 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!