Can i remove /initrd.img and /vmlinuz in root?
If you haven't seen them before, it's because you never looked.
– @deadflowr on "vmlinuz and initrd.img symbolic links in / directory" at Ubuntu Forums
The /vmlinuz
and /initrd.img
symlinks point to the latest
compressed Linux kernel executable and initial RAM disk, respectively, and their *.old
counterparts are the symlinks to the preceeding version. If you dig around in your GRUB configuration (found at /boot/grub/grub.cfg
), you will find that there is no reference to /vmlinuz
or /initrd.img
, rather the original file.
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-2290c2ad-8832-4d80-a82d-e966d73c23e9' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root 2290c2ad-8832-4d80-a82d-e966d73c23e9
else
search --no-floppy --fs-uuid --set=root 2290c2ad-8832-4d80-a82d-e966d73c23e9
fi
linux /boot/vmlinuz-4.15.0-23-generic root=UUID=2290c2ad-8832-4d80-a82d-e966d73c23e9 ro console=tty1 console=ttyS0
initrd /boot/initrd.img-4.15.0-23-generic
}
Output of ls -l /
provided for context.
lrwxrwxrwx 1 root root 33 Jun 20 06:57 initrd.img -> boot/initrd.img-4.15.0-23-generic
lrwxrwxrwx 1 root root 33 May 22 10:54 initrd.img.old -> boot/initrd.img-4.15.0-22-generic
...
lrwxrwxrwx 1 root root 30 Jun 20 06:57 vmlinuz -> boot/vmlinuz-4.15.0-23-generic
lrwxrwxrwx 1 root root 30 May 22 10:54 vmlinuz.old -> boot/vmlinuz-4.15.0-22-generic
Because your grub.cfg
is auto-updated with each kernel release, it is much safer to reference the actual file than a symlink (in case it is deleted or changed). But if you are doing some of your own modifications to the grub.cfg
(not recommended because they might get overwritten), /vmlinuz
or /initrd.img
can be used to your convenience as a link to the latest kernel images.
Is it safe to delete them? Yeah, but they will get recreated when/if you update your kernel (using apt upgrade
) or update your GRUB (update-grub
).
Read more
- "vmlinuz and initrd.img symbolic links in / directory" at Ubuntu Forums
- "Anatomy of the initrd and vmlinuz" by Munshi Hafizul Haque of IBM
If you look (with file
etc) you'll probably notice they are symbolic links.
Should your system not boot (and you end up in grub-recovery) they are really handy to have your system boot as you don't have to remember, or go looking to see the full path & filename for the kernel & initial.ramdisk for either your current [latest] or prior [old] kernel. I may not use them often, but I consider them very handy.
A file /vm*
on my box showed
guiverc@d960-ubu2:~$ file /vm*
/vmlinuz: symbolic link to boot/vmlinuz-4.15.0-23-generic
/vmlinuz.old: symbolic link to boot/vmlinuz-4.15.0-22-generic
guiverc@d960-ubu2:~$ uname -r
4.15.0-23-generic
being my current & prior kernels. Removing them won't give me any more disk space (as they are only directory entries; links to the real file in boot/).
If you are using the standard GRUB configuration, then you are using the files in /boot directly and not using the symlinks in root. You can delete them. If you like, you can disable the tools from creating them again. See the man page for linux-update-symlinks for details. Settings in /etc/kernel-img.conf
http://manpages.ubuntu.com/manpages/bionic/man1/linux-update-symlinks.1.html
Note: at the grub prompt you can use "tab" for file name completion, so you can find which images you have in /boot during boot when needed.