Create a mini linux

Source: Internet
Author: User
Tags ide hard drive
Make yourself a mini-linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: cexoyq

Hda1 ---- newly installed RH9
Hdc1 ---- 64 m hard disk, the generated small linux is installed on this disk, has not been partitioned and formatted.
Environment: ms virtual machine version 5.1.

Re-compile the kernel first and remove all unnecessary ones. In this way, the module only has a few MB. Compiled and generated
Kernel: vmlinuz-2.4.20-8custom
Initrd: initrd-2.4.20-8custom.img (this doesn't work, using it in GRUB won't start, prompting you to add the init Kernel Parameter .)
Loadable module:/lib/modules/2.4.20-8 custom

Fdisk/dev/hdc partition, activate it, save it, and exit.
Mkext2fs/dev/hdc1
Mkdir/mnt/hd2
Mount/dev/hdc1/mnt/hd2
Mkdir/mnt/hd2/boot/grub-p
Cp/boot/vmlinuz.2.4.20-8 custom/mnt/hd2/boot/-
Cp/boot/initrd.2.4.20-8 custom/mnt/hd2/boot/-
Cp/boot/grub/stage? /Mnt/hd2/boot/grub/-
Cp/boot/grub. conf/mnt/hd2/boot/grub/-
Cp/boot/grub/e2fs_stage00005/mnt/hd2/boot/grub/-
Then run: grub
Root (hdc1, 0)
Setup (hdc)
Quit
In this way, the small hard disk can be started (but the kernel will die after it is started ). But remember to configure grub. conf and change it:
Default = 1
Timeout = 10
Title linux
Root (hd0, 0)
Kernel/boot/vmlinuz-2.4.20-8custom ro root =/dev/hda1
Initrd cannot be added. Otherwise, errors may occur. Can anyone tell me what they know? Cexoyq1020@163.com, thanks.

File System Creation
Create a directory:/home,/mnt,/proc,/lib,/sbin,/bin,/root,/etc,/dev
Required file:/dev
/Dev/console
The system console device is very important.
/Dev/fd0
First soft drive
/Dev/hda
/Dev/hda [1-8]
IDE hard drive and partition
/Dev/initctl
It is actually a FIFO device, which is related to init (used for communication between the new init and the original init when the running level is switched)
/Dev/initrd
Initial RAM disk
/Dev/input
(Directory) Input core (including game lever, mouse, etc)
/Dev/kmem
Kernel virtual memory
/Dev/loop [0-7]
Loopback device
/Dev/mem
Access physical memory
/Dev/null
NULL Device
/Dev/psaux
PS/2 mouse
/Dev/ptmx
UNIX98 PTY master
/Dev/pts
(Directory) UNIX98 PTY slaves
/Dev/ptyp [0-7]
Master pseudo-terminal device (used for remote logon)
/Dev/ram [0-7]
/Dev/ramdisk
/Dev/ram
RAM Disk device. At least/dev/ram0 is required to apply the initrd mechanism.
The/dev/ramdisk link to/dev/ram0 is reserved to be compatible with earlier versions of the kernel.
/Dev/ram links to/dev/ram1.
/Dev/random
Random number generator
/Dev/sda
/Dev/sda [1-8]
SCSI disks and partition Devices
/Dev/shm
Shared memory device
/Dev/policty
The symbolic link to the system tty device, generally tty0.
/Dev/tty
Current TTY device
/Dev/tty [0-7]
Virtual console)
/Dev/ttyp [0-7]
Pseudo Terminal Slave Device
/Dev/ttyS0
/Dev/ttyS1
Serial Port (COM1 and COM2)
/Dev/urandom
Random number generator with faster speed and poor security
/Dev/zero
Zero device, read 0 only
Required file:/etc
Etc/default
(Directory) default settings of a command (such as useradd) (man useradd (8 ))
/Etc/ld. so. cache
Generated by the ldconfig command according to the/etc/ld. so. conf file
/Etc/ld. so. conf
Library file path configuration file. The ldconfig command generates/etc/ld. so. cache based on the configuration file
/Etc/localtime
Local time and time zone settings
/Etc/login. defs
Global default settings
/Etc/fstab
File System list (man fstab (5 ))
/Etc/group
Group files (man group (5 ))
/Etc/hosts
List host names and IP addresses (man hosts (5 ))
/Etc/init. d
Symbolic Link to/etc/rc. d/init. d
/Etc/initlog. conf
Initlog configuration file (man initlog (8 ))
/Etc/inittab
Init configuration file (man inittab (5 ))
/Etc/ioctl. save
This file contains the serial port and terminal parameters used for single-user mode, because these parameters are set by getty,
Getty is not run in single-user mode. Therefore, this file is used to save parameters. Single-user mode for System Security
This is a threat. We should disable the single-user mode. Therefore, this file does not have to be copied.
.
/Etc/issue
Logon Information and Identity file (man issue (5 ))
/Etc/modules. conf
Module configuration file (man modules. conf (5 ))
/Etc/mtab
List of mounted file systems (man mount (8 ))
/Etc/nsswitch. conf
Name Service Switch configuration file (configuration Name Service data source and query order) (man nss
Witch. conf (5 ))
/Etc/pam. d
Directory for storing the PAM Configuration File (for more information about PAM, see section 5.5)
/Etc/passwd
User Password File (man passwd (5 ))
/Etc/profile
System environment variables and logon configuration files
/Etc/rc. d
Directory where the startup script is placed
/Etc/services
List available network services and their ports (man services (5 ))
/Etc/termcap
Terminal function database (man termcap (5 ))
In addition, files related to network parameters must be copied one by one. Otherwise, you have to manually configure the network parameters.

