Create a small linux system named mylinux

Source: Internet
Author: User
Make a small linux system named mylinux-general Linux technology-Linux programming and kernel information. For more information, see the following. Use the grub boot program to guide the compiled Kernel File bzImage, convert the file system into a ramdisk image file, and load the image file in the memory to inject the file system; the command generates the bin and sbin files by compiling busybox. Note:

Kernel File + File System Image File + grub boot program <= 1440 K

Detailed steps:

1. Install grub on a floppy disk)

The procedure is as follows:

# Mke2fs/dev/fd0

An ext2 file is created.

# Mount/dev/fd0/mnt/floppy

Now, create some directories and copy some key files to the floppy disk:

# Mkdir/mnt/floppy/boot

# Mkdir/mnt/floppy/boot/grub

# Cp/boot/grub/stage1/mnt/floppy/boot/grub

# Cp/boot/grub/stage2/mnt/floppy/boot/grub


Run the grub command

At the grub> prompt, enter:

Grub> root (fd0)

Grub> setup (fd0)

Grub> quit

Boot Disk complete.


2. Configure busybox

Create a directory to store data:

# Mkdir/floppylinux

Use make menuconfig to configure busybox

# Cpbusybox-1.00.tar.gz/floppylinux

# Cd/floppylinux

# Tar xvfz busybox-1.00.tar.gz

# Cd busybox-1.00

# Make menuconfig

The following are functional options that need to be compiled into busybox,


General Configuration options

Show verbose applet usage messages

Runtime SUID/SGID configuration via/etc/busybox. conf

Build Options

Build BusyBox as a static binary (no shared libs)

Installation Options

Don't use/usr

Other options are some basic linux Command Options default

After configuration, exit and save.


Compile and install busybox


# Make

# Make install

After compilation, generate the subdirectory _ install in the busybox directory. The content is as follows:

Drwxr-xr-x 2 root 4096 November 24 15:28 bin

Lrwxrwxrwx 1 root 11 November 24 15:28 linuxrc-> bin/busybox

Drwxr-xr-x 2 root 4096 November 24 15:28 sbin

The executable file busybox is in the bin directory, and all others point to its symbolic link.


3. Create a root file system

Create a temporary directory, which is a floppy File System

# Mkdir/tmp/floppy-linux

Copy the files in the _ install directory in busybox:

# Cp./_ install/tmp/floppy-linux? R


# Cd/tmp/floppy-linux

# Mkdir dev etc/init. d proc mnt tmp var

# Chmod 755 dev etc/init. d bin mnt tmp var

# Chmod 555 proc

# Cd dev

# Mknod tty c 5 0

# Mknod console c 5 1

# Chmod 666 tty console

# Mknod tty0 c 4 0

# Chmod 666 tty0

# Mknod ram0 B 1 0

# Chmod 600 ram0

# Mknod fd0 B 2 0

# Chmod 600 fd0

# Mknod null c 1 3

# Chmod 666 null


Create the startup configuration file:

/Etc/inittab,

/Etc/init. d/rcS,

/Etc/fstab

/Boot/grub. conf

/Boot/menu. lst

Where

# Ln? S grub. conf menu. lst

Initab:

: Sysinit:/etc/init. d/rcS

: Askfirst:/bin/sh


RcS:

#! /Bin/sh

Mount? A

# Chmod 755 rc. sysinit


Fstab:

Proc/proc defaults 0 0


Grub. conf:

Timeout 10

Default 0

Title FloppyLinux root (fd0) kernel/boot/bzImage initrd/initrd.img.gz


4. Create an image file for Ramdisk:

# Dd if =/dev/zero of =/dev/ram1

Dd: Writing '/dev/ram1': the device has no space.

Read 8193 + 0 blocks

Output 8192 + 0 blocks

# Mke2fs-m0/dev/ram1

# Mkdir/mnt/ram

# Mount/dev/ram1/mnt/ram

Copy the previously prepared floppylinux root file system to ram1.

# Cp-R/tmp/floppy-linux/*/mnt/ram

# Umount/dev/ram1

# Dd if =/dev/ram1 of =/tmp/floppy-linux/initrd. img

# File initrd. img

Initrd. img: Linux rev 1.0 ext2 filesystem data

Use the loop device to re-mount it to the file system:

# Mount-o loop initrd. img/mnt/ram/

