Manually destroy the grub configuration file yourself, manually install Grub

Source: Internet
Author: User

I. First method of installing grub

1. First determine the partition on which your system resides

[[email protected] boot]# fdisk -ldisk /dev/sda: 21.4 gb, 21474836480  bytes255 heads, 63 sectors/track, 2610 cylindersunits = cylinders  of 16065 * 512 = 8225280 bytes   Device Boot       Start         End       Blocks   Id  System/dev/sda1   *            1           25      200781   83  linux/dev/sda2               26           89      514080   82  linux swap  / solaris/dev/sda3              90         2610    20249932+  83  linux

2. Manually destroy the bootloader (as long as the first 446 bytes in the MBR are destroyed)

[[email protected] boot]# dd If=/dev/zero OF=/DEV/SDA bs=400 count=1

Then synchronize the data to the disk

[[email protected] boot]# sync[[email protected] boot]# sync

Remember not to reboot at this time, if it is restarted only in emergency rescue mode to repair

3. Enter the GRUB command line interface with the GRUB command

[[email protected] boot]# Grub

4. Specify the partition where the kernel is located and the partition to be installed on

grub> root (hd0,0) Filesystem type is EXT2FS, partition type 0x83grub> setup (hd0) Checking if "/boot/grub/stage1" E Xists ... no Checking if "/grub/stage1" exists ... yes Checking if "/grub/stage2" exists ... yes Checking if "/grub/e2fs_stag  E1_5 "exists ... yes Running" embed/grub/e2fs_stage1_5 (hd0) "...  Sectors is embedded.succeeded Running "Install/grub/stage1 (hd0) (hd0) 1+15 P (hd0,0)/grub/stage2/grub/grub.conf" ... Succeededdone.grub> quit

5. Then restart it.

Two. Install grub in the second way

1. Add another hard drive for testing, then partition and format the new hard drive

[[Email protected] ~]# fdisk /dev/sdbdevice contains neither a valid  DOS partition table, nor Sun, SGI or OSF disklabelBuilding  A new dos disklabel. changes will remain in memory only,until  you decide to write them. After that, of course, the  Previouscontent won ' t be recoverable. warning: invalid flag 0x0000 of partition table 4 will be  Corrected by w (rite) command  (m for help): p        disk /dev/sdb: 1073 mb, 1073741824 bytes255 heads, 63 sectors/ track, 130 cylindersunits = cylinders of 16065 * 512 =  8225280 bytes   device boot     &nbSp start         end      blocks    Id  SystemCommand  (M&NBSP;FOR&NBSP;HELP): ncommand action    e   extended   p   primary partition  (1-4) 1invalid partition number for type  ' 1 ' command action   e    extended   p   primary partition  (1-4) ppartition  number  (1-4): 1first cylinder  (1-130, default 1): using default  value 1last cylinder or +size or +sizem or +sizek  (1-130,  default 130): +100mcommand  (m for help):  ncommand action   e    extended   p   primary partition  (1-4) ppartition  number  (1-4):  2first cylinder  (14-130, default 14): using default value 14last  cylinder or +size or +sizem or +sizek  (14-130, default 130):  +500M Command  (M&NBSP;FOR&NBSP;HELP): ncommand action   e    extended   p   primary partition  (1-4) ppartition number   (1-4): 3first cylinder  (76-130, default 76):  using default value  76Last cylinder or +size or +sizeM or +sizeK  (76-130,  default 130): +100mcommand  (m for help): &NBSP;PDISK&NBSP;/DEV/SDB:&NBSP;1073&NBSP;MB,  1073741824 bytes255 heads, 63 sectors/track, 130 cylindersunits =  cylinders of 16065 * 512 = 8225280 bytes   device  boot      start         end       blocks   id  system/dev/sdb1                1          13       104391   83  Linux/dev/sdb2               14           75      498015   83  Linux/dev/sdb3               76           88      104422+  83   linuxcommand  (m for help): tpartition number  (1-4): 3Hex code  ( Type l to list cOdes):  l 0  empty           1e   Hidden W95 FAT1 80  Old Minix        bf  Solaris         1  FAT12            24  NEC DOS          81  Minix / old Lin c1  DRDOS/sec  ( fat- 2  xenix root      39  plan 9           82  linux swap / so c4   DRDOS/sec  (fat- 3  xenix usr       3c   PartitionMagic  83  Linux            c6  drdos/sec  (Fat- 4  fat16 <32m      40  venix  80286     84  OS/2 hidden C:  c7   syrinx          5  extended         41  PPC PReP Boot   85  Linux  extended  da  non-fs data     6  fat16            42  SFS              86  ntfs volume set db  cp/m  / CTOS / . 7  HPFS/NTFS       4d   QNX4.x          87  NTFS volume  Set de  dell utility    8  aix              4e  qnx4.x 2nd part 88  linux plaintext df   bootit          9  aix bootable     4f  QNX4.x 3rd part 8e  Linux LVM        e1  dos access      a  os /2 boot manag 50  ontrack dm      93   amoeba          e3  dos r/o          b  w95 fat32       51   ontrack dm6 aux 94  amoeba bbt      e4   speedstor       c  w95 fat32  (LBA)  52  CP/M             9f  BSD/OS           eb  BeOS fs          e  w95 fat16  (LBA) &NBSP;53&NBSP;&NBSP;ONTRACK&NBSP;DM6&NBSP;AUX&NBSP;A0&NBSP;&NBSP;IBM  thinkpad hi ee  efi gpt         f   w95 ext ' d  (LBA)  54  ontrackdm6      a5   FreeBSD         ef  EFI  (FAT-12/16/10   opus            55  ez-drive         a6  OpenBSD          f0 &nbsp linux/pa-risc b11  hidden fat12    56  golden bow       a7  NeXTSTEP        f1   speedstor      12  compaq diagnost 5c  priam  edisk     a8  darwin ufs      f4   speedstor      14  hidden fat16 <3 61   SpeedStor       a9  NetBSD           f2  DOS secondary  16  Hidden  Fat16    63  gnu hurd or sys ab  darwin boot      fb  VMware VMFS    17  Hidden  Hpfs/ntf 64  novell netware  b7  bsdi fs          fc  VMware VMKCORE 18  AST SmartSleep  65   novell netware  b8  bsdi swap       fd   linux raid auto1b  hidden w95 fat3 70  disksecure mult  bb  Boot Wizard hid fe  LANstep         1c  Hidden W95 FAT3 75  PC/IX            be  solaris boot    ff  bbt             Hex code  (type l  To list codes):  82changed system type of partition 3 to 82   (LINUX&NBSP;SWAP&NBSp;/ solaris) command  (m for help): pdisk /dev/sdb: 1073 mb,  1073741824 bytes255 heads, 63 sectors/track, 130 cylindersunits =  Cylinders of 16065 * 512 = 8225280 bytes   device boot       Start         End       Blocks   Id  System/dev/sdb1                1           13      104391   83  Linux/dev/sdb2               14           75      498015   83   Linux/dev/sdb3              76           88      104422+  82  linux swap  / SolarisCommand  (M&NBSP;FOR&NBSP;HELP): wthe partition table has  been altered! Calling ioctl ()  to re-read partition table. Syncing disks. [[Email protected] ~]# partprobe /dev/sdb[[email protected] ~]# sync[[email  protected] ~]# sync[[email protected] ~]# sync[[email protected] ~]#  sync[[email protected] ~]# sync[[email protected] ~]# fdisk -l

