Linux on the U disk

zhaozj2021-02-12  180

LINUX author on the U disk: Ben netmails@163.com Read: 382 times First let's take a look at LINUX USB devices, Linux USB drivers have three different USB host controller options, this is because the motherboard and PCI card There are three different types of USB chips. "EHCI" driver is designed to provide support for chips that implement new high-speed USB 2.0 protocols. The "OHCI" driver is used to provide support for the USB chip on the non-PC system (and the PC motherboard with SIS and Ali chipsets). "UHCI" driver is used to support most other PC motherboards (including Intel and Via). Simply select the "? HCI" driver corresponding to the type of USB support you want to enable. After the "USB Support" and the appropriate "? HCI" USB main controller driver, the USB starts and runs only a few steps. "Preliminary USB Device FileSystem", SCSI Computer Standard Interface, because usually our USB storage device, analog to the SCSI hard disk, about the kernel USB-Storage module included in the kernel but due to the initialization process of the U disk / Sbin / init slows, causing the kernel to complete, the USB flash drive has not completed the initialization work, so the root file system is not loaded, and the execution / sbin / init command is definitely unsuccessful. So the system's core initialization code is modified 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 corrent" 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: ... Follow the need to recompile the kernel. You can also load initrd.img when you start the kernel. Document to memory, wait for 3 seconds to make the USB flash drive to complete the initialization, then execute / sbin / init instruction.

1. Establish Initrd.Img file # mkdir -p / mnt / initrd # cd / tmp/ mkinitrd /tmp/initrd.gz 2.4.20-USB 2, unzip the initrd.img file, modify the startup script Linuxrc # Gunzip Initrd.gz # Mount -o loop / tmp / initrd / mnt / initrd # cp / sbin / busybox / mnt / initrd / bin # CD / mnt / initrd / bin # ln-s busybox sleep # VI / MNT / INITRD / LinuxRC Add to Separate: Echo 'Wait 3 Seconds .....' / bin / sleep 3 3, regenerate the initrd.img file due to the default initrd file (4MB), in order to speed up the startup of the USB flash drive, it must be reduced. The specific operations are as follows: # mkdir -p / mnt / initrdusb # cd / tmp # DD if = / dev / zero of = / tmp / initrdusb BS = 1M count = 1 # mke2fs -m 0 initrdusb # mount -o loop / TMP / Initrdusb / mnt / initrdusb # cp -a / mnt / initrd / * / mnt / initrdusb # umount / mnt / initrd # umount / mnt / initrdusb # CD / TMP # gzip -9 initrdusb # cp initrdusb.gz / boot / initrd- 2.4.20-USB.IMG II. Establishing a USB flash drive configuration and directory structure (/ dev, / proc, / bin, / etc, / lib, / usr, / tmp, / var) 1, divide the USB flash drive into two partitions Give the Linux partition capacity, depending on which system maintenance tools are installed, the results are as follows: # fdisk -l / dev / sda disk / 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, the sector size must be set to 63 sectors, you can pass FDISK x command Extended the HEADS, SECTORS and CYLINDERS parameters.

It is best to build the tool corresponding tool. 2, build and generate EXT2 partition # mke2fs -m 0 / dev / sda2 # mkdir -p / mnt / sda2 # mount / dev / sda2 / mnt / sda2 # CD / MNT / SDA2 3. Establish the boot directory to copy the compiled kernel to the initrd.img file to the boot directory, compile the module to copy to the lib / modules directory, and copy the / boot / grub file to the boot directory, edit boot / grub / menu .lst file, the content 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 init.img, this sentence does not install GRUB, the specific operation is as follows: GRUB> root (HD1, 1) GRUB> Setup (HD1) 4 Establish a bin directory based on self-work requires copy system maintenance tools such as INSMOD, FSCK, and MKDOSFS. For common tools, it is recommended to use TinyLogin http://tinylogin.busybox.net or busybox http://www.busybox.net, you can think that you save universal space. In addition, if you use Bash, you must edit and cut / ETC / TERMCAP and as follows: / bin / bash / etc / termcap / usr / share / terminfo / l / linux / usr / share / terminfo / k / klone ACS / USR / Share / Terminfo / K / Klone Color / usr / share / terminfo / k / klone sgr 5, establish a DEV PROC USR SBIN directory using a CP -A command copying the usual device file, including console, tty1, tty2, tty3sda, sda1, sda2, hda, hdb, and hda1, etc. Device file. If your kernel uses devfs, just create this directory. Create the Proc USR SBIN directory, you can establish the connection connection of the ln -s bin sbin. 6. Establish the lib directory Be sure to pay attention to using the LDD command to check those shared library files, These files need to copy to the lib directory according to the original path.

