Grub repair and installation and Linux system cropping

Source: Internet
Author: User
Tags network function

One. Grub Repair

1. Analog grub.conf Damage

#mv grub.conf Grub.conf.bak

Reboot, go directly to command line mode

Grub>

2. Manually configure GRUB

Grub>root (hd0,0) (Use Find and tab to auto-complete the location of the grub partition)

Grub>kernel/vmlinuz. Ro Root=/dev/root (the system can not find the words, only their own memory) quiet

Grub>initrd/initramfs....img

Grub>boot

Rewrite grub.conf can


3. Simulating grub corruption

#dd If=/dev/zero OF=/DEV/SDA bs=100 count=1

4. Use the disc to enter rescue mode and go to the command line

First Installation Method #chroot/mnt/sysimage/

#grub

Grub>root (hd#,#)

Grub>setup (hd#)

Grub>quit

The second way

#chroot/mnt/sysimage

#grub-install--root-directory=/(Specify the directory where boot is located)/dev/sda

#sync (Load the memory data onto the hard disk)

When the configuration file is missing, you need to write your own grub.conf



Two. System cropping

1. Partitioning the target disk

Two partitions:

On host:/DEV/SDB1,/DEV/SDB2

/DEV/SDB1 Mount to/mnt/boot

/DEV/SDB2 Mount to/mnt/sysroot

2. Install GRUB to target disk

#grub-install--root-directory=/mnt/dev/sdb

3. Copy kernel and INITRD files

Cp/boot/vmlinuz-version/mnt/boot/vmlinuz (easy to simplify, no plus version number)

Cp/boot/initramfs-version.img/mnt/boot/initramfs.img


4. Create a root system file for the target host

Mkdir-pv/mnt/sysroot/{etc/rc.d,usr,var,proc,sys,dev,lib/modules,lib64,bin,sbin,boot,src,mnt,media,home,root}


Then go to the root filesystem of the target host by porting commands such as Bash

Cp/lib/modules/2.6.32-642.el6.x86_64/kernel/drivers/net/e1000/e1000.ko/mnt/sysroot/lib/modules (easy to simplify, no deeper catalogs created)


5. Provide configuration files for grub

Vim/mnt/boot/grub/grub.conf

Default=0

Timeout=5

Title My First Minilinux

Root (hd0,0)

Kernel/vmlinuz ro root=/dev/sda2 selinux=0 init=/sbin/init (not specified also can, the system will find this executable program by default)

Initrd/initramfs

6. Write an init script to initialize (simulate/sbin/init)

#!/bin/bash

#

Echo-e "\t\033[34mwelcome My linux\033[0m"

Mount-n-T proc Proc/proc

Mount-n-T Sysfs Sysfs/sys

Insmod/lib/modules/e1000.ko

Ifconfig Lo 127.0.0.1/8

Ifconfig eth0 192.168.0.110/16

Mount-n-o remount,rw/dev/sda2/(re-mount the root file system)

/bin/bash

Because the script uses commands such as ifconfig,insmod,mount, you need to port the relevant commands to the root file system we created (/mnt/sysroot), and the migrated commands can be scripted to facilitate porting

You can complete a simple Linux with network function through the above steps.










Grub repair and installation and Linux system cropping

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.