Create your own Linux release on a USB disk-general Linux technology-Linux programming and kernel information. For more information, see the following. Preface;
I have been trying to build a Linux system that can be started and run on a USB flash drive. Recently I have spent some time and made a system that can basically run on it. Now I want to record it, one is for your reference. The other is to learn from and learn from each other. The third is to increase the popularity of this forum.
1. My production environment;
I would like to talk about the hardware environment, but it may be related to the production of the system: My USB flash drive is an earlier version of longke 64M, And the motherboard chip is an earlier version of Sis. I think the new motherboard and new USB flash drives should have better hardware compatibility than my hardware. I first set the boot media in the Bios to a USB-HDD, and the other three USB boot methods I can not start this time.
My software environment, or my operating system is Sarge.
2. My basic ideas
It is true that a relatively complete practical system is to be processed and modified on the basis of existing Linux releases, for example, re-processed on the basis of Morphix, Knoppix, DSL, etc, however, the main purpose of my system is to satisfy my curiosity. It is also a way of learning, so I started from a more basic step, including compiling the kernel by yourself, making the root directory system by yourself, and making various configurations by yourself-of course, it is best to start from the basics of writing all source code by yourself, but that is impossible.
3. production process;
3.1. Compile the kernel;
The specific compilation process will not be mentioned, and the materials can be seen everywhere. The key here is to note that a patch is required to enable the USB flash drive to find its root directory system. For details about the patch, see:
Http://www.lammerts.org/software/kernelpatches/
Because the patch is for Kernel 2.4.22, I download the source code of version 2.4.22. I don't know if the patch works for other versions of kernel 2.4, the patch for the 2.6 kernel is different.
Then decompress the package, patch it, and compile it to get bzImage.
3.2. Create a root directory system;
There are also many articles about the root directory system. I will not repeat them here. It is worth noting that:
3.21 because the current USB flash drive is much looser than the floppy disk, I didn't use busybox, instead, I copied the required items directly from the bin sbin lib and other directories of the Sarge system I work on.
3.22. We generally use initrd to start Linux in two phases, and initrd will mount the file system on the USB flash disk. I don't know why. I don't like this method. Experiments have proved that it is feasible to specify the root directory file system directly by grub or syslinux.
3.23. There are almost no configuration files in my root directory, even inittab fstab. Please try again later.
3.3. process the USB flash drive;
First, use fdisk cfdisk to partition the USB disk. I divide my USB disk into two zones: the first 10 m boot zone and the second 50 m root zone, make sure that the boot partition is set to start-activate it in DOS.
Then we need to create a file system, because I am more familiar with syslinux Than grub, so I use:
# Mkdosfs/dev/sda1
# Mke2fs/dev/sda2
Create a boot partition as a FAT file system and a root partition as an ext2 File System-use grub to avoid this problem, next time I will study how to use grub to load the kernel on the boot USB disk.
Then perform syslinux processing on the USB flash drive as follows:
# Syslinux/dev/sda
Copy related files to the USB flash drive. After mounting the corresponding file system, copy the previously compiled kernel bzImage to sda1 and copy the self-built root file system to sda2.
Finally, write a configuration file for syslinux and copy it to sda1. (In fact, sda1 contains only three files, one is the kernel, the other is the syslinux system file, and the other is the following syslinux. cfg)
# Nano syslinux. cfg
Title myusb
Kernel bzImage
Root/dev/sda2
After the preparation is complete, start the computer and you will be able to smoothly access my USB flash drive. Although the kernel will report that the root file system cannot be found at startup, after a few hard times, it finds and runs init smoothly, and now appears on the computer:
Init #
Indicates that you can use a USB flash drive Linux.
However, this system can't do anything, and many configuration files need to be created. For example, the current system uses nano vi and other editing files to generate an error "error opening terminal" and exit, you must copy the/etc/terminfo/l/linux file of the original system to run properly.
I originally wanted to create a small C language learning system that can run Gcc + Rhide-just like I used a floppy disk and copied Dos + TurboC 1.0 to learn C language everywhere, but now things seem much more complicated. Now it is very troublesome to install Gcc, and we still need to constantly explore.
Thank you;
Thanks to doom3d for making this small system!
About this article;
This article is an instance of USB Linux developed by yhyzh brother. If you need it, sort it out. after organizing the Org forum, it is not too difficult in the process of organizing the Forum, but it is okay to make appropriate typography. Thanks to yhyzh and doom3d;
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