我在 Ubuntu 22.10 上,当尝试运行apt
或apt-get
使用时{install|remove|auto-remove}
出现以下错误:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up initramfs-tools (0.140ubuntu17) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools (0.140ubuntu17) ...
/usr/sbin/update-initramfs: 175: awk: Too many levels of symbolic links
dpkg: error processing package initramfs-tools (--configure):
installed initramfs-tools package post-installation script subprocess returned
error exit status 127
Errors were encountered while processing:
initramfs-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)
错误信息显示:
/usr/sbin/update-initramfs: 175: awk: Too many levels of symbolic links
所以我尝试update-initramfs
单独运行
ya22y@IYB:~$ sudo update-initramfs -u
/usr/sbin/update-initramfs: 175: awk: Too many levels of symbolic links
确保文件权限
ya22y@IYB:~$ stat ../../usr/sbin/update-initramfs
File: ../../usr/sbin/update-initramfs
Size: 6906 Blocks: 16 IO Block: 4096 regular file
Device: 803h/2051d Inode: 6553706 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
据我所知,文件 A 引用文件 B 的无限循环导致了此错误。我检查了 update-initramfs 代码,但我不知道如何解决此错误。
编辑我update-initramfs
再次检查,错误来源是启动选项
ro_boot_check()
{
# check irrelevant inside of a chroot
if [ ! -r /proc/mounts ] || ischroot; then
return 0
fi
#shellcheck disable=SC1004
boot_opts=$(awk '/boot/{if ((match($4, /^ro/) || match($4, /,ro/)) \
&& $2 == "/boot") print "ro"}' /proc/mounts)
if [ -n "${boot_opts}" ]; then
echo "W: /boot is ro mounted." >&2
echo "W: update-initramfs: Not updating ${initramfs}" >&2
exit 0
fi
}
启动目录
ya22y@IYB:~$ ls ../../boot
config-5.19.0-35-generic memtest86+.elf
efi memtest86+_multiboot.bin
grub System.map-5.19.0-35-generic
initrd.img vmlinuz
initrd.img-5.19.0-35-generic vmlinuz-5.19.0-35-generic
memtest86+.bin
我试过
awk
Command 'awk' not found, but can be installed with:
sudo apt install gawk # version 1:5.1.0-1build3, or
sudo apt install mawk # version 1.3.4.20200120-3.1
sudo apt install original-awk # version 2018-08-27-1
正如@Bodo 提到的
ya22y@IYB:~$ ls -l ../../usr/bin/awk
lrwxrwxrwx 1 root root 12 mars 6 23:17 ../../usr/bin/awk -> /usr/bin/awk
也尝试过
sudo sh -c 'awk'
sh: 1: awk: Too many levels of symbolic links
所以我决定换awk
到mawk
里面/usr/sbin/update-initramfs
#shellcheck disable=SC1004
#changing awk to mawk
boot_opts=$(mawk '/boot/{if ((match($4, /^ro/) || match($4, /,ro/)) \
&& $2 == "/boot") print "ro"}' /proc/mounts)
检查
ya22y@IYB:~$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-5.19.0-35-generic
ya22y@IYB:~$
现在我收到了另一个错误
sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up initramfs-tools (0.140ubuntu17) ...
update-initramfs: deferring update (trigger activated)
Setting up original-awk (2018-08-27-1) ...
update-alternatives: error: cannot stat file '/usr/bin/awk': Too many levels of
symbolic links
dpkg: error processing package original-awk (--configure):
installed original-awk package post-installation script subprocess returned err
or exit status 2
主要awk
是链接坏了,我该如何修复?
答案1
手动更改下面的文件/etc/alternatives/
将破坏 Ubuntu Alternatives 系统并导致错误...请参见例如:错误:无法统计文件‘/etc/alternatives/my.cnf’:参数无效
awk
Ubuntu 上安装的默认变体是mawk
...您应该能够正确地修复awk
下面的损坏/不可用的文件/链接/etc/alternatives/
,方法是先将其删除,如下所示:
sudo rm /etc/alternatives/awk
然后,以正确的方式重新创建它,如下所示:
sudo dpkg-reconfigure mawk
注意:如果gawk
您的系统上安装了,则它将优先,并且该链接应为:
$ ls -l /etc/alternatives/awk
lrwxrwxrwx 1 root root 13 Mar 17 11:44 /etc/alternatives/awk -> /usr/bin/gawk
或者,应为:
$ ls -l /etc/alternatives/awk
lrwxrwxrwx 1 root root 13 Mar 17 11:44 /etc/alternatives/awk -> /usr/bin/mawk
另请注意:这/usr/bin/awk
仅仅是由 Ubuntu Alternatives 系统管理的一个符号链接,它指向/etc/alternatives/awk
并应该是这样的:
$ ls -l /usr/bin/awk
lrwxrwxrwx 1 root root 21 Jan 8 2022 /usr/bin/awk -> /etc/alternatives/awk
因此,您也不应该手动更改那个,或者您需要先删除它们来修复它们,如下所示:
$ sudo rm /etc/alternatives/awk /usr/bin/awk
然后,以正确的方式重新创建它们,如下所示:
$ sudo dpkg-reconfigure mawk
之后,它们应该被修复并看起来像这样:
$ ls -l /etc/alternatives/awk /usr/bin/awk
lrwxrwxrwx 1 root root 13 Mar 17 14:02 /etc/alternatives/awk -> /usr/bin/gawk
lrwxrwxrwx 1 root root 21 Mar 17 14:02 /usr/bin/awk -> /etc/alternatives/awk
答案2
简单地删除断开的链接将解决问题。
ya22y@IYB:/usr/bin$ sudo rm awk
(编辑)
然后创建一个新链接
sudo ln -s /etc/alternatives/awk /usr/bin/awk