无法从完整启动盘中删除旧内核

无法从完整启动盘中删除旧内核

我无法在我的计算机上安装或更新任何软件。

利用我惊人的推理能力,我推断出 /boot 已满并且导致了我心痛。

notlinus@NS0:/boot$df -h

Filesystem                Size  Used Avail Use% Mounted on
udev                      2.0G  4.0K  2.0G   1% /dev
tmpfs                     396M  656K  395M   1% /run
/dev/mapper/NS0--vg-root   36G  3.6G   30G  11% /
none                      4.0K     0  4.0K   0% /sys/fs/cgroup
none                      5.0M     0  5.0M   0% /run/lock
none                      2.0G     0  2.0G   0% /run/shm
none                      100M     0  100M   0% /run/user
/dev/sda1                 236M  234M     0 100% /boot

notlinus@NS0:/boot$ls -l

total 229780
-rw-r--r-- 1 root root  1270654 Aug 12  2015 abi-3.19.0-26-generic
-rw-r--r-- 1 root root  1271100 Sep  1  2015 abi-3.19.0-28-generic
-rw-r--r-- 1 root root  1271518 Oct  3 00:54 abi-3.19.0-30-generic
-rw-r--r-- 1 root root  1271689 Oct  8 13:01 abi-3.19.0-31-generic
-rw-r--r-- 1 root root  1271689 Oct 22 13:14 abi-3.19.0-32-generic
-rw-r--r-- 1 root root  1271689 Nov  6 20:39 abi-3.19.0-33-generic
-rw-r--r-- 1 root root  1271691 Nov 23 16:57 abi-3.19.0-37-generic
-rw-r--r-- 1 root root   177632 Aug 12  2015 config-3.19.0-26-generic
-rw-r--r-- 1 root root   177651 Sep  1  2015 config-3.19.0-28-generic
-rw-r--r-- 1 root root   177730 Oct  3 00:54 config-3.19.0-30-generic
-rw-r--r-- 1 root root   177790 Oct  8 13:01 config-3.19.0-31-generic
-rw-r--r-- 1 root root   177790 Oct 22 13:14 config-3.19.0-32-generic
-rw-r--r-- 1 root root   177790 Nov  6 20:39 config-3.19.0-33-generic
-rw-r--r-- 1 root root   177790 Nov 23 16:57 config-3.19.0-37-generic
drwxr-xr-x 5 root root     1024 Feb 17 13:47 grub
-rw-r--r-- 1 root root 20754747 Aug 27  2015 initrd.img-3.19.0-26-generic
-rw-r--r-- 1 root root 20753554 Sep  9 06:29 initrd.img-3.19.0-28-generic
-rw-r--r-- 1 root root 20756217 Oct  6 07:03 initrd.img-3.19.0-30-generic
-rw-r--r-- 1 root root 20758684 Oct 22 13:04 initrd.img-3.19.0-31-generic
-rw-r--r-- 1 root root 20757000 Nov  5 06:55 initrd.img-3.19.0-32-generic
-rw-r--r-- 1 root root 20758873 Nov 10 07:17 initrd.img-3.19.0-33-generic
-rw-r--r-- 1 root root 20757964 Dec  2 06:54 initrd.img-3.19.0-37-generic
-rw-r--r-- 1 root root  3463561 Feb 17 13:46 initrd.img-3.19.0-39-generic
-rw-r--r-- 1 root root  3463563 Feb 17 13:47 initrd.img-3.19.0-42-generic
drwx------ 2 root root    12288 Aug 27  2015 lost+found
-rw-r--r-- 1 root root   176500 Mar 12  2014 memtest86+.bin
-rw-r--r-- 1 root root   178176 Mar 12  2014 memtest86+.elf
-rw-r--r-- 1 root root   178680 Mar 12  2014 memtest86+_multiboot.bin
-rw------- 1 root root  3626965 Aug 12  2015 System.map-3.19.0-26-generic
-rw------- 1 root root  3626779 Sep  1  2015 System.map-3.19.0-28-generic
-rw------- 1 root root  3627906 Oct  3 00:54 System.map-3.19.0-30-generic
-rw------- 1 root root  3628177 Oct  8 13:01 System.map-3.19.0-31-generic
-rw------- 1 root root  3628149 Oct 22 13:14 System.map-3.19.0-32-generic
-rw------- 1 root root  3628149 Nov  6 20:39 System.map-3.19.0-33-generic
-rw------- 1 root root  3628776 Nov 23 16:57 System.map-3.19.0-37-generic
-rw------- 1 root root  6570192 Aug 12  2015 vmlinuz-3.19.0-26-generic
-rw------- 1 root root  6568848 Sep  1  2015 vmlinuz-3.19.0-28-generic
-rw------- 1 root root  6572496 Oct  3 00:54 vmlinuz-3.19.0-30-generic
-rw------- 1 root root  6572336 Oct  8 13:01 vmlinuz-3.19.0-31-generic
-rw------- 1 root root  6572944 Oct 22 13:14 vmlinuz-3.19.0-32-generic
-rw------- 1 root root  6572432 Nov  6 20:39 vmlinuz-3.19.0-33-generic
-rw------- 1 root root  6571920 Nov 23 16:57 vmlinuz-3.19.0-37-generic

