Tips to effectively deal with Linux kernel panic
Thanks to netizen 墢一雨音 for the contribution
There is a reason for writing this article. In order to configure a completely silent boot, I performed improper mkinitcpio operations on Linux running on my work computer because I ignored a logic error in the mkinitcpio.conf file. This causes mkinitcpio to produce a new kernel file, but this kernel file does not work properly. When restarting, the kernel startup aborts in the Panic state.
Generally, when the new kernel does not work properly, you can temporarily start the system by using the fallback version of the initramfs kernel file, or even directly overwrite the fallback version to roll back the changes, but this time, mkinitcpio is running at the same time The vmlinuz kernel file has been modified, and vmlinuz does not have a fallback version. For ordinary users, they can directly reinstall the system; however, the author's workstation environment configuration is quite complicated, which means that in addition to the possible loss of my working files, I also need to spend a lot of extra time to reconfigure the development environment.
Note: The "repair" of this tutorial refers to "attempting to roll back devastating human changes", so it cannot be used to recover from unknown kernel crashes.
1. Boot from LiveCD and view the disk
Based on the experience accumulated during my part-time Linux server operation and maintenance period, I immediately thought that I could use LiveCD to boot to obtain a temporary Linux environment for repairing the kernel.
The author is using the 64-bit version of Arch Linux, so I booted from the LiveCD of Arch Linux. After correctly entering the built-in root user of LiveCD, we need to check the device name of our main hard disk. Execute fdisk -l. In my case, the device file corresponding to my main hard disk and the partition mounted to the root directory is /dev/sdb2.
2. chroot to the system root directory on the hard disk
To chroot to the system root directory on the hard disk and be able to normally call the system components on the hard disk to make changes to the system on the hard disk, we must first manually mount the root partition on the hard disk. Execute (my device file is /dev/sdb2):
mount /dev/sdb2 /mnt
Don’t rush yet. At this time, although you can enter the bash of the main system on the hard disk by chrooting to /mnt, you can hardly complete any complex tasks correctly because there are still some important directories that are not mounted. We execute the instructions to mount the proc directory, /sys directory, /dev directory and /run directory respectively. Enter /mnt and execute respectively:
mount -t proc proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/
mount --rbind /run run/
The functions of these directories are:
proc directory: Virtual, Procfs format file system, used to store process status files (under Linux, these files appear to be text files on the surface, but are actually file mappings of the process status) );
/sys directory: For Arch Linux, this is a virtual file system in Sysfs format similar to the proc directory, used to store device files connected to the system; for traditional Unix and Unix-like, it Is a soft link pointing to the kernel code tree;
/dev directory: stores device files, for example, your hard disk is /dev/sdXY;
/run directory: stores part of the system information after the latest startup;
After mounting these things, we can chroot to the root directory of our main hard disk:
chroot /mnt
Regret medicine. For me, I only needed to modify the mkinitcpio.conf file and re-execute the mkinitcpio operation to regenerate the correct kernel file. Generally, if the kernel panic is caused by incorrectly modifying the configuration, this environment can solve most problems.
3. Some skills
1. Many configuration files have correct versions or templates for the system in the LiveCD. If you don’t remember what they look like normally, you can refer to them;
2. For Arch Linux, you can directly use the pacstrap command to manage software packages on the /mnt mount point without chrooting to /mnt;
3. It can be operated under two ttys, so that after chrooting to /mnt, files can still be transferred from the LiveCD file system to /mnt.
This tutorial should be available for most Linux distributions, and I hope it will be helpful to some Linux users.
related suggestion:
How to configure dual graphics cards in Linux system?
The above is the detailed content of Tips to effectively deal with Linux kernel panic. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)
