Closed PJ-Singh-001 closed 2 months ago
How to remove all snaps from Ubuntu?
Requirements:
Background:
You can not use the snap
command in Cubic's Terminal environment. Furthermore, you can not simply execute apt autoremove --purge snapd
to remove all snap packages, like you could with previous versions of Ubuntu. The new installer, Subiquity, is a snap package itself, so it requires snapd
to be present.
Approach:
Therefore we must leave snapd
installed to allow the Live ISO to boot up. However, we can leverage cloud-config
to automatically remove snapd
once the installation is complete.
Limitations:
Although version 2024.09.88 of Cubic better reflects your changes in the Live environment, there are still some limitations. These are due to the snap based Subiquity installer and the layered file system Caonical adopted in Ubuntu Server 21.10 and Ubuntu Desktop 23.04.
Here is a list of known limitations.
The Live Environment of your customized ISO will contain snapd
and the standard snap packages. For Ubuntu Desktop, these are:
If you have installed the deb versions of Firefox or Thunderbird, your customized ISO will retain both the snap and deb versions of these applications while the user is in the Live Environment. After installation, only your deb packages will remain, because we will instruct the installer to remove snapd
(along with all snap packages).
You will not be able to edit /etv/default/grub
because the file does not exist in Cubic's Terminal environment. If you want to make changes to this file and execute update-grub
, use the late-commands
section of coud-config
, which we discuss below.
I've noticed some App Icons do not render in the Live Environment. But they worked fine after installing the customized OS.
There may be other issues or challenges that you encounter because certain files are stored in the "Installer Layer" of the ISO (which Cubic can not customize) or because the Live ISO requires snapd
. You may be able to work around these by using late-commands
, shown below.
Instructions:
Launch Cubic version 2024.09.88 or newer.
Customize your ISO. Do NOT remove snapd
.
Click on the Preseed tab, and create a file named autoinstall.yaml
in the preseed
folder.
Add the following to autoinstall.yaml
:
#cloud-config
version: 1
interactive-sections:
# Prompt the user during installation.
- locale
- refresh
- keyboard
- network
- storage
- identity
- timezone
- user-data
late-commands:
# Remove snapd.
- curtin in-target --target=/target -- rm -rf /var/cache/snapd
- curtin in-target --target=/target -- rm -rf /var/lib/snapd
- curtin in-target --target=/target -- rm -rf /var/cache/snapd
- curtin in-target --target=/target -- apt --yes remove --purge snapd
- curtin in-target --target=/target -- apt --yes install snapd
This is an autoinstall file which would normally install Ubuntu without user input. (This could be dangerous, especially if it overwrites your partitions). Therefore, under under interactive-sections
, we specify that the installer must stop and ask the user for input for the listed sections.
After the installation is complete, we instruct the installer to execute a series of commands in the newly installed OS. These commands are listed in the late-commands
section, and this is where we remove snapd
. You should not need to use sudo
, but make sure the commands do not require any user interaction; this is why we use the --yes
argument to apt
. You could add other commands here as well. (Note that executing the snap
command does not seem to work here because it requires the snapd
service to be running in the target environment. If you try to execute a snap
command here, it will actually run on your Live Environment, and this is not what you intended).
Click on the Boot tab.
Select grub.cfg
in the left hand pane and add subiquity.autoinstallpath=/cdrom/preseed/autoinstall.yaml
as shown. This will instruct the installer to use the autoinstall.yaml
file you created in step 4. NOTE: On the Boot tab, you are editing the grub.cfg
file used by the live ISO; this is NOT the grub.cfg
used by your customized OS.
set timeout=30
loadfont unicode
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
menuentry "Try or Install Ubuntu" {
set gfxpayload=keep
linux /casper/vmlinuz subiquity.autoinstallpath=/cdrom/preseed/autoinstall.yaml --- quiet splash
initrd /casper/initrd.gz
}
menuentry "Ubuntu (safe graphics)" {
set gfxpayload=keep
linux /casper/vmlinuz nomodeset subiquity.autoinstallpath=/cdrom/preseed/autoinstall.yaml --- quiet splash
initrd /casper/initrd.gz
}
grub_platform
if [ "$grub_platform" = "efi" ]; then
menuentry 'Boot from next volume' {
exit 1
}
menuentry 'UEFI Firmware Settings' {
fwsetup
}
else
menuentry 'Test memory' {
linux16 /boot/memtest86+x64.bin
}
fi
Select loopback.cfg
in the left hand pane and add subiquity.autoinstallpath=/cdrom/preseed/autoinstall.yaml
as shown. This will instruct the installer to use the autoinstall.yaml
file you created in step 4. NOTE: On the Boot tab, you are editing the loopback.cfg
file used by the live ISO; this is NOT the loopback.cfg
used by your customized OS.
menuentry "Try or Install Ubuntu" {
set gfxpayload=keep
linux /casper/vmlinuz subiquity.autoinstallpath=/cdrom/preseed/autoinstall.yaml iso-scan/filename=${iso_path} --- quiet splash
initrd /casper/initrd.gz
}
menuentry "Ubuntu (safe graphics)" {
set gfxpayload=keep
linux /casper/vmlinuz nomodeset subiquity.autoinstallpath=/cdrom/preseed/autoinstall.yaml iso-scan/filename=${iso_path} --- quiet splash
initrd /casper/initrd.gz
}
Ubuntu Server 21.10 and Ubuntu Desktop 23.04 use a layered file system for the ISO, and they use the Subiquity snap package for the installer.
Considering these limitations, how to customize Ubuntu in Cubic to remove all snaps?