Preparation of the linuxU disk startup system

Source: Internet
Author: User
Tags ide hard drive
Article Title: production of The linuxU disk boot system. 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.

Two days ago, a linux system of the company was accidentally deleted and the file could not be imported into the system. The data in the system was very important. To restore the data on the hard disk, I thought of multiple methods. Of course, many methods are feasible, for example, you can take the hard disk and put it on another linux system to test the data. For example, you can skip the console and enter the system to test the data. Later, I wanted to create a linux system started with a USB flash drive. It would be easier to do something later. So I studied it for two hours. The following is the production process for you to share. When performing mknod, I read a lot of English documents and finally understood it.

I. process the USB flash drive

1. Partitioning: (plug in the USB flash drive)

# Fdisk/dev/sdb

D Enter delete original Partition

N Enter to create a primary Partition

W Enter Save settings

# Partprobe/dev/sdb refresh the USB flash disk

2. Set the USB flash drive partition to the active partition.

# Fdisk/dev/sdb

A Enter is set to active partition

1 Enter select Partition

3. format the hard disk partition and format it into the ext3 format.

# Mkfs. ext3/dev/sdb1

Ii. Install the filesystem package (objective: to generate the root directory, such as root, usr, var)

1. Configure yum

2. Load the USB flash drive to/net

# Mount/dev/sdb1/net

3. Install

# Yum-y install -- installrot =/net filesystem

After the installation is complete, you can view multiple directories under/net.

Iii. loading system startup items

1. # cp/boot/vmlinuz-2.6.18-128.el5/net/boot/

2. Generate initrd. img 'uname-R' to get the system version number.

# Mkinitrd -- with = usb-storage/net/boot/initrd-usb.img 'uname-R'

3. Check whether vmlinuz and initrd exist in/net/boot /.

4. Create a boot loader (grub)

1. # yum-y install -- installroot =/net grub

2. If grub. conf is not automatically generated, it must be manually created.

# Cp/boot/grub. conf/net/boot/grub. conf and modify it

# Cat/net/boot/grub. conf

Default = 0

Timeout = 5

Title redhat-usb-linux

Root (hd0, 0)

Kernel/boot/vmlinuz-2.6.18-128.el5 ro root =/dev/sdb1 init =/dev/bash

Initrd/boot/initrd-usb.img

The entered content must be consistent with the file name under/net/boot/grub /.

5. Install the command Library File

# Yum-y install -- installroot =/net bash coreutils pam setup vim-enhanced vim-minimal util-

Linux net-tools SysVinit passwd shadow-utils authconfig

You can view the package name through rpm-qf/bin/mount.

In this case, the command just installed can be used in chroot/net.

6. Create a disk partition

# Mknod/net/dev/sdb B 8 16

# Mknod/net/dev/sdb1 B 8 17

B Indicates a block device. 8 indicates the primary device number, and 16 or 17 indicates the next device number.

--------------------------

| Device number explanation:

| 1. For a SCSI/SATA hard drive (in the format of sd *), the master device number is 8,

| The device number of the first hard disk is 0-15, and the device Number of the second hard disk is

| The Sn is 16-31, and so on. Because for hard disks

| A maximum of four partitions are supported. You can have three primary partitions and one extended partition.

| The partition can still be partitioned, but the total number of partitions is 16 at most.

| The number of devices used for each hard disk is 16 (0-15, 16-31 ).

| 2. For an IDE Hard Drive (in the format of hd *), set the primary device number to 3.

| The first part of the Sn is 0-63, and the second part is 64-127.

| 3. # ls-l/dev/sd *

| Brw-r ----- 1 root disk 8, 0 10-16 14:53/dev/sda

| Brw-r ----- 1 root disk 8, 1 10-16 14:54/dev/sda1

| Brw-r ----- 1 root disk 8, 2 10-16 14:53/dev/sda2

| Brw-r ----- 1 root disk 8, 3 10-16 14:54/dev/sda3

| Brw-r ----- 1 root disk 8, 16 10-16 :50/dev/sdb

| Brw-r ----- 1 root disk 8, 17 10-16/dev/sdb1

| Brw-r ----- 1 root disk 8, 32 10-16 15:50/dev/sdc

| Brw-r ----- 1 root disk 8, 36 10-16/dev/sdc4

| One hard disk is inserted on one of my hosts and two USB flash drives are displayed.

| We can see the display of the device number.

| 4. in linux, everything is a file, and the hardware is also reflected by a file.

| All hardware devices are displayed in/dev.

| 5. For more information about device numbers, see the following files.

| # Yum install kernel-doc

#/Usr/share/doc/kernel-doc-2.6.18/Documentation/devices.txt

---------------------------

7.

1. Create mtab

# Cat/net/etc/mtab

/Dev/sdb1/ext3 rw 0 0

2. Create fstab

# Cat/net/etc/fstab

/Dev/sdb1/ext3 default 1 1 1

8. Install grub

# Chroot/net

# Grub-install/dev/sdb1

Note:

1. If the hard disk partition is not correctly configured during creation, an error will be reported in Step 8:

The file/boot/grub/stage1 not read correctly

2. After starting with a USB flash drive, enter the system in the USB flash drive. Now we can use

Command set installed, but the file system is read-only at this time, we cannot vim,

At this time, you must use the following command to re-read and write the mount:

# Mount-o remount, rw/

After remounting, you can.

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.