最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

ubuntu小技巧6

互联网 admin 3浏览 0评论

ubuntu小技巧6

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 ]; thenset have_grubenv=trueload_env
fi
if [ "${next_entry}" ] ; thenset default="${next_entry}"set next_entry=save_env next_entryset boot_once=true
elseset default="0"
fiif [ x"${feature_menuentry_id}" = xy ]; thenmenuentry_id_option="--id"
elsemenuentry_id_option=""
fiexport menuentry_id_optionif [ "${prev_saved_entry}" ]; thenset saved_entry="${prev_saved_entry}"save_env saved_entryset prev_saved_entry=save_env prev_saved_entryset boot_once=true
fifunction savedefault {if [ -z "${boot_once}" ]; thensaved_entry="${chosen}"save_env saved_entryfi
}
function recordfail {set recordfail=1if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {if [ x$feature_all_video_module = xy ]; theninsmod all_videoelseinsmod efi_gopinsmod efi_ugainsmod ieee1275_fbinsmod vbeinsmod vgainsmod video_bochsinsmod video_cirrusfi
}if [ x$feature_default_font_path = xy ] ; thenfont=unicode
else
insmod part_msdos
insmod ext2
set root='hd0,msdos7'
if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos7 --hint-efi=hd0,msdos7 --hint-baremetal=ahci0,msdos7  fd063068-eb9a-4314-9b62-5caa732cc77a
elsesearch --no-floppy --fs-uuid --set=root fd063068-eb9a-4314-9b62-5caa732cc77a
fifont="/usr/share/grub/unicode.pf2"
fiif loadfont $font ; thenset gfxmode=autoload_videoinsmod gfxtermset locale_dir=$prefix/localeset lang=en_USinsmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; thenset timeout=30
elseif [ x$feature_timeout_style = xy ] ; thenset timeout_style=menuset timeout=10# Fallback normal timeout code in case the timeout_style feature is# unavailable.elseset timeout=10fi
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; thenclear
fi
### END /etc/grub.d/05_debian_theme ###### BEGIN /etc/grub.d/10_linux ###
function gfxmode {set gfxpayload="${1}"if [ "${1}" = "keep" ]; thenset vt_handoff=vt.handoff=7elseset vt_handoff=fi
}
if [ "${recordfail}" != 1 ]; thenif [ -e ${prefix}/gfxblacklist.txt ]; thenif hwmatch ${prefix}/gfxblacklist.txt 3; thenif [ ${match} = 0 ]; thenset linux_gfx_mode=keepelseset linux_gfx_mode=textfielseset linux_gfx_mode=textfielseset linux_gfx_mode=keepfi
elseset 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' {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioinsmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfilinux	/vmlinuz-4.4.0-31-generic root=UUID=fd063068-eb9a-4314-9b62-5caa732cc77a ro  quiet splash $vt_handoffinitrd	/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' {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioinsmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfiecho	'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_handoffecho	'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' {recordfailload_videoinsmod gzioinsmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfiecho	'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_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfiknetbsd	/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {insmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfilinux16	/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_msdosinsmod ntfsset root='hd0,msdos2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2  449E2C939E2C8012elsesearch --no-floppy --fs-uuid --set=root 449E2C939E2C8012fiparttool ${root} hidden-chainloader +1
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; thenset 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 ]; thensource ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; thensource $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###


注意:

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

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


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


ubuntu小技巧6

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 ]; thenset have_grubenv=trueload_env
fi
if [ "${next_entry}" ] ; thenset default="${next_entry}"set next_entry=save_env next_entryset boot_once=true
elseset default="0"
fiif [ x"${feature_menuentry_id}" = xy ]; thenmenuentry_id_option="--id"
elsemenuentry_id_option=""
fiexport menuentry_id_optionif [ "${prev_saved_entry}" ]; thenset saved_entry="${prev_saved_entry}"save_env saved_entryset prev_saved_entry=save_env prev_saved_entryset boot_once=true
fifunction savedefault {if [ -z "${boot_once}" ]; thensaved_entry="${chosen}"save_env saved_entryfi
}
function recordfail {set recordfail=1if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {if [ x$feature_all_video_module = xy ]; theninsmod all_videoelseinsmod efi_gopinsmod efi_ugainsmod ieee1275_fbinsmod vbeinsmod vgainsmod video_bochsinsmod video_cirrusfi
}if [ x$feature_default_font_path = xy ] ; thenfont=unicode
else
insmod part_msdos
insmod ext2
set root='hd0,msdos7'
if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos7 --hint-efi=hd0,msdos7 --hint-baremetal=ahci0,msdos7  fd063068-eb9a-4314-9b62-5caa732cc77a
elsesearch --no-floppy --fs-uuid --set=root fd063068-eb9a-4314-9b62-5caa732cc77a
fifont="/usr/share/grub/unicode.pf2"
fiif loadfont $font ; thenset gfxmode=autoload_videoinsmod gfxtermset locale_dir=$prefix/localeset lang=en_USinsmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; thenset timeout=30
elseif [ x$feature_timeout_style = xy ] ; thenset timeout_style=menuset timeout=10# Fallback normal timeout code in case the timeout_style feature is# unavailable.elseset timeout=10fi
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; thenclear
fi
### END /etc/grub.d/05_debian_theme ###### BEGIN /etc/grub.d/10_linux ###
function gfxmode {set gfxpayload="${1}"if [ "${1}" = "keep" ]; thenset vt_handoff=vt.handoff=7elseset vt_handoff=fi
}
if [ "${recordfail}" != 1 ]; thenif [ -e ${prefix}/gfxblacklist.txt ]; thenif hwmatch ${prefix}/gfxblacklist.txt 3; thenif [ ${match} = 0 ]; thenset linux_gfx_mode=keepelseset linux_gfx_mode=textfielseset linux_gfx_mode=textfielseset linux_gfx_mode=keepfi
elseset 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' {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioinsmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfilinux	/vmlinuz-4.4.0-31-generic root=UUID=fd063068-eb9a-4314-9b62-5caa732cc77a ro  quiet splash $vt_handoffinitrd	/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' {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioinsmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfiecho	'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_handoffecho	'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' {recordfailload_videoinsmod gzioinsmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfiecho	'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_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfiknetbsd	/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {insmod part_msdosinsmod ext2set root='hd0,msdos5'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  c865eff9-82bb-4ddc-8076-2cebdc5eec7belsesearch --no-floppy --fs-uuid --set=root c865eff9-82bb-4ddc-8076-2cebdc5eec7bfilinux16	/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_msdosinsmod ntfsset root='hd0,msdos2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2  449E2C939E2C8012elsesearch --no-floppy --fs-uuid --set=root 449E2C939E2C8012fiparttool ${root} hidden-chainloader +1
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; thenset 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 ]; thensource ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; thensource $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###


注意:

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

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


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


与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论