Linux kernel to iso

Kernel/Traditional compilation

This article is an introduction to building custom kernels from kernel.org sources. This method of compiling kernels is the traditional method common to all distributions. It can be, depending on your background, more complicated than using the Kernels/Arch Build System. Consider the Arch Build System tools are developed and maintained to make repeatable compilation tasks efficient and safe.

Contents

Preparation

It is not necessary (or recommended) to use the root account or root privileges (i.e. via Sudo) for kernel preparation.

Install the core packages

Install the base-devel package group, which contains necessary packages such as make and gcc . It is also recommended to install the following packages, as listed in the default Arch kernel PKGBUILD: xmlto , kmod , inetutils , bc , libelf , git , cpio , perl , tar , xz .

Create a kernel compilation directory

It is recommended to create a separate build directory for your kernel(s). In this example, the directory kernelbuild will be created in the home directory:

Download the kernel source

Download the kernel source from https://www.kernel.org. This should be the tarball ( tar.xz ) file for your chosen kernel.

It can be downloaded by simply right-clicking the tar.xz link in your browser and selecting Save Link As. , or any other number of ways via alternative graphical or command-line tools that utilise HTTP, TFTP, Rsync, or Git.

In the following command-line example, wget has been installed and is used inside the

/kernelbuild directory to obtain kernel 4.8.6:

You should also verify the correctness of the download before trusting it. First grab the signature, then use that to grab the fingerprint of the signing key, then use the fingerprint to obtain the actual signing key:

Note the signature was generated for the tar archive (i.e. extension .tar ), not the compressed .tar.xz file that you have downloaded. You need to decompress the latter without untarring it. Verify that you have xz installed, then you can proceed like so:

Do not proceed if this does not result in output that includes the string «Good signature».

If wget was not used inside the build directory, it will be necessary to move the tarball into it, e.g.

Unpack the kernel source

Within the build directory, unpack the kernel tarball:

To finalise the preparation, ensure that the kernel tree is absolutely clean; do not rely on the source tree being clean after unpacking. To do so, first change into the new kernel source directory created, and then run the make mrproper command:

Kernel configuration

This is the most crucial step in customizing the default kernel to reflect your computer’s precise specifications. Kernel configuration is set in its .config file, which includes the use of Kernel modules. By setting the options in .config properly, your kernel and computer will function most efficiently.

You can do a mixture of two things:

  • Use the default Arch settings from an official kernel (recommended)
  • Manually configure the kernel options (optional, advanced and not recommended)

Default Arch configuration

This method will create a .config file for the custom kernel using the default Arch kernel settings. If a stock Arch kernel is running, you can use the following command inside the custom kernel source directory:

Otherwise, the default configuration can be found online in the official Arch Linux kernel package.

Advanced configuration

There are several tools available to fine-tune the kernel configuration, which provide an alternative to otherwise spending hours manually configuring each and every one of the options available during compilation.

Those tools are:

  • make menuconfig : Command-line ncurses interface superseded by nconfig
  • make nconfig : Newer ncurses interface for the command-line
  • make xconfig : User-friendly graphical interface that requires packagekit-qt5 to be installed as a dependency. This is the recommended method — especially for less experienced users — as it is easier to navigate, and information about each option is also displayed.
  • make gconfig : Graphical configuration similar to xconfig but using gtk. This requires gtk2 , glib2 and libgladeAUR .

The chosen method should be run inside the kernel source directory, and all will either create a new .config file, or overwrite an existing one where present. All optional configurations will be automatically enabled, although any newer configuration options (i.e. with an older kernel .config ) may not be automatically selected.

Once the changes have been made save the .config file. It is a good idea to make a backup copy outside the source directory. You may need to do this multiple times before you get all the options right.

Читайте также:  Как читается windows live

If unsure, only change a few options between compilations. If you cannot boot your newly built kernel, see the list of necessary config items here.

Running lspci -k # from liveCD lists names of kernel modules in use. Most importantly, you must maintain cgroups support. This is necessary for systemd. For more detailed information, see Gentoo:Kernel/Gentoo Kernel Configuration Guide and Gentoo:Intel#Kernel or Gentoo:Ryzen#Kernel for Intel or AMD Ryzen processors.

Compilation

