为什么 apt 会输出“警告:以下必需软件包将被删除。”并在清除软件包时提示我输入完整短语?

为什么 apt 会输出“警告:以下必需软件包将被删除。”并在清除软件包时提示我输入完整短语?

不要尝试这个命令。

当我尝试清除包时login,包管理器要求我输入整个文本而不是[Y/n]

avinash@avinash-VirtualBox:~$ sudo apt-get purge login
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  login*
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  login
0 upgraded, 0 newly installed, 1 to remove and 303 not upgraded.
After this operation, 1,212 kB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
 ?] 

为什么提示我输入整个文本?如果我输入或Yes, do as I say!会发生什么?YYes

答案1

login软件包由诸如loginnewgrp和之类的程序组成su。这些程序也称为系统登录工具。这些工具是登录和使用系统所必需的。

  • 登录程序调用您的用户 shell 并允许命令执行。

  • newgrp 程序用于更改您的有效组 ID(适用于工作组类型的情况)。

  • su 程序允许改变您的有效用户 ID(有助于以另一个用户的身份执行命令)。

这是一个必不可少的系统包。因此警告消息 (除非您清楚自己在做什么,否则不应这样做!) 出现如下提示并要求您输入整个短语Yes, do as I say!,同时尝试清除包login

This should NOT be done unless you know exactly what you are doing!
      login
0 upgraded, 0 newly installed, 1 to remove and 303 not upgraded.
After this operation, 1,212 kB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
?] 

Y如果我输入或会发生什么Yes

您必须输入正确的短语Yes, do as I say!,这样包login才会被删除。如果您输入YYes,它将中止清除包的过程。即使是感叹号、空格、大小写字母也会被严格考虑。

Yes  -  Abort
Yes, do as I say  -  Abort
yes, do as I say  -  Abort
Yes,do as I say!  -  Abort
Yes, do as I say! -  Success

成功输入短语后,dpkg删除login启用强制选项的包,

To continue type in the phrase 'Yes, do as I say!'
 ?] Yes, do as I say!
dpkg: warning: overriding problem because --force enabled:
 This is an essential package - it should not be removed.
(Reading database ... 162860 files and directories currently installed.)
Removing login ...
Purging configuration files for login ...
Processing triggers for man-db ...

恭喜,现在您无法再登录系统。

答案2

线索就在提示中

下列基本的软件包将被删除

apt对那些被认为非常重要的软件包进行了特殊分类,如果没有它们,你的系统就会崩溃。删除它们,但apt要再三确认你事后不会责怪它。

您可以看到已安装的基本软件包,aptitude search '~E~i'目前(在 13.10 机器上)提供以下软件包:

apt base-files base-passwd bash bsdutils coreutils dash debianutils diffutils dpkg e2fsprogs findutils grep gzip hostname libc-bin login mount ncurses-base ncurses-bin perl-base sed tar util-linux

我很好奇这些命令可能包括什么(我知道coreutils它们相当庞大),所以构建了以下怪物查询 for f in $(aptitude search '~E~i' | awk '{print $2}' | xargs dpkg -L); do [[ $(type -P "${f##*/}") == "$f" ]] && echo ${f##*/}; done

[ addpart add-shell agetty apt-cache apt-cdrom apt-config apt-get apt-key apt-mark arch badblocks base64 basename bash bashbug blkid blockdev captoinfo cat catchsegv cfdisk chattr chcon chgrp chkdupexe chmod chown chroot chrt cksum clear clear_console cmp comm cp csplit ctrlaltdel cut cytune dash date dd ddate debugfs delpart df diff diff3 dir dircolors dirname dmesg dnsdomainname domainname dpkg dpkg-deb dpkg-divert dpkg-maintscript-helper dpkg-query dpkg-split dpkg-statoverride dpkg-trigger du dumpe2fs e2freefrag e2fsck e2image e2label e2undo e4defrag echo egrep env expand expr factor faillog fallocate false fdformat fdisk fgrep filefrag find findfs findmnt flock fmt fold fsck fsck.cramfs fsck.ext2 fsck.ext3 fsck.ext4 fsck.ext4dev fsck.minix fsfreeze fstrim getconf getent getopt getty grep groups gunzip gzexe gzip head hostid hostname hwclock i386 iconv iconvconfig id infocmp infotocap install install-info installkernel ionice ipcmk ipcrm ipcs ischroot isosize join lastlog ldattach ldconfig ldconfig.real ldd line link linux32 linux64 ln locale localedef logger login logname logsave losetup ls lsattr lsblk lscpu mcookie md5sum md5sum.textutils mkdir mke2fs mkfifo mkfs mkfs.bfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.ext4dev mkfs.minix mklost+found mknod mkswap mktemp more mount mv namei ncurses5-config ncursesw5-config newgrp nice nisdomainname nl nohup nologin nproc od oldfind partx paste pathchk perl perl5.14.2 pg pinky pivot_root pldd pr printenv printf ptx pwd raw rbash readlink readprofile remove-shell rename.ul renice reset resize2fs resizepart rev rgrep rm rmdir rmt-tar rtcwake runcon run-parts savelog script scriptreplay sdiff sed seq setarch setsid setterm sfdisk sg sh sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf sleep sort split start-stop-daemon stat stdbuf stty su sum swaplabel swapoff swapon switch_root sync tabs tac tail tailf tar tarcat taskset tee tempfile test tic timeout toe touch tput tr true truncate tset tsort tty tune2fs tunelp tzselect umount uname uncompress unexpand uniq unlink unshare update-alternatives update-locale update-passwd users validlocale vdir wall wc whereis which who whoami wipefs x86_64 xargs yes ypdomainname zcat zcmp zdiff zdump zegrep zfgrep zforce zgrep zic zless zmore znew

答案3

软件包有几个字段,里面填满了信息,其中一个字段说明了软件包的重要性,称为priority。软件包有两个优先级,如果没有它们,系统就无法正常运行,它们是essentialrequired

这些软件包默认安装在所有 Ubuntu/Debian 安装中。每当你尝试删除它们时,安装程​​序都会要求你明确说明你确定,这样您就了解自己行为的后果。因此,如果您继续删除,则很有可能系统某些部分会彻底损坏,您无法再启动。


要获取具有这些优先级的软件包列表,我建议使用 aptitude:

aptitude search ~prequired
aptitude search ~pimportant

或者,如果您喜欢 synaptic,您应该选择显示包优先级。

答案4

删除login会导致您无法正常登录,因此请不要删除此软件包。相反,查看/var/log/apt/history.log您安装和删除了哪些软件包导致了这种情况,并小心地撤消每个操作。“小心”是指使用--simulate不带选项sudo测试 apt 或 apt-get 命令,而不会对系统进行任何实际更改。

例如,不要运行此命令:

sudo apt remove package1 package2 package3 

sudo像这样模拟上面的命令:

删除- 模拟软件包1 软件包2 软件包3

您还可以使用该--simulate选项模拟安装和删除手动下载的 .deb 软件包。要模拟安装名为文件.deb将目录更改为cd包含 FILE.deb 的目录并运行以下命令:

apt install --simulate ./FILE.deb

如果安装 FILE.deb 所需的任何未满足的依赖项,上述命令将列出它们。

相关内容