A method for supporting hot plug of a system disk for a LINUX kernel operating system
By checking and synchronizing device IDs in the Linux kernel, the crash problem of the Linux operating system during hot-swapping of the system disk was resolved, achieving stable system operation and data protection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHENGSHU NETWORK TECH CO LTD
- Filing Date
- 2022-12-19
- Publication Date
- 2026-05-08
AI Technical Summary
Operating systems based on the Linux kernel are prone to crashing during hot-swapping of the system disk, leading to system data corruption and boot failure.
By checking the consistency between the removable storage device and the system disk in the kernel, matching whether the unmounted device is consistent with the system disk, comparing the device ID after insertion, and activating the kernel thread after data write-back synchronization, the system is ensured to recover.
It enables hot-swapping of the system disk without restarting the system, preventing data loss and system crashes, and supports stable operation of various Linux desktop operating systems.
Smart Images

Figure CN116028411B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of operating system technology, and in particular relates to a method for supporting hot-swapping of system disks in a LINUX kernel operating system. Background Technology
[0002] Currently, Linux-based desktop systems are gaining increasing popularity among users. The use of removable storage devices as system disks to install operating systems, facilitating convenient portability for customized or secure systems, is also driving users to transition from Windows to Linux. In practical use, Windows 10 allows hot-unmounting of the system disk during operation; after unmounting, the system may freeze, but re-inserting the system disk restores normal operation without data loss. However, with Linux-based operating systems, complete system crashes and data corruption on the system disk can occur, preventing the system from booting successfully even after a restart.
[0003] Operating systems based on the Linux kernel cannot perform hot-swapping of the system disk during use, thus making it impossible to run securely, stably, and conveniently in scenarios where a removable storage device is used as the system disk. Summary of the Invention
[0004] To address the shortcomings of existing technologies, the purpose of this invention is to provide a method for hot-swapping system disks in a Linux kernel operating system. After hot-swapping the system disk, reinserting the removed system disk ensures that the system can continue to function normally without restarting, while the data on the system disk and other mounted disks will not be damaged or lost.
[0005] This invention provides the following technical solution:
[0006] A method for supporting hot-swapping of the system disk in a Linux kernel operating system includes the following steps:
[0007] a. Check the consistency between the removable storage device and the system disk. When the removable storage device is unloaded, check whether the unloaded device is consistent with the system disk.
[0008] b. If the unloaded removable storage device is the same as the system disk, the superblock will not be released, and all running kernel threads will be suspended, waiting for the device to be inserted. If the unloaded removable storage device is different from the system disk, it will be processed according to the normal procedure.
[0009] c. After the removable storage device is inserted, when the mounting is complete and automatic mounting begins, identify the device ID of the mounted device and compare it with the system disk ID;
[0010] d. If the ID of the mounted device matches the ID of the system disk, the device is mapped to the superblock of the original system disk. After the data write-back and synchronization are completed, all threads in the kernel are activated to complete system recovery. If the ID of the mounted device does not match the ID of the system disk, the normal process is followed.
[0011] Preferably, when the system starts, the init thread starts and reads the / etc / fstab file. After the mount is completed, it reads the / etc / fstab file again, finds the UUID or label value corresponding to the root directory, polls the superblock list, finds the superblock that matches the UUID or label value, and records the superblock object pointer and UUID or label value in a global variable object.
[0012] Preferably, in the kernel umount function, the ID of the device to be unmounted is compared to prevent the kernel from unmounting the system disk and releasing the superblock. At the same time, the kernel thread is suspended to ensure that data is not written to the system disk and to prevent a large number of I / O read and write errors.
[0013] Preferably, the nameidate value is obtained by name, and the device's UUID or label value is obtained by the nameidate value. This value is then compared with the system disk ID value in the global variable table.
[0014] Preferably, in the kernel do_mount function, the ID number of the device to be mounted is compared. If the system disk is reinserted, the mapping relationship between the superblock and the device is restored directly, and a data write-back is performed to prevent data loss. After that, all suspended kernel threads are started to restore the system running state.
[0015] Preferably, in the kernel do_mount function, the path value is obtained through dir_name, and after obtaining the nameidate through the nameidate value, the UUID or label value of the device is obtained through the nameidate value, and the value is compared with the system disk ID value in the global variable table.
[0016] Preferably, while restoring the system's running state, the frozen parameters in the global variable table are set to 0.
[0017] Compared with the prior art, the present invention has the following beneficial effects:
[0018] (1) The present invention provides a method for hot-plugging system disks in the LINUX kernel operating system. In the kernel do_mount function, the ID number of the device to be mounted is compared. If the system disk is reinserted, the mapping relationship between the superblock and the device is restored directly, and a data write-back is completed to prevent data loss. Then, all suspended kernel threads are started to restore the system running state.
[0019] (2) The present invention provides a method for hot-plugging the system disk in the LINUX kernel operating system. After the init thread reads the / etc / fstab file and completes the mounting, it rereads the / etc / fstab file and writes the uuid or label value corresponding to the system disk. In the kernel umount function, the ID number of the device to be unmounted is compared to prevent the kernel from unmounting the system disk and releasing the superblock. At the same time, the kernel thread is suspended to ensure that data is no longer written to the system disk and to prevent a large number of I / O read and write errors.
[0020] (3) The present invention provides a method for hot-plugging system disks in LINUX kernel operating systems. By adapting to different kernel versions, the source code is patched into the kernel code. After the kernel is compiled, the kernel can be used to support various desktop operating systems based on Linux.
[0021] (4) The present invention provides a method for hot-swapping system disks in a LINUX kernel operating system. It does not require any modification to the desktop system layer or user layer data, and does not require the user to configure the system. The hot-swapping function of the system disk can be completed seamlessly. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained from these drawings without creative effort.
[0023] Figure 1 This is a flowchart of the system startup process of the present invention.
[0024] Figure 2 This is a flowchart of the process of removing the storage disk according to the present invention.
[0025] Figure 3 This is a flowchart of the process of inserting the storage disk according to the present invention. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0027] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0028] Example 1:
[0029] like Figure 1-3 As shown, a method for supporting hot-swapping of the system disk in a Linux kernel operating system includes the following steps:
[0030] a. Check the consistency between the removable storage device and the system disk. When the removable storage device is unloaded, check whether the unloaded device is consistent with the system disk.
[0031] b. If the unloaded removable storage device is the same as the system disk, the superblock will not be released, and all running kernel threads will be suspended, waiting for the device to be inserted. If the unloaded removable storage device is different from the system disk, it will be processed according to the normal procedure.
[0032] c. After the removable storage device is inserted, when the mounting is complete and automatic mounting begins, identify the device ID of the mounted device and compare it with the system disk ID;
[0033] d. If the ID of the mounted device matches the ID of the system disk, the device is mapped to the superblock of the original system disk. After the data write-back and synchronization are completed, all threads in the kernel are activated to complete system recovery. If the ID of the mounted device does not match the ID of the system disk, the normal process is followed.
[0034] During system startup, the init thread starts and reads the ` / etc / fstab` file. After mounting, it rereads ` / etc / fstab` to find the UUID or label value corresponding to the root directory. It then polls the superblock list to find the superblock that matches the UUID or label value and records the superblock object pointer and its UUID or label value in a global variable object. In the kernel's `umount` function, the device to be unmounted is compared with its ID to prevent the kernel from unmounting the system disk and releasing the superblock. Simultaneously, kernel threads are suspended to ensure that data is not written to the system disk, preventing a large number of I / O read / write errors. The `nameidate` value is obtained through `name`, and the device's UUID or label value is obtained through `nameidate`. This value is then compared with the system disk ID value in the global variable table.
[0035] In the kernel's `do_mount` function, the ID number of the device to be mounted is compared. If the system disk is reinserted, the mapping relationship between the superblock and the device is restored directly, and a data write-back is performed to prevent data loss. After that, all suspended kernel threads are started to restore the system's running state. At the same time, the frozen parameters in the global variable table are set to 0.
[0036] In the kernel's `do_mount` function, the path value is obtained through `dir_name`, and then the nameidate is obtained through that value. The UUID or label value of the device is then obtained through the nameidate value, and this value is compared with the system disk ID value in the global variable table.
[0037] Example 2
[0038] During disk unloading, the system checks if the unloading device matches the system disk. If they match, the superblock is not released, and all kernel threads are suspended, waiting for the device to be inserted. After the device is inserted, when mounting is complete and automatic mounting begins, the device ID (device label or UUID) of the mounted device is compared with the system disk ID. If the IDs match, the device is mapped to the superblock of the original system disk. After data write-back and synchronization are complete, all kernel threads are activated, and system recovery is complete.
[0039] This invention pertains to kernel patch files, and its main operational process is as follows: Figure 1-3 As shown, the patch point is in the init thread, umount and do_mount kernel functions, which respectively complete the tasks of obtaining the device UUID, retaining the unmount state and restoring the mount data.
[0040] The global variable table object data structure is as follows:
[0041] {
[0042] super_block *root_super_block; / / Pointer to the system disk superblock object;
[0043] char block_id
[255] ; / / System disk UUID or LABEL value;
[0044] char islock; / / Frozen state value;
[0045] }
[0046] After the init thread reads the / etc / fstab file and completes the mounting, it reads the / etc / fstab file again and writes the corresponding UUID or label value of the system disk.
[0047] In the kernel umount function, the ID number of the device to be unmounted is compared to prevent the kernel from unmounting the system disk and releasing the superblock. At the same time, the kernel thread is suspended to ensure that data is no longer written to the system disk, thus preventing a large number of I / O read and write errors.
[0048] In the kernel's do_mount function, the ID number of the device to be mounted is compared. If the system disk is reinserted, the mapping relationship between the superblock and the device is restored directly, and a data write-back is performed to prevent data loss. After that, all suspended kernel threads are started to restore the system's running state.
[0049] This invention is a patch file that adapts to different kernel versions by patching the source code into the kernel code. After kernel compilation, this kernel can be used to support various Linux-based desktop operating systems. No data needs to be modified at the desktop system or user level, and no user configuration is required, enabling seamless hot-swapping of the system disk.
[0050] After the Linux kernel is patched, the desktop operating system hosted on this kernel can support hot-swapping of the system disk. After hot-swapping the system disk, reinserting the removed system disk ensures that the system can continue to be used normally without restarting, and the data on the system disk and other mounted disks will not be damaged or lost.
[0051] This method allows desktop operating systems with a Linux kernel (such as Ubuntu, CentOS, Debian, Kylin, Galaxy Kylin, UnionTech UOS, etc.) installed on removable storage devices (such as USB flash drives, external hard drives, SD cards, etc.) to be hot-swapped without shutting down the system, without affecting the normal use of the operating system.
[0052] The device obtained through the above technical solution is a method that supports hot-swapping of system disks in a Linux kernel operating system. It enables hot-swapping of system disks in Linux-based desktop operating systems (hereinafter referred to as Linux desktop operating systems) while ensuring the system continues to operate normally after the system disk is hot-swapped, without data loss or system disk damage. It perfectly solves the problem of system disk damage, system crashes, and data loss that can occur when using removable disk devices such as USB flash drives as system disks in Linux desktop operating systems due to unstable contact and careless plugging and unplugging of removable devices.
[0053] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention can have various modifications and variations; any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for supporting hot-swapping of the system disk in a LINUX kernel operating system, characterized in that, Includes the following steps: a. Check the consistency between the removable storage device and the system disk. When the removable storage device is unloaded, check whether the unloaded device is consistent with the system disk. b. If the unloaded removable storage device is the same as the system disk, the superblock will not be released, and all running kernel threads will be suspended, waiting for the device to be inserted. If the unloaded removable storage device is different from the system disk, it will be processed according to the normal procedure. c. After the removable storage device is inserted, when the mounting is complete and automatic mounting begins, identify the device ID of the mounted device and compare it with the system disk ID; d. If the ID of the mounted device matches the ID of the system disk, the mounted device is mapped onto the superblock of the original system disk. After the data write-back and synchronization are completed, all threads in the kernel are activated to complete system recovery. If the ID of the mounted device does not match the ID of the system disk, the normal process is followed. When the system starts, the init thread starts and reads the / etc / fstab file. After the / etc / fstab file is mounted, it reads the / etc / fstab file again, finds the UUID or label value corresponding to the root directory, polls the superblock list and finds the superblock that matches the UUID or label value, and records the object pointer, UUID or label value of the superblock in a global variable object. In the kernel umount function, the ID of the device to be unmounted is compared to prevent the kernel from unmounting the system disk and releasing the superblock. At the same time, the kernel thread is suspended to ensure that data is no longer written to the system disk, thus preventing a large number of I / O read and write errors.
2. The method for supporting hot-swapping of the system disk in a LINUX kernel operating system according to claim 1, characterized in that, Get the nameidate value through the name, get the device's UUID or label value through the nameidate value, and compare the UUID value with the system disk ID value in the global variable table.
3. The method for supporting hot-swapping of the system disk in a LINUX kernel operating system according to claim 1, characterized in that, In the kernel's do_mount function, the ID number of the device to be mounted is compared. If the system disk is reinserted, the mapping relationship between the superblock and the device is restored directly, and a data write-back is performed to prevent data loss. After that, all suspended kernel threads are started to restore the system's running state.
4. The method for supporting hot-swapping of the system disk in a LINUX kernel operating system according to claim 3, characterized in that, In the kernel's `do_mount` function, the `path` value is obtained through `dir_name`. After obtaining `nameidate` through `dir_name`, the `uuid` or `label` value of the device is obtained through `nameidate`. The `path` value is then compared with the system disk ID value in the global variable table.
5. The method for supporting hot-swapping of the system disk in a LINUX kernel operating system according to claim 3, characterized in that, While restoring the system to its running state, the frozen parameters in the global variable table are set to 0.
Citation Information
Patent Citations
Method for improving stability of EXT (extended) file system
CN102955720A
Method for mounting multi-partition storage device in Android system
CN104391657A