Compilation time will vary from as little as fifteen minutes to over an hour, depending on your kernel configuration and processor capability. Once the .config file has been set for the custom kernel, within the source directory run the following command to compile:

Installation

Install the modules

Once the kernel has been compiled, the modules for it must follow. First build the modules:

Then install the modules. As root or with root privileges, run the following command to do so:

This will copy the compiled modules into /lib/modules/ — . For example, for kernel version 4.8 installed above, they would be copied to /lib/modules/4.8.6-ARCH . This keeps the modules for individual kernels used separated.

Copy the kernel to /boot directory

The kernel compilation process will generate a compressed bzImage (big zImage) of that kernel, which must be copied to the /boot directory and renamed in the process. Provided the name is prefixed with vmlinuz- , you may name the kernel as you wish. In the examples below, the installed and compiled 4.8 kernel has been copied over and renamed to vmlinuz-linux48 :

Make initial RAM disk

If you do not know what making an initial RAM disk is, see Initramfs on Wikipedia and mkinitcpio.

Automated preset method

An existing mkinitcpio preset can be copied and modified so that the custom kernel initramfs images can be generated in the same way as for an official kernel. This is useful where intending to recompile the kernel (e.g. where updated). In the example below, the preset file for the stock Arch kernel will be copied and modified for kernel 4.8, installed above.

First, copy the existing preset file, renaming it to match the name of the custom kernel specified as a suffix to /boot/vmlinuz- when copying the bzImage (in this case, linux48 ):

Second, edit the file and amend for the custom kernel. Note (again) that the ALL_kver= parameter also matches the name of the custom kernel specified when copying the bzImage :

Finally, generate the initramfs images for the custom kernel in the same way as for an official kernel:

Manual method

Rather than use a preset file, mkinitcpio can also be used to generate an initramfs file manually. The syntax of the command is:

  • -k ( —kernel ): Specifies the modules to use when generating the initramfs image. The name will be the same as the name of the custom kernel source directory (and the modules directory for it, located in /usr/lib/modules/ ).
  • -g ( —generate ): Specifies the name of the initramfs file to generate in the /boot directory. Again, using the naming convention mentioned above is recommended.

For example, the command for the 4.8 custom kernel installed above would be:

Copy System.map

The System.map file is not required for booting Linux. It is a type of «phone directory» list of functions in a particular build of a kernel. The System.map contains a list of kernel symbols (i.e function names, variable names etc) and their corresponding addresses. This «symbol-name to address mapping» is used by:

  • Some processes like klogd, ksymoops, etc.
  • By OOPS handler when information has to be dumped to the screen during a kernel crash (i.e info like in which function it has crashed).

If your /boot is on a filesystem which supports symlinks (i.e., not FAT32), copy System.map to /boot , appending your kernel’s name to the destination file. Then create a symlink from /boot/System.map to point to /boot/System.map- :

After completing all steps above, you should have the following 3 files and 1 soft symlink in your /boot directory along with any other previously existing files:

  • Kernel: vmlinuz-
  • Initramfs: Initramfs- .img
  • System Map: System.map-
  • System Map kernel symlink

Bootloader configuration

Add an entry for your new kernel in your bootloader’s configuration file. See Arch boot process#Feature comparison for possible boot loaders, their wiki articles and other information.

Источник

MEMDISK

MEMDISK is meant to allow booting legacy operating systems. MEMDISK can boot floppy images, hard disk images and some ISO images.

MEMDISK simulates a disk by claiming a chunk of high memory for the disk and a (very small — typically, 2K) chunk of low (DOS) memory for the driver itself, then hooking the INT 13h (disk driver) and INT 15h (memory query) BIOS interrupts.

Contents

Usage

MEMDISK is an auxiliary module, used in conjunction with a boot loader that can load linux kernels (EXTLINUX / ISOLINUX / PXELINUX / SYSLINUX, grub, grub4dos, grub2, . ). You need a disk image as well as the memdisk file itself. As far as the bootloader is concerned, MEMDISK is the «kernel» and disk image is the initial ramdisk (initrd).

Читайте также:  Windows 10 settings window

The disk image, passed as initrd, can be a compressed zip or gzip file.

In the next examples:

  • hdt.img is a floppy image and
  • hdt.iso is an ISO image containing Hardware Detection Tool (running directly on SYSLINUX)
  • and dosboot.img is a floppy image containing some version of DOS.

