Compile and install a small kernel

Source: Internet
Author: User
Tags dropbear

Preparation environment: host machine, target machine, Hard Disk

On the host machine:

First, prepare a hard disk SDB on the host machine. The size is 10 Gb. It is divided into two zones: sdb1 (50 m) and sdb2 (512 m ).

Format the disk

# mke2fs -t ext4 /dev/sdb1# mke2fs -t ext4 /dev/sdb2

Separate mounting

# mount /dev/sdb1 /mnt/boot/ # mount /dev/sdb2 /mnt/sysroot/

Create a grub File

# grub-install --root-directory=/mnt /dev/sdb

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/47/BF/wKioL1P_OQ6ApeXAAAElma8fCIs723.jpg "Title =" image 002.png" alt = "wkiol1p_oq6apexaaaelma8fcis723.jpg"/>

# Cd/mnt/boot/edit the grub configuration file # Vim grub/grub. conf

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/47/BF/wKioL1P_OSWDdoDwAABd1Rb7kPQ418.jpg "Title =" image 003.png" alt = "wkiol1p_oswddodwaabd1rb7kpq418.jpg"/>

# cd /mnt/sysroot/

Create directory

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/47/BD/wKiom1P_OCCAief9AABqrupx8UE412.jpg "Title =" image 004.png" alt = "wkiom1p_occaief9aabqrupx8ue412.jpg"/>

Edit # Vim/sbin/init

Echo-e "Welcome to Zhou \ 033 [33 med \ 033 [0 m Linux"
Mount-n-t proc/proc
Mount-n-t sysfs/sys
Mount-n-t devtmpfs NONE/dev
Mount-n-o remount, RW/dev/sda2/
/Bin/bash

Grant the execution permission

# chmod +x sbin/init


Run the script bincp. Sh Copy command:

[[Email protected] ~] # Bash bincp. Sh
Plz enter a command: Bash
Plz enter a command: Mount
Plz enter a command: umount
Plz enter a command: ls
Plz enter a command: Kill
Plz enter a command: ifconfig
Plz enter a command: Quit

 

Decompress the kernel

# tar xf linux-3.13.6.tar.xz# cd linux-3.13.6# make allnoconfig# make menuconfig

Kernel options to be manually selected
64-kit Kernel
Ceneral setup
--> Local version-append to kernel release
--> System V IPC
Enable loadable module support
--> Module unloading
Enable the block layer
--> Block layer SG support v4
Processor type and features
--> Hierarchical Ric multi-processing support
--> Processor family
--> Core 2/newer Xeon
--> Multi-core scheduler suppor
Bus options (pCI etc .)
--> PCI support
Executable file formats/emulations
--> Kernel support for elf Binaries
--> Kernel support for scripts starting #!
Networking Support
--> Networking options
--> TCP/IP networking
Device Drivers
--> Generic driver options
--> Maintain a devtmpfs filesystem to mount at/dev
--> Automount devtmpfs at/dev, after the kernel mounted the rootfs
--> SCSI Device Support
--> SCSI Device Support
--> SCSI disk support
--> Fusion MPT Device Support
--> Fusion MPT scsihost drivers for Spi
--> Fusion MPT logging facility
--> Network device support
--> Ethernet Driver Support
--> Intel Devices
--> Intel (r) Pro/1000 Gigabit Ethernet support
--> Intel (r) Pro/1000 PCI-Express Gigabit Ethernet support
--> Input Device Support
--> Mouse Interface
--> Keyboards
--> Mice
--> USB support
--> Xhci HCD (USB 3.0) Support
--> Ehci hcd (USB 2.0) Support
--> Ohci hcd (USB 1.1) Support
--> Uhci HCD (most intel and via) Support
File Systems
--> The extended 4 (ext4) filesystem

# make –j 4

Copy bzimage

# cp arch/x86/boot/bzImage /mnt/boot/

Then, put the disk into the target machine. Can the experiment be started normally?

 

# make menuconfig    # make -j 3       # make install             # cp _install/* /mnt/sysroot       # ls /mnt/sysroot/              clipboard[54] # cp /root/busybox-1.22.1/_install/* /mnt/sysroot/ -r

Create a root file system for the target.

# cd /mnt/sysroot # mkdir -pv boot dev etc/{rc.d,sysconfig,profile.d} home/{gentoo,fedora,test,}  proc root sys usr/{bin,sbin,local,lib,lib64} # chown gentoo.gentoo home/gentoo       # chown test.test  home/test # chown fedora.fedora home/fedora

Configuration File

# vim /mnt/boot/grub/grub.conf


Timeout 3
Default 0
Title nihao Linux
Root (hd0, 0)
Kernel/bzimage Ro root =/dev/sda2


Inittab of the physical console:
: Sysinit:/etc/rc. d/rc. sysinit
Console: respawn:-/bin/sh
: Ctrlaltdel:/sbin/reboot
: Shutdown:/bin/umount-a-r


