我根本无法使用 APT 命令

我根本无法使用 APT 命令

我根本无法使用 APT 命令,每次我尝试使用它时都会出现这种情况:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  haguichi-indicator
The following packages will be REMOVED:
  linux-image-4.4.0-36-generic linux-image-4.4.0-38-generic
  linux-image-4.4.0-42-generic linux-image-4.4.0-45-generic
  linux-image-extra-4.4.0-36-generic linux-image-extra-4.4.0-38-generic
  linux-image-extra-4.4.0-42-generic linux-image-extra-4.4.0-45-generic
The following NEW packages will be installed:
  haguichi haguichi-indicator
0 upgraded, 2 newly installed, 8 to remove and 9 not upgraded.
16 not fully installed or removed.
Need to get 311 kB of archives.
After this operation, 871 MB disk space will be freed.
Get:1 http://ppa.launchpad.net/webupd8team/haguichi/ubuntu xenial/main amd64 haguichi amd64 1.3.6~ubuntu16.04.1 [295 kB]
Get:2 http://ppa.launchpad.net/webupd8team/haguichi/ubuntu xenial/main amd64 haguichi-indicator amd64 0.3.2~ubuntu16.04.1 [16.4 kB]
Fetched 311 kB in 33s (9,292 B/s)                                              
(Reading database ... 350665 files and directories currently installed.)
Removing linux-image-extra-4.4.0-36-generic (4.4.0-36.55) ...
depmod: FATAL: could not load /boot/System.map-4.4.0-36-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
Error! Your kernel headers for kernel 4.4.0-36-generic cannot be found.
Please install the linux-headers-4.4.0-36-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-36-generic cannot be found.
Please install the linux-headers-4.4.0-36-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-36-generic cannot be found.
Please install the linux-headers-4.4.0-36-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-36-generic
WARNING: missing /lib/modules/4.4.0-36-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.4.0-36-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_shj3j9/lib/modules/4.4.0-36-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_shj3j9/lib/modules/4.4.0-36-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 127
dpkg: error processing package linux-image-extra-4.4.0-36-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-4.4.0-36-generic (4.4.0-36.55) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-36-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-4.4.0-36-generic.postrm line 328.
dpkg: error processing package linux-image-4.4.0-36-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-extra-4.4.0-38-generic (4.4.0-38.57) ...
depmod: FATAL: could not load /boot/System.map-4.4.0-38-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
Error! Your kernel headers for kernel 4.4.0-38-generic cannot be found.
Please install the linux-headers-4.4.0-38-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-38-generic cannot be found.
Please install the linux-headers-4.4.0-38-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-38-generic cannot be found.
Please install the linux-headers-4.4.0-38-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-38-generic
WARNING: missing /lib/modules/4.4.0-38-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.4.0-38-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_q0p1fx/lib/modules/4.4.0-38-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_q0p1fx/lib/modules/4.4.0-38-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 127
dpkg: error processing package linux-image-extra-4.4.0-38-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-4.4.0-38-generic (4.4.0-38.57) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-38-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-4.4.0-38-generic.postrm line 328.
dpkg: error processing package linux-image-4.4.0-38-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Removing linux-image-extra-4.4.0-42-generic (4.4.0-42.62) ...
depmod: FATAL: could not load /boot/System.map-4.4.0-42-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
Error! Your kernel headers for kernel 4.4.0-42-generic cannot be found.
Please install the linux-headers-4.4.0-42-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-42-generic cannot be found.
Please install the linux-headers-4.4.0-42-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-42-generic cannot be found.
Please install the linux-headers-4.4.0-42-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-42-generic
WARNING: missing /lib/modules/4.4.0-42-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.4.0-42-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_sRVHmx/lib/modules/4.4.0-42-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_sRVHmx/lib/modules/4.4.0-42-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 127
dpkg: error processing package linux-image-extra-4.4.0-42-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Removing linux-image-4.4.0-42-generic (4.4.0-42.62) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-42-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-4.4.0-42-generic.postrm line 328.
dpkg: error processing package linux-image-4.4.0-42-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Removing linux-image-extra-4.4.0-45-generic (4.4.0-45.66) ...
depmod: FATAL: could not load /boot/System.map-4.4.0-45-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
Error! Your kernel headers for kernel 4.4.0-45-generic cannot be found.
Please install the linux-headers-4.4.0-45-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-45-generic cannot be found.
Please install the linux-headers-4.4.0-45-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-45-generic cannot be found.
Please install the linux-headers-4.4.0-45-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-45-generic
WARNING: missing /lib/modules/4.4.0-45-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.4.0-45-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_lvRMvc/lib/modules/4.4.0-45-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_lvRMvc/lib/modules/4.4.0-45-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 127
dpkg: error processing package linux-image-extra-4.4.0-45-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Removing linux-image-4.4.0-45-generic (4.4.0-45.66) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-45-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-45-generic /boot/vmlinuz-4.4.0-45-generic
/usr/sbin/grub-mkconfig: 6: /etc/default/grub: 10: not found
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-4.4.0-45-generic.postrm line 328.
dpkg: error processing package linux-image-4.4.0-45-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-image-extra-4.4.0-36-generic
 linux-image-4.4.0-36-generic
 linux-image-extra-4.4.0-38-generic
 linux-image-4.4.0-38-generic
 linux-image-extra-4.4.0-42-generic
 linux-image-4.4.0-42-generic
 linux-image-extra-4.4.0-45-generic
 linux-image-4.4.0-45-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

