Fedora40使用Timeshift恢复数据后无法启动(解决办法)

在Fedora40上安装TimeShift后,可以保存多个系统数据备份快照,但有时候恢复快照后,会发生系统无法启动,系统停留在如下界面:

此时有系统图形界面,说明系统的GRUB引导区和/boot/efi分区是正常的。

这时按键盘 Esc键,应该可以看到如下错误:

js 复制代码
systemd[1]: Unable to fix SELinux security context of /dev/usbmon3: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/bus/usb/001/001: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/bus/usb/001/002: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/bus/usb/001/003: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/bus/usb/001/004: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/input/mice: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/input/event0: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/input/event1: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/input/event2: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/input/event3: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/input/event4: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/rtc0: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda1: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda2: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda3: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda4: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda5: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda6: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda7: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda8: Permission denied
systemd[1]: Unable to fix SELinux security context of /dev/sda9: Permission denied

出错原因

SELinux(Security-Enhanced Linux)是 Linux 的一个安全模块,用于强制实施访问控制安全策略。它由美国国家安全局(NSA)开发,最早于 2000 年作为 Linux 的扩展发布,其主要目标是通过使用强制访问控制(MAC)模型来增强 Linux 系统的安全性。SELinux 于 2003 年合并到 Linux 内核主线,并成为 Fedora、Red Hat Enterprise Linux 等发行版的重要组成部分。

出现SELinux的错误,是因为安装了一些Flathub软件,或者其他的一些软件,在Timeshift恢复数据过程中,这些软件没有被正确标记SELinux 标签和安全上下文导致的。

解决办法

现在强制关机,重启电脑后进入如下界面:选择第一行,按 E 键进行编辑

进入编辑界面

在第四行,以linux开头的一行的末尾,增加 selinux=0 ,然后按 Ctrl+X 键重新启动系统。

selinux=0可以让系统以无视SELinux安全上下文的方式启动,然后我们手工重新标记SELinux标签即可。

如何系统没有正常启动,请看本篇结尾的《方法二启动》

现在系统可以正常启动了。但此时系统是忽视SELinux的系统,有安全隐患

登陆系统后,然后打开一个终端,输入如下命令:

js 复制代码
# 打开目录
cd /etc/selinux/
ls
# 临时修改SELinux的配置文件
sudo nano config
js 复制代码
原来的
SELINUX=enforcing
修改为
SELINUX=permissive

Ctrl + X 保存退出

下边命令会重新触发 SELinux (Security-Enhanced Linux)的文件系统重新标记操作

js 复制代码
# 运行后,系统下次重启之前,会重新标记所有文件 (本条命令运行很快,下次重启后触发)
sudo touch /.autorelabel

# 重启系统
sudo reboot

正常启动系统,会进入这个界面,等待大概5分钟,不要做任何操作,此时系统正在进行重新标记操作

完成后,系统可以正常登陆了

登陆系统,打开一个命令终端,恢复SELinux的默认配置文件

js 复制代码
sudo nano /etc/selinux/config
js 复制代码
# 恢复默认配置
SELINUX=enforcing

以上操作完毕后,系统可以正常登陆使用。

如果在上边的操作中,使用增加selinux=0 后,依然无法进入系统,请使用下边方式恢复。

方法二启动

使用LiveCD进入系统 在系统启动时,按Fn + F12 (联系小新电脑),选择U盘启动

启动后界面如下:

此时电脑上除了LiveCD移动盘外,不要插入其他U盘,修改livecd路径

js 复制代码
# 中间行的部分代码修改为:修改后如下图所示
... root=live:/dev/sdb4 rd.live ...

Ctrl + X ,登陆系统

打开一个终端,挂载原系统盘和各个分区:

js 复制代码
# 挂载系统盘后,一会通过`chroot` 环境进入出问题的系统
sudo mkdir /mnt/fedora
sudo mount /dev/sda9 /mnt/fedora
sudo mount /dev/sda2 /mnt/fedora/boot
sudo mount /dev/sda1 /mnt/fedora/boot/efi

# 我的系统var,home也做了单独分区,也挂载上
sudo mount /dev/sda4 /mnt/fedora/var
sudo mount /dev/sda5 /mnt/fedora/home

为让`chroot` 环境运行得像一个正常的环境,你需要挂载一些额外的虚拟文件系统:
sudo mount --bind /dev /mnt/fedora/dev 
sudo mount --bind /proc /mnt/fedora/proc 
sudo mount --bind /sys /mnt/fedora/sys 
sudo mount --bind /run /mnt/fedora/run

进入原系统:

js 复制代码
# 进入待修改的系统, chroot环境是已损坏的Fedora40系统
sudo chroot /mnt/fedora
    
# 临时修改SELinux默认配置 ,本命令不要加 `sudo`
nano /etc/selinux/config
 
# 把原来的
SELINUX=enforcing

# 修改为
SELINUX=permissive

Ctrl + X 保存退出

下边命令会重新触发 SELinux (Security-Enhanced Linux)的文件系统重新标记操作

js 复制代码
# 运行后,系统下次重启之前,会重新标记所有文件 (本条命令运行很快,下次重启后触发)
touch /.autorelabel

# 重启系统
reboot

请无视下边图片上的 sudo

正常启动系统,会进入这个界面,等待大概5分钟,不要做任何操作,此时系统正在进行重新标记操作

完成后,系统可以正常登陆了

登陆系统,打开一个命令终端,恢复SELinux的默认配置文件

js 复制代码
sudo nano /etc/selinux/config
js 复制代码
# 恢复默认配置
SELINUX=enforcing

以上操作完毕后,系统可以正常登陆使用了

友情赞助

大家如果有空闲,帮忙试用下,国货抖音出品的AI编程代码插件,比比看GitHub Copilot那个好**^-^**

(适用JetBrains全家桶系列、Visual Studio家族IDE工具安装等主流IDE工具,支持100+种编程语言)
帮忙去助力>>

timeshift使用

如果恢复数据过大,系统操作时间太长,需要禁用Fedora40的自动锁屏功能

否则会出现异常

相关推荐
it技术分享just_free7 分钟前
基于Jenkins+K8S构建DevOps自动化运维管理平台
linux·运维·容器·kubernetes·k8s·jenkins·devops
爱吃涮毛肚的肥肥(暂时吃不了版)14 分钟前
Linux高阶——0928—Github数据上传&markdown语言
linux·git·github
码农中的小白17 分钟前
鸿蒙OS启动流程
linux·华为·harmonyos·鸿蒙系统
肖爱Kun1 小时前
prctl的函数和pthread_self函数
linux
reverie.Ly1 小时前
从0开始linux(12)——命令行参数与环境变量
android·linux·c++
L-李俊漩1 小时前
%pip和!pip的区别
linux·python·pip
黄毛火烧雪下1 小时前
TypeScript - type
linux·ubuntu·typescript
王木木很酷_3 小时前
【Linux】基本认知全套入门
linux·运维·服务器
滴滴哒哒答答7 小时前
ubuntu双系统分区划分
linux·运维·ubuntu
qq_427506088 小时前
linux和windows系统使用k8s控制节点的kubernetes资源
linux·运维·kubernetes