Inittab on the user logon Interface
: Sysinit:/etc/rc. d/rc. sysinit
: Respawn:/sbin/Getty 19200 tty1
: Respawn:/sbin/Getty 19200 tty2
: Respawn:/sbin/Getty 19200 tty3
: Respawn:/sbin/Getty 19200 tty4
: Respawn:/sbin/Getty 19200 tty5
: Respawn:/sbin/Getty 19200 tty6
: Ctrlaltdel:/sbin/reboot
: Shutdown:/bin/umount-a-r

 

# vim /mnt/sysroot/etc/fstab           /dev/sda2 / ext4 defaults 0 0    /dev/sda1 /boot ext4 defaults 0 0    proc /proc proc defaults 0 0    sysfs /sys sysfs defaults 0 0

 

# vim /mnt/sysroot/etc/rc.d/rc.sysinit


#! /Bin/sh
#
Echo-e "Welcome to \ 033 [34mwukui \ 033 [0 m Linux"
Echo "remounting root filesystem"
Mount-n-o remount, RW/dev/sda2/
Echo "Mount all filesystem"
Mount-
Echo "create Device File"
Mdev-S
Echo "set hostname is $ hostname"
[-R/etc/sysconfig/network] & source/etc/sysconfig/Network
[-Z "$ hostname"] & hostname $ hostname | hostname localhost
Export PS1 = '[\ [email protected] \ H \ W] \ $'

 

# vim  /mnt/sysroot/etc/passwd


Root: X: 0: 0: Root:/root:/bin/sh
Fedora: X: 501: 501:/home/Fedora:/bin/sh
Test: X: 502: 502:/home/test:/bin/sh


# Vim/mnt/sysroot/etc/group
Root: X: 0:
Fedora: X: 501:
Test: X: 502:
# OpenSSL passwd-1-salt 'openssl rand-hex 4'
Password:
$1 $ fc73284e $ q/ntg8fkysasdbzjp/sakjo


# Vim/mnt/sysroot/etc/shadow
Root: $1 $ fc66576e $ q/ntg4okyue0bzjp/uh4t0: 16272: 0: 99999: 7 :::
Fedora: $1 $ fc66576e $ q/ntg4okyue0bzjp/uh4t0: 16302: 0: 99999: 7 :::
Test: $1 $ fc66576e $ q/ntg4okyue0bzjp/uh4t0: 16302: 0: 99999: 7 :::
# Chmod 600/mnt/sysroot/etc/shadow
# Vim/mnt/sysroot/etc/sysconfig/Network
Hostname = mylinux
 

Provide dropbaer
Compile

#./Configure -- prefix =/usr/local/dropbear
# Make Programs = "dropbear dbclient dropbearkey dropbearconvert SCP"
# Make Programs = "dropbear dbclient dropbearkey dropbearconvert SCP" Install
# Cd/usr/local/dropbear/
# Ls bin/
Clipboard [55]


# Ls sbin/


Key File

# Bin/dropbearkey-t dss-F/etc/dropbear/dropbear_dss_host_key # bin/dropbearkey-t rsa-s 2048-F/etc/dropbear/dropbear_rsa_host_key # ll/etc/dropbear/ clipboard [57] # sbin/dropbear-P 22022-e-f front-end clipboard [58] # SS-tnlp | grep 22022 clipboard [59] Test clipboard login in xshell [60] start porting # Path =/usr/local/dropbear/bin /: /usr/local/dropbear/sbin /: $ PATH clipboard [61] clipboard [62] # mkdir/mnt/sysroot/etc/dropbear # dropbearkey-t dss-F/mnt/sysroot/etc/dropbear/dropbear_dss_host_key # dropbearkey- t RSA-s 2048-F/mnt/sysroot/etc/dropbear/dropbear_rsa_host_ke # mkdir-PV/mnt/sysroot/var/run dropbear # cp/etc/shells/mnt/sysroot /etc # echo/bin/ash>/mnt/sysroot/etc/shellsdropbare nsswitch dependent on at startup # cp/etc/nsswitch. conf/mnt/sysroot/etc # cp-a-d/usr/lib64/libnsspem. so/usr/lib64/libnsssysinit. so/usr/lib64/libnssutil3.so/mnt/sysroot/usr/lib64 # cp-a-d/lib64/libnss_files */mnt/sysroot/lib64 # cp-a-d/usr /lib64/libnss3.so/usr/lib64/libnss_files.so/mnt/sysroot/usr/lib64 automatic mounting upon startup # echo "devets/dev/PTS devpts gid = 5, mode = 620 0 0 ">/mnt/etc/fstab # Vim/mnt/sysroot/etc/rc. d/RC. sysinit mkdir/dev/PTS placed in front of Mount-a clipboard [63] # Vim/mnt/sysroot/etc/rc. d/RC. sysinit/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0/sbin/ifconfig eth0 192.168.127.53 netmask 255.255.255.0 export Path =/usr/local/dropbear/bin:/usr/local/dropbear/sbin: $ path/usr/local/dropbear/sbin/dropbear-P 22


Compile and install a small kernel

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.