exec03_troubleshooting.txt

本文详细介绍Linux系统中常见的故障类型及解决方法,包括MBR丢失、超级块损坏、GRUB配置错误等问题,并提供实用的排错技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--




linux troubleshooting


linux rescue 进入后

如果正常情况下,会把你要修复的系统mount到/mnt/sysimage
chroot /mnt/sysimage 再去修改

有些情况下,没有mount到/mnt/sysimage
fdisk -l 查看所有分区
然后自己手动建立目录用来挂载排错
例mkdir /aaa
mount /dev/sda1 /aaa
在/aaa目录下排错就可以了




1,mbr 446(启动设备)+64(分区信息)+2(结束位)

mbr丢失,现象:启动时候黑屏,左上角一个光标在闪
如果没有备份,尝试使用挽救模式进入系统,然后grub-install

双系统的情况:正确的安装顺序为先安装windows,再安装linux,这样可以使用linux的grub程序去引导windows; 如果windows重装,也会出现上面的现象,尝试使用挽救模式进入系统,然后grub-install
如果安装的顺序为先安装linux,再安装windows,现象也一样,尝试使用挽救模式进入系统,修改grub,然后grub-install


2,superblock 超级块
superblock是记录innode节点和空闲磁盘空闲信息的

模拟superblock坏掉的情况:
dd if=/dev/zero of=/dev/sda13 bs=1 count=1024 seek=1024

[root@li ~]# mount -t ext3 /dev/sda13 /quota/
mount: wrong fs type, bad option, bad superblock on /dev/sda13,
missing codepage or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

[root@li ~]# dumpe2fs /dev/sda13
dumpe2fs 1.39 (29-May-2006)
dumpe2fs: Bad magic number in super-block while trying to open /dev/sda13
Couldn't find valid filesystem superblock.

使用e2fsck命令去修复
e2fsck - check a Linux ext2/ext3 file system

[root@li ~]# e2fsck /dev/sda13 --修复superblock损坏的磁盘




3,grub

grub文件丢失 ,现象就是启动系统时进入到 grub> 提示符界面

模拟grub文件不存在的情况
[root@li ~]# mv /boot/grub/grub.conf /boot/grub/grub.conf.bak --删除或者重命名来模拟grub文件丢失

重启系统,发现出现了grub > 提示符的界面,进不了系统

这时候可以手动在grub >提示符下编辑grub进入系统 (参考ule05.txt)


[root@li ~]# mv /boot/grub/grub.conf.bak /boot/grub/grub.conf --进入系统后没有grub就要手动编写,就OK


4,/etc/fstab

/etc/fstab内容错误:
模拟/etc/fstab错误,比如我这里把根的label故意写错
重启系统,在启服务的第三步左右,就会报错,进不了系统
此时输入root密码,回车进入(repair system)# 提示符界面
(repair system)# vim /etc/fstab --这样是不能修改的,是readonly的,强制写入也不行
(repair system)# mount -o remount,rw / --这样以读写的方式重mount你的根,再用vi修改/etc/fstab就可以进入系统了

/etc/fstab丢失:
模拟/etc/fstab丢失,
[root@li ~]# mv /etc/fstab /etc/fstab.bak
重启系统
进入系统后,问题很多
使用tty1-tty6终端去手动编写,或者使用linux rescue模式进入系统手动编写/etc/fstab

5,inittab
如果inittab定义的是启动5级别,但你的图形安装包并没有安装完全,就会在文本模式进不了图形,会报错

网络不通
mii-tool 查看网卡是否支持,link ok表示网线插好,no link表示网线没有插好,如果报
SIOCGMIIPHY on 'eth0' failed: Invalid argument
no MII interfaces found
之类的错误,那么就是系统不支持网卡,或者网卡模块丢失
/etc/sysconfig/network-scripts/ifcfg-eth0 查看此文件是否存在,里面的onboot=yes(不能等于no)

不能上网,route -n 查看路由和网关, cat /etc/resolv.conf查看DNS指向,能否ping通,还有就是iptables和selinux没有限制,firefox不是代理上网


