How to create a Linux ISO image from scratch (Graphic tutorial)
Table of Contents
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: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:
3. Then usemake bzImage
Command to compile the kernel, as shown in the following figure:
The compiled kernel file is inarch
The folder is under the corresponding schema folder, as shown in the following figure:
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: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.config
In the configuration file, you need to setCONFIG_STATIC=y
If not, you can add it, as shown in the figure below:
3. Then usemake busybox install
Command to compile busybox. After compilation, one will be produced under the current directory_install
Folder, as shown in the figure below:
4. Then create arootfs
Folder, and_install
Except under folderlinuxxrc
All files and folders other than are copied torootfs
Folder, and finally createdev
And other folders, and finally create them under the root directoryinit
File is enough, and the contents of the file are shown in the following figure:
5. Finally use the commandfind . | cpio -R root:root -H newc -o | gzip > ../rootfs.gz
Package the file system. At this point, a file system is created, as shown in the following figure:
4、 BIOS
1. Here we usesyslinux
To createbios
Boot a Linux ISO image,syslinux
The official download address is as follows:mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/
2. Download the downloadedsyslinux
Unzip and create a folderisobios
, the unzippedsyslinux
Under folderbios/core/isolinux.bin
、bios/com32/elflink/ldlinux/ldlinux.c32
Copy toisobios
Below the folder, as shown in the following figure:
3. Inisobios
Create profile under folderisolinux.cfg
, the contents of the document are as follows:
4. Finally, inisobios
Use 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:
5. Use virtual machinevmware
Create a virtual machine, as shown in the figure below, which is how a Linux ISO image we created runs.
5、 UEFI
1. UEFI heresystem-boot
andsyslinux
First, create two foldersisouefi
andtmp
, where,isouefi
To mount the device,tmp
The folder is used to temporarily store files to calculate the size, and thentmp
Create under folderEFI/BOOT
andloader/entries
Directory, and then, the unzippedsystemboot
Belowuefi_boot/EFI/BOOT/BOOTx64.EFI
Copy files totmp/EFI/BOOT
Under the directory, as shown in the following figure:
2. Then, intmp/loader
Under the directory, create a fileloader.conf
Configuration file, the first line indicates that the default configuration isentries
For the file in the directory, set the default timeout in the second line; Then inentries
Create the corresponding configuration file under the folder. Here ismll-x86_64.conf
, document content andbios
It’s almost the same. I won’t elaborate separately. Finally, I’ll copy the previously prepared kernel and file system totmp
Under the directory, as shown in the following figure:
3. At this time, you cantmp
The total size of the folder creates a folder of the same sizeimg
File, heretmp
yes11M
, to be on the safe side, create one here12M
ofimg
File, command istruncate -s 12M uefi.img
, and then uselosetup -f
Command to find a logical device that is not currently in use, and then uselosetup
The command will be the one we created earlierimg
The file is virtualized into a logical device, and then usedmkfs.vfat
Format the device asvfat
System, then usemount
Command to mount it toisouefi
Under the folder, finallytmp
Copy all files and folders under the folder toisouefi
Under the directory, as shown in the following figure:
4. Then useumount
The command cancels the mount so that we get a file containingkernel
、file system
Waitimg
File, and then create aiso
Folder, and a folder will be created under itboot
Folder, and thenimg
Copy toiso/boot
Next, finally usexorriso
Tool generationiso
File, as shown in the figure below:
5. Finally, create a new virtual machine, boot, select UEFI and start it, as shown in the following figure:
6、 Related links
GitHub link: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!
Read more here: Source link