U disk to start Linux

Source: Internet
Author: User

U disk to start Linux
1. Install grub to the USB flash drive
1. Use the fdisk tool provided by Linux to format the USB flash disk as the boot disk.
1), => fdisk-l view the mount point of the USB flash disk
My USB flash drive is mounted to/dev/SDC, And the boot option has a serial number *, which indicates that my USB flash drive is not a boot disk.
2), => fdisk/dev/SDC to enter fdisk, format the USB flash disk
A. Run Command m to view available commands and instructions:
==> M
B. Enter the following command in sequence to create a partition:
==> N adds a new partition;
=> P: set this partition as the primary partition;
=> Partition 1 is 1;
==> 1 The first cylindrical Number of the partition is 1;
==> 999 M partition large limit 999 m;
C. Set the new Shard to the active shard.
==> A activates the partition command;
=> 1 activate the created partition 1;
Run the p command to view the partition table. * is displayed under the boot option, indicating that the partition has been activated.
D. Write and exit the sail Partition Table
==> W
2. format the fan U disk in ext2 format
=> Umount/dev/sdc1 unmount the USB flash disk first;
=> Mke2fs/dev/sdc1 format the USB flash disk;
3. Install grub
=> Mount/dev/sdc1/mnt
=> Mkdir/mnt/boot
=> Mkdir/mnt/boot/GRUB
=> CP/boot/GRUB/stage */mnt/boot/GRUB/
=> Grub
==> Root (hd2, 0)
==> Setup (hd2)
In bin :( hd2, 0), hd2 represents my USB flash drive, and 0 represents the first partition. different operating systems may be different. If the installation is successful, the following message is displayed:
4. Create the configuration file grub. conf In the grub directory.
=> Vim/mnt/boot/GRUB/grub. conf
Write the following content into the file:
Default 0
Timeout 15
Title Linux
Kernel/bzimage
Initrd/image.gz
Use WQ to save the configuration file.
Ii. Compile the kernel
1. Prepare the following software packages before Compilation: Build-essential, libcurses5-dev,
Mkinitramfs, kernel-package, libqt3-headers, libqt3-mt-dev
=> Apt-Get install build-essential
=> Apt-Get install libcurses5-dev
=> Apt-Get install mkinitramfs
=> Apt-Get install kernel-Package
=> Apt-Get install libqt3-headers
=> Apt-Get install libqt3-mt-dev
2. Download and decompress the Linux Kernel
=> Tar-jxvf linux-2.6.16.tar.bz2 Decompression
=> Cd linux-2.6.16 to enter the source code directory
3. Configure kernel options
=> Make menuconfig
Configuration options to be selected
1) Device Driver> Block devices:
RAM disk support
Initial RAM disk support
2) in graphics support
Support for Frame Buffer deiveces
Console display driver support-> framebuffer console support
Bin: when selecting the kernel module, there are two situations. One is the X number, which indicates that the sail selection function is compiled into the kernel. The other is
The "M" symbol indicates that the sail selection function is compiled into a module, and the sail module is loaded as needed after the train system is run.
4. Compile the kernel
=> Make bzimage
After compilation, there is a bzimage file in arch/i386/boot/, copy it to the root directory of the USB flash drive.
3. Compile busybox
1. Download busybox: busybox-1.2.0.tar.bz2
=> Tar-jxvf busybox-1.2.0.tar.bz2
=> Cd busybox-1.2.0
2. Configure busybox
=> Make menuconfig
Configuration options to be selected
1) ASH IN SHELL
2) Init in init Utility
3). You can select some other common commands such as LS, CD, mkdir ......
3. Compile busybox
=> Make
4. After compilation, create a temporary directory to save the files generated by busybox.
=> Create a temporary directory for mkdir/tmp/USB;
=> Make prefix =/tmp/USB install the files generated by compiling busybox are saved to the/tmp/USB directory;
Iv. File preparation
1. Create the inittab and RC. s files required for the startup of the worker system.
=> Mkdir/tmp/USB/etc
=> Cd/tmp/USB/etc
=> Vim inittab
Write in the file:
: Sysinit:/etc/rc. s
: Askfirst:/bin/ash
WQ save and exit
Sysinit indicates that the entire program is executed during the initialization of the primary system, and askfirst indicates the process started after the initialization of the primary system.
. If the execution of this program ends, the supervisor starts it again.
=> Vim RC. s
Write in the file:
#! /Bin/ash
/Bin/Mount-T proc/proc
Export Path =/bin/:/sbin/:/usr/sbin/
2. Create a device file.
=> Mkdir/tmp/USB/dev
=> Cd/tmp/USB/dev
=> Mknod console C 5 1
=> Mknod fb0 C 29 0
=> Mknod hda B 3 0
=> Mknod hda1 B 3 1
=> Mknod loop0 B 7 0
=> Mknod null C 1 3
=> Mknod ram0 B 1 0
=> Mknod tty C 5 0
=> Mknod tty0 C 4 0
=> Ln-s fb0 FB
3. Create a file upload system image.
1) Create an empty file with a size of 16 MB:
=> Dd If =/dev/Zero of =/tmp/image BS = 1024 COUNT = 16384
2) record the entire empty file to a device file:
=> Losetup/dev/loop1/tmp/Image
3) format the image in ext2 format:
=> Mke2fs/dev/loop1
4) mount the formatted image to the file system of the host.
=> Mount/dev/loop1/mnt/
5) copy the created file from/tmp/USB.
=> CP/tmp/USB/*/mnt/-ar
6) unmount the image from the uniform.
=> Umount/dev/loop1
=> Losetup-D/dev/loop1
=> Sync
7) compress the created image
=> Cd/tmp
=> Gzip-9 Image
Image.gz upload is our File System
8) copy the created file to the root directory of the USB flash drive.
5. Set the boot from USB (USB-HDD), the boot will start to busybox
For the shell. So far, the task of starting Linux from U has been completed, but this Linux operating system is the most simple
After finding out the whole process, you can try to add the cool and cool functions you want to the system. Good luck!

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.