Memory Exhaustion: Resolving update-initramfs Return Code 137 on Ubuntu
Encountering return code 137 during a kernel update or a manual update-initramfs -u execution is a specific and often confusing error. Unlike typical disk space errors (Return Code 1), code 137 is the shell's way of saying a process was terminated by a SIGKILL signal. In the context of Ubuntu 24.04 and newer, this almost always indicates that the Linux OOM (Out of Memory) Killer stepped in to terminate the process because the system ran out of available RAM or swap during the compression phase of the initial ramdisk generation. This guide addresses how to mitigate memory spikes and resolve endpoint security interference that often triggers this "Killed" status.
Table of Content
- Purpose of Memory Management in Initramfs
- Common Scenarios for Return Code 137
- Step-by-Step: Fixing the OOM Termination
- Best Results: Balancing Compression and RAM
- FAQ
- Disclaimer
Purpose
The primary purpose of this troubleshooting guide is to stabilize the ramdisk generation process. When update-initramfs runs, it executes mkinitramfs, which gathers kernel modules, scripts, and binaries into a single archive. This archive is then compressed (usually via zstd or lz4).
- Memory Spikes: Modern compression algorithms, especially at high settings, can consume several gigabytes of RAM momentarily.
- Process Termination: If the system has no swap or very low RAM (common in VMs), the kernel kills the compression process to prevent a system-wide freeze, resulting in the 137 error.
- Security Interference: In some cases, third-party endpoint security software misinterprets the rapid file creation in
/var/tmpas malicious activity and kills the process.
Use Case
Follow this tutorial if you see the following in your terminal during an apt upgrade:
- The "Killed" Message:
update-initramfs: Generating /boot/initrd.img-... Killed - Specific Exit Code:
update-initramfs: failed ... with 137. - DPKG Error:
Sub-process /usr/bin/dpkg returned an error code (1)tied toinitramfs-tools.
Step-by-Step
1. Monitor Memory During Execution
Before changing configs, verify if it truly is an OOM issue.
- Open a second terminal window and run:
watch -n 1 free -m - In your main terminal, attempt the update:
sudo update-initramfs -u - Watch the "available" memory. If it drops to near zero before the "Killed" message appears, you have a memory bottleneck.
2. Reduce Compression Memory Usage
By default, Ubuntu may use a high-compression setting that is RAM-intensive. Switching to a "sparse" module set can help.
- Open the configuration:
sudo nano /etc/initramfs-tools/initramfs.conf - Change
MODULES=mosttoMODULES=dep. This tells the tool to only include drivers needed for your specific hardware, significantly reducing the archive size and RAM usage. - Optionally, change the
COMPRESSsetting tolz4orgzipif you are currently usingzstd.
3. Temporarily Increase Swap Space
If you are on a Virtual Machine with 1GB or 2GB of RAM, you need a "buffer" for the compression spike.
- Create a temporary 2GB swap file:
sudo fallocate -l 2G /swapfile_tempsudo chmod 600 /swapfile_tempsudo mkswap /swapfile_tempsudo swapon /swapfile_temp - Try the update again:
sudo update-initramfs -u - Once successful, you can disable it:
sudo swapoff /swapfile_temp && sudo rm /swapfile_temp.
4. Check for Endpoint Security Interference
If RAM is not the issue, a security agent may be killing the process.
- Check the system logs for signals:
journalctl -xe | grep -i "killed" - If you see messages from SentinelOne, CrowdStrike, or ClamAV, you may need to temporarily disable them or add an exclusion for
/usr/sbin/mkinitramfsand the/var/tmpdirectory.
Best Results
| System Type | Primary Solution | Performance Impact |
|---|---|---|
| Low-RAM VPS (< 2GB) | Add Swap + MODULES=dep |
Boot speed slightly slower |
| Production Server | Check Security Agents / Logs | No change |
| Desktop (8GB+ RAM) | Clean /tmp and /var/tmp |
Standard performance |
FAQ
Why is 137 different from error code 1?
Error code 1 usually means the process finished but encountered a logical error (like "No space left on device"). Error 137 means the process was forcibly stopped from the outside by the OS kernel, typically due to 128 + 9 (SIGKILL).
Will 'MODULES=dep' make my system unbootable?
It is safe if you are not planning on moving your hard drive to a completely different computer with different hardware. If you move the drive, the "dep" (dependencies) might not include the drivers for the new motherboard's storage controller.
Does clearing old kernels help?
Not directly for a 137 error. Clearing kernels helps with disk space (Error 1). However, having fewer kernels reduces the number of times update-initramfs needs to run during a system update, reducing the chance of hitting a peak memory event.
Disclaimer
Generating a corrupted or incomplete initramfs can result in a "Kernel Panic" or a failure to boot. If update-initramfs fails, do not reboot until you have successfully generated a valid image. Always keep at least one known-working older kernel in your GRUB menu. This guide is updated for Ubuntu 24.04 LTS as of March 2026.
Tags: Ubuntu, Initramfs, OOMKiller, LinuxKernel
