ubuntu小技巧6--如何修复Ubuntu系统引导项

ubuntu小技巧6--如何修复Ubuntu系统引导项

        当我们安装双系统的时候,若先安装windows后安装Ubuntu,安装后则会出现一个默认的系统选择界面,如图1,但是先装Ubuntu后装Windows或者双系统装好了又重装windows的时候,就会出现Ubuntu引导丢失的情况,此时可以如下恢复启动界面。

图1


1、  进入Ubuntu启动盘,获取root权限,察看磁盘各个区的内容

sudo -i

get root privilege

如图2,3

图2

图3


3 挂载相关区,重新生成引导文件

mount /dev/sda7  /mnt

mount /dev/sda5  /mnt/boot (no boot,skip it)

grub-install --root-directory=/mnt/  /dev/sda


if ok,it says "installationfinished.No error reported."

 

以上即将/(根目录,2中fdisk –l命令可以查看各个区安装什么内容)挂载在/mnt下面,将/boot目录挂载在/mnt/boot处,然后grub-install生成引导文件

如图4,5

图4将grub-install --root-directory=/mnt/ /dev/sda

打错了,图5重新输入正确后,修复引导成功

图4


图5

 

4 重启电脑,进入ubuntu再次修复引导项,就会出现图1的界面

restart PC,it will show grub interface

enter ubuntu OS,then update-grub

as picture 6,it's finished!

restart PC,you can see familiar options

重启电脑,启动项完全恢复了!

图6


 

经过1、2、3就出现了一个ubuntu和一个windows引导项,但是windows选项还不太完美,enter进入windows后会提示按任意键进入系统,这是1、2、3之后不完美的地方,当然若多次恢复或还原windows后,可能会改变windows的引导位置此时生成的windows引导可能无法进入windows系统,因此需要使用update-grub来修复一下。

 

5 删除多余的启动项

if you want to delete some options,youcan edit /boot/grub/grub.cfg

and delete options you don't need 

 

具体删除的地方如配置文件所示,删除之前最好备份一下原诗grub.cfg文件

删除后就又剩下两个必须的启动项了,如下图所示:

 

grub.cfg 文件(#删除  #删除结束,标志删除内容)

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_msdos
insmod ext2
set root='hd0,msdos7'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos7 --hint-efi=hd0,msdos7 --hint-baremetal=ahci0,msdos7  fd063068-eb9a-4314-9b62-5caa732cc77a
else
  search --no-floppy --fs-uuid --set=root fd063068-eb9a-4314-9b62-5caa732cc77a
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=menu
    set timeout=10
  # Fallback normal timeout code in case the timeout_style feature is
  # unavailable.
  else
    set timeout=10
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30,0; then
  clear
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
	set gfxpayload="${1}"
	if [ "${1}" = "keep" ]; then
		set vt_handoff=vt.handoff=7
	else
		set vt_handoff=
	fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-fd063068-eb9a-4314-9b62-5caa732cc77a' {
	recordfail
	load_video
	gfxmode $linux_gfx_mode
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos5'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7b
	else
	  search --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7b
	fi
	linux	/vmlinuz-4.4.0-31-generic root=UUID=fd063068-eb9a-4314-9b62-5caa732cc77a ro  quiet splash $vt_handoff
	initrd	/initrd.img-4.4.0-31-generic
}
#删除1
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-fd063068-eb9a-4314-9b62-5caa732cc77a' {
	menuentry 'Ubuntu, with Linux 4.4.0-31-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-31-generic-advanced-fd063068-eb9a-4314-9b62-5caa732cc77a' {
		recordfail
		load_video
		gfxmode $linux_gfx_mode
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos5'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7b
		else
		  search --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7b
		fi
		echo	'Loading Linux 4.4.0-31-generic ...'
		linux	/vmlinuz-4.4.0-31-generic root=UUID=fd063068-eb9a-4314-9b62-5caa732cc77a ro  quiet splash $vt_handoff
		echo	'Loading initial ramdisk ...'
		initrd	/initrd.img-4.4.0-31-generic
	}
	menuentry 'Ubuntu, with Linux 4.4.0-31-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-31-generic-recovery-fd063068-eb9a-4314-9b62-5caa732cc77a' {
		recordfail
		load_video
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos5'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7b
		else
		  search --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7b
		fi
		echo	'Loading Linux 4.4.0-31-generic ...'
		linux	/vmlinuz-4.4.0-31-generic root=UUID=fd063068-eb9a-4314-9b62-5caa732cc77a ro recovery nomodeset 
		echo	'Loading initial ramdisk ...'
		initrd	/initrd.img-4.4.0-31-generic
	}
}
#删除1 结束
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
#删除2
menuentry 'Memory test (memtest86+)' {
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos5'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7b
	else
	  search --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7b
	fi
	knetbsd	/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos5'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7b
	else
	  search --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7b
	fi
	linux16	/memtest86+.bin console=ttyS0,115200n8
}
#删除2 结束
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows 7 (loader) (on /dev/sda2)' --class windows --class os $menuentry_id_option 'osprober-chain-449E2C939E2C8012' {
	insmod part_msdos
	insmod ntfs
	set root='hd0,msdos2'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2  449E2C939E2C8012
	else
	  search --no-floppy --fs-uuid --set=root 449E2C939E2C8012
	fi
	parttool ${root} hidden-
	chainloader +1
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; then
  set timeout=10
fi
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###


注意:

若安装双系统的时候无法进入linux只能进入windows系统,则可以用以上方法恢复系统引导,也可以使用easybcd工具来引导系统;

若只能进入linux无法显示windows,则可以使用相关启动盘(老毛桃、大白菜等)修复启动项,修复后就只有windows启动了,然后使用以上方法修复linux启动项即可


以上是修复Ubuntu系统启动项的一点小心得,写在此处以供学习!


  • 10
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
好的,我会尽力回答你的问题。下面是一些在Ubuntu下编写终端界面交互式C++小程序时的一些Trick: 1. 使用ncurses库来创建终端界面。ncurses是一个用于创建文本用户界面(TUI)的库,可以让你创建菜单、窗口、文本框等控件,以及响应用户的输入。在Ubuntu下,你可以使用以下命令来安装ncurses库: ``` sudo apt-get install libncurses5-dev libncursesw5-dev ``` 2. 使用ANSI转义序列来控制终端输出。ANSI转义序列是一种特殊的字符序列,可以让你控制终端的颜色、光标位置等。例如,你可以使用以下代码来将文本输出为红色: ```c++ cout << "\033[31mHello, world!\033[0m" << endl; ``` 其中,\033[31m表示设置前景色为红色,\033[0m表示重置颜色。 3. 使用readline库来读取用户的输入。readline是一个用于读取用户输入的库,可以让你处理用户输入的历史记录、自动完成等。在Ubuntu下,你可以使用以下命令来安装readline库: ``` sudo apt-get install libreadline-dev ``` 4. 使用gnome-terminal来运行你的程序。gnome-terminal是Ubuntu下的一个终端模拟器,可以让你在一个新的终端窗口中运行你的程序。你可以使用以下命令来打开一个新的gnome-terminal窗口: ``` gnome-terminal -e "./your_program" ``` 其中,./your_program是你的程序的可执行文件路径。 希望这些Trick对你有所帮助!如果你有任何问题,请随时问我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昕光xg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值