A method for modifying and repacking an ISO image based on a domestic Galaxy Kirin system
Patent Information
- Application Number
- CN202610878303.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-17
- Publication Date
- 2026-10-30
AI Technical Summary
[0005]针对上述问题,本发明提供一种基于国产银河麒麟系统的ISO镜像修改与重打包方法,以解决用户对银河麒麟系统的iso镜像不会修改,不好修改的问题
本发明可一键读取ISO镜像,支持通过chroot进入文件系统,直接查看软件包信息等;本发明可高效地一键安装软件包到镜像文件系统,还可一键重打包生成新的ISO镜像文件。
Smart Images

Figure CN123011259A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to ISO images, and more particularly to a method for modifying and repackaging ISO images based on the domestically developed Galaxy Kylin system, belonging to the field of computer technology. Background Technology
[0002] The live environment used during system installation will revert to its original state upon restarting and re-entering the live environment. However, if there are bugs in the live environment, some problems will be difficult to troubleshoot. For example, the occasional black screen issue encountered in the live environment was only easily reproduced when first entering the live environment, and because logging was not enabled, the log information of the desktop programs could not be viewed. Thus, the problem could be debugged by modifying the ISO image. However, system images are generated by pulling software packages from a specific platform, and each generation takes a significant amount of time. Moreover, ordinary users do not have the platform environment, making it difficult to recreate and modify the ISO.
[0003] On the other hand, if users want to quickly customize and modify images, a method needs to be provided that allows them to efficiently and visually modify the ISO, such as installing some deb packages in the ISO, modifying some configuration files, and so on, and then regenerating the ISO file.
[0004] To facilitate users in modifying the contents of ISO system images, it is necessary to develop an efficient, fast, and visual ISO modification tool that can perform functions such as installing software packages and repackaging ISOs. Summary of the Invention
[0005] To address the aforementioned issues, this invention provides a method for modifying and repackaging ISO images based on the domestically developed Galaxy Kylin system, thereby resolving the problem that users are unable or unwilling to modify the Galaxy Kylin system's ISO images.
[0006] To achieve the above objectives, the technical solution of this invention is: a method for modifying and repackaging an ISO image based on the domestically developed Galaxy Kylin system, comprising the following steps: Step S1: System initialization. Verify whether there are directories A and B for mounting the ISO image and storing the mounted copy. If not, create them. Also, create a deb directory to store deb files. Step S2: Select the ISO image file that needs to be modified; Step S3: Read the image. After selecting the image, call the mount command to mount the ISO to directory A. After mounting is complete, clear directory B, and then call shutil.copytree to copy the contents of directory A to directory B. After copying is complete, call umount to unmount the ISO image, and then use unsquashfs to decompress the file system. Step S4: Click the "Add DEB" button to bring up the file selection dialog box and display the selected deb file in the list control; Step S5: Click the "Install DEB" button, copy the selected deb file to the deb directory, first call chroot to enter the file system, and then execute dpkg to install the deb package; Step S6: Click the "Enter chroot in terminal" button to open the terminal and enter the chroot environment, and then perform custom operations on the ISO image; Step S7: Click the "Generate New ISO" button to repackage the file system and generate a new ISO image.
[0007] Furthermore, in step S2, QFileDialog is used to select the local ISO image file.
[0008] Furthermore, step S6, a custom operation, includes checking the package version, modifying files, and uninstalling the package.
[0009] Furthermore, in step S7, generating the new ISO portion involves first using mksquashfs to generate the file system, and then using genisoimage to repackage it into two ISO portions.
[0010] The beneficial effects of the ISO image modification and repackaging method based on the domestic Galaxy Kylin system of the present invention are as follows: This invention can read ISO images with one click, supports entering the file system via chroot, and directly view package information, etc.; this invention can efficiently install packages to the image file system with one click, and can also repackage and generate new ISO image files with one click. Attached Figure Description
[0011] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0012] Figure 1 This is a general technical framework diagram of the present invention; Figure 2 This is a flowchart illustrating the implementation of the present invention. Detailed Implementation
[0013] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art can make similar extensions without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0014] Definitions of abbreviations and key terms Python: A widely used high-level programming language applied in various fields such as web development, data science, artificial intelligence, scientific computing, automation scripting, and education. Its flexibility and ease of use make Python the language of choice for many developers and data scientists.
[0015] PyQt5: A Qt5 framework wrapped in Python for rapidly developing cross-platform graphical user interface (GUI) applications.
[0016] ISO: A disc image file format used to store and copy the complete contents of discs (such as CDs and DVDs). It is commonly used to distribute operating system installation discs, software installation packages, etc., and can be used through virtual drives or burning tools.
[0017] chroot: Used to change the root directory ( / ) of a process, restricting the process to access only the specified directory and its subdirectories. It is often used in sandbox environments, system installation, or troubleshooting.
[0018] dpkg is the underlying package management tool for Debian and its derivative systems (such as Ubuntu), used to install, uninstall, and manage .deb format software packages.
[0019] filesystem.squashfs: A read-only compressed file system format based on SquashFS. It reduces the size of the file system through compression technology while maintaining high read performance.
[0020] mksquashfs: A command-line tool for creating SquashFS file systems that compresses one or more files or directories into a single SquashFS image file.
[0021] genisoimage: A tool for creating ISO 9660 format disc image files, commonly used to generate ISO files for CDs / DVDs, and supports various options to customize the image content and structure.
[0022] Example 1 Combination Figure 1 As shown, the ISO image modification and repackaging method based on the domestic Galaxy Kylin system of this invention mainly includes several parts: UI display, image selection, image reading, image modification, and new ISO generation. The overall implementation process is as follows: (1) The UI display uses the cross-platform and easy-to-use PyQt5 library, mainly using lists, buttons, text boxes, etc.
[0023] (2) Select the local ISO file using QFileDialog for subsequent reading and modification.
[0024] (3) The image reading process uses multiple commands: mount to mount the ISO to a directory, shutil for file copying, umount to unmount the ISO, and unsquashfs to decompress the file system. Subsequent image modifications are based on the decompressed file system.
[0025] (4) Modifying the image mainly includes two points. First, it supports adding deb packages that need to be installed and using chroot with the dpkg command to install them into the decompressed file system. Second, it supports calling mate-terminal with the chroot command to enter the file system, and then using commands to make other modifications to the file system, such as modifying or deleting files, installing or uninstalling packages, checking package versions, etc.
[0026] (5) Generating a new ISO part involves first using mksquashfs to generate a file system, and then using genisoimage to repackage it into an ISO part.
[0027] Example 2 Based on Example 1, combined with Figure 2 The specific implementation process of the method of the present invention is described in detail, including the following steps: Step S1. The first step is initialization. Since the ISO needs to be mounted, directories A and B will be created during initialization if they do not already exist. Directory A is used to mount the ISO image, and directory B stores the mounted copy. A `.deb` directory is created to store `.deb` files. The UI is developed using PyQt5, utilizing controls such as QLabel, QLineEdit, QPushButton, QListWidget, and QFileDialog.
[0028] Step S2. The user clicks the "Select Image" button to bring up the file selection dialog box and selects the ISO image file to be modified.
[0029] Step S3. Read the image. After selecting the image, the user clicks the "Read Image" button. First, the `mount` command is called to mount the ISO to directory A. After mounting, directory B is cleared. Then, `shutil.copytree` is called to copy the contents of directory A to directory B. After copying, `umount` is called to unmount the ISO image (because the ISO is still mounted after copying, and the original ISO file will not be used again later; also, if the ISO image is mounted to the same directory again, the mount will fail, so unmounting is necessary). Then, `unsquashfs` is used to decompress the file system. The file system path is `B / casper / filesystem.squashfs`, and it is decompressed to the `squashfs-root` directory. The image reading is now complete. After mounting, the ISO image is in read-only state. Subsequent operations on the file system, including installing deb files and chroot access to add, delete, modify, and query data, will all be based on the decompressed file system.
[0030] Step S4. The user clicks the "Add DEB" button, which brings up the file selection dialog box and displays the selected deb file in the list control.
[0031] Step S5. The user clicks the "Install DEB" button, first copies the selected deb file to the deb directory, then defines chroot_cmd = ["sh", "-c",f"chroot {self.squashfs_root} sh -c 'dpkg --install / deb / Then, it calls self.proc.start(chroot_cmd[0], chroot_cmd[1:]) to complete the installation operation. Here, self.squashfs_root is the squashfs-root directory, and self.proc is a QProcess instance used to start the sh process. The "sh -c" in the above chroot_cmd command executes a string command, which is "chroot {self.squashfs_root} sh -c 'dpkg --install / deb / "deb" means that chroot is called first to enter the file system, and then dpkg is executed to install the deb package.
[0032] Step S6. The user clicks the "Enter chroot in terminal" button to launch the terminal and enter the chroot environment. Define command = ["mate-terminal", "--working-directory", self.squashfs_root, "--","chroot", self.squashfs_root, " / bin / bash"], and then use self.proc.start(command[0], command[1:]) to start the terminal and enter the chroot environment. After entering, the user can perform custom operations such as viewing package versions, modifying files, and uninstalling packages.
[0033] Step S7. The user clicks the "Generate New ISO" button, which will repackage the file system and generate a new ISO image. First, `self.proc.start("mksquashfs",[self.squashfs_root,self.squashfs_current_path,"-noappend","-comp", "xz"])` is executed to generate a new file system, where `self.squashfs_root` is the squashfs-root directory, `self.squashfs_current_path` is the current directory, and the new file system is `filesystem.squashfs`. Then, `shutil.move` is used to move `filesystem.squashfs` to B / casper, replacing the old file system. Finally, define cmd = ["genisoimage","-J", "-r", "-T", "-joliet-long", "-allow-leading-dots", "-l","-A", "KylinOS Live","-p", "kylinlivebuildd","-publisher", "http: / / www.kylinos.cn / ","-V", "Kylin-Desktop-V10-GFB","-eltorito-alt-boot", "-e", "boot / grub / efi.img", "-no-emul-boot","-o", "output.iso",self.target_dir_b], and then call self.proc.start(cmd[0], cmd[1:]) to run, generating a new ISO file output.iso, where self.target_dir_b is the path to directory B.
[0034] In summary, this invention, based on Python and ISO, utilizes methods such as mount, umount, shutil, unsquashfs, chroot, mate-terminal, dpkg, mksquashfs, and genisoimage to implement image reading, package installation, chroot access to the file system, and one-click repackaging. The methods described above can significantly improve work efficiency in practical scenarios such as operating system package debugging, image information viewing, and image modification.
[0035] Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
Claims
1. A method for modifying and repackaging an ISO image based on the domestically developed Galaxy Kylin system, characterized in that, Includes the following steps: Step S1: System initialization. Verify whether there are directories A and B for mounting the ISO image and storing the mounted copy. If not, create them. And create a deb directory to store deb files; Step S2: Select the ISO image file that needs to be modified; Step S3: Read the image. After selecting the image, call the mount command to mount the ISO to directory A. After mounting is complete, clear directory B, and then call shutil.copytree to copy the contents of directory A to directory B. After copying is complete, call umount to unmount the ISO image, and then use unsquashfs to decompress the file system. Step S4: Click the "Add DEB" button to open the file selection dialog box and display the selected deb file in the list control; Step S5: Click the "Install DEB" button, copy the selected deb file to the deb directory, first call chroot to enter the file system, and then execute dpkg to install the deb package; Step S6: Click the "Enter chroot in terminal" button to open the terminal and enter the chroot environment, and then perform custom operations on the ISO image; Step S7: Click the "Generate New ISO" button to repackage the file system and generate a new ISO image.
2. The method according to claim 1, characterized in that, In step S2, QFileDialog is used to select the local ISO image file.
3. The method according to claim 1, characterized in that, Step S6, the custom operation, includes checking the package version, modifying files, and uninstalling the package.
4. The method according to claim 1, characterized in that, Step S7 involves generating a new ISO part by first using mksquashfs to generate a file system, and then using genisoimage to repackage it into two parts, the ISO.
