I need to compress the initramfs to reduce their size

Asked by Merry Goodger on 2020-11-13

I am not computer literate. I have a command I use to clean out old kernals. That has always been sufficient to provide space for updates. I updated to Ubuntu 20.04.1. Now I need to update and cleaning out the kernals is not enough to provide necessary space. The notice said to compress the initramfs to make more space. But I cannot figure out how to do this. Do you do it in terminal? What commands do you enter? I need precise instructions since I have no idea what I am doing.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
2020-12-01
Last reply:
2020-12-01

This question was reopened

Initramfs is already compressed.

Are you low on space? What is the output of:

lsb_release -a; uname -a; df -h

Thanks

Merry Goodger (diana-hands) said : #2

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
sakialele@merry-X550CA
:~$ uname -a
Linux merry-X550CA 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
sakialele@merry-X550CA
:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 383M 1.9M 381M 1% /run
/dev/mapper/ubuntu--vg-root 454G 42G 390G 10% /
tmpfs 1.9G 27M 1.9G 2% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/loop0 9.2M 9.2M 0 100% /snap/canonical-livepatch/94
/dev/loop1 9.2M 9.2M 0 100% /snap/canonical-livepatch/95
/dev/loop3 98M 98M 0 100% /snap/core/10185
/dev/loop2 98M 98M 0 100% /snap/core/10126
/dev/sda2 237M 108M 117M 48% /boot
/dev/sda1 511M 7.8M 504M 2% /boot/efi
tmpfs 383M 40K 383M 1% /run/user/1002

Merry Goodger (diana-hands) said : #3

Before I upgraded, my boot could always be reduced to 33%. Now I can't get it under 48%.

You have plenty of space here. You can remove old kernels if required.

Manfred Hampl (m-hampl) said : #5

/dev/sda2 237M 108M 117M 48% /boot

237 MB for /boot is very small for the kernel files of current kernel versions, probably too small.

What is the output of the commands

ls -l /boot
dpkg -l | grep linux-image

Merry Goodger (diana-hands) said : #6

ls -l /boot
total 99700
-rw-r--r-- 1 root root 237807 Oct 15 05:28 config-5.4.0-52-generic
drwxr-xr-x 3 root root 4096 Dec 31 1969 efi
drwxr-xr-x 5 root root 1024 Nov 11 18:05 grub
lrwxrwxrwx 1 root root 27 Oct 23 16:22 initrd.img -> initrd.img-5.4.0-52-generic
-rw-r--r-- 1 root root 84454054 Nov 6 16:21 initrd.img-5.4.0-52-generic
lrwxrwxrwx 1 root root 27 Oct 28 16:48 initrd.img.old -> initrd.img-5.4.0-52-generic
drwx------ 2 root root 12288 Jun 11 2016 lost+found
-rw-r--r-- 1 root root 182704 Aug 18 05:46 memtest86+.bin
-rw-r--r-- 1 root root 184380 Aug 18 05:46 memtest86+.elf
-rw-r--r-- 1 root root 184884 Aug 18 05:46 memtest86+_multiboot.bin
-rw------- 1 root root 4743490 Oct 15 05:28 System.map-5.4.0-52-generic
lrwxrwxrwx 1 root root 24 Oct 23 16:22 vmlinuz -> vmlinuz-5.4.0-52-generic
-rw------- 1 root root 11678464 Oct 15 05:33 vmlinuz-5.4.0-52-generic
lrwxrwxrwx 1 root root 24 Oct 28 16:48 vmlinuz.old -> vmlinuz-5.4.0-52-generic
sakialele@merry-X550CA
:~$ dpkg -l | grep linux-image
ii linux-image-5.4.0-52-generic 5.4.0-52.57 amd64 Signed kernel image generic
ii linux-image-generic 5.4.0.52.55 amd64 Generic Linux kernel image

Merry Goodger (diana-hands) said : #7

To actionparsnip (andrew-woodhead666) I have cleared out old kernals. I found a command a couple of years ago that clears out all old kernals. The update still says there is not enough room.