It should generally be as follows: / lib: -rwxr-xr-x 1 root root 45415 NOV 1 15:39 ld-2.0.7.so lrwxrwrwx 1 root root 11 NOV 1 15:39 ld-linux.so.2 -> LD-2.0.7.SO -RWXR-XR-x 1 root root 731548 NOV 1 15:39 libc-2.0.7.so lrwxrwx1 root root 13 NOV 1 15:39 libc.so.6 -> libc-2.0. 7.so lrwxrwxrwx 1 root root 17 NOV 1 15:39 libcom_err.so.2-> libcom_err.so.2.0 -rwxr-xr-x 1 root root 6209 NOV 1 15:39 libcom_err.so.2.0 -rwxr-xr- x 1 root root 153881 NOV 1 15:39 libcrypt-2.0.7.so lrwxrwxrwx 1 root root 17 NOV 1 15:39 Libcrypt.so.1 -> libcrypt-2.0.7.so -rwxr-xr-x 1 root root 12962 NOV 1 15:39 libdl-2.0.7.so lrwxrwrwx 1 root root 14 NOV 1 15:39 libdl.so.2-> libdl-2.0.7.so lrwxrwxrwx 1 root root 14 Nov 1 15:39 LibPam.so .0-> libpam.so.0.64 -rwxr-xr-x 1 root root 26906 NOV 1 15:39 libpam.so.0.64 lrwxrwxrwx 1 root root 19 Nov 1 15:39 libpam_misc.so.0 -> libpam_misc.so. 0.64 -RWXR-XR-X 1 root root 7086 NOV 1 15:39 libpam_misc.so.0.64 -R-XR-XR-x 1 root root 35615 NOV 1 15:39 libproc.so.1.2.6 lrwxrwrwx 1 root root 19 NOV 1 15 : 39 LIBTERMCAP.SO.2 -> LIBTERMCAP.SO.2.0.8 -RWXR-XR-x 1 root root 12041 NOV 1 15:39 Libtermcap.SO.2.0.8 -RWXR-XR-X 1 root root 12874 NOV 1 15:39 Libutil-2.0.7.so lrwxrwxrwx 1 root root 16 NOV 1 15:39 Libutil.so.1 ->

Libutil-2.0.7.so drwx - x - x 3 root root 1024 NOV 1 15:39 Modules Drwx - x - x 2 Root root 1024 NOV 1 15:39 Security / lib / modules: drwx - x --X 4 root root 1024 NOV 1 15:39 2.0.35 /lib/modules/2.0.35: drwx - x - x 2 root root 1024 NOV 1 15:39 block DRWX - X - X 2 root Root 1024 NOV 1 15:39 CDROM /LIB/Modules/2.0.35/block: drwx ------ 1 root root 7156 NOV 1 15:39 loop.o /lib/modules/2.0.35/ cdrom: drwx ------ 1 root root 24108 NOV 1 15:39 CDU31a.o / lib / security: -rwx - x - x 1 root root 8771 NOV 1 15:39 Pam_Permit.so III, establish a configuration file 1, Edit the ETC / INIT.D / RCS? The file name is determined in the ETC / ITTAB content as follows: #! / Bin / sh path = / sbin: / bin export path mount -n -t proc none / proc umount / initrd mount -n O remount, rw / mount -n -o transount, rw -t proc none / proc iFconfig LO 127.0.0.1 Hostname USBBoot 2, edit ETC / FSTAB file contents as follows: / dev / sda2 / ext2 defaults 1 1 None / Proc Proc Defaults 0 0 3, establish an ETC / ITTAB file, if you generate the file with busybox, you can. ID: 2: INITDEFAULT: SI :: Sysinit: / etc / rcs 1: 2345: Respawn: / sbin / getty 9600 TTY1 2: 23: Respawn: / sbin / getty 9600 TTY2 4, establish nsswitch.conf file passwd: files shadow : files group: files hosts: files services: files networks: files protocols: files rpc: files ethers: files netmasks: files bootparams: files automount: files aliases: files netgroup: files publickey: files 5, the establishment of /etc/pam.conf file 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, establish passwd, The simplest method of Group, Shadow file is to copy the files of the original system. Due to space relationships, there is no detailed instructions for some steps, you can refer to the following documents. Can also communicate with me.

转载请注明原文地址:https://www.9cbs.com/read-7069.html

New Post(0)