Can Ubuntu 24 be installed on an empty partition using minimal.squashfs through the terminal

system-installation

I encountered an issue while attempting to install Ubuntu via live USB. The graphical installer did not offer the option to choose manual partitioning. Even when I selected the empty partition, the installer showed an empty partition list. I also faced a similar situation while selecting the hard drive to install the bootloader. As a result, I had to install Ubuntu 24 alongside another previously installed version of Ubuntu.

Can Ubuntu 24 be installed on an empty partition using minimal.squashfs through the terminal?

Best Answer

In this guide, we'll install a fully functional and bootable Ubuntu 24 on an empty partition using minimal.squashfs file via the terminal. You can use either the current Ubuntu/Linux or Ubuntu Live USB disk.
However, before proceeding, please make sure to create a backup of your data. Also, if you're not familiar with commands like mkfs, mount, umount, and /dev/XXX, I advise you not to read this answer.

1- Formatting the partition

sudo mkfs.ext4 /dev/XXX    
#make sure to select the right litters to replace with xxx

2- Mount that empty partition

 sudo mkdir /ubuntu             #If don't work, use sudo -i at first
 sudo mount /dev/XXX /ubuntu    #make sure to select the right litters to replace with xxx

3- Extract the files to the empty partition

sudo unsquashfs -f -d /ubuntu /xxx/minimal.squashfs      
#make sure to select the right path of minimal.squashfs to replace with xxx.

If you haven't done so already, it's recommended that you install squashfs-tools.

if you are not using live Ubuntu from a USB flash drive, go to the step no.4

If you're using live Ubuntu from a USB flash drive, you'll need to mount another partition to copy the minimal.squashfs file to it. You can find the minimal.squashfs in the ISO file or the Ubuntu live USB in the /casper directory.
to mount another partition:

mkdir sdaz
mount /dev/sdaz  sdaz  #replace z with your partition` that inclode the minimal.squashfs file

copy the minimal.squashfs file to this partition, and put the path in the previous step.

Please make sure that you have entered the correct path in the previous step before proceeding further.

To complete the installation process without any errors:

4- Configure external mount points:

sudo mount --bind /dev /ubuntu/dev
sudo mount --bind /run /ubuntu/run

5- Access chroot environment

sudo chroot /ubuntu

6- Define chroot environment

mount none -t proc /proc
mount none -t sysfs /sys
mount none -t devpts /dev/pts
export HOME=/root
export LC_ALL=C

7- Configure machine-id and divert

dbus-uuidgen > /etc/machine-id
ln -fs /etc/machine-id /var/lib/dbus/machine-id
dpkg-divert --local --rename --add /sbin/initctl 
ln -s /bin/true /sbin/initctl                    

8- Upgrade packages

apt-get -y upgrade

9- Install packages needed for the System (Install Grub and Linux Kernel)

apt-get install -y grub-common grub-gfxpayload-lists grub-pc grub-pc-bin grub2-common
apt-get install -y --no-install-recommends linux-generic

In this step, you will see recommended grub and kernel packages for your device. If they are not listed in my commands, please install them.

In case, you are unable to access the internet, you can locate all these packages in the Ubuntu ISO file, or buntu Live USB disk under the /pool directory. You can then copy all these packages to the /ubuntu directory and execute the following command: dpkg -i *.deb, or make new folder /deb as an example, and execute the following command: dpkg -i /ubuntu/deb/*.deb

It's possible to install drivers and custom apps using the terminal either online or by placing them in the /deb directory and executing the command dpkg -i /deb/*.deb.

10- Grub (update the boot menu in the new OS)

update-grub

11- Create fstab
A simple example of fstab is

echo "/dev/sdxx / ext4  errors=remount-ro 0 1" >> /etc/fstab      
## Inside chroot! 
#make sure to sellect the right litters to replace with xx

12- Cleanup the chroot environment

truncate -s 0 /etc/machine-id
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl
apt-get clean
rm -rf /tmp/* ~/.bash_history
umount /proc
umount /sys
umount /dev/pts
export HISTSIZE=0

exit

13- Unbind mount points

sudo umount /ubuntu/dev
sudo umount /ubuntu/run

14- update the boot menu in the current OS
This step when you use Ubuntu/Linux from your device

sudo update-grub


If you use Ubuntu Live from a USB drive, cancel this command, install the grub bootloader on the Hard disk, or use the boot-repair package.

15- Reboot
After rebooting your computer, you can set up your account, local, and language settings. Everything should work properly on the first try after the splash screen ends.

These pages helped me in these steps:

How to create a bootable fully functional Ubuntu from debootstrap ?

Installation/FromLinux

How to create a custom Ubuntu live from scratch

Create USB drive contains multi Ubuntu versions

Related Question