一、问题描述:
用户卸载了python3.6,电脑重启后,发现只能到命令行界面,图形化界面消失。
Ubuntu 18.04.6 LTS sh-OptiPlex-4080 tty1
sh-OptiPlex-4080 login: sh
Password:
/etc/update-motd.d/91-release-upgrade: 4: /etc/updatemotd.d/91-release-upgrade: lsb_release: not found
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-150-generic x86_64)
*Documentation:https://help.ubuntu.com
* Management:https://landscape.canonical.com
* Support:https://ubuntu.com/advantage
* Introducing Expanded Security Maintenance for Appliccations
Receive updates to over 25,000 software packageswith your
Ubuntu Pro subscription. Free for personal use.
https://ubuntu.com/pro
299 updates can be applied immediately.
273 of these updates are standard security updates
To see these additional updates run: apt list --uipgradable
sh@sh-OptiPlex-4080 :~$
二、问题分析:
Ubuntu 18.04 的图形化界面(通常是 GNOME 或 Unity)依赖 Python3 来运行一些关键组件。如果误删了 Python 3.6,系统可能就无法正常加载图形界面。
其次在处理问题过程中发现,包括网络服务也不可用,netplan都依赖python环境。
三、处理方法:
①、使用安装盘进入 Live 模式修复系统
- 插入安装盘或 U 盘,启动电脑时选择从安装盘启动。
- 在启动菜单中选择 “Try Ubuntu without installing”(试用 Ubuntu)。
- 进入 Live 系统后,打开终端,挂载你的原系统分区:
sudo mount /dev/sdXn /mnt
②、挂载必要的系统目录:
for dir in /dev /proc /sys /run; do sudo mount --bind $dir /mnt$dir; done
③、进入原系统环境:
sudo chroot /mnt
现在你就像是在原系统里操作,可以重新安装 Python、NetworkManager、ubuntu-desktop 、netplan.io等关键组件。
④、先检查网络是否畅通,可以ping 223.5.5.5试试,如果畅通,可以跳过设置临时IP这个操作,直接做重新安装的步骤
设置临时 IP 和路由
sudo ifconfig enp3s0 10.100.10.31 netmask 255.255.255.0
sudo ip route add default via 10.100.10.1
如果你用的是 ip
命令,也可以这样写:
sudo ip addr add 10.100.10.31/24 dev enp3s0
sudo ip link set enp3s0 up
sudo ip route add default via 10.100.10.1
即使你设置了 IP 和路由,如果没有 DNS,域名解析也会失败。你可以手动设置 DNS:
sudo nano /etc/resolv.conf
添加:
nameserver 223.5.5.5
nameserver 114.114.114.114
保存后尝试:
ping www.baidu.com
⑤、重新安装 Python3.6:
apt update
apt install python3.6
⑥、修复网络和图形界面:
apt install --reinstall network-manager ubuntu-desktop gdm3
apt install -y netplan.io
netplan apply
⑦、退出 chroot 并重启:
exit
sudo reboot