notlinus@NS0:/boot$uname -r

3.19.0-37-generic

notlinus@NS0:~$sudo apt-get clean

notlinus@NS0:/boot$sudo apt-get autoremove

Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run ‘apt-get -f install’ to correct these.
The following packages have unmet dependencies.
 linux-image-extra-3.19.0-49-generic : Depends: linux-image-3.19.0-49-generic but it is not installed
 linux-image-generic-lts-vivid : Depends: linux-image-3.19.0-49-generic but it is not installed
                                 Recommends: thermald but it is not installed
E: Unmet dependencies. Try using -f.

notlinus@NS0:/boot$sudo dpkg --list 'linux-image*'

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                Version                Architecture           Description
+++-===================================-======================-======================-===========================================================================
un  linux-image                         <none>                 <none>                 (no description available)
un  linux-image-3.0                     <none>                 <none>                 (no description available)
rc  linux-image-3.19.0-25-generic       3.19.0-25.26~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-3.19.0-26-generic       3.19.0-26.28~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-3.19.0-28-generic       3.19.0-28.30~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-3.19.0-30-generic       3.19.0-30.34~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-3.19.0-31-generic       3.19.0-31.36~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-3.19.0-32-generic       3.19.0-32.37~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-3.19.0-33-generic       3.19.0-33.38~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-3.19.0-37-generic       3.19.0-37.42~14.04.1   amd64                  Linux kernel image for version 3.19.0 on 64 bit x86 SMP
in  linux-image-3.19.0-39-generic       <none>                 amd64                  (no description available)
in  linux-image-3.19.0-42-generic       <none>                 amd64                  (no description available)
in  linux-image-3.19.0-49-generic       <none>                 amd64                  (no description available)
rc  linux-image-extra-3.19.0-25-generic 3.19.0-25.26~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-extra-3.19.0-26-generic 3.19.0-26.28~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-extra-3.19.0-28-generic 3.19.0-28.30~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-extra-3.19.0-30-generic 3.19.0-30.34~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-extra-3.19.0-31-generic 3.19.0-31.36~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-extra-3.19.0-32-generic 3.19.0-32.37~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
ii  linux-image-extra-3.19.0-33-generic 3.19.0-33.38~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
iF  linux-image-extra-3.19.0-37-generic 3.19.0-37.42~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
iU  linux-image-extra-3.19.0-49-generic 3.19.0-49.55~14.04.1   amd64                  Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
iU  linux-image-generic-lts-vivid       3.19.0.49.34           amd64                  Generic Linux kernel image

notlinus@NS0:/boot$sudo apt-get remove linux-image-3.19.0-26-generic

Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies.
 linux-image-extra-3.19.0-26-generic : Depends: linux-image-3.19.0-26-generic but it is not going to be installed
 linux-image-extra-3.19.0-49-generic : Depends: linux-image-3.19.0-49-generic but it is not going to be installed
 linux-image-generic-lts-vivid : Depends: linux-image-3.19.0-49-generic but it is not going to be installed
                                 Recommends: thermald but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

