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