Merry Goodger (diana-hands) said : #8

Thank you, both.

Is the system a virtual machine or is it a real system?

Manfred Hampl (m-hampl) said : #10

You might experiment with options, see e.g. https://askubuntu.com/a/344252
No warranty given that your system still boots after doing that.

Merry Goodger (diana-hands) said : #11

actionparsnip (andrew-woodhead666)
I don't even know for sure what a virtual machine is. I loaded Trusty Taur on an Asus computer, wiping out the Windows that it came with.

Merry Goodger (diana-hands) said : #12

Manfred Hampl (m-hampl)

When I run Software Updater, it brings up a 'not enough free disc space' notice. This reads in part:

you could also set COMPRESS=xz in /etc/initramfs-tools/initramfs.conf to reduce the size of your initramfs.

How do I do this? Please? I need full instructions.
Step one: open terminal
Step two: put in?

Thank you

Merry Goodger (diana-hands) said : #13

I was looking for the answer to a question years ago when I ran across a conversation. Someone was complaining about the /boot being so small. The questioner wanted to know why the file could not be enlarged as part of an upgrade or update. The expert answering him said that he thought that ought to be done. But I don't think it ever has. It's not as though I don't have space on my hard drive. I think I'm using less than 10%

Manfred Hampl (m-hampl) said : #14

"wanted to know why the file could not be enlarged"

The item involved is not a file, but a disk partition, and modifying disk partitions is not an easy task.

To check whether it is possible to enlarge the partition in-place, or if a complete re-allocation has to be done, what is the output of the command

sudo fdisk -l

Manfred Hampl (m-hampl) said : #15

"you could also set COMPRESS=xz in /etc/initramfs-tools/initramfs.conf to reduce the size of your initramfs."

What is the output of the command

cat -n /etc/initramfs-tools/initramfs.conf

Merry Goodger (diana-hands) said : #16

Manfred Hampl (m-hampl)

sudo fdisk -l
Disk /dev/loop0: 9.7 MiB, 9506816 bytes, 18568 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop1: 9.7 MiB, 9510912 bytes, 18576 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop2: 97.72 MiB, 102445056 bytes, 200088 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop3: 97.76 MiB, 102486016 bytes, 200168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop4: 55.37 MiB, 58052608 bytes, 113384 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop5: 162.89 MiB, 170778624 bytes, 333552 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop6: 62.9 MiB, 65105920 bytes, 127160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop7: 64.79 MiB, 67915776 bytes, 132648 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sda: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WD5000LPVX-8
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: C61421AB-34A9-4490-9FAB-0ED9E912C5FA

Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 1550335 499712 244M Linux filesystem
/dev/sda3 1550336 976771071 975220736 465G Linux filesystem

Disk /dev/mapper/sda3_crypt: 465.2 GiB, 499310919680 bytes, 975216640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mapper/ubuntu--vg-root: 461.12 GiB, 495125004288 bytes, 967041024 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mapper/ubuntu--vg-swap_1: 3.91 GiB, 4173332480 bytes, 8151040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/loop8: 179.17 MiB, 187871232 bytes, 366936 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop9: 94.77 MiB, 99356672 bytes, 194056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

cat -n /etc/initramfs-tools/initramfs.conf