我确信这一定是一个重复的问题,但在搜索类似问题的解决方案后并没有缓解我的困境。

最后,我是一名 RHEL 管理员,所以请原谅我的无知——我们的 BIND 服务器必须安装在 Ubuntu 上,这是我们姊妹公司提供一些免费托管空间的条件。我做错了什么导致了这个问题,我该如何避免将来再次发生这种情况?

当我在此网站上尝试类似的解决方案时,例如如何在 /boot 中释放更多空间?我得到:

notlinus@NS0:/boot$ sudo dpkg -fl linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]' | xargs sudo apt-get -y purge
You might want to run ‘apt-get -f install’ to correct these.
The following packages have unmet dependencies.
 linux-image-extra-3.19.0-26-generic : Depends: linux-image-3.19.0-26-generic but it is not installed
 linux-image-extra-3.19.0-28-generic : Depends: linux-image-3.19.0-28-generic but it is not installed
 linux-image-extra-3.19.0-30-generic : Depends: linux-image-3.19.0-30-generic but it is not installed
 linux-image-extra-3.19.0-31-generic : Depends: linux-image-3.19.0-31-generic but it is not installed
 linux-image-extra-3.19.0-32-generic : Depends: linux-image-3.19.0-32-generic but it is not installed
 linux-image-extra-3.19.0-33-generic : Depends: linux-image-3.19.0-33-generic but it is not installed
 linux-image-extra-3.19.0-49-generic : Depends: linux-image-3.19.0-49-generic but it is not installed
 linux-image-generic-lts-vivid : Depends: linux-image-3.19.0-49-generic but it is not installed
                                 Recommends: thermald but it is not installed
E: Unmet dependencies. Try using -f.

答案1

谢谢@mikewhatever,

sudo dpkg --force-all -P pkgname答案是

所以:sudo dpkg --force-all -P linux-image-extra-3.19.0-26-generic 为我做了

答案2

问题是由于 /boot 分区上的空间不足。

通过以下方式轻松创建一些自由空间sudo truncate -s 0 /boot/initrd.img-oldest-version

注意:不要截断最高的 2 个 initrd 版本!

此后sudo apt autoremove -f将会成功,但它将需要很长时间才能完成,因为它将为所有映像重建 initrd 并重新安装 grub两次每次删除一个旧内核映像时,它都会重建 initrds 近 400 次!

您可以通过禁用 initrd 生成工具来解决这个荒谬的重建问题:

sudo mv /etc/kernel/postinst.d/initramfs-tools /etc/kernel/postinst.d/initramfs-tools.real
sudo ln -s /bin/true /etc/kernel/postinst.d/initramfs-tools

然后发出sudo apt autoremove -f,当你完成时...

sudo rm /etc/kernel/postinst.d/initramfs-tools
sudo mv /etc/kernel/postinst.d/initramfs-tools.real /etc/kernel/postinst.d/initramfs-tools
sudo /etc/kernel/postinst.d/initramfs-tools $( uname -r )

注意:如果正在运行的内核不再位于 /boot 中,那么您可能需要手动提供内核版本来代替uname -r

完成后,请考虑手动安装特定内核(例如当前内核),然后启用apt-autoremove。这将确保您始终拥有要启动的选定映像以及最新版本。

答案3

如果您的问题是由于空间不足,那么您可能有办法解决。如果仔细观察,您会发现:

 Filesystem                Size  Used Avail Use% Mounted on
 /dev/sda1                 236M  234M     0 100% /boot

您将看到分区的大小为 236M,而已使用的空间为 234M。系统已保留 2 MB 以备紧急情况。通过发出以下命令释放它以供您使用:

 sudo tune2fs -m 0 /dev/sda1

您将有 2M 的可用空间,这可能会帮助您摆脱困境。

另一种解决方法是完全放弃该分区作为启动分区,并更改 fstab(删除 /boot)并在根分区上创建 /boot。

将所有内容从(现在的)旧启动复制到新启动,然后完成命令。

相关内容