A server image file simulation method based on Linux container technology
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XLY SALVATIONDATA TECHNOLOGY INC
- Filing Date
- 2022-12-27
- Publication Date
- 2026-06-12
AI Technical Summary
Existing virtual machine technology suffers from problems such as complex processes, high resource consumption, low simulation success rate, and inability to simulate multiple image files when simulating server image files.
By using Linux container technology, a separate Linux system kernel environment is isolated through disk mounting and container environment configuration to run the service code in the server image file, thereby achieving service simulation.
It simplifies the simulation process, reduces resource consumption, improves the simulation success rate, and supports simulating multiple server image files.
Smart Images

Figure CN115878268B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of electronic forensics and server simulation, and relates to a server image file simulation method, particularly a server image file simulation method based on Linux container technology. Background Technology
[0002] Server emulation refers to using various technical solutions to re-run various services of a server or a server image file obtained through forensics, and enabling normal access to these services locally.
[0003] The commonly used server image file emulation technology is virtual machine technology, such as VMware and VirtualBox. Virtual machine technology can emulate a server from the hardware instruction level. The simulation steps are as follows:
[0004] 1. First, build a virtual machine for virtual server hardware.
[0005] 2. Use the server image file as the system hard drive for the virtual machine.
[0006] 3. Start the virtual machine. The virtual machine begins to execute virtual hardware instructions and starts the server system from the system hard drive.
[0007] The advantages of virtual machine technology are that the startup and operation of the simulation server are the same as those of a real physical machine, resulting in high fidelity. However, the disadvantages of virtual machine technology include a complex simulation process, a probability of failure in the simulation server image file, and the need for the real server system password to log in after simulating the server. Obviously, logging into the server system without knowing the password is difficult and inconvenient, and interaction with the simulated server system is also inconvenient. The entire virtual machine simulation process is also relatively complex, time-consuming, and consumes a lot of system resources. In addition, virtual machine technology cannot simulate multiple server image files. Summary of the Invention
[0008] To address the technical problems of existing technologies, this invention provides a server image file simulation method based on Linux container technology: simulating server image files based on Linux container technology.
[0009] Linux Container Technology (LXC) is a kernel-lightweight operating system-level virtualization technology. By isolating a separate Linux system kernel environment and resources using LXC, the service code from the server image file is run within this isolated environment, thus enabling the server's services to run and be accessed locally.
[0010] Since Linux container technology is based on file emulation, we can emulate the service by finding the file containing the corresponding service code resources in the image, regardless of which image the file is in.
[0011] The method provided by this invention includes the following steps:
[0012] S100: Using disk / image mounting, mount the server image file to the current system directory and confirm that the server image file is successfully mounted;
[0013] S200: Modify the container configuration file, configure the network interface to the physical network interface of the system currently in use, and configure the container network interface IP address to communicate with the container and access container services;
[0014] S300: Configure the root directory of the container: Modify the value of lxc.rootfs.path in the container configuration file to the mount point path of the server image file under the current system;
[0015] S400: Delete all device files in the / dev directory under the system root directory of the mounted server image file, and create container device files in the / dev directory. The container device files include pts, shm, tty, console, tty0, tty1, tty2, tty3, tty4, tty5, tty6, full, initctl, and ptmx.
[0016] S500: Modify the fstab file in the / etc directory under the system root directory of the mounted server image file to clear all mount points;
[0017] S600: Start container simulation using the container command lxc-start and the container configuration file;
[0018] S700: Determine if the container is running. If yes, proceed to step S800; otherwise, proceed to step S700.
[0019] S800: Check the status of services started by the system;
[0020] S900: Check if the mysqld data service is running. If yes, proceed to step SA00; otherwise...
[0021] Execute step S900;
[0022] SA00: Access web services using the IP address of the container network interface.
[0023] Preferably, the method for determining that the server image file has been successfully mounted is as follows:
[0024] S101: Check if the server image file name exists in the mounted directory. If it does, proceed to step S102; otherwise, proceed to step S101.
[0025] S102: Check if the directories / dev and / etc exist in the directory of the server image file name. If they do, proceed to step S200; otherwise, proceed to step S102.
[0026] Preferably, in step S200, the network interface is configured as any unused physical network interface of the currently used system.
[0027] Preferably, the mount point path of the server image file in the current system in step S300 is the same as the path of the directory in the current system where the server image file is mounted in step S100.
[0028] Preferably, the method for determining whether a container is running is: determining whether the status corresponding to the container name is RUNNING.
[0029] Preferably, the method for determining whether the mysqld data service is running is to check whether the / usr / libexec / mysqld process has a corresponding PID process ID and PPID process ID.
[0030] The present invention has the following beneficial effects:
[0031] 1. It avoids the disadvantages of virtual machine simulation, such as technical complexity, high resource consumption, time-consuming process, and low simulation success rate. Moreover, this technical solution can simulate multiple server image files.
[0032] 2. This technical solution is simple, lightweight, efficient, and highly applicable. Attached Figure Description
[0033] Figure 1 This is a flowchart of the server image file simulation method based on Linux container technology provided by the present invention. Detailed Implementation
[0034] Figure 1 A flowchart of the server image file simulation method based on Linux container technology provided by the present invention is shown.
[0035] like Figure 1 As shown, the method includes the following steps:
[0036] S100: Use disk / image mounting to mount the server image file to the current system directory and confirm that the server image file is mounted successfully;
[0037] In this embodiment, the server image file 1.disk is mounted to the / mnt / rootfs directory of the current system in the following manner:
[0038] guestmount-oallow_other-ononempty-a / mnt / disk / 1.disk-i / mnt / rootfs
[0039] In addition, the method to confirm that the server image file is mounted successfully is as follows:
[0040] S101: Check if the server image file name 1.disk exists under the mounted directory / mnt / rootfs. If it does, proceed to step S102; otherwise, proceed to step S101.
[0041] S102: Check if the directories / dev and / etc exist in the directory of the server image file name 1.disk. If they do, proceed to step S200; otherwise, proceed to step S102.
[0042] S200: Modify the container configuration file, configure the network interface to the physical network interface of the currently used system, and configure the container network interface IP address to communicate with the container and access container services; in step S200, the network interface is configured to any unused physical network interface of the currently used system.
[0043] For example, in the currently used system, the unused physical network interfaces are lxc.net.0.link, lxc.net.1.link, lxc.net.2.link, etc. The container configuration file lxc.conf is configured as follows:
[0044] lxc.net.0.type = phys
[0045] lxc.net.0.flags=up
[0046] lxc.net.0.link = enp0s8 / / Sets the container to use the physical network interface card enp0s8
[0047] lxc.net.0.ipv4.gateway=192.168.99.1
[0048] lxc.net.0.ipv4.address=192.168.99.99 / / Set the IP address of the network card
[0049] lxc.uts.name = lxcservicevm / / Set the name of the container
[0050] lxc.tty.max = 4
[0051] lxc.rootfs.path = / mnt / rootfs / / Sets the root directory of the container system
[0052] In the above embodiment, lxc.net.0.link is configured as a network interface and its IP address is configured as 192.168.99.99.
[0053] S300: Configure the root directory of the container: Modify the value of lxc.rootfs.path in the container configuration file to the mount point path of the server image file under the current system: / mnt / rootfs;
[0054] As shown in the container configuration file in the above embodiment, the mount point path of the server image file in the current system in step S300 is the same as the path of the directory where the server image file is mounted to the current system in step S100, that is, / mnt / rootfs.
[0055] S400: In this implementation, the command `rm -r / dev` is used to delete all device files in the ` / dev` directory under the system root directory of the mounted server image file (note that this is not the ` / dev` directory under the current system root directory). Then, using the `mknod` command, container device files are created in the ` / dev` directory under the system root directory of the mounted server image file. These container device files include pts, shm, tty, console, tty0, tty1, tty2, tty3, tty4, tty5, tty6, full, initctl, and ptmx.
[0056] For example, mknod-m666tty
[0057] S500: In this embodiment, the fstab file in the / etc directory under the system root directory of the mounted server image file is modified by echo "">> / etc / fstab to clear all mount points;
[0058] S600: Start container simulation using the container command lxc-start and the container configuration file;
[0059] In this embodiment, the container emulation is started using the command: lxc-start-naa-flxc.conf.
[0060] Here, aa is the name of the container we started; lxc.conf is the container configuration file we configured.
[0061] After executing the command, the container started running, and the services in the server image also started running.
[0062] S700: Determine if the container is running. If yes, proceed to step S800; otherwise, proceed to step S700.
[0063] In this embodiment, the method for determining whether a container is running is as follows: use the container command: lxc-ls-lDEBBUG –f, check the container status and determine whether the status corresponding to the container name is RUNNING.
[0064] S800: Check the status of services started by the system; in this embodiment, we enter the container using the container command lxc-attach-naa and use the Linux command ps-ef to check the status of services started.
[0065] S900: Determine if the mysqld data service is running. If yes, proceed to step SA00; otherwise, proceed to step S900.
[0066] To determine if the mysqld data service is running, use the Linux command `ps -ef` to check if the ` / usr / libexec / mysqld` process has a corresponding PID and PPID. If so, it means the mysqld data service is running.
[0067] SA00: Access the web service using the container's network interface IP address. If both the httpd web service and the mysqld data service are running, we can access the web service through the configured container IP address 192.168.99.99. This completes the simulation of a server image file based on Linux container technology.
[0068] The method provided by this invention solves the technical problem that there is no existing method for simulating server image files based on Linux container technology.
[0069] It should be understood that the present invention is not limited to the examples described above. Those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. A method for emulating a server image file based on Linux container technology, characterized in that, Includes the following steps: S100: Using disk / image mounting, mount the server image file to the current system directory and confirm that the server image file is successfully mounted; S200: Modify the container configuration file, configure the network interface to the physical network interface of the system currently in use, and configure the container network interface IP address to communicate with the container and access container services; S300: Configure the root directory of the container: Modify the value of lxc.rootfs.path in the container configuration file to the mount point path of the server image file under the current system; S400: Delete all device files in the / dev directory under the system root directory of the mounted server image file, and create container device files in the / dev directory. The container device files include pts, shm, tty, console, tty0, tty1, tty2, tty3, tty4, tty5, tty6, full, initctl, and ptmx. S500: Modify the fstab file in the / etc directory under the system root directory of the mounted server image file to clear all mount points; S600: Start container simulation using the container command lxc-start and the container configuration file; S700: Determine if the container is running. If yes, proceed to step S800; otherwise, proceed to step S700. S800: Check the status of services started by the system; S900: Determine if the mysqld data service is running. If yes, proceed to step SA00; otherwise, proceed to step S900. SA00: Access web services using the IP address of the container network interface.
2. The server image file simulation method based on Linux container technology according to claim 1, characterized in that, The method to determine if the server image file is successfully mounted is as follows: S101: Check if the server image file name exists in the mounted directory. If it does, proceed to step S102; otherwise, proceed to step S101. S102: Check if the directories / dev and / etc exist in the directory of the server image file name. If they do, proceed to step S200; otherwise, proceed to step S102.
3. The server image file simulation method based on Linux container technology according to claim 1, characterized in that, In step S200, the network interface is configured as any unused physical network interface of the currently used system.
4. The server image file simulation method based on Linux container technology according to claim 1, characterized in that, The mount point path of the server image file in the current system in step S300 is the same as the path of the directory in the current system where the server image file is mounted in step S100.
5. The server image file simulation method based on Linux container technology according to claim 1, characterized in that, The method to determine whether a container is running is to check if the status corresponding to the container name is RUNNING.
6. The server image file simulation method based on Linux container technology according to claim 1, characterized in that, The method to determine whether the mysqld data service is running is to check whether the / usr / libexec / mysqld process has a corresponding PID process ID and PPID process ID.