CentOS7恢复模式下FTP/SSH启动及内核修复求助(yum更新故障)
Alright, let's work through this problem step by step—you've got a CentOS 7 server stuck in kernel panic after a botched yum update, can only get into recovery mode, yum is broken (missing yummain), and FTP isn't working to export files. Let's cover how to get remote access up first, then fix either yum or the kernel directly.
1. Enable SSH in Recovery Mode (More Reliable Than FTP)
SSH is way easier for file transfers and remote troubleshooting than FTP. Here's how to fire it up:
- When you boot into Recovery Mode, select Rescue a CentOS system and follow the prompts to mount your root filesystem to
/mnt/sysimage(usually option 1: "Continue"). - Switch to the root environment of your installed system:
chroot /mnt/sysimage - By default, SSH might block root login or be stopped. Fix that:
- Edit the SSH config file:
vi /etc/ssh/sshd_config - Find the line starting with
PermitRootLoginand change it toPermitRootLogin yes(you can revert this later for security). - Start the SSH service:
systemctl start sshd
- Edit the SSH config file:
- Check your server's IP address with
ip addr, then you can SSH in from another machine to transfer files or run commands remotely.
2. Fix the Broken Yum (To Repair the Kernel)
The "missing yummain" error means core yum packages are corrupted. Let's reinstall them manually:
- First, mount your CentOS 7 installation media (ISO or physical CD/DVD) in VMware, then mount it in recovery mode:
- List block devices to find the optical drive:
lsblk(look forsr0usually) - Create a mount point:
mkdir /mnt/cdrom - Mount the drive:
mount /dev/sr0 /mnt/cdrom
- List block devices to find the optical drive:
- Reinstall the core yum packages from the installation media:
rpm -ivh --force /mnt/cdrom/Packages/yum-*.rpm /mnt/cdrom/Packages/yum-metadata-parser-*.rpm /mnt/cdrom/Packages/yum-plugin-fastestmirror-*.rpm - Test if yum works now:
yum clean all && yum update—if it runs without errors, you're good to go.
3. Fix the Kernel Panic Issue
Once yum is working, you can reinstall the kernel to fix the panic:
- List all installed kernels to see what's available:
rpm -qa | grep kernel - Install the latest stable kernel:
yum install kernel - Update GRUB to set the new kernel as the default boot option:
(You can verify the default withgrub2-mkconfig -o /boot/grub2/grub.cfg grub2-set-default 0grub2-editenv list—0is usually the newest kernel.) - Exit the chroot environment with
exit, then reboot the server:reboot—it should boot normally now.
If Yum Can't Be Fixed: Manual Kernel Installation
If yum is beyond repair, grab a kernel RPM from another CentOS 7 machine and transfer it via SSH:
- On a working CentOS 7 box, download the matching kernel RPM (replace the version with your system's compatible one):
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/kernel-3.10.0-1160.el7.x86_64.rpm - SCP it to your recovery mode server:
scp kernel-3.10.0-1160.el7.x86_64.rpm root@your-server-ip:/root/ - Back in the chroot environment on your broken server, install the kernel:
rpm -ivh /root/kernel-3.10.0-1160.el7.x86_64.rpm - Update GRUB as shown earlier and reboot.
Backup Files Without FTP/SSH
If you can't get remote access working, use a USB drive to export files:
- Add a USB device to your VMware virtual machine.
- In recovery mode, find the USB device with
lsblk(look forsdb1or similar). - Mount it:
mkdir /mnt/usb mount /dev/sdb1 /mnt/usb - Copy your files to the USB drive:
cp -r /path/to/important/files /mnt/usb/ - Unmount safely before removing:
umount /mnt/usb
内容的提问来源于stack exchange,提问作者Alex