Syslinux family

You can use MEMDISK straight off the boot loader command line:

. where hdt.img is the name of the disk image file. In the above example, the memdisk file and the disk image are expected to be present in the appropriate location (e.g. for PXELINUX → on your TFTP server , for ISOLINUX → in the «isolinux» directory on your CD, etc).

Normally, however, you would put something like the following in the configuration file :

GRUB and GRUB4DOS

In your menu.lst file, use something like:

On some systems you may receive an «error 28: Selected item cannot fit into memory» message despite the physical memory being far larger than the requirements of the OS in the image. In this case, try adding an appropriate «uppermem » statement to your grub configuration, e.g. 1G for CorePlus:

Note that the parameter for the (GRUB) uppermem command is interpreted as «allow/show/allocate KiB above the first 1MiB».

GRUB2

Add the following in your config scripts for grub2:

Image types

The image file should contain either:

The disk image can be compressed with zip or gzip.

Floppy images

If the disk image is less than 4,194,304 bytes (4096K, 4 MiB) then it is assumed to be a floppy image and MEMDISK will try to guess its geometry based on the size of the file. MEMDISK recognizes all the standard floppy sizes as well as common extended formats:

A small perl script, included in the MEMDISK directory, can determine the geometry that MEMDISK would select for other sizes; in general, MEMDISK will correctly detect most physical extended formats used, with 80 cylinders or slightly higher.

If your image is larger than 4 MiB and it is a floppy image, you can force MEMDISK to treat it as a floppy image:

Hard disk images

If the image is 4 MiB or larger, then it is assumed to be a hard disk image, and should typically have an MBR and a partition table. The image may optionally have a DOSEMU geometry header; in such case the header is used to determine the C/H/S geometry of the disk. Otherwise, the geometry is determined by examining the partition table, so the entire image should be partitioned for proper operation; it may be divided between multiple partitions, though.

If your image is smaller than 4 MiB and it is a hard disk image, you can force MEMDISK to treat it as a hard disk image:

ISO images

For ISO images, the parameter ‘iso’ must be passed to MEMDISK.

is a more appropriate «APPEND» option. For example, some Windows ISOs need the ‘raw’ option on some PCs.

It is possible to map and boot from some CD/DVD images using MEMDISK. » No-emulation «, «floppy emulation» and «hard disk emulation» ISOs are supported.

The «map» process is implemented using INT 13h — any disk emulation will remain accessible from an OS that uses compatible mode disk access, e.g. DOS and Windows 9x . However, the emulation via INT 13h can’t be accessed from an OS that uses protected mode drivers (e.g. Windows NT/2000/XP/2003/Vista/2008/7. Linux, FreeBSD) once the protected mode kernel drivers take control. If the OS contains drivers for accessing this mapped ISO, or knows how to find the ISO on the disk, there is no booting problem (see the next section).

ISOHYBRID images

If the image is a so-called ISOHYBRID image, you can also treat it as a hard disk image. This is possible because such an image also contains a Master Boot Record (MBR).

To check if your image is ISOHYBRID, run:

For a normal ISO image, the output will look like this:

For an ISOHYBRID image, the output will look like this:

INT 13h access

Not all images will complete the boot process! The following sections describe some cases and possible solutions.

Using INT 13h BIOS calls

Real mode operating systems such as DOS (MS-DOS, FreeDOS, DR-DOS, . ), Windows 95/98/ME that use INT 13h BIOS calls, and boot loaders (the Syslinux family, grub, grub4dos, gujin, gag, mbldr, . ) that use INT 13h to read from disks will successfully complete the boot process with MEMDISK (assuming that there are no BIOS bugs, or software bugs).

Windows NT based

Examples of «Windows NT»-based OS: Windows NT/2000/XP/2003/Vista/2008/7. These Windows versions do not use INT 13h access, except during the start of the booting process (loading only the necessary drivers). Once the protected mode drivers are functional to access the disks, Windows can’t see the memory-mapped drives created by MEMDISK (CD/DVD, hard disk and floppy disk images) and it will fail to complete the boot process.

Читайте также:  Пропала кнопка создать папку windows 10

Examples of Potential Solutions:

Windows drivers

WinVBlock and Firadisk, each one (independently) is a Windows driver that overcomes this problem. The Windows driver detects the MEMDISK-mapped drives (CD/DVD, hard disk and floppy disk images) so Windows can read and write to those disks.

