删除一些旧内核后

我删除了一些必要的内核部分以扩大我的启动分区上的可用空间。首先,我按照这个链接做了操作。然而,问题与链接中的情况不完全相同(请参阅Eliah的回答)。我最初尝试的是以下步骤,首先是我的分区方案的输出:
ubuntu@ubuntu:~$  sudo parted -l
Model: ATA ST3500418AS (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
 1      32.3kB  535MB   535MB   primary  ext4            boot
 2      535MB   5914MB  5379MB  primary  linux-swap(v1)
 3      5914MB  106GB   100GB   primary  ext4
 4      106GB   500GB   394GB   primary  ext4


Model: WD 5000AAC External (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End    Size   Type     File system  Flags
 1      32.3kB  500GB  500GB  primary  ext4


Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0
has been opened read-only.
Error: Can't have a partition outside the disk!                           

ubuntu@ubuntu:~$ 

我将引导分区放在sda1上,sda2是我的交换分区,sda3是我的根目录,sda4是我的主目录。我按照第二个答案(由Eliah提供)的指示进行操作。这意味着:
     ubuntu@ubuntu:~$ sudo mount /dev/sda3 /mnt 
ubuntu@ubuntu:~$ sudo mount --bind /dev /mnt/dev 
ubuntu@ubuntu:~$ sudo mount /dev/sda1 /mnt/boot

Then I chrooted: ``` ubuntu@ubuntu:~$ sudo chroot /mnt root@ubuntu:/# mount -t proc none /proc root@ubuntu:/# mount -t sysfs none /sys root@ubuntu:/# mount -t devpts none /dev/pts root@ubuntu:/# export HOME=/root root@ubuntu:/# export LC_ALL=C ```
I tried to install new kernel: ``` apt-get update apt-get -y install linux-image-generic ```
这里我遇到了以下错误:
root@ubuntu:/# apt-get -y install linux-image-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
linux-image-generic is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.
4 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up linux-image-3.8.0-29-generic (3.8.0-29.42) ...
Internal Error: Could not find image (/boot/vmlinuz-3.8.0-29-generic)
dpkg: error processing linux-image-3.8.0-29-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of linux-image-extra-3.8.0-29-generic:
 linux-image-extra-3.8.0-29-generic depends on linux-image-3.8.0-29-generic; however:
  Package linux-image-3.8.0-29-generic is not configured yet.

dpkg: error processing linux-image-extra-3.8.0-29-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-3.8.0-29-generic; however:
  Package linux-image-3.8.0-29-generic is not configured yet.
 linux-image-generic depends on linux-image-extra-3.8.0-29-generic; however:
  Package linux-image-extra-3.8.0-29-generic is not configured yet.

dpkg: error processing linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-imNo apport report written because the error message indicates its a followup error from a previous failure.
     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
             age:
 linux-image depends on linux-image-generic; however:
  Package linux-image-generic is not configured yet.

dpkg: error processing linux-image (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 linux-image-3.8.0-29-generic
 linux-image-extra-3.8.0-29-generic
 linux-image-generic
 linux-image
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@ubuntu:/# 


umount /proc || umount -lf /proc
umount /sys /dev/pts
exit
sudo umount /mnt/dev /mnt

我也尝试了卸载所有东西并运行。
apt-get install linux-generic linux-image-generic linux-headers-generic

当然了
update-grub

我在启动时仍然遇到了memtest。正如Eliah指出的那样,上述解决方案在我的情况下不适用。因此,我按照他在下面的答案中提供的说明进行操作。然而,这并没有解决问题。我得到了以下输出:
   ubuntu@ubuntu:~$ sudo mount /dev/sda3 /mnt
ubuntu@ubuntu:~$ sudo mount --bind /dev /mnt/dev
ubuntu@ubuntu:~$ sudo mount /dev/sda1 /mnt/boot
ubuntu@ubuntu:~$ sudo chroot /mnt
root@ubuntu:/# mount -t proc none /proc
root@ubuntu:/# mount -t sysfs none /sys
root@ubuntu:/# mount -t devpts none /dev/pts
root@ubuntu:/# export HOME=/root
root@ubuntu:/# export LC_ALL=C

然后运行apt-get update,然后按照建议进行操作。
root@ubuntu:/# apt-get -y --purge --reinstall install linux-image-3.8.0-29-generic linux-image-extra-3.8.0-29-generic linux-image-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 3 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/43.3 MB of archives.
After this operation, 0 B of additional disk space will be used.
dpkg: warning: files list file for package 'linux-image-3.8.0-29-generic' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'initramfs-tools' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'linux-image-extra-3.8.0-29-generic' missing; assuming package has no files currently installed
(Reading database ... 251414 files and directories currently installed.)
Preparing to replace linux-image-3.8.0-29-generic 3.8.0-29.42 (using .../linux-image-3.8.0-29-generic_3.8.0-29.42_amd64.deb) ...
Done.
Unpacking replacement linux-image-3.8.0-29-generic ...
Preparing to replace linux-image-extra-3.8.0-29-generic 3.8.0-29.42 (using .../linux-image-extra-3.8.0-29-generic_3.8.0-29.42_amd64.deb) ...
Unpacking replacement linux-image-extra-3.8.0-29-generic ...
Preparing to replace linux-image-generic 3.8.0.29.47 (using .../linux-image-generic_3.8.0.29.47_amd64.deb) ...
Unpacking replacement linux-image-generic ...
Setting up linux-image-3.8.0-29-generic (3.8.0-29.42) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Failed to symbolic-link /boot/initrd.img-3.8.0-29-generic to initrd.img:File exists at /var/lib/dpkg/info/linux-image-3.8.0-29-generic.postinst line 614.
dpkg: error processing linux-image-3.8.0-29-generic (--configure):
 subprocess installed post-installation script returned error exit status 17
dpkg: dependency problems prevent configuration of linux-image-extra-3.8.0-29-generic:
 linux-image-extra-3.8.0-29-generic depends on linux-image-3.8.0-29-generic; however:
  Package linux-image-3.8.0-29-generic is not configured yet.

dpkg: error processing linux-image-extra-3.8.0-29-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-3.8.0-29-generic; however:
  Package linux-image-3.8.0-29-generic is not configured yet.
 linux-image-generic depends on linux-image-extra-3.8.0-29-generic; however:
  Package linux-image-extra-3.8.0-29-generic is not configured yet.

dpkg: error processing linux-image-generic (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                          No apport report written because the error message indicates its a followup error from a previous failure.
                                                    Errors were encountered while processing:
 linux-image-3.8.0-29-generic
 linux-image-extra-3.8.0-29-generic
 linux-image-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@ubuntu:/# 

@EliahKagan 如果我按照说明操作,我会遇到以下问题,请查看我的编辑过的问题。 - math
你能编辑一下你的问题,包括所有发生的细节吗?你链接的论坛主题包含了各种信息,不清楚你具体遇到了哪个挑战。 - Eliah Kagan
apt-get工作吗? - Dillmo
@EliahKagan,我按照你的建议编辑了我的问题。希望现在一切都清楚了。我完全按照你的答案操作,但是使用apt-get -y linux-image-generic时出现了问题。 - math
@Dillmo 是的,我可以运行例如apt-get update等命令,但是如果我想安装新的linux-image,会出现错误信息(请参见我编辑过的问题)。 - math
我还尝试了卸载 'linux-generic linux-image-generic linux-headers-generic' 并重新安装所有内容。之后我还运行了 'update-grub'。然而,在启动时它又开始了内存测试。 - math
@EliahKagan 你知道我怎么解决这个问题吗?我完全按照你的指示操作,但仍然无法启动。感谢你的耐心。 - math
3个回答

那里的答案是针对没有内核的情况而写的,因为提供内核的软件包已被删除。

你的情况类似但有些不同。看起来在你的系统上发生的是,没有内核,因为它们的文件已被手动删除(或者被某个自动化进程其他于软件包卸载之外的方式删除)。在软件包管理器看来,似乎你仍然安装了内核。

要解决这个问题,可能只需告诉软件包管理器重新安装内核软件包。

你运行了这个命令:

apt-get -y install linux-image-generic

使用相同的步骤(包括之前的apt-get update命令),尝试用以下命令替换那个apt-get -y install命令:
apt-get -y --purge --reinstall install linux-image-3.8.0-29-generic linux-image-extra-3.8.0-29-generic linux-image-generic

--purge标志是可选的,因为这个问题与系统范围的配置文件无关。但它不会有任何损害。)
这将卸载那些由于文件被删除而无法正常工作的软件包,然后重新安装它们,确保所有文件都从软件包存档中复制过来。它不应该依赖于任何软件包文件的存在,所以即使一些软件包文件似乎已经被手动删除,它也应该能够正常工作。 linux-image-generic是一个元软件包;安装它会导致为您的系统安装最新的稳定内核,因为linux-image-generic声明了提供该内核的软件包作为依赖项。指定要“从头开始”重新安装linux-image-generic并不一定会导致所有相关的依赖项被重新安装,这就是为什么我在上面的命令中明确列出了它的相关依赖项的原因。
我从你的问题中包含的输出中得到了它们的名称(linux-image-extra-3.8.0-29-genericlinux-image-extra-3.8.0-29-generic)。其他遇到这个问题的人不一定想要明确指定安装这些软件包,而是应该查看linux-image-generic依赖的软件包,并明确重新安装至少缺少文件的软件包。
因此,导致我建议这个解决方案的输出的关键部分是:
Setting up linux-image-3.8.0-29-generic (3.8.0-29.42) ...
Internal Error: Could not find image (/boot/vmlinuz-3.8.0-29-generic)
dpkg: error processing linux-image-3.8.0-29-generic (--configure):

这有可能不会起作用。如果软件包损坏,阻止包管理器“卸载”它们,就会发生这种情况。如果出现这样或其他任何问题,请更新您的问题,并提供详细信息。
(对于除了发表此问题的作者之外的人来说,如果发生这种情况并且这里的信息不能帮助您解决问题,请发布一个新问题,并尽可能提供详细信息,或者如果您已经发布关于该问题的问题,请添加详细信息。)

感谢您的回答,看到我的编辑了(对于Eliah的第二次编辑)。类似的问题。 - math
我还编辑了我的问题,以澄清实际的问题是什么。再次感谢您的耐心。也许应该删除“这个问题可能已经有答案了”,因为我的问题是不同的。 - math
你看到我的更新问题了吗?我需要提供更多细节吗?如果需要,请让我知道。谢谢你的帮助。 - math
奇怪的是,现在它使用以下内核:root@ubuntu:/# uname -r 3.5.0-17-generic。因此,uname -r 的输出是3.5.0-17。 - math
@math 自从您应用了这个解决方案以来,它使用了那个内核吗?如果是这样,我猜您可以通过运行sudo apt-get update然后运行sudo apt-get upgrade来升级内核(在正常启动系统后进行,因为任何成功安装的内核都应该允许)。 - Eliah Kagan

一个朋友解决了这个问题。他给出了以下建议,对我起到了作用:
apt-get purge grub grub-pc grub-common 
apt-get install grub-common grub-pc 
update-grub

好主意!我之前没有考虑重新安装GRUB软件包(这是在这里所做的,与常见的将GRUB重新安装到MBR的操作不同)。安装和卸载内核时出现的一些问题与修改GRUB的脚本有关,所以这个解决方案是有道理的。我很高兴这个方法有效。顺便说一下,前两个命令可能可以合并为一个:apt-get --purge --reinstall grub-common grub-pc - Eliah Kagan

根据上述信息,我使用了以下内容。
uname -r

让我们把以上命令的输出称为南瓜
然后我输入了:
dpkg --list | grep linux-image

我查看了这个列表的输出,并注意到了linux-image-PUMPKIN。
如果不是我的linux-image-PUMPKIN,你可以根据适用于你的命令来删除其他内容。
sudo apt-get purge linux-image-(your non-PUMKIN entry goes here)

然后一个

sudo update-grub
sudo update-grub2

最后
sudo apt-get update
sudo apt-get autoremove
sudo apt-get upgrade

我重新启动后就好了。