User-configured Linux kernel

Source: Internet
Author: User

User Mode Linux is a Linux version that can be started in the client state, and the latest version of the Linux kernel has been supported. This allows us to use the latest Linux kernel on systems similar to OpenVZ virtualization technology, and can be started under non-root users.

Use

Debug kernel modules, network experiments, experience the latest features ...

Tool Code Preparation

Installing the kernel Compilation tool
apt-get install build-essential libncurses5-dev
and the calculator gadget BC (used when compiling): Apt-get install BC
Download kernel source, select newer version:
wget HTTPS://CDN.KERNEL.ORG/PUB/LINUX/KERNEL/V4.X/LINUX-4.14.2.TAR.XZ
Extractxz -d linux-4.*.tar.xz && tar xf linux-4.*.tar
You can also download the corresponding kernel patches, or regardless.

Compiling the user mode kernel

Configuration schema for user mode:
CD linux-4.*
make defconfig arch=um # Configure default properties
make Menuconfig Arch=um # go to the Configuration menu
Enter Uml-speci FIC options→ Select Force a static link to be able to connect statically (including glibc, etc.)
Enter Networking support→networking options→tcp:advanced congestio N Control page, move to BBR TCP, note that you need to press Y when entering the TCP subdirectory tcp:advanced congestion control to select. Then BBR TCP is selected. Enter the Default TCP congestion control selected BBR below. Always ESC, save to exit.
However, in order to compile the smallest and meet the BBR needs of the kernel, using the minimum configuration as modified below, first save the following content as Kernel-mini.config file (if you need to compile 64-bit kernel, then directly the beginning of the Config_ 64bit=n This line can be removed, if the dynamic compilation, remove Config_static_link):
Kernel-mini.config

config_64bit=nconfig_binfmt_elf=yconfig_binfmt_script=yconfig_core_dump_default_elf_headers=nconfig_hostfs= yconfig_mconsole=yconfig_magic_sysrq=yconfig_kernel_stack_order=1config_swap=nconfig_sysvipc=yconfig_expert= Nconfig_embedded=nconfig_slub_debug=nconfig_block=yconfig_lbdaf=yconfig_devtmpfs=yconfig_devtmpfs_mount= Yconfig_blk_dev_bsg=nconfig_blk_dev=yconfig_blk_dev_ubd=yconfig_blk_dev_loop=yconfig_iosched_deadline=yconfig_ Iosched_cfq=nconfig_default_iosched= "Deadline" Config_netdevices=nconfig_stderr_console=yconfig_ssl=yconfig_ Null_chan=yconfig_port_chan=yconfig_pty_chan=yconfig_tty_chan=yconfig_xterm_chan=yconfig_unix98_ptys=yconfig_ ext2_fs=yconfig_proc_fs=yconfig_proc_sysctl=yconfig_tmpfs=yconfig_sysfs=yconfig_sched_debug=nconfig_net= Yconfig_unix=yconfig_inet=yconfig_tcp_cong_advanced=yconfig_tcp_cong_cubic=yconfig_tcp_cong_bbr=yconfig_ default_bbr=yconfig_default_tcp_cong= "BBR" Config_ipv6=nconfig_syn_cookies=yconfig_net_sched=yconfig_net_sch_ qfq=yconfig_net_sch_codel=yconfig_net_sCh_fq_codel=yconfig_net_sch_fq=yconfig_net_sch_fifo=yconfig_uml_net=yconfig_uml_net_tuntap=yconfig_uml_net_vde =yconfig_debug_kernel=nconfig_magic_sysrq_default_enable=0x1
    • Enabled the UML Hostfs and Mconsole and so on very useful function;
    • Support UML UBD block device, also opened the loop device support, removed the RAMDisk and other useless equipment support;
    • Support Proc, SYSFS, Tmpfs and other virtual file systems, the real file system only retains the ext2 support, need to ext3 or EXT4 support friends, please modify their own;
    • Turn on BBR and set as default congestion control algorithm, also need to enable Fair Queue Packet Scheduler for BBR;
    • Remove the support for IPV6, remove all the network card device drivers;
    • Almost all kernel debugging information is removed.
    • Open Tap Network connection mode, remove the VDE network connection mode. The VDE switching device is a network switching device that is simulated by software. If you want to turn on Apt-get install Libvdeplug-dev, refer to Http://blog.sina.com.cn/s/blog_3e4774e30101qyde.html

To generate a new kernel configuration file using Mini.config:
make ARCH=um allnoconfig KCONFIG_ALLCONFIG=kernel-mini.config
The new configuration will be written to the. config file
Use the minimized configuration described above to make ARCH=um vmlinux -j$(nproc) compile.
Dynamic Link compiled by vmlinux about 4.7M; statically linked 5.3M, strip vmlinux followed by 4.4M after the debug symbol was removed.

$ ldd vmlinux        not a dynamic executable$ file vmlinuxvmlinux: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), statically linked, for GNU/Linux 2.6.24, stripped

setting in. config CONFIG_STATIC_LINK=y will be statically compiled

You can view the kernel configuration used at compile time by compiling the vmlinux:
./vmlinux --showconfig

Rootfs

Use BusyBox to do rootfs:https://busybox.net/
Configuration compilation:
Make Defconfig
Make Menuconfig
Select Busybox settings->1, build options->, select [*] Build Busybox as a static binary (no shared libs);
If the compile-time dynamic link, compiled BusyBox less than 1M, statically compiled 2.5M.

Make-j compiling
Make Config_prefix=~/root install to ~/root folder
Copy etc directory: Cp-r examples/bootfloppy/etc ~/root

Rootfs File System

Download the Rootfs file system that can run the kernel, which uses the arch file system image (140M) and, of course, a small file system such as Alpine or Ubuntu.
wget http://mirror.rackspace.com/archlinux/iso/latest/archlinux-bootstrap-2017.11.01-x86_64.tar.gz
Tar xzf archlinux-bootstrap-*.tar.gz
MV Root.x86_64 Root

Control UML Systems

If you need to log in to the UML system, you can first use the Uml_mconsole command to get the virtual terminal assigned to the UML system (the second parameter is the UML system ID):
uml_mconsole $uml_id config con0
OK PTS:/DEV/PTS/2

Then use the screen command to connect to the virtual terminal (the default is nothing, you need to press ENTER terminal to come out):
screen /dev/pts/2

If you want to shut down the entire UML system directly in the OpenVZ host system, it is also very simple:
uml_mconsole shadowsocks halt

Follow-up work

Remember to pack backups after the operating system is ready.

Do not want to toss directly with Alpine rootfs good, root bad environment has been configured:
The official website of the minirootfs inside the lack of OPENRC and other procedures, http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/x86_64/ Alpine-minirootfs-3.7.0-x86_64.tar.gz
This version is recommended: http://uk.images.linuxcontainers.org/images/alpine/

Run Times Error:
Checking prot_exec mmap In/dev/shm ... Operation not permitted
/DEV/SHM must is not mounted noexec

Workaround:

Mkdir/tmp/uml
Chown ROOT.ROOT/TMP/UML
chmod 777/tmp/uml
Export TMPDIR=/TMP/UML

User-configured Linux kernel

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.