Each of these Windows drivers can do more than detecting MEMDISK-mapped drives.

For more info about WinVBlock and how to build your Windows images: http://reboot.pro/8168/

For more info about Firadisk and how to build your Windows images: http://reboot.pro/8804/

Windows images may need the ‘raw’ parameter on some PCs:

Windows PE based

You can also build a RAMdisk-based Windows PE. RAMdisk-based discs use ramdisk.sys and setupldr.bin files from Windows 2003 Server SP1 source, see:

WIM images

Windows Vista/2008/7 can be booted from a WIM image (loaded from disk via INT 13h).

If you get the following message while booting the ISO:

Linux

The majority of Linux-based ISO images will also fail to work with MEMDISK ISO emulation. Linux distributions require kernel and initrd files to be specified. As soon as these files are loaded, the protected mode kernel driver(s) take control and the virtual CD will no longer be accessible. If any other files are required from the CD/DVD, they will be missing, resulting in boot error(s).

Linux distributions that only require kernel and initrd files will fully function via ISO emulation, as no other data needs access from the virtual CD/DVD drive once they have been loaded; the boot loader has read all necessary files to memory by using INT 13h, before booting the kernel.

Examples of Potential Solutions: There are ways to get around the problem of not finding the required files:

Kernel parameters

Some distributions allow you to pass/append an extra parameter to the kernel (append) line, which tells the init scripts to look for an ISO file on a disk. Some distros require for the drive and partition number (where the ISO is stored) to be explicitly specified, while others will search each partition for the specified filename.

Such parameter is distro-specific, so look at the docs of your distro. Some popular ones:

memdiskfind and kernel modules

There is also another solution, which requires the phram and mtdblock kernel modules and the memdiskfind utility of the Syslinux package ([bios/]utils/memdiskfind) . memdiskfind will detect the MEMDISK-mapped image and will print the start and length of it in a format phram understands:

This will create a /dev/mtdblock0 device, which should be the ISO image, and should be mountable.

If your image is bigger than 128MiB and you have a 32-bit OS, then you have to increase the maximum memory usage of vmalloc, by adding:

to your kernel parameters.

memdiskfind can be compiled with the klibc library (instead of the glibc C library) to get a much smaller binary for use in the initramfs:

More info and links to the Arch Linux implementation: memdisk driver for linux

Parameters and options

  • #Image_geometry_and_type:
  • #Memory_access_method:
  • #Write-protect_images:
  • #Hide_real_drives:
  • #EDD BIOS Enhanced Disk Drive Services:
  • #PXE:
  • #Pause Read MEMDISK messages:
  • #Stack_size:

Image geometry and type

You can also manually specify the geometry and type of the image with the following command line options:

Memory access method

MEMDISK normally uses the BIOS «INT 15h mover» API to access high memory. This is well-behaved with extended memory managers which load later. Unfortunately, it appears that the «DOS boot disk» from WinME/XP *deliberately* crashes the system when this API is invoked. The following command-line options tell MEMDISK to enter protected mode directly, whenever possible:

Your image might work fine without those parameters on some PCs or virtual machines, but might fail to boot on other PCs. In this situation, adding ‘raw’ will normally solve your problem.

Write-protect images

The MEMDISK-mapped (floppy or hard) disk is normally writable (although, of course, there is nothing backing it up, so it only lasts until reset). You can mimic a write-protected disk by specifying the command line option:

Hide real drives

Some systems without a floppy drive have been known to have problems with floppy images. To avoid such problems, first of all make sure you don’t have a floppy drive configured on the BIOS screen. If there is no option to configure that, or that doesn’t work, you can use:

MEMDISK supports BIOS Enhanced Disk Drive Services (EDD/EBIOS). On hard disks, EDD is set on by default, but not on floppy disks. This can be controlled with the options:

If you’re booting DOS over the network using PXELINUX, you can use the «keeppxe» option and use the generic PXE (UNDI) NDIS network driver, which is part of the PROBOOT.EXE distribution from Intel: [1]

Pause

To view the messages produced by MEMDISK, use:

Stack size

The following option can be used to set the real-mode stack size. The default is 512 bytes, but if there is a failure it might be interesting to set it to something larger:

Источник

Оцените статью