Teach you to make a USB boot disk for the Linux operating system

  
                  

USB flash memory storage device (USB flash drive) has the advantages of being light and exquisite, easy to use, and easy to carry. Especially, the contrast floppy disk has the characteristics of large capacity, safe and reliable, and fast reading speed. More and more people use this. The device replaces the floppy drive with the floppy disk and exchanges files between PCs. At present, the new motherboard BIOS supports USB floppy disk and hard disk boot mode, which makes it more convenient for Windows system maintenance and installation. However, the manufacturer only provides the production tool for making the Windows 98 boot disk, and does not provide the production tool for the Linux boot disk. Setting up a Linux boot disk on a USB flash drive is more practical for system maintenance personnel. You can use Linux to build a small kernel, establish a network environment, and quickly determine and troubleshoot network problems and transfer files. This article takes Red Hat as an example, using Netac's dual-boot USB flash drive to build a Linux boot disk for USB flash drives.

Download related software: e3, bvi, Linux kernel.

Compiling the kernel

First, the motherboard of the computer must support the startup mode of the USB hard disk, and the USB flash drive used is the bootable USB flash drive.

I will use Linux-2.4.20 as an example. When compiling, be careful not to compile unnecessary modules, such as sound card drivers and other driver modules, so that the compiled kernel is as small as possible. To support bootable USB, SCSI devices, usbcore, usb-storage, Loopback device support, RAM disk support, and initrd must be compiled into the kernel.

Many people will ask, why the usb-storage module is already included in the kernel. Why should I create an initrd.img file? This is because the initialization process of the USB flash drive is slower than the execution of /sbin/init, causing the kernel to be booted. The USB flash drive has not yet completed the initialization work, so the root file system is not loaded. At this time, executing the /sbin/init command is definitely unsuccessful. By creating the initrd.img file, load the initrd.img file into memory when the kernel is started, wait 3 seconds for the USB flash drive to complete initialization, and then execute the /sbin/init command. The specific steps are as follows.

1. Create initrd.img file

 # mkdir -p /mnt/initrd # cd /tmp # mkinitrd /tmp/initrd.gz 2.4.20-usb 

2. Decompress 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 the following:

 echo 'wait 3 seconds.....' /bin/sleep 3 

3. Regenerate Initrd.img file

Since the initrd file created by default is relatively large (4MB), in order to speed up the boot of the USB flash drive, it must be reduced. The specific operation is 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

4. Test whether the compiled kernel starts normally.

Test whether the compiled kernel is started normally, and whether the information about the USB flash drive can be seen during the boot process.

establishment of USB boot disk

1. The USB partitions into two

left Linux which drive size depends entirely on the system installation and maintenance tool, the following results :

 # modprobe usb-storage # 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 with a USB stick, the sector size must be set to 63 sectors, which can be modified by fdisk x command extension. Heads, sectors, and cylinders parameters. //This article comes from the computer software and hardware application network www.45it.com reproduced please specify

2. Create and generate ext2 partition

 # mke2fs -m 0 /dev/sda2 # mkdir -p /mnt/Sda2 # mount /dev/sda2 /mnt/sda2 # cd /mnt/sda2

3.Create boot directory

Copy the compiled kernel and initrd-2.4.20-usb.img file to the boot directory and compile Copy the good module to the lib/modules directory, and copy the /boot/grub file to the boot directory. Edit the boot/grub/menu.lst file 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/vmlinuz-2.4.20-usb ro root=/dev/sda2 initrd /boot/initrd-2.4.20-usb.img

Install grub as follows:

 grub> root (hd1,1) grub> setup (hd1) 4. Create bin directory

Copy system maintenance tools such as insmod, fsck, and mkdo as needed for your work Utilities such as sfs. Be sure to check the shared library files using the ldd command, which needs to be copied to the lib directory according to the original path. Due to disk space limitations, using the busybox command instead of some common Linux commands, the main reason is that the busybox file is very small and statically linked, including many common Linux commands (such as cat, init, ifconig, route) with ln - s busybox establishes a symbolic link to these files. You can recompile busybox according to your personal needs, including vi and other commands, or you can use small e3 instead of vi.

In addition, if you use bash, you must also edit and cut /etc/termcap and the following files:

 /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.Create dev directory

Copy frequently using cp -a command Device files, including device files such as console, tty1, tty2, tty3sda, sda1, sda2, hda, hdb, and hda1.

6. Edit etc/init.d/rcS

The contents are 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 remount,rw -t proc none /proc ifconfig lo 127.0.0.1

7. Edit the etc/fstab file

as follows:

< PRE> /dev/sda2 /ext2 defaults 1 1 none /proc proc defaults 0 0

Application examples

Give an example of a transfer file. Execute on a working Linux machine A (IP=192.168.100.5):

 $ tar cf - win98 
						
Copyright © Windows knowledge All Rights Reserved