1 #
     2 # initramfs.conf
     3 # Configuration file for mkinitramfs(8). See initramfs.conf(5).
     4 #
     5 # Note that configuration options from this file can be overridden
     6 # by config files in the /etc/initramfs-tools/conf.d directory.
     7
     8 #
     9 # MODULES: [ most | netboot | dep | list ]
    10 #
    11 # most - Add most filesystem and all harddrive drivers.
    12 #
    13 # dep - Try and guess which modules to load.
    14 #
    15 # netboot - Add the base modules, network modules, but skip block devices.
    16 #
    17 # list - Only include modules from the 'additional modules' list
    18 #
    19
    20 MODULES=most
    21
    22 #
    23 # BUSYBOX: [ y | n | auto ]
    24 #
    25 # Use busybox shell and utilities. If set to n, klibc utilities will be used.
    26 # If set to auto (or unset), busybox will be used if installed and klibc will
    27 # be used otherwise.
    28 #
    29
    30 BUSYBOX=auto
    31
    32 #
    33 # COMPCACHE_SIZE: [ "x K" | "x M" | "x G" | "x %" ]
    34 #
    35 # Amount of RAM to use for RAM-based compressed swap space.
    36 #
    37 # An empty value - compcache isn't used, or added to the initramfs at all.
    38 # An integer and K (e.g. 65536 K) - use a number of kilobytes.
    39 # An integer and M (e.g. 256 M) - use a number of megabytes.
    40 # An integer and G (e.g. 1 G) - use a number of gigabytes.
    41 # An integer and % (e.g. 50 %) - use a percentage of the amount of RAM.
    42 #
    43 # You can optionally install the compcache package to configure this setting
    44 # via debconf and have userspace scripts to load and unload compcache.
    45 #
    46
    47 COMPCACHE_SIZE=""
    48
    49 #
    50 # COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz ]
    51 #
    52
    53 COMPRESS=lz4
    54
    55 #
    56 # NFS Section of the config.
    57 #
    58
    59 #
    60 # DEVICE: ...
    61 #
    62 # Specify a specific network interface, like eth0
    63 # Overridden by optional ip= or BOOTIF= bootarg
    64 #
    65
    66 DEVICE=
    67
    68 #
    69 # NFSROOT: [ auto | HOST:MOUNT ]
    70 #
    71
    72 NFSROOT=auto
    73
    74 #
    75 # RUNSIZE: ...
    76 #
    77 # The size of the /run tmpfs mount point, like 256M or 10%
    78 # Overridden by optional initramfs.runsize= bootarg
    79 #
    80
    81 RUNSIZE=10%

Merry Goodger (diana-hands) said : #17

Since I last messaged, I have suddenly had to move. I have been too busy to go to a neighbor's to get online. That is why it has been so long.
Thank you.

Manfred Hampl (m-hampl) said : #18

1. The information about /dev/sda shows that there is no free space around partition /dev/sda2 (which is the /boot partition), so you would have to completely rearrange also the /dev/sda3 partition to increase the size of /boot.

2. To change the compression to xz do the following:
open a terminal window
issue the command
sudo gedit /etc/initramfs-tools/initramfs.conf
scroll down to line 53 and replace
COMPRESS=lz4
by
COMPRESS=xz
then save the file and close the editor.

Merry Goodger (diana-hands) said : #19

How do I know if anything happened? The /boot is still at 48%. I still cannot run an update. Can I go back to Ubuntu 18?

The issue isn't the release. Whomever setup your system made a poor choice of size for the /boot partition. You could reinstall 18.04 (I assume that's what you mean by "Ubuntu 18". There is no Ubuntu 18. It doesn't exist) and you'd still have the same problems. The file system is just too small.

If you are going to reinstall, I suggest don't use a separate partition for /boot and you'll not run into this problem. You can then use Ubuntu 20.04 and enjoy LTS support until April 2025

The issue isn't the release. Whomever setup your system made a poor choice of size for the /boot partition. You could reinstall 18.04 (I assume that's what you mean by "Ubuntu 18". There is no Ubuntu 18. It doesn't exist) and you'd still have the same problems. The file system is just too small.

If you are going to reinstall, I suggest don't use a separate partition for /boot and you'll not run into this problem. You can then use Ubuntu 20.04 and enjoy LTS support until April 2025

Manfred Hampl (m-hampl) said : #22

"How do I know if anything happened"

After changing the compression algorithm in the initramfs.conf configuration file you have to create a new version of the initramfs file with the command

sudo update-initramfs -u

You should check with

ls -l /boot

before and after that command, whether there is a significant change in size.

And for the need for a separate /boot partition:
I see that your root file system is using lvm (Logical Volume Manager) functions. Is there a specific reason for that?

Can you help with this problem?

Provide an answer of your own, or ask Merry Goodger for more information if necessary.

To post a message you must log in.