2. Create a boot directory under/mnt/for mounting boot

[[Email protected] boot]# cd /mnt/[[email protected] mnt]# ls -a. &NBSP;&NBSP, .... [[email protected] mnt]# mkdir -pv bootmkdir: created directory  ' Boot ' [[email protected] mnt]# ls -a.  ..   boot[[email protected] mnt]# mount/dev/sda3 on / type ext3   (rw) proc on /proc type proc  (rw) SYSFS&NBSP;ON&NBSP;/SYS&NBSP;TYPE&NBSP;SYSFS   (rw) devpts on /dev/pts type devpts  (rw,gid=5,mode=620)/dev/sda1 on / boot type ext3  (rw) tmpfs on /dev/shm type tmpfs  (rw) none on  /proc/sys/fs/binfmt_misc type binfmt_misc  (rw) sunrpc on /var/lib/nfs/rpc_pipefs  type rpc_pipefs  (rw) [[email protected] mnt]# fdisk -l /dev/sdbdisk / dev/sdb: 1073 mb, 1073741824 bytes255 heads, 63 sectors/track, 130 cylindersunits = cylinders of 16065  * 512 = 8225280 bytes   Device Boot       Start         End       blocks   id  system/dev/sdb1                1          13       104391   83  Linux/dev/sdb2               14           75      498015   83  Linux/dev/sdb3               76            88      104422+  82  linux swap / solaris[[ email protected] mnt]# mount /dev/sdb1 /mnt/boot/[[email protected] mnt]# &NBSP;LS&NBSP;-A.&NBSP;&NBSP, ....   boot

3. Install grub Manually

[[email protected] mnt]# Grub-install--root-directory=/mnt/dev/sdbprobing devices to guess BIOS drives. This could take a long time. Installation finished. No Error reported. This was the contents of the device Map/mnt/boot/grub/device.map.check if this was correct or not. If any of the lines is incorrect,fix it and re-run the script ' Grub-install '. (fd0)/dev/fd0 (hd0)/DEV/SDA (HD1)/dev/sdb

4. The grub directory is automatically generated in the/mnt/boot/directory

[Email protected] boot]# ls-a.  .. Grub Lost+found

5. Manually provide the/mnt/boot/grub/grub.conf file

Default=0timeout=5title This is my Linux root (hd0,0) Kernel/vmlinuz initrd/initrd.img

6. Uninstalling the device files

[Email protected] boot]# umount/mnt/boot/

7. Suspend the current system to re-create a new virtual machine (using an existing virtual hard disk, created above)

Start a virtual machine

This article is from "Luo Chen's blog" blog, please be sure to keep this source http://luochen2015.blog.51cto.com/9772274/1650379

Manually destroy the grub configuration file yourself, manually install Grub

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.