View the content in/mnt/ram, which is exactly the same as that in/tmp/floppy-linux /.

# Ls/mnt/ram

Bin dev etc lost + found mnt proc sbin tmp var

# Umount/mnt/ram

Compress initrd. img impression files

# Gzip-v9 initrd. img

Initrd. img: 90.1% -- replaced with initrd.img.gz

View the compressed size:

# Ls-lh initrd.img.gz

406 K


5. Compile the linux Kernel

# Cp linux-2.4.20.bz2/usr/src/

# Cd/usr/src

# Tar xfvj linux-2.4.20.bz2

# Ln-s linux-2.4.20 linux

Go to the linux source code directory:

# Cd linux

Clear source code tree:

# Make mrproper

Run the configuration program:

# Make menuconfig


Code maturity level options

Select N first. If you have configured the regular items and want to add framebuffer support, select Y. If you do not select Y in code maturity level options, you cannot configure framebuffer.

Loadable module support

Select N. In order to simplify system creation, I do not select support for loading kernel modules in this project.

Processor type and features

Select worker CPU in processor family

Select N for all other options.

General setup

Networking support select Y

Select Y for PCI support

System V ipc select Y

Select Y for systrl support

Kernel support for ELF select Y

You can select N for other content,

Chnology devices (MTD)

Parallel port support

Plug and Play configuration

Select N for all the preceding three items.

Block devices

Normal floppy disk support

Loopback device support

RAM disk support

Initial RAM disk (initrd) support

Per partition statics in/proc/partitions

Select Y for the preceding items, and N for all others.

Multi-device support (RAID and LVM)

Cryptography support (CryptoAPI)

Select N for all the two items

Networking options

In this project, you only need to compile the following items into the kernel:

Packet socket: mmapped IO

TCP/IP networking

Telephony Support select N

ATA/IDE/MFM/RLL support

Select Y, and then the 'ide, ATA, and ATAPI Block devices' button will be activated.

Select Y for the following items, and the rest can be N.

Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support

Include IDE/ATA-2 DISK support

Auto-Geometry Resizing support

Include IDE/ata cdrom support


SCSI support

Fusion MPT device support

IEEE 1394 (FireWire) support

I2O device support

Select N for all

Network device support

Select Y

Click Ethernet (10 or 100 Mbit) and select the NIC Driver (Reltek8139)

Amateur Radio support

IrDA (infrared) support

ISDN subsystem

The Old CD-ROM drivers (not SCSI, not IDE)

Input core support

Select N for all

Charcter devices

Except Virtual terminal and Support for console on terminal, select N

Multimedia devices

Crypto Hardware support

Select N.

File sytems

Three of them are selected:

/Proc file system support.

Second extended fs support basic file system of BabyLinux.

CD for ISO 9660 CDROM filesytem support.

Console drivers

. Select Y for all the first three,

The Frame-buffer support button is gray and cannot be selected. Don't worry. Return to the first major option:

Code maturity level options select Y to activate this button.

Select Y for the following options:

Support for framebuffer devices

Vesa vga graphics console

Support only 8 pixels wide fonts

Select N for all the remaining items.

Save and exit. The configuration program will automatically generate a hidden configuration file. config


# Make dep

# Make bzImage

BzImage is 654 K


6. Integrated boot disk

# Cp bzImage/mnt/floppy/boot

# Cp/tmp/floppy-linux/initrd.img.gz/mnt/floppy

All files (folders) are as follows:


/Lost + found/

/Boot/

/Boot/grub/

/Boot/grub/stage1

/Boot/grub/stage2

/Boot/grub/menu. lst

/Boot/grub. conf

/Boot/bzImage

/Initrd.img.gz


5. problems encountered in the experiment and summary

1. When creating the boot disk, run the grub command to go To the grub interface and run:

Grub> setup (fd0)

The result may sometimes be an error. It may be a problem with the floppy disk.

2. After a floppy disk is created, restart the machine. An error may occur when grub starts to boot:

Error 16: Inconsistent filesystem strutwre

This is also a problem with floppy disks.

3, in the compilation of the kernel, sometimes may not pass, in Redhet9.0 (kernel-2.4.20) with the gcc-3.3.3 can be compiled through the 2.4.20 version of the kernel, but in the Fedora Core 2 with gcc-3.4.2 will not work, may be the gcc version problem.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.