How to create a Linux ISO image from scratch (Graphic tutorial)

Time:2022-1-13

1、 Foreword

For a very simplified Linux system, it only needs three parts: a Linux kernel, a root file system and boot. The following are the systems and software used to create Linux ISO image in this paper:

    OS: ubuntu 20
Software: xorriso

2、 Making Linux kernel

1. First, you need to go to the official website to select a required version and download it. The official website download address is:https://mirrors.edge.kernel.org/pub/linux/kernel/

2. Use tar to decompress it, then enter its directory, and then configure the kernel. The common configurations are as follows:
A. make defconfig – default configuration
B. make allyesconfig – create a configuration where yes can be selected
C. make allnoconfig – create a configuration where no can be selected
D. make menuconfig – ncurser based graphical interface configuration
Here, use the command make defconfig and use the default, as shown in the following figure:

1.png

3. Then usemake bzImageCommand to compile the kernel, as shown in the following figure:

2.png

The compiled kernel file is inarchThe folder is under the corresponding schema folder, as shown in the following figure:

3.png

3、 Make root file system

1. We use busybox to create a root file system. Busybox can be simply understood as a collection of Linux tools. First, Download busybox. Download address on the official website:https://busybox.net/downloads/

2. The steps of compiling busybox are basically the same as those of compiling the kernel. Decompress the downloaded compressed package, then enter the folder, and use make defconfig to configure the default compilation options. Note that in the generated.configIn the configuration file, you need to setCONFIG_STATIC=yIf not, you can add it, as shown in the figure below:

4.png

7.png

3. Then usemake busybox installCommand to compile busybox. After compilation, one will be produced under the current directory_installFolder, as shown in the figure below:
 

5.png
 

6.png

4. Then create arootfsFolder, and_installExcept under folderlinuxxrcAll files and folders other than are copied torootfsFolder, and finally createdevAnd other folders, and finally create them under the root directoryinitFile is enough, and the contents of the file are shown in the following figure:

8.png

9.png

5. Finally use the commandfind . | cpio -R root:root -H newc -o | gzip > ../rootfs.gzPackage the file system. At this point, a file system is created, as shown in the following figure:

10.png

4、 BIOS

1. Here we usesyslinuxTo createbiosBoot a Linux ISO image,syslinuxThe official download address is as follows:https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/

2. Download the downloadedsyslinuxUnzip and create a folderisobios, the unzippedsyslinuxUnder folderbios/core/isolinux.binbios/com32/elflink/ldlinux/ldlinux.c32Copy toisobiosBelow the folder, as shown in the following figure:

11.png

3. InisobiosCreate profile under folderisolinux.cfg, the contents of the document are as follows:

12.png

4. Finally, inisobiosUse commands under foldersxorriso -as mkisofs -o ../testbios.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table ./Generate an ISO image file, as shown in the following figure:

13.png

5. Use virtual machinevmwareCreate a virtual machine, as shown in the figure below, which is how a Linux ISO image we created runs.

14.png

5、 UEFI

1. UEFI heresystem-bootandsyslinuxFirst, create two foldersisouefiandtmp, where,isouefiTo mount the device,tmpThe folder is used to temporarily store files to calculate the size, and thentmpCreate under folderEFI/BOOTandloader/entriesDirectory, and then, the unzippedsystembootBelowuefi_boot/EFI/BOOT/BOOTx64.EFICopy files totmp/EFI/BOOTUnder the directory, as shown in the following figure:

15.png

2. Then, intmp/loaderUnder the directory, create a fileloader.confConfiguration file, the first line indicates that the default configuration isentriesFor the file in the directory, set the default timeout in the second line; Then inentriesCreate the corresponding configuration file under the folder. Here ismll-x86_64.conf, document content andbiosIt’s almost the same. I won’t elaborate separately. Finally, I’ll copy the previously prepared kernel and file system totmpUnder the directory, as shown in the following figure:

16.png

17.png

18.png

3. At this time, you cantmpThe total size of the folder creates a folder of the same sizeimgFile, heretmpyes11M, to be on the safe side, create one here12MofimgFile, command istruncate -s 12M uefi.img, and then uselosetup -fCommand to find a logical device that is not currently in use, and then uselosetupThe command will be the one we created earlierimgThe file is virtualized into a logical device, and then usedmkfs.vfatFormat the device asvfatSystem, then usemountCommand to mount it toisouefiUnder the folder, finallytmpCopy all files and folders under the folder toisouefiUnder the directory, as shown in the following figure:

19.png

20.png

4. Then useumountThe command cancels the mount so that we get a file containingkernelfile systemWaitimgFile, and then create aisoFolder, and a folder will be created under itbootFolder, and thenimgCopy toiso/bootNext, finally usexorrisoTool generationisoFile, as shown in the figure below:

21.png

5. Finally, create a new virtual machine, boot, select UEFI and start it, as shown in the following figure:

22.png

23.png

6、 Related links

GitHub link:https://github.com/windy-purple/make_linux_iso

This is the end of this article on how to create a Linux ISO image (Graphic tutorial) from scratch. For more information about Linux ISO image, please search the previous articles of developpaer or continue to browse the relevant articles below. I hope you will support developpaer in the future!