![更新 1](https://linux22.com/image/1008995/%E6%9B%B4%E6%96%B0%201.png)
我设立unattended-upgrades
在我的 Ubuntu 16.04 服务器上。我今天检查了一下,空间/boot
不足。apt-get
其他答案建议运行apt-get purge <old-kernels>
,但该命令对我来说也失败了。我猜想这是由于部分配置的包造成的?
我如何强制apt-get
删除旧的软件包/boot
?另外,有没有办法配置unattended-upgrades
定期删除旧的、未使用的内核软件包?
这是我尝试升级和清除软件包时的控制台输出
user@host:~$ sudo apt-get upgrade
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-4.4.0-116-generic : Depends: linux-image-4.4.0-116-generic but it is not installed
linux-image-extra-4.4.0-130-generic : Depends: linux-image-4.4.0-130-generic but it is not installed
linux-image-generic : Depends: linux-image-4.4.0-130-generic but it is not installed
Recommends: thermald but it is not installed
E: Unmet dependencies. Try using -f.
user@host:~$ sudo 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-4.4.0-101 linux-headers-4.4.0-101-generic linux-headers-4.4.0-103 linux-headers-4.4.0-103-generic linux-headers-4.4.0-116 linux-headers-4.4.0-116-generic linux-headers-4.4.0-89 linux-headers-4.4.0-89-generic linux-headers-4.4.0-92
linux-headers-4.4.0-92-generic linux-headers-4.4.0-93 linux-headers-4.4.0-93-generic linux-headers-4.4.0-96 linux-headers-4.4.0-96-generic linux-headers-4.4.0-97 linux-headers-4.4.0-97-generic linux-headers-4.4.0-98 linux-headers-4.4.0-98-generic
linux-image-4.4.0-101-generic linux-image-4.4.0-103-generic linux-image-4.4.0-116-generic linux-image-4.4.0-89-generic linux-image-4.4.0-92-generic linux-image-4.4.0-93-generic linux-image-4.4.0-96-generic linux-image-4.4.0-97-generic linux-image-4.4.0-98-generic
linux-image-extra-4.4.0-101-generic linux-image-extra-4.4.0-103-generic linux-image-extra-4.4.0-116-generic linux-image-extra-4.4.0-89-generic linux-image-extra-4.4.0-92-generic linux-image-extra-4.4.0-93-generic linux-image-extra-4.4.0-96-generic
linux-image-extra-4.4.0-97-generic linux-image-extra-4.4.0-98-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
amd64-microcode intel-microcode iucode-tool linux-generic linux-headers-4.4.0-130 linux-headers-4.4.0-130-generic linux-headers-generic linux-image-4.4.0-116-generic linux-image-4.4.0-130-generic linux-image-extra-4.4.0-130-generic linux-image-generic
Suggested packages:
fdutils linux-doc-4.4.0 | linux-source-4.4.0 linux-tools
Recommended packages:
thermald
The following NEW packages will be installed:
amd64-microcode intel-microcode iucode-tool linux-headers-4.4.0-130 linux-headers-4.4.0-130-generic linux-image-4.4.0-116-generic linux-image-4.4.0-130-generic linux-image-extra-4.4.0-130-generic
The following packages will be upgraded:
linux-generic linux-headers-generic linux-image-generic
3 upgraded, 8 newly installed, 0 to remove and 130 not upgraded.
13 not fully installed or removed.
Need to get 70.7 MB/92.7 MB of archives.
After this operation, 372 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-4.4.0-130-generic amd64 4.4.0-130.156 [22.1 MB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-extra-4.4.0-130-generic amd64 4.4.0-130.156 [36.5 MB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 iucode-tool amd64 1.5.1-1ubuntu0.1 [33.8 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 intel-microcode amd64 3.20180425.1~ubuntu0.16.04.1 [1,145 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 amd64-microcode amd64 3.20180524.1~ubuntu0.16.04.1 [32.9 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-generic amd64 4.4.0.130.136 [1,792 B]
Get:7 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-generic amd64 4.4.0.130.136 [2,532 B]
Get:8 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-4.4.0-130 all 4.4.0-130.156 [10.0 MB]
Get:9 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-4.4.0-130-generic amd64 4.4.0-130.156 [815 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-headers-generic amd64 4.4.0.130.136 [2,498 B]
Fetched 70.7 MB in 47s (1,475 kB/s)
Selecting previously unselected package linux-image-4.4.0-130-generic.
(Reading database ... 491770 files and directories currently installed.)
Preparing to unpack .../linux-image-4.4.0-130-generic_4.4.0-130.156_amd64.deb ...
Done.
Unpacking linux-image-4.4.0-130-generic (4.4.0-130.156) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-130-generic_4.4.0-130.156_amd64.deb (--unpack):
cannot copy extracted data for './boot/vmlinuz-4.4.0-130-generic' to '/boot/vmlinuz-4.4.0-130-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-130-generic /boot/vmlinuz-4.4.0-130-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-130-generic /boot/vmlinuz-4.4.0-130-generic
Selecting previously unselected package linux-image-extra-4.4.0-130-generic.
Preparing to unpack .../linux-image-extra-4.4.0-130-generic_4.4.0-130.156_amd64.deb ...
Unpacking linux-image-extra-4.4.0-130-generic (4.4.0-130.156) ...
Selecting previously unselected package iucode-tool.
Preparing to unpack .../iucode-tool_1.5.1-1ubuntu0.1_amd64.deb ...
Unpacking iucode-tool (1.5.1-1ubuntu0.1) ...
Selecting previously unselected package intel-microcode.
Preparing to unpack .../intel-microcode_3.20180425.1~ubuntu0.16.04.1_amd64.deb ...
Unpacking intel-microcode (3.20180425.1~ubuntu0.16.04.1) ...
Selecting previously unselected package amd64-microcode.
Preparing to unpack .../amd64-microcode_3.20180524.1~ubuntu0.16.04.1_amd64.deb ...
Unpacking amd64-microcode (3.20180524.1~ubuntu0.16.04.1) ...
Preparing to unpack .../linux-generic_4.4.0.130.136_amd64.deb ...
Unpacking linux-generic (4.4.0.130.136) over (4.4.0.116.122) ...
Preparing to unpack .../linux-image-generic_4.4.0.130.136_amd64.deb ...
Unpacking linux-image-generic (4.4.0.130.136) over (4.4.0.116.122) ...
Selecting previously unselected package linux-headers-4.4.0-130.
Preparing to unpack .../linux-headers-4.4.0-130_4.4.0-130.156_all.deb ...
Unpacking linux-headers-4.4.0-130 (4.4.0-130.156) ...
Selecting previously unselected package linux-headers-4.4.0-130-generic.
Preparing to unpack .../linux-headers-4.4.0-130-generic_4.4.0-130.156_amd64.deb ...
Unpacking linux-headers-4.4.0-130-generic (4.4.0-130.156) ...
Preparing to unpack .../linux-headers-generic_4.4.0.130.136_amd64.deb ...
Unpacking linux-headers-generic (4.4.0.130.136) over (4.4.0.116.122) ...
Preparing to unpack .../linux-image-4.4.0-116-generic_4.4.0-116.140_amd64.deb ...
Examining /etc/kernel/preinst.d/
Done.
Unpacking linux-image-4.4.0-116-generic (4.4.0-116.140) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-116-generic_4.4.0-116.140_amd64.deb (--unpack):
cannot copy extracted data for './boot/vmlinuz-4.4.0-116-generic' to '/boot/vmlinuz-4.4.0-116-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-116-generic /boot/vmlinuz-4.4.0-116-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-116-generic /boot/vmlinuz-4.4.0-116-generic
Processing triggers for man-db (2.7.5-1) ...
Errors were encountered while processing:
/var/cache/apt/archives/linux-image-4.4.0-130-generic_4.4.0-130.156_amd64.deb
/var/cache/apt/archives/linux-image-4.4.0-116-generic_4.4.0-116.140_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
当我尝试清除包时,出现以下信息:
user@host:~$ sudo apt-get purge linux-image-4.4.0-89-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-4.4.0-116-generic : Depends: linux-image-4.4.0-116-generic but it is not going to be installed
linux-image-extra-4.4.0-130-generic : Depends: linux-image-4.4.0-130-generic but it is not going to be installed
linux-image-extra-4.4.0-89-generic : Depends: linux-image-4.4.0-89-generic but it is not going to be installed
linux-image-generic : Depends: linux-image-4.4.0-130-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).
以下是所有已安装或部分安装/配置的软件包:
user@host:~$ dpkg -l | grep linux-.* | grep '^.[iFH]'
ii linux-base 4.0ubuntu1 all Linux image base package
iF linux-firmware 1.157.16 all Firmware for Linux kernel drivers
ii linux-headers-4.4.0-101 4.4.0-101.124 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-101-generic 4.4.0-101.124 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-103 4.4.0-103.126 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-103-generic 4.4.0-103.126 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-104 4.4.0-104.127 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-104-generic 4.4.0-104.127 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-109 4.4.0-109.132 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-109-generic 4.4.0-109.132 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-112 4.4.0-112.135 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-112-generic 4.4.0-112.135 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-89 4.4.0-89.112 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-89-generic 4.4.0-89.112 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-92 4.4.0-92.115 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-92-generic 4.4.0-92.115 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-93 4.4.0-93.116 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-93-generic 4.4.0-93.116 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-96 4.4.0-96.119 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-96-generic 4.4.0-96.119 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-97 4.4.0-97.120 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-97-generic 4.4.0-97.120 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-headers-4.4.0-98 4.4.0-98.121 all Header files related to Linux kernel version 4.4.0
ii linux-headers-4.4.0-98-generic 4.4.0-98.121 amd64 Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-101-generic 4.4.0-101.124 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-103-generic 4.4.0-103.126 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-104-generic 4.4.0-104.127 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
iF linux-image-4.4.0-109-generic 4.4.0-109.132 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
iF linux-image-4.4.0-112-generic 4.4.0-112.135 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-89-generic 4.4.0-89.112 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-92-generic 4.4.0-92.115 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-93-generic 4.4.0-93.116 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-96-generic 4.4.0-96.119 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-97-generic 4.4.0-97.120 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-98-generic 4.4.0-98.121 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-101-generic 4.4.0-101.124 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-103-generic 4.4.0-103.126 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
iF linux-image-extra-4.4.0-104-generic 4.4.0-104.127 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-89-generic 4.4.0-89.112 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-92-generic 4.4.0-92.115 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-93-generic 4.4.0-93.116 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-96-generic 4.4.0-96.119 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-97-generic 4.4.0-97.120 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii linux-image-extra-4.4.0-98-generic 4.4.0-98.121 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
系统和内核信息:
user@host:~$ uname -a
Linux host 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
磁盘使用情况:
user@host:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 376M 11M 366M 3% /run
/dev/mapper/host--vg-root 225G 17G 197G 8% /
tmpfs 1.9G 4.0K 1.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 472M 467M 0 100% /boot
tmpfs 376M 0 376M 0% /run/user/1000
更新 1
我dpkg --purge
按照评论中的建议尝试了一下,得到了以下结果
user@host:~$ sudo dpkg --purge linux-image-extra-4.4.0-89-generic linux-image-4.4.0-89-generic
(Reading database ... 523323 files and directories currently installed.)
Removing linux-image-extra-4.4.0-89-generic (4.4.0-89.112) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-89-generic /boot/vmlinuz-4.4.0-89-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-89-generic /boot/vmlinuz-4.4.0-89-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-89-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-89-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-89-generic (--purge):
subprocess installed post-removal script returned error exit status 1
Removing linux-image-4.4.0-89-generic (4.4.0-89.112) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-89-generic /boot/vmlinuz-4.4.0-89-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-89-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-89-generic /boot/vmlinuz-4.4.0-89-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-112-generic
Found linux image: /boot/vmlinuz-4.4.0-109-generic
Found linux image: /boot/vmlinuz-4.4.0-104-generic
Found initrd image: /boot/initrd.img-4.4.0-104-generic
Found linux image: /boot/vmlinuz-4.4.0-103-generic
Found initrd image: /boot/initrd.img-4.4.0-103-generic
Found linux image: /boot/vmlinuz-4.4.0-101-generic
Found initrd image: /boot/initrd.img-4.4.0-101-generic
Found linux image: /boot/vmlinuz-4.4.0-98-generic
Found initrd image: /boot/initrd.img-4.4.0-98-generic
Found linux image: /boot/vmlinuz-4.4.0-97-generic
Found initrd image: /boot/initrd.img-4.4.0-97-generic
Found linux image: /boot/vmlinuz-4.4.0-96-generic
Found initrd image: /boot/initrd.img-4.4.0-96-generic
Found linux image: /boot/vmlinuz-4.4.0-93-generic
Found initrd image: /boot/initrd.img-4.4.0-93-generic
Found linux image: /boot/vmlinuz-4.4.0-92-generic
Found initrd image: /boot/initrd.img-4.4.0-92-generic
done
Purging configuration files for linux-image-4.4.0-89-generic (4.4.0-89.112) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-89-generic /boot/vmlinuz-4.4.0-89-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-89-generic /boot/vmlinuz-4.4.0-89-generic
Errors were encountered while processing:
linux-image-extra-4.4.0-89-generic
更新 2
成功!有趣的是,dpkg --purge
失败了具体来说在4.4.0-89-generic
软件包上。我不太清楚为什么。它对其他人有用,并成功释放了空间。在运行了dpkg --purge
几个软件包后,我在 上有足够的空间/boot
。
有效的命令(省略输出)
sudo dpkg --purge linux-image-4.4.0-92-generic linux-image-extra-4.4.0-92-generic
sudo dpkg --purge linux-image-4.4.0-96-generic linux-image-extra-4.4.0-96-generic
sudo dpkg --purge linux-image-4.4.0-93-generic linux-image-extra-4.4.0-93-generic
sudo dpkg --purge linux-image-4.4.0-97-generic linux-image-extra-4.4.0-97-generic
已释放的空间/root
现在仅为 51%。
user@host:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 376M 11M 366M 3% /run
/dev/mapper/host--vg-root 225G 17G 198G 8% /
tmpfs 1.9G 4.0K 1.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 472M 226M 222M 51% /boot
tmpfs 376M 0 376M 0% /run/user/1000
现在apt-get -f install
和后续apt-get purge <package>
命令都成功。
答案1
根据评论
解决方案是使用dpkg --purge
删除旧内核包。具体来说,必须删除linux-image-x.x.xx-xxx-generic
和包。当我仅指定其中一个时,仍然失败。linux-image-extra-x.x.xx-xxx-generic
dpkg
还,请注意,dpkg --purge
某些软件包仍然会失败。我认为这是由于某些软件包配置了一半或安装了一半,尽管我没有检查。
以下是purge
我运行成功的命令:
sudo dpkg --purge linux-image-4.4.0-92-generic linux-image-extra-4.4.0-92-generic
sudo dpkg --purge linux-image-4.4.0-96-generic linux-image-extra-4.4.0-96-generic
sudo dpkg --purge linux-image-4.4.0-93-generic linux-image-extra-4.4.0-93-generic
sudo dpkg --purge linux-image-4.4.0-97-generic linux-image-extra-4.4.0-97-generic
之后/root
只填充了 51%,而不是原来的 100%
# Original
user@host:~$ df -h
Filesystem Size Used Avail Use% Mounted on
~~~ snip ~~~
/dev/sda1 472M 467M 0 100% /boot
# After dpkg --purge
user@host:~$ df -h
Filesystem Size Used Avail Use% Mounted on
~~~ snip ~~~
/dev/sda1 472M 226M 222M 51% /boot
现在我可以使用以下方法成功修复损坏的安装
apt-get -f install