How to Create a usb boot disk for Linux

Source: Internet
Author: User
Article Title: Teach you how to create a usb boot disk for Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
USB flash storage device (USB flash drive) generally only has the key chain size, the storage capacity is 32 MB and 64 MB. Because of its advantages such as lightweight, exquisite, easy to use, and easy to carry, especially compared with a floppy disk, it features high capacity, safety and reliability, and fast reading speed, more and more people are using this device to replace the floppy disk and swap files between PCs. Currently, the new motherboard BIOS supports USB floppy disk and hard disk boot methods, making it easier to maintain and install Windows 98 systems. However, manufacturers only provide tools to create Windows 98 boot disks, but not linux boot disks. Creating 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 and a network environment, quickly identifies and resolves network faults and transfers files. This document uses Red Hat 8.0 as an example to create a Linux boot disk with a dual-boot USB flash drive.
  
Download related software: e3, bvi, and Liuux kernel.
  
   Compile the kernel
  
First, the computer's motherboard must support the USB hard drive boot mode, and the used USB flash drive is the boot type.
I take Linux-2.4.20 as an example. During compilation, be sure not to compile unnecessary modules, such as sound card drivers, so that the compiled kernel is as small as possible. To support usb Flash boot, you must compile SCSI devices, usb core, usb-storage, Loopback device support, RAM disk support, and initrd into the kernel.
Many people may ask why the usb-storage module is already included in the kernel to create an initrd. imgfile? This is because the initialization process of the USB flash drive is slower than the execution of/sbin/init. As a result, the kernel has been started and the initialization of the USB flash drive has not been completed. Therefore, the root file system has not been loaded, at this time, the execution of the/sbin/init command is definitely not successful. Create an initrd. imgfile to load the initrd. imgfile to the 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 procedure is as follows.
  
1. Create an initrd. imgfile
  
# Mkdir-p/mnt/initrd
# Cd/tmp
# Mkinitrd/tmp/initrd.gz 2.4.20-usb
  
2. decompress the initrd. imgfile and 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 content:
Echo 'wait 3 seconds .....'
/Bin/sleep 3
  
3. regenerate the initrd. imgfile
  
Because the default initrd file is large (4 MB), you must reduce it to speed up the startup of the USB flash drive. The procedure is as follows:
# Mkdir-p/mnt/initrdusb
# Cd/tmp
# Dd if =/dev/zero of =/tmp/initrdusb bs = 1 M 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 is properly started.
  
Test whether the compiled kernel is started normally and whether the information about the USB flash drive is visible during startup.
  
  
   Create a boot disk
  
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:
# Modprobe usb-storage
# 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.
  
2. Create and generate ext2 partitions
  
# Mke2fs-m 0/dev/sda2
# Mkdir-p/mnt/sda2
# Mount/dev/sda2/mnt/sda2
# Cd/mnt/sda2
  
3. Create a boot directory
  
Copy the compiled kernel and initrd-2.4.20-usb.img files to the boot directory, the compiled modules to the lib/modules directory, and copy the/boot/grub files to the boot directory, 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/vmlinuz-2.4.20-usb ro root =/dev/sda2
Initrd/boot/initrd-2.4.20-usb.img
  
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. 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. Due to disk space restrictions, busybox commands are used to replace some common Linux commands. The main reason is that the busybox file is very small and is statically linked, including many common Linux commands (such as cat, init, ifconig, and route), use ln-s busybox to establish symbolic connections to these files. You can re-compile busybox as needed, including vi and other commands, or use small e3 to replace vi.
In addition, if bash is used, you must 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 the dev directory
  
Run the cp-a command to copy common device files, including devices such as console, tty1, tty2, tty3sda, sda1, sda2, hda, hdb, and hda1.
  
6. Edit etc/init. d/rcS
  
The content is 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
  
The content is as follows:
/Dev/sda2/ext2 defaults 1 1
None/proc defaults 0 0
  
   Application Example
  
Here is an example of transferring files. Run:
$ Tar cf-win98 | nc-l-p 5555
Note: You can use the USB flash drive to start the machine on machine B and telnet to machine A to execute the above commands.
Run the following command on machine B with a USB flash drive:
# Mount-t vfat-o codepage = 938, iocharset = cp936/dev/hda5/mnt/2dos
# Cd/mnt/2dos
# Modprobe eepro00
# Ifconfig eth0 192.168.1.10
# Route add default gw 192.168.1.1
# Ping 192.168.10.5
# Nc 192.168.10.5 5555 | tar xf-
  
If you cannot create a Windows 98 boot disk by using the format/s command, you can use the following method:
# Mkdosfs-F 16/dev/sda1
# Xxd-c 16/dev/sda1 | less
  
Record the Boot Record 32 ~ 35 bytes (in this example, 60 91 01 00, which records the total number of sectors in the FAT partition ), use the Boot disk tool provided by longke to create a Windows 98 Boot disk. Then, use the bvi tool in Linux or the tool that can edit the binary file to modify the 32 ~ Boot Record ~ 35 bytes is the original content. In this way, we can implement a three-way startup (Windows Dual Boot + Linux boot ). '
Related Article

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.