Required file:/lib
Use the "ldd command name" to obtain the LIB library required by the command, and then copy it (create a directory ).

/Bin and/sbin: copy the corresponding files as needed. I copied iptables, tc, and so on.

Required file:/lib/modules
After the kernel is re-compiled, the entire "2.4.20-8 custom" directory is copied. Because of the cropping, I only have 5 MB, which is not very usable. This is very important, network-driven,
Iptables and tc depend on it.

Download busybox and compile and install it. Http://www.busybox.net/downloads
Download the latest busybox-1.1.2.tar.bz2 to/root
Unzip and enter the busybox-1.1.2
Make menuconfig ----- select the command you need and copy it from the source RH9. However, copying LIB is troublesome. Remember to select static compilation and init.
Make
Makeinstall
Then, generate the "_ install" directory under the directory, and copy all directories and files to the hard disk.

Reconfigure/etc/inittab,/etc/fstab,/etc/rc. d/rc. sysinit
/Etc/inittab
: Sysinit:/etc/rc. d/rc. sysinit
: Askfirst:-/bin/sh
Tty2: askfirst:-/bin/sh
Tty3: askfirst:-/bin/sh
Tty4: askfirst:-/bin/sh
: Restart:/sbin/init
: Ctrlaltdel:/sbin/reboot
: Shutdown:/bin/umount-a-r
: Shutdown:/sbin/swapoff-

/Etc/fstab
Proc/proc defaults 0 0

/Etc/rc. d/rc. sysinit
#! /Bin/sh
Mount-
Add your own startup script.

Then shut down and set the small hard disk to the first hard disk in the Virtual Machine (hd0, 0)
You can see that your mini-linux is running.

Problem:
After the system is started, the NIC Driver is loaded (because I compiled it in the kernel), but "ifconfig eth0" cannot see its configuration information, which may be not configured,
All the configuration files/etc/have been copied. You can only use "ifconfig eth0 10.0.0.103" to configure the network.

The initrd parameter cannot be used in grub. If the error message is displayed, the init Kernel Parameter must be added, but the init parameter cannot be added. Remove initrd and you can start it. Very strange.
Ask experts for advice.
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.