/ boot满了后,如何删除旧内核/安装新内核?


31

我知道这个问题以前曾被问过很多次,但是我猜这跟我有点不同。

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       224G  5.2G  208G   3% /
udev            1.9G  4.0K  1.9G   1% /dev
tmpfs           777M  260K  777M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            1.9G     0  1.9G   0% /run/shm
/dev/sda2        90M   88M     0 100% /boot
/dev/sda6       1.9G  514M  1.3G  29% /tmp

我的启动分区已满。

当前内核:

# uname -r
3.2.0-35-generic

所有内核:

# dpkg --list | grep linux-image
ii  linux-image-3.2.0-32-generic    3.2.0-32.51                         Linux kernel image for version 3.2.0 on 64 bit x86 SMP
ii  linux-image-3.2.0-34-generic    3.2.0-34.53                         Linux kernel image for version 3.2.0 on 64 bit x86 SMP
ii  linux-image-3.2.0-35-generic    3.2.0-35.55                         Linux kernel image for version 3.2.0 on 64 bit x86 SMP
iF  linux-image-3.2.0-37-generic    3.2.0-37.58                         Linux kernel image for version 3.2.0 on 64 bit x86 SMP
iF  linux-image-3.2.0-38-generic    3.2.0-38.60                         Linux kernel image for version 3.2.0 on 64 bit x86 SMP
iU  linux-image-generic             3.2.0.37.45                         Generic Linux kernel image

所以我想用以下方法删除3.2.0.32-通用内核:

# sudo apt-get purge linux-image-3.2.0-32-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-generic : Depends: linux-headers-generic (= 3.2.0.37.45) but 3.2.0.38.46 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

没有成功

当我尝试时,apt-get -f install它也失败了:

# apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  linux-headers-3.2.0-34 linux-headers-3.2.0-35 linux-headers-3.2.0-34-generic linux-headers-3.2.0-35-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  linux-generic linux-image-generic
The following packages will be upgraded:
  linux-generic linux-image-generic
2 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
5 not fully installed or removed.
Need to get 0 B/4,334 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
Setting up initramfs-tools (0.99ubuntu13.1) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-image-3.2.0-37-generic (3.2.0-37.58) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-3.2.0-38-generic
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.2.0-37-generic /boot/vmlinuz-3.2.0-37-generic
update-initramfs: Generating /boot/initrd.img-3.2.0-37-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-3.2.0-37-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-3.2.0-37-generic.postinst line 1010.
dpkg: error processing linux-image-3.2.0-37-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
Setting up linux-image-3.2.0-38-generic (3.2.0-38.60) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-3.2.0-37-generic
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.2.0-38-generic /boot/vmlinuz-3.2.0-38-generic
update-initramfs: Generating /boot/initrd.img-3.2.0-38-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-3.2.0-38-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-3.2.0-38-generic.postinst line 1010.
dpkg: error processing linux-image-3.2.0-38-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-3.2.0-37-generic; however:
  Package linux-image-3.2.0-37-generic is not configured yet.
dpkg: error processing linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 3.2.0.37.45); however:
  Package linux-image-generic is not configured yet.
 linux-generic depends on linux-headers-generic (= 3.2.0.37.45); however:
  Version of linux-headers-generic on system is 3.2.0.38.46.
dpkg: error processing linux-generic (--configure):
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools ...
No apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because MaxReports is reached already
  update-initramfs: Generating /boot/initrd.img-3.2.0-35-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-3.2.0-35-generic with 1.
dpkg: error processing initramfs-tools (--configure):
 subprocess installed post-installation script returned error exit status 1
No apport report written because MaxReports is reached already
Errors were encountered while processing:
 linux-image-3.2.0-37-generic
 linux-image-3.2.0-38-generic
 linux-image-generic
 linux-generic
 initramfs-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)

任何帮助将不胜感激。

更新:我做了:

sudo rm /boot/*-3.2.0-32-generic /boot/*-3.2.0-34-generic

之后,出现以下问题apt-get -f install

root@localhost:/# apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  linux-generic
The following packages will be upgraded:
  linux-generic
1 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1,722 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 3.2.0.37.45); however:
  Version of linux-image-generic on system is 3.2.0.38.46.
 linux-generic depends on linux-headers-generic (= 3.2.0.37.45); however:
  Version of linux-headers-generic on system is 3.2.0.38.46.
dpkg: error processing linux-generic (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error     from a previous failure.
                      Errors were encountered while processing:
 linux-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)


请参阅我的答案,以了解由于空间不足而无法自动删除的情况。
nslntmnx

Answers:


22

当内核过时时,不能使用apt-get。

cd /boot
sudo rm *-2.6.35-6.9-generic
sudo rm *-3.16.0-23-generic

用于ls查看文件夹中的内容,删除最旧的一两个,然后

sudo apt-get -f install

然后,您可以像下面这样随意清洗

sudo apt-get purge linux-image-3.2.0-32-generic linux-image-3.2.0-34-generic

或只是继续rm。

你还应该sudo update-grub在结束时


install命令重新安装了许多旧内核,从而产生了完整的启动盘。清除命令为我解决了这个问题。
SPRBRN

我一直遵循这个答案直到sudo apt-get -f install,然后重新启动以确保一切都很好,并apt autoremove按照前面的命令输出中的建议删除了其余的内容。
巴特C

10

显然,这可行:

sudo apt-get autoremove 

根据apt-get手册页:

autoremove用于删除为满足其他软件包的依赖性而自动安装的软件包,现在不再需要它们。

3.16.0-39是我尝试安装的版本,但由于/ boot已满而失败。我当前的版本是3.16.0-38。您可以看到-38被跳过了。

server:~$ uname -r
3.16.0-38-generic
server:~$ sudo apt-get autoremove 
[sudo] password for mikeb: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic
  linux-headers-3.16.0-31 linux-headers-3.16.0-31-generic
  linux-headers-3.16.0-33 linux-headers-3.16.0-33-generic
  linux-headers-3.16.0-34 linux-headers-3.16.0-34-generic
  linux-headers-3.16.0-36 linux-headers-3.16.0-36-generic
  linux-headers-3.16.0-39 linux-headers-3.16.0-39-generic
  linux-image-3.16.0-30-generic linux-image-3.16.0-31-generic
  linux-image-3.16.0-33-generic linux-image-3.16.0-34-generic
  linux-image-3.16.0-36-generic linux-image-3.16.0-39-generic
  linux-image-extra-3.16.0-30-generic linux-image-extra-3.16.0-31-generic
  linux-image-extra-3.16.0-33-generic linux-image-extra-3.16.0-34-generic
  linux-image-extra-3.16.0-36-generic linux-image-extra-3.16.0-39-generic
0 upgraded, 0 newly installed, 24 to remove and 0 not upgraded.

我喜欢这个答案,但是却错过了一些手册,无法确切了解其autoremove用途。
s3m3n 2015年

1
仅当任何先前排队的apt操作正确完成时,autoremove才起作用。如果您已经遇到“设备上没有剩余空间”错误,自动删除将不起作用-那些先前排队的操作将失败,并且自动删除将无法运行。换句话说,自动删除有效...直到无效。
user535733 2015年

@ user535733你是正确的。请参阅我的答案,以了解由于空间不足而无法自动删除的情况。
nslntmnx

7

在终端中,执行以下命令:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get purge

此命令列出了所有当前安装的Linux内核,然后选择所有当前未使用的Linux内核并将其删除。


2
也许您想解释一下此命令的确切作用。它看起来相当复杂:通常,建议人们不要运行他们不理解的命令,尤其是对系统至关重要的命令。
mtdevans 2014年

@mtdevans:我已经添加了上面的命令,列出了所有当前安装的Linux内核,然后选择了所有当前未使用的内核,然后删除了所有当前未使用的内核。
克里斯蒂安

4
该命令很有用,只需先运行“ | xargs”之前的部分,以检查要删除的内容。另外,可能需要grep -v来保留最新的内核,但可能尚未使用,但需要。
罗曼·苏西

4
这很危险,因为它也匹配linux-libc-dev:amd64
Frederick Nord

2
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

如果运行上面的命令而没有“ sudo apt-get -y purge”与您的linux-libc-dev:amd64相匹配,则可以在正则表达式中添加分号以不包含它:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ :]*\).*/\1/;/[0-9]/!d' | xargs

现在只需确保它看起来不错,然后添加“ sudo apt-get -y purge”


1

对于Ubuntu 12.04,请尝试此 sudo apt-get purge linux-image-[kernel version]

这将删除任何内核版本。如果您的启动文件夹中包含许多内核,请不要忘记更新grub和重新启动系统

例如 sudo apt-get清除linux-image-3.11.6 *


2
问题是,当有人遇到依赖问题时,例如前面的问题,这将不再起作用。
圣保罗Ebermann

这对我有用!
丹尼尔(Daniel)

0

许多答案都说要使用“ apt autoremove”,但是在/ boot满时可能无法使用,因为apt尝试在删除之前添加内核。

下一步apt autoremove将不会删除/etc/apt/apt.conf.d/01autoremove-kernels中提到的任何内核,因此我们需要对其进行修复。

这是对我有用的过程。

删除不需要的内核配置文件。

sudo dpkg --purge $(COLUMNS = 200 dpkg -l | grep“ linux-image-extra” | grep“ ^ rc” | tr -s''| cut -d''-f 2)

通过运行以下命令更新/etc/apt/apt.conf.d/01autoremove-kernels ...

须藤/etc/kernel/postinst.d/apt-auto-removal

希望apt autoremove可以工作。

sudo apt自动删除--purge

如果不是这样,您应该能够从/ boot手动删除非常老旧的内核。

首先找出您正在运行的内核。

匿名-r

不要删除您当前的内核或以前的内核。

须藤rm /boot/initrd.img-V.XX.Y-ZZ-generic

现在,您应该有足够的空间来再次尝试apt自动删除。如果不是,请删除另一个非常旧的内核。当然,请保持最新和次老。


-2

我希望这可以帮助:

我通常使用ubuntu-tweak管理员删除旧内核,并提供良好的GUI和简单的:)

单击“系统”,将出现旧内核列表,只需单击它并清理


1
这是一个Ubuntu服务器,我通过腻子连接起来。(但是我也可以在服务器上使用Webmin)
Marcel

请问如何安装这个ubuntu-tweak管理员?
珍妮·奥莱利
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.