有什么建议吗?我无法删除有问题的软件包,我不知道为什么。

答案1

我经常遇到这种问题。我运行一堆 KODI 盒(我创建的),它们都通过 PXE 从专用服务器启动。因此,当我通过 chroot(或其他方式)更新我的 PXE 盒时,我经常会遇到内核更新问题。所以,最近我决定创建一个脚本,它将创建 depmod/apt-get 正在寻找的垃圾,以便您可以正确删除这些内核。

要运行脚本,只需将代码复制并粘贴到文件中。在终端中,输入以下内容使其可执行:

$> chmod +x fixKernels.sh

其中“fixKernels.sh”是脚本的名称。

从那里,通过键入以下内容运行脚本:

$> sudo ./fixKernels.sh

然后只需按照指示操​​作即可。

#!/bin/bash

####################################################
#
# NAME: fixKernels.sh
#
#
# DESCRIPTION: This script was designed to create
# fake kernel entries in places depmod and apt-get
# would normally look for existing kernels. The purpose
# of this script is to trick depmod or apt-get into
# believing these kernels exist on your system so it
# can successfully remove them without causing errors
# and preventing YOU from installing other things.
#
####################################################

# Spinner! Shows a rotating line animation
spinner()
{
    sleep 1
    PROC=$1
    BACKSPACE='\010'
    SPINNER='|/-\'
    INDEX=0
    while [ -d /proc/$PROC ]
    do
        echo -n -e "${SPINNER:$INDEX:1}"
        sleep 0.2
        (( INDEX = ($INDEX + 1) % 4 ))
        echo -n -e "$BACKSPACE"

    done

}

# Check for root
cp /etc/shadow /tmp/isroot 2>/dev/null

# IF ROOT
if [ ! -f /tmp/isroot ]; then
    echo "You ain't root, baby!"
    exit
else
    # Remove temp file
    rm /tmp/isroot
fi

# Make sure parameter is not empty
if [[ $1 != "" ]] && [[ `echo $1 | grep -i "linux"` == "" ]]; then

    # Needed echo! Great for displaying purposes
    echo

    # Determine if uname exists
    if [[ ! -d /lib/modules/`uname -r` ]]; then

        # Examine all the kernels found on the system
        for x in `ls -l /lib/modules | awk '{print $9}'`
        do

            # Determine that all the pieces exist before we use them!
            if [[ -f /boot/System.map-$x ]] && [[ -f /boot/vmlinuz-$x ]]; then

                # Use whatever we've got!!
                UNAME=$x

            fi


        done

        # IF the pieces aren't found... Not much else we can do!!
        if [[ $UNAME == "" ]]; then

            # Error
            echo "There's no kernel found on your system!! How are you reading this??"

            # Exit the script
            exit

        fi

    else # We've got what we need

        UNAME=`uname -r`
    fi

    # Make sure the kernel isn't copying on top of itself
    if [[ $1 != $UNAME ]]; then

        # Create a fake version of that kernel
        echo "Creating Fake System Map..."
        sudo cp /boot/System.map-$UNAME /boot/System.map-$1 -rfap &

        # Create a short animation to show user it's working
        spinner $!

        # Create the vmlinuz... But it's fake
        echo "Creating Fake Vmlinuz..."
        sudo cp /boot/vmlinuz-$UNAME /boot/vmlinuz-$1 -rfap &

        # Create a short animation
        spinner $!

        # Create the fake modules
        echo "Creating Fake Kernel Modules..."
        sudo cp /lib/modules/$UNAME /lib/modules/$1 -rfap &

        # Create a short animation
        spinner $!
    else

        # Warn user
        echo "This kernel exists... Skipping!"

    fi

else

    echo "USAGE: ./`basename $0` <kernel version>"
    echo "EXAMPLE: ./`basename $0` 4.4.0-31-generic"
fi

相关内容