Using Grub2

Using grub on ubuntu

 

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

GNU GRUB 2 Manual:   http://grub.enbug.org/Manual

Grub on Ubuntu:  https://wiki.ubuntu.com/Grub2

 

 

Grub 2 Files & Folders


The main Grub 2 instruction file is now grub.cfg . This file is produced by various scripts run when either the "update-grub" or "update-grub2" command is executed. The files primarily responsible for the content of grub.cfg are /etc/default/grub and individual script files located in /etc/grub.d/

 

grub.cfg (/boot/grub/grub.cfg)

 

 

DO NOT EDIT THIS FILE This is the main Grub 2 file. It "replaces" Grub Legacy's /boot/grub/menu.lst . This file contains the Grub menu instructions. Unlike Grub Legacy's menu.lst file, grub.cfg is NOT MEANT TO BE EDITED!!!

 

  • grub.cfg is automatically generated or updated whenever "update-grub" is executed. The command must be run as root .

  • The scripts used to generate grub.cfg include the files contained in /etc/grub.d and information gathered from /etc/default/grub

  • The file is divided into sections. Each section of the file is clearly delineated and is recognizable by the section header ### BEGIN . The information on this line references the file in the /etc/grub.d folder which is used to incorporate the information into grub.cfg

grub (/etc/default/grub)

This file contains information previously found in the upper section of /boot/grub/menu.lst . It contains settings primarily affecting Grub's menu display. This file can be edited by root to make changes to these settings; they will be imported into grub.cfg when "update-grub" is executed.

  • GRUB_DEFAULT=0

    • Sets the default and pre-selected menu entry. Entries may be numeric or saved

    • GRUB_DEFAULT=0

      • Sets the default menu entry by menu position. As with Grub Legacy, the first "menuentry" in grub.cfg is 0, the second is 1, etc.
    • GRUB_DEFAULT="Windows XP Professional (on /dev/sda1)"

      • Sets the default menu entry by name.
    • GRUB_DEFAULT=saved

      • Sets the default menu entry with whatever was selected on the last boot. If the menu is displayed during boot, the previously selected option will be highlighted. If no action is taken, this is selection which will be booted at the end of the timeout, or if the menu is hidden.
  • GRUB_TIMEOUT=5

    • No change from Grub Legacy. This is the number of seconds before the default entry is automatically booted.
    • Setting a value of -1 will display the menu until the user makes a selection (no timeout).

  • GRUB_HIDDEN_TIMEOUT=0

    • The menu will be hidden unless a # symbol is present at the beginning of this line. ( # GRUB_HIDDEN_TIMEOUT=0 )

    • The default setting initially depends on the presence of other operating systems.
      • Another OS Detected: The menu will be displayed. ( The line will begin with a # symbol. )
      • No other OS Detected: The menu will be hidden.
    • For integers greater than 0, the system will pause, but not display the menu, for the entered number of seconds.
    • 0 The menu will not be displayed. There will be no delay.
      • When this entry is set to 0:
        • The user may force displaying the menu as the computer boots by holding down the SHIFT key.
          • During boot, the system will check the SHIFT key status. If it cannot determine the key status, a short delay will enable the user to display the menu by pressing the ESC key.
        • If enabled, the splash screen designated in 05_debian_theme will be displayed even if the hidden menu feature is selected.
  • GRUB_HIDDEN_TIMEOUT_QUIET=true

    • true - No countdown is displayed. The screen will be blank.
    • false - A counter will display on a blank screen for the duration of the GRUB_HIDDEN_TIMEOUT value.
  • GRUB_DISTRIBUTOR =lsb_release -i -s 2> /dev/null || echo Debian

    • Determines the descriptive name in the menu entry. (Ubuntu, Xubuntu, Debian, etc.)
  • GRUB_CMDLINE_LINUX

    • If it exists, this line imports any entries to the end of the linux command line (Grub Legacy's "kernel" line) for both normal and recovery modes. This is similar to the "altoptions" line in menu.lst

  • GRUB_CMDLINE_LINUX_DEFAULT ="quiet splash"

    • This line imports any entries to the end of the 'linux' line (Grub Legacy's "kernel" line). The entries are appended to the end of the normal mode only. This is similar to the "defoptions" line in menu.lst . If you want a black screen with scrolling boot messages, remove "quiet splash". If you want a grub splash screen with limited messages underneath the Ubuntu logo, use only "splash". < This [only "splash"]will not work in Karmic during boot as the xsplash does not display the messages , but the messages at shutdown will be displayed.

  • #GRUB_TERMINAL =console

    • Uncomment to disable graphical terminal (grub-pc only).
  • #GRUB_GFXMODE=640x480

    • Uncomment (remove '#' from beginning of the line) to change (increase) resolution of your boot loader. Use one of classic (4:3 rate):
      • GRUB_GFXMODE=640x480 (is used if isn't here a proper value)
      • GRUB_GFXMODE=800x600
      • GRUB_GFXMODE=1024x768
      • GRUB_GFXMODE=1600×1200
    • or make experiments with some others nonstandarts like widescreen (16:10 ratio in my case), here is list of most of commonly use Display resolution :

      • GRUB_GFXMODE=640x400
      • GRUB_GFXMODE=800x500
      • GRUB_GFXMODE=1024x640
      • GRUB_GFXMODE=1280x800
      • GRUB_GFXMODE=1680x1050
  • #GRUB_DISABLE_LINUX_UUID =true

    • Uncomment this line if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux.
  • GRUB_DISABLE_LINUX_RECOVERY=true

    • Add or uncomment this line to prevent "Recovery" mode kernel options from appearing in the menu.
  • GRUB_DISABLE_OS_PROBER=true

    • Enables/disables the os-prober check of other partitions for operating systems, including Windows, Linux, OSX and Hurd.

Recover Grub 2 via LiveCD

  • First, grab a copy of the latest Ubuntu LiveCD and boot it.

  • Open a terminal and type

$ sudo fdisk -l

  • Now, you need to remember which device listed is your linux distribution, for reference, /dev/sda1 will be used. Now we need to mount the filesystem to /mnt

$ sudo mount /dev/sda1 /mnt

  • If you have /boot on a separate partition, that need's to be mounted aswell. For reference, /dev/sda2 will be used.

$ sudo mount /dev/sda2 /mnt/boot Make sure you don't mix these up, pay attention to the output of FDISK

  • Now mount the rest of your devices

$ sudo mount --bind /dev /mnt/dev

  • Now chroot into your system

$ sudo chroot /mnt

You should be chroot'd into your system as root, you can now run commands as root, without the need for sudo.

  • Now you need to edit the /etc/default/grub file to fit your system

$ nano /etc/default/grub

  • When that is done you need to run update-grub to create the configuration file.

$ update-grub

  • To install GRUB 2 to the MBR, next you need to run grub-install /dev/sda

$ grub-install /dev/sda

  • If you encounter any errors, try grub-install --recheck /dev/sda

$ grub-install --recheck /dev/sda

  • Press Ctrl+D to exit out of the chroot.
  • Once you exit back to your regular console, undo all the mounting, first the /dev

$ sudo umount /mnt/dev

  • Now you can unmount the root system

$ sudo umount /mnt

  • And you should be free to restart your system right into GRUB 2 and then into your system installation.
If you had alternate OS entries, update-grub might say "Cannot find list of partitions!". Ignore it and continue - once you can boot into your linux installation, do so and then rerun update-grub and grub-install /dev/sda as root.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值