6,服务
应用服务启动不了: 一般是配置文件写错,系统权限问题,iptables和selinux的限制问题,所有分区磁盘使用率满了
排错:看启服务时的报错,看相关服务的错误日志,或者/var/log/messages等日志
关闭iptables iptables -F
service iptables stop
chkconfig iptables off

关闭selinux vim /etc/selinux/config
SELINUX=disabled --把这一句改为disabled,再重启系统

7,密码
密码修改不了,看/etc/passwd和/etc/shadow文件的权限问题,lsattr /etc/shadow是否有隐藏属性(i属性)

破解root密码
1,单用户模式进入去修改 (进入单用户模式的方法为在grub里第二行,按e编辑,然后在后面加1 ,回车,按b启动)
2,如果grub加了密码,就不能用单用户模式,就要用linux resuce模式进入修改

8,包的安装,yum
rpm 安装是如果报错(不是依赖性),可能是包本身的问题,可能尝试--noscript等参数安装,但不保证功能的完整性

如果安装包并没有拷贝完全,报的错类似于
error: unpacking of archive failed on file /usr/lib/vmware/isoimages/linux.iso;4c2eb301: cpio: read
看到类似报错,就可以去用ll 查看包的大小


yum的错误:
一般是配置文件路径写错
或者就是iso没有拷贝完全
如果报key相关的错误,首先系统版本是否一致,尝试导入iso包里的key文件rpm --import RPM-GPG-KEY-redhat-release

如果刚安装好的系统,忘记安装你的中文包,配置好yum,然后使用system-config-packages调出图形安装包的界面(就是刚开始安装系统时选包的界面),去选择中文支持安装就可以了


图形界面
启动后,登录图形系统界面非常慢,很有可能是主机名造成的,把主机名三步给修改好,如果还是有问题,可以使用如下步骤
rm /root/.gnome -rf
rm /root/.gnome2 -rf
find /tmp -name "*root*" -exec rm {} -rf /;
reboot

主机名临时修改过,会造成开机时sendmail会等待很久

/etc/hosts里的IP与主机名对应不要写错,127.0.0.1那一行也不要删除

图形登录,报xsession持续10秒的情况,很可能是/etc/passwd的root用户那一行有问题


有规律的重启或者是做一些事情

有规律的重启,要注意是否在启动系统要读取的文件里加了重启的命令,比如/etc/rc.local加了/sbin/init 6等,还有要检查crontab

比如说在登录用户时,就会执行一些事情或者脚本,就应该要考虑全局的环境变量文件是否加了一些代码 /etc/profile /etc/bashrc

对于单独用户而言,那就要查看/home/用户名/.bash* 那几个文件



mount, nfs ,其他

mount命令如果不存在,文件几乎都不能保存

nfs umount时,如果等待时间比较长,一般是做过大量数据拷贝后,程序在sync
umount 不了 ,尝试fuser -k /mnt 去杀掉进程

/usr/src/kernels/`uname -r` 包含了内核的源码,所以不要删除,否则虚拟机安装不了,因为虚拟机要去这里找这里的文件去编译使用的模块

/lib/modules/`uname -r`不能删除,否则不能modprobe加载模块




排错系统的做法:

在kickstart的基础上做

vim ks.cfg 文件 ,在最后加上下面的脚本


%post
rm -rf /boot/grub/grub.conf
rm -rf /etc/fstab
chmod o-t /tmp
chmod 000 /
echo "/sbin/init 6" > /etc/rc.local
echo "/sbin/init 6" > /etc/profile
chattr +i /etc/passwd
chattr +i /etc/rc.local
mv /bin/mount /bin/mountbak
mv /usr/bin/yum /usr/bin/yumbak
rm -rf /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '/^root/s/bin/in/g' /etc/passwd


然后把相关的firewall 改为--enable
selinux 改为--enforcing
在安装包里不安装gnome桌面环境和x windows组


-------------------------------------------


附录:排错系统的ks.cfg文件的范例


#platform=x86, AMD64, 或 Intel EM64T
# System authorization information
auth --useshadow --enablemd5
key --skip
# System bootloader configuration
bootloader --append="rhgb quiet" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging --level=info
# Use NFS installation media
nfs --server=10.1.1.35 --dir=/yum
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$OSweU0dP$G44pQjHMuHcdhc8U5YAsQ1

# SELinux configuration
selinux --enforcing
# System timezone
timezone America/New_York
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig --defaultdesktop=GNOME --depth=16 --resolution=800x600 --startxonboot
# Disk partitioning information
part /boot --asprimary --bytes-per-inode=4096 --fstype="ext3" --size=100
part / --asprimary --bytes-per-inode=4096 --fstype="ext3" --size=10000
part swap --bytes-per-inode=4096 --fstype="swap" --size=1024

%packages
@development-libs
@development-tools
@system-tools
@mysql
@legacy-software-development
@gnome-software-development
@graphical-internet
@java
@dns-server
@office
@legacy-software-support
@java-development
@mail-server
@editors
@ftp-server



%post
rm -rf /boot/grub/grub.conf
rm -rf /etc/fstab
chmod o-t /tmp
chmod 000 /
echo "/sbin/init 6" > /etc/rc.local
echo "/sbin/init 6" > /etc/profile
chattr +i /etc/passwd
chattr +i /etc/rc.local
mv /bin/mount /bin/mountbak
mv /usr/bin/yum /usr/bin/yumbak
rm -rf /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '/^root/s/bin/in/g' /etc/passwd









IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.9 from "D:\anaconda3\envs\dl\python.exe" * The NumPy version is: "1.23.5" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。 (Triggered internally at C:\cb\pytorch_1000000000000\work\torch\csrc\utils\tensor_numpy.cpp:84.) cpu = _conversion_method_template(device=torch.device("cpu")) Traceback (most recent call last): File "D:\anaconda3\envs\dl\lib\site-packages\numpy\_core\__init__.py", line 23, in <module> from . import multiarray File "D:\anaconda3\envs\dl\lib\site-packages\numpy\_core\multiarray.py", line 10, in <module> from . import overrides File "D:\anaconda3\envs\dl\lib\site-packages\numpy\_core\overrides.py", line 8, in <module> from numpy._core._multiarray_umath import ( ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\anaconda3\envs\dl\lib\site-packages\numpy\_core\__init__.py", line 49, in <module> raise ImportError(msg) ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.9 from "D:\anaconda3\envs\dl\python.exe" * The NumPy version is: "1.23.5" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。 Traceback (most recent call last): File "F:\24849\Documents\Smart_Construction-master\Smart_Construction-master\visual_interface.py", line 38, in <module> from detect_visual import YOLOPredict File "F:\24849\Documents\Smart_Construction-master\Smart_Construction-master\detect_visual.py", line 13, in <module> from models.experimental import * File "F:\24849\Documents\Smart_Construction-master\Smart_Construction-master\models\experimental.py", line 3, in <module> from models.common import * File "F:\24849\Documents\Smart_Construction-master\Smart_Construction-master\models\common.py", line 3, in <module> from utils.utils import * File "F:\24849\Documents\Smart_Construction-master\Smart_Construction-master\utils\utils.py", line 13, in <module> import cv2 File "D:\anaconda3\envs\dl\lib\site-packages\cv2\__init__.py", line 181, in <module> bootstrap() File "D:\anaconda3\envs\dl\lib\site-packages\cv2\__init__.py", line 153, in bootstrap native_module = importlib.import_module("cv2") File "D:\anaconda3\envs\dl\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: numpy._core.multiarray failed to import
06-04
<think>我们正在处理用户关于Python中在`__init__`方法内调用`create_troubleshooting_dock`函数的问题。用户希望了解实现方法或可能遇到的问题。根据提供的引用,虽然引用内容与Linux内核初始化、U-Boot初始化以及Eigen库的错误信息相关,但并没有直接关于Python中`__init__`方法调用特定函数的信息。因此,我们需要基于一般Python编程知识来回答。在Python中,`__init__`方法是类的构造函数,在创建类的新实例时自动调用。在`__init__`中调用其他函数(如`create_troubleshooting_dock`)是常见的做法,用于初始化对象的状态或执行必要的设置。可能的问题包括:1.函数未定义:在调用`create_troubleshooting_dock`之前,必须确保该函数在作用域内(例如,它是类的方法、全局函数或已导入)。2.循环依赖:如果两个类的`__init__`方法相互调用,可能导致循环初始化问题。3.异常处理:在`__init__`中调用的函数可能抛出异常,需要适当处理,否则实例创建会失败。4.性能问题:如果`create_troubleshooting_dock`执行耗时操作,可能影响实例化速度。下面是一个示例实现:```pythonclassMyApplication:def__init__(self):#初始化其他属性self.initialized=False#调用创建故障排除窗口的函数self.create_troubleshooting_dock()self.initialized=Truedefcreate_troubleshooting_dock(self):#实现创建故障排除窗口的逻辑print("创建故障排除窗口...")#例如,这里可能包含创建GUI元素的代码```在这个例子中,`create_troubleshooting_dock`是类的一个方法,在`__init__`中调用。如果`create_troubleshooting_dock`是外部函数,可以这样写:```pythondefcreate_troubleshooting_dock():print("创建故障排除窗口...")classMyApplication:def__init__(self):create_troubleshooting_dock()#调用全局函数#其他初始化代码```注意事项:-确保函数在调用前已定义(在同一个文件中,或正确导入)。-如果函数依赖于尚未初始化的对象状态,可能导致错误。因此,注意调用顺序。如果用户遇到特定问题,需要更具体的错误信息或上下文。§§相关问题§§1.在Python的`__init__`方法中调用函数有哪些最佳实践?2.如何处理`__init__`方法中可能出现的异常?3.如何避免在`__init__`方法中执行耗时操作?</think>在 Python 的 `__init__` 方法中调用 `create_troubleshooting_dock` 函数是一种常见的对象初始化模式,主要用于在对象创建时执行特定的初始化逻辑(如创建 GUI 组件、配置调试工具等)。以下是实现方法和潜在问题的分析: ### 实现方法 ```python class Application: def __init__(self): # 初始化其他属性 self.config = load_config() # 调用故障排查窗口创建函数 self.create_troubleshooting_dock() # 关键调用点 def create_troubleshooting_dock(self): """创建并配置故障排查面板""" self.dock = QDockWidget("诊断工具", parent=self) self.log_viewer = QTextEdit() self.dock.setWidget(self.log_viewer) # 添加更多GUI配置... print("故障排查面板初始化完成") ``` ### 关键注意事项 1. **调用顺序问题** 需确保在调用 `create_troubleshooting_dock()` 前完成所有必要依赖项的初始化(如 `self.config`)。错误的顺序可能导致: ```python AttributeError: 'Application' object has no attribute 'config' ``` 2. **循环依赖风险** 若 `create_troubleshooting_dock()` 内部又尝试访问 `__init__` 中未初始化的属性,会引发递归错误: ```python RecursionError: maximum recursion depth exceeded ``` 3. **GUI框架的特殊性**(如 PyQt) 在 GUI 应用中,若在 `__init__` 中过早创建窗口组件: ```python def create_troubleshooting_dock(self): # 错误示例:未传入有效的父组件 self.dock = QDockWidget() # 可能导致窗口层级错乱 ``` 需显式指定 `parent` 参数确保组件归属正确[^2]。 4. **异常处理** 建议添加异常捕获防止初始化失败: ```python def __init__(self): try: self.create_troubleshooting_dock() except Exception as e: print(f"初始化失败: {str(e)}") # 回滚或降级处理 ``` ### 典型应用场景 1. **诊断工具集成**:为应用程序自动生成调试面板 2. **插件系统初始化**:动态加载扩展功能组件 3. **资源预加载**:提前创建耗时资源(如数据库连接池) > 实践建议:对于复杂初始化,可将 `create_troubleshooting_dock` 拆分为多阶段方法(如 `_setup_ui()`,`_connect_signals()`),通过 `__init__` 按序调用以提升可维护性[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值