6

Can I remove /initrd.img and /vmlinuz and their .old files?

The /initrd.img links boot/initrd.img-4.13.0-45-generic, I don't know why /initrd.img appear here, I didn't see it here before.

enter image description here

  • 1
    "I didn'tsee it here before." IIRC it's been like that since I started using Ubuntu (~9.10) and likely well before that. – muru Jun 25 '18 at 1:43
  • Maybe I am wrong.@muru – Ben Jun 25 '18 at 1:47
  • 1
    If you are wanting to remove outdated versions of the kernel, use 'sudo apt autoremove'. This is the correct, safe way to deal with older outdated kernel versions. deleting such files manually could cause all sorts of problems. – Craig Jun 25 '18 at 1:56
  • 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 name for the kernel/initial.ramdisk (current version or prior one [old]). I may not use them often, but I consider them very handy. A file /vm* on my box showed "/vmlinuz: symbolic link to boot/vmlinuz-4.15.0-23-generic /vmlinuz.old: symbolic link to boot/vmlinuz-4.15.0-22-generic" being my current & prior kernel. – guiverc Jun 25 '18 at 1:57
3

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/).

| improve this answer | |
  • 3
    Not to mention they'll probably get recreated the next time the kernel is upgraded. – muru Jun 25 '18 at 2:08
5

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

| improve this answer | |
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.