Boot Destruction and Repair
Self-made Linux system
CentOS 6 startup process:
POST--Boot Sequence (BIOS)--Boot Loader---
Kernel (RAMDisk)--Rootfs, Switchroot--/sbin/init--
> (/etc/inittab,/etc/init/*.conf)--Set default RunLevel--System
Init script Rc.sysinit--turn off or start the corresponding level of service--start terminal
Grub:grand Unified Bootloader
Grub 0.x:grub Legacy
Grub 1.X:GRUB2
Grub Legacy:
Stage1:mbr
STAGE1_5:MBR after the sector, let Stage1 in the bootloader
To identify the file system on the partition where the stage2 resides
Stage2: Disk partition (/boot/grub/)
=================================================================
Power-on encryption password prevents single-user malicious password breaking
Generate encrypted password
First step:
[[email protected] ~]# grub-md5-crypt
Password: Do not show
Retype Password when entering a password: Do not display when entering a password
$1$6ldgy$wpwxtfaka/mcc6gow90if. This is the password after encryption
command is also a
OpenSSL passwd-1
that can generate an encrypted password XXXXXX
xxxxxx
Step two:
in config file: vim/boot/grub/grub.conf
Add: Add a password with password--MD5 encrypted above the first title opened
For example:
Password--md5 $1$6ldgy$wpwxtfaka/mcc6gow90if
Title CentOS 6 (2.6.32-642.el6.x86_64)
root (hd0,0)
and then save the restart
Step three:
Start the boot by any key to enter the menu interface: This is a single user ace and other passwords are invalid, prompting input p will let input passwd: That is, the encryption password that was saved above, the input success shows the ACE and other passwords, input can enter the single user to change the password, of course, if the user does not know the encryption password directly hit Enter will normally start, prevent the malicious password
You can also put the encrypted password before and after the configuration file, and put it in front to prevent access to the single user interface
Password--md5 $1$6ldgy$wpwxtfaka/mcc6gow90if
Title CentOS 6 (2.6.32-642.el6.x86_64)
Root (hd0,0)
kernel/vmlinuz-2.6.32-642.el6.x86_64 ro root=/dev/mapper/vg_compro-lv_root rd_no_luks rd_NO_MD rd_LVM_LV=vg_compro/ Lv_swap Crashkernel=auto LANG=ZH_CN. UTF-8 keyboardtype=pc keytable=us rd_lvm_lv=vg_compro/lv_root rd_no_dm rhgb quiet
Initrd/initramfs-2.6.32-642.el6.x86_64.img
Password Password
Add encryption at the end of the password is the start of about a few seconds, just pop it out passwd: Enter the encrypted password login to start the system
================================================================
Boot any key to enter a background image of the menu interface
The following characters are found in the configuration file
Splashimage= (hd0,0)/grub/splash.xpm.gz
Modify Background
1 First make a resolution 640*480 map named BJTP upload System home Directory
2 Installing a Linux fix map tool
[Email protected] ~]# yum-y install ImageMagick
3 Convert Picture format
[Email protected] ~]# convert-resize 640x480-colors bjtp.png bjtp.xpm
View format
[Email protected] ~]# more bjtp.xpm
Compression
[Email protected] ~]# gzip bjtp.xpm
Copy to Grub
[email protected] ~]# CP bjtp.xpm.gz/boot/grub/
Modifying a configuration file
[Email protected] ~]# vim/boot/grub/grub.conf
Splashimage= (hd0,0)/grub/bjtp.xpm.gz Modify the file name to do it.
Restart reboot Press any key during boot to enter the menu interface, it is also possible to see the picture just changed
==================================================================
Break the 1th stage and fix
[[email protected] ~]# dd If=/dev/zero OF=/DEV/SDA Bs=1 count=446
And take a look.
[Email protected] ~]# HEXDUMP-C-v/dev/sda-n 512
Restart reboot this time will be unable to start the boot when automatically enter the CD-ROM boot interface, when you select the third rescue mode
Repair:
Enter the shell interface in rescue mode cutting root
bash-4.1# chroot/mnt/sysimage/
bash-4.1# GRUB-INSTALL/DEV/SDA
bash-4.1# exit
bash-4.1# exit
Reboot, just reboot.
================================================================
Destroy phase 1.5 and fix
[[email protected] ~]# dd If=/dev/zero OF=/DEV/SDA bs=512 count=2 seek=1
[Email protected] ~]# hexdump-c-v/dev/sda-n 1024
Manual disc boot into rescue mode shell interface after reboot
Input Command Grub
bash-4.1# grub> Root (hd0,0)
grup> Setup (hd0)
Grup> quit
bash-4.1# exit
Reboot, just reboot.
=================================================================
Delete all contents of/grub directory
[Email protected] ~]# rm-rf/boot/grub/
[[email protected] ~]# reboot restart
Boot manual disc booting into rescue mode
bash-4.1# Chroot/mnt/sysimage
bash-4.1# Cd/boot
bash-4.1# GRUB-INSTALL/DEV/SDA
bash-4.1# cd/boot/grub/This time there is no grub.conf configuration files need to be handwritten one copy
bash-4.1# exit
bash-4.1# exit
Reboot restart
The Start screen prompts grub> to enter content
grub> Kernel (hd0,0)/vmlinuz ... root=/dev/sda2
Grub> initrd (hd0,0)/initramfs ....
grub> Boot
During the repair process, you are prompted to enter the above command again, but before the beginning, add grub> root (hd0,0) is OK.
Create vim/boot/grub/grub.conf
Default=0
Timeout=5
Title Compro
Root (hd0,0)
kernel/vmlinuz-2.6 ... root=/dev/sda2
Initrd/inirtamfs ....
==========================================================
Delete boot directory and restore (big strokes, one trick deadly, solve all of the above damage)
[Email protected] ~]# Umount/boot
[Email protected] ~]# Rm-rf/boot
[email protected] ~]# reboot
Direct access to rescue mode
bash-4.1# Mkdir/mnt/cdrom
bash-4.1# Mount/dev/cdrom/mnt/cdrom
bash-4.1# rpm-ivh/mnt/cdrom/pachages/kernel-2*--root=/mnt/sysimage--replacepkgs or force
bash-4.1# chroot/mnt/sysimage/
bash-4.1# Grub-install/dev/ada
bash-4.1# vim/boot/grub/grub.conf
Default=0
Timeout=3
Title Compro
Root (hd0,0)
Kernel/vmlinuz ... root=/dev/sda2
Initrd/initagfs ....
==================================================================
Self-made Linux systems:
Add a new hard drive with [[email Protected]ompro ~]# echo '--' >/sys/class/scsi_host/host2/scan load
1 partitioning and creating a file system
[Email protected] ~]# Fdisk/dev/sdb
Divided into two necessary partitions
/DEV/SDB1 corresponding/boot/dev/sdb2 corresponding to the root/
[Email protected] ~]# MKFS.EXT4/DEV/SDB2
[Email protected] ~]# MKFS.EXT4/DEV/SDB2
2 Mount Boot
[Email protected] ~]# Mkdir/mnt/boot
[Email protected] ~]# mount/dev/sdb1/mnt/boot/
[Email protected] ~]# cd/mnt/boot/
[Email protected] boot]# cp/boot/vmlinuz-2.6.32-642.el6.x86_64/boot/initramfs-2.6.32-642.el6.x86_64.img.
3 Installing Grub
[Email protected] boot]# Grub-install/dev/sdb--root-directory=/mnt
4, Establish grub.conf:
[Email protected] boot]# CD grub/
[Email protected] grub]# vim grub.conf
Default=0
Default=0
Timeout=3
Title Compro
Root (hd0,0)
kernel/vmlinuz-2.6.32-642.el6.x86_64 root=/dev/sda2 selinux=0 Init=/bin/bash
Initrd/initramfs-2.6.32-642.el6.x86_64.img
5. Create a level directory
[Email protected] ~]# Mkdir/mnt/sysroot
[Email protected] ~]# mount/dev/sdb2/mnt/sysroot/
[Email protected] ~]# cd/mnt/sysroot/
[Email protected] sysroot]# MKDIR-PV {etc,lib,lib64,bin,sbin,tmp,var,usr,sys,proc,opt,home,root,boot,dev,mnt, Media
6, [[email protected] sysroot]# vim Etc/fstab
/dev/sda1/boot EXT4 Defaults 1 1
/DEV/SDA2/EXT4 Defaults 1 2
8. Copy bash and related library files copy related commands and related library files
such as: Ls,cat,vim,reboot,hostname, etc.
The script is used here
[Email protected] sysroot]#/root/copycmd.sh
Please input a Command:bash
Please input a command or Quit:vim
Please input a command or Quit:cat
Please input a command or Quit:ls
Please input a command or quit:ifconfig
Please input a command or QUIT:DF
Please input a command or Quit:mount
Please input a command or Quit:umount
Please input a command or quit:rpm
Please input a command or quit:reboot
Please input a command or quit:hostname
Please input a command or Quit:halt
Please input a command or quit:quit
It's done here, here's what the script looks
#!/bin/bash
ch_root= "/mnt/sysroot"
[!-d $ch _root] && mkdir $ch _root
Bincopy () {
If which $ &>/dev/null; Then
Local cmd_path= ' which--skip-alias $ '
Local bin_dir= ' dirname $cmd _path '
[-D ${ch_root}${bin_dir}] | | Mkdir-p ${ch_root}${bin_dir}
[-F ${ch_root}${cmd_path}] | | CP $cmd _path ${ch_root}${bin_dir}
return 0
Else
echo "Command not found."
Return 1
Fi
}
Libcopy () {
Local lib_list=$ (LDD ' which--skip-alias $ ' | grep-eo '/[^[:space:]]+ ')
For loop in $lib _list;do
Local lib_dir= ' dirname $loop '
[-D ${ch_root}${lib_dir}] | | Mkdir-p ${ch_root}${lib_dir}
[-F ${ch_root}${loop}] | | CP $loop ${ch_root}${lib_dir}
Done
}
Read-p "Please input a command:" command
While ["$command"! = "Quit"];d o
If Bincopy $command; then
Libcopy $command
Fi
Read-p "Please input a command or quit:" command
Done
=====================================================================
This article from "Pony Brother Linux system operation and Maintenance" blog, reproduced please contact the author!
About start-up encryption destruction repair Homemade Linux system