The LINUX operating system on the USB flash disk-general Linux technology-Linux programming and kernel information. The following is a detailed description. Summary
This article describes how to create a Linux boot system on a USB storage device.
First, let's take a look at the USB device in LINUX. the Linux USB driver has three different USB master controller options, because there are three different types of USB chips on the motherboard and PCI Card. The "EHCI" driver is designed to support new high-speed USB 2.0 chips. The "OHCI" driver is used to provide support for USB chips on non-PC systems (as well as on PC boards with SiS and ALi chipsets. The "UHCI" driver is used to support USB implementations on most other PC boards, including Intel and. You only need to select the type corresponding to the USB support you want to enable "? HCI driver.
Enable "USB support" and appropriate "? After HCI "USB master controller driver, you only need to perform a few steps to enable and run USB. Enable the "Preliminary USB device filesystem" and SCSI computer standard interface, because our USB storage device simulates access to the SCSI hard disk.
1. About the kernel
The usb-storage module is included in the kernel, but the usb flash disk initialization process is slower than the execution of/sbin/init. As a result, the kernel has been started and the usb flash disk has not yet completed initialization, therefore, the root file system is not loaded, and the execution of the/sbin/init command is definitely not successful. Therefore, you must modify the system kernel initialization Code as follows:
/Init/do_mounts.c
......
* Allow the user to distinguish between failed open
* And bad superblock on root device.
*/
-Printk ("VFS: Cannot open root device" % s "or % s ",
+ Printk ("VFS: Cannot open root device" % s "or % s,
Retrying in 1 second. ", root_device_name, kdevname (ROOT_DEV ));
-Printk ("Please append a correct" root = "boot option ");
-Panic ("VFS: Unable to mount root fs on % s ",
-Kdevname (ROOT_DEV ));
+ Printk ("You may need to append a correct" root = "boot option ");
+ Printk ("or wait for the root device to become ready .");
+
+/* Wait 1 second and try again,
+ * Allowing time for hubs/devices to become ready */
+ Set_current_state (TASK_INTERRUPTIBLE );
+ Schedule_timeout (HZ );
+ Goto retry;
}
Panic ("VFS: Unable to mount root fs on % s", kdevname (ROOT_DEV ));
Out:
......
Recompile the kernel as needed.
You can also load the initrd. imgfile to the memory when starting the kernel, wait 3 seconds for the USB flash drive to complete initialization, and then execute the/sbin/init command.
2. Create the startup configuration and directory structure of the USB flash drive
(/Dev,/proc,/bin,/etc,/lib,/usr,/tmp,/var)
1. Divide the USB flash drive into two partitions.
The size of the partition size for Linux depends on which system maintenance tools are installed. The result is as follows:
# Fdisk-l/dev/sda
Disks/dev/sda: 16 heads, 63 sectors, 126 cylinders
Units = cylinders of 1008*512 bytes
Device Boot Start End Blocks Id System
/Dev/sda1 1 102 51376 + 6 FAT16
/Dev/sda2 103 126 12096 83 Linux
Note: If you need To Boot Windows 98 with a USB flash drive, the slice size must be set to 63. You can use the fdisk x command to expand and modify the parameters of heads, sectors, and cylinders. It is best to use the corresponding USB flash drive tool to create a disk.
Combine the compiled kernel with initrd. copy the imgfile to the boot directory, compile the module to the lib/modules directory, copy the/boot/grub file to the boot directory, and edit boot/grub/menu. the content of the lst file is as follows:
Timeout 10
Color 0x17 0x70
Default 0
Title Windows 98
Rootnoverify (hd0, 0)
Makeactive
Chainloader + 1
Title GNU/Linux Redhat 8.0 (2.4.20-usb)
Root (hd0, 1)
Kernel/boot/bzImage ro root =/dev/sda2
Initrd/boot/initrd. img // if there is no initrd. img, do not use this sentence.
To install grub, perform the following operations:
Grub> root (hd1, 1)
Grub> setup (hd1)
4. Create a bin directory
Copy System maintenance tools such as insmod, fsck, and mkdosfs as needed.
For commonly used tools, it is recommended to use tinylogin http://tinylogin.busybox.net or busybox http://www.busybox.net, they can recognize that you save no space.
In addition, if bash is used, you must edit and cut/etc/termcap and the following files:
Run the cp-a command to copy common device files, including devices such as console, tty1, tty2, tty3sda, sda1, sda2, hda, hdb, and hda1. If your kernel uses Devfs, you only need to create this directory.
Create the proc usr sbin directory. Can you use ln? S bin sbin establishes a sbin connection.
6. Create the lib directory
Be sure to use the ldd command to check the shared library files. These files need to be copied to the lib directory according to the original path.
Generally, the following files should be generated:
/Lib:
? Rwxr? Xr? X 1 root 45415 Nov 1 :39 ld? 2.0.7.so
Lrwxrwxrwx 1 root 11 Nov 1 :39 ld? Linux. so.2?>
Ld? 2.0.7.so
? Rwxr? Xr? X 1 root 731548 Nov 1 :39 libc? 2.0.7.so
Lrwxrwxrwx 1 root 13 Nov 1 :39 libc. so.6?>
Libc? 2.0.7.so
Lrwxrwxrwx 1 root 17 Nov 1 :39 libcom_err.so.2?>
Libcom_err.so.2.0
? Rwxr? Xr? X 1 root 6209 Nov 1 :39 libcom_err.so.2.0
? Rwxr? Xr? X 1 root 153881 Nov 1 :39 libcrypt? 2.0.7.so
Lrwxrwxrwx 1 root 17 Nov 1 :39 libcrypt. so.1?>
Libcrypt? 2.0.7.so
? Rwxr? Xr? X 1 root 12962 Nov 1 :39 libdl? 2.0.7.so
Lrwxrwxrwx 1 root 14 Nov 1 :39 libdl. so.2?>
Libdl? 2.0.7.so
Lrwxrwxrwx 1 root 14 Nov 1 :39 libpam. so.0?>
Libpam. so.0.64
? Rwxr? Xr? X 1 root 26906 Nov 1 :39 libpam. so.0.64
Lrwxrwxrwx 1 root 19 Nov 1 :39 libpam_misc.so.0?>
Libpam_misc.so.0.64
? Rwxr? Xr? X 1 root 7086 Nov 1 libpam_misc.so.0.64
? R? Xr? Xr? X 1 root 35615 Nov 1 :39 libproc. so.1.2.6
Lrwxrwxrwx 1 root 19 Nov 1 :39 libtermcap. so.2?>
Libtermcap. so.2.0.8
? Rwxr? Xr? X 1 root 12041 Nov 1 :39 libtermcap. so.2.0.8
? Rwxr? Xr? X 1 root 12874 Nov 1 :39 libutil? 2.0.7.so
Lrwxrwxrwx 1 root 16 Nov 1 :39 libutil. so.1?>
Libutil? 2.0.7.so
Drwx ?? X ?? X 3 root 1024 Nov 1 modules
Drwx ?? X ?? X 2 root 1024 Nov 1 security
/Lib/modules:
Drwx ?? X ?? X 4 root 1024 Nov 1 :39 2.0.35
/Lib/modules/2.0.35:
Drwx ?? X ?? X 2 root 1024 Nov 1 block
Drwx ?? X ?? X 2 root 1024 Nov 1 cdrom
/Lib/modules/2.0.35/block:
Drwx ?????? 1 root 7156 Nov 1 :39 loop. o
/Lib/modules/2.0.35/cdrom:
Drwx ?????? 1 root 24108 Nov 1 :39 cdu31a. o
/Lib/security:
? Rwx ?? X ?? X 1 root 8771 Nov 1 :39 pam_permit.so
3. Create a configuration file
1. Edit etc/init. d/rcS? The file name is determined by etc/inittab.
OTHER auth optional/lib/security/pam_permit.so
OTHER account optional/lib/security/pam_permit.so
OTHER password optional/lib/security/pam_permit.so
OTHER session optional/lib/security/pam_permit.so
6. Create a passwd, group, and shadow file.
The simplest way is to copy the original system file and then edit it.
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.