USB中的Ubuntu ..从固定硬盘启动?
我在USB笔式驱动器上安装了Ubuntu 12.04 minimal; 我在几个系统上用作便携式操作系统。
我正在考虑edit the boot parameters
以便在加载主Ubuntu OS之前,它会显示Boot from Hard Drive
5秒的选项,然后启动到Ubuntu。
这样我就可以选择启动安装在硬盘上的操作系统,而无需移除或拔掉我的ubuntu USB记忆棒。
如何编辑启动参数来实现此目的?
这实际上是一个比起初看起来要复杂得多的场景,因为几乎所有的BIOS都有重新排序它们如何呈现驱动器以使你从中启动的驱动器始终是“第一”驱动器的烦人趋势,这也是一些引导加载程序(如微软)期望的(如果你试图链式加载到Windows中,如果看起来包含Windows的驱动器不是BIOS列出的“第一个”),那么事情将无法正常工作。 从CD启动时不会出现此问题,因为CD与硬盘驱动器分开处理,并且不会更改顺序。 还有一个事实是可能有多个内部驱动器可供选择,因此在这种情况下,您应该能够选择要从哪个驱动器启动。
要添加到此Ubuntu,对grub-mkconfig进行了更改,以便忽略/ etc / default / grub中的GRUB_TIMEOUT设置,除非检测到另一个操作系统(想法是如果您没有其他操作系统,则计算机应该启动除非你按住shift键,否则不要等grub菜单更快。 下面的解决方案处理所有这些问题,我希望有足够的评论,很清楚正在做什么。
运行gksudo gedit /boot/grub/custom.cfg
并将以下内容复制并粘贴到其中:
# Set grub's timeout to 5 secons. By setting it here we are overriding any # settings for the timeout in /etc/default/grub. This is to be sure that we get # a five second timeout even if Ubuntu's grub-mkconfig thinks it's the only # Operating System and disables showing of the menu. timeout=5 insmod regexp # Grab just the drive portion of $prefix, to determine what drive we booted # from. # The third parameter in the following command is a regular expression which # says to capture just the "hdX" portion of a prefix like # "(hd1,msdos5)/boot/grub". Note that the parentheses in the regular expression # denote what needs to be captured (like in perl and most other regular # expression engines), they're not the parentheses that denote a device in grub. regexp --set=current_drive '(hd.)' "$prefix" # Loop through all drives (but not partitions) for drive in *; do # If the drive is the same as the one we're booted from just continue on to # the next without creating a menu entry for it. if [ "$drive" = "(${current_drive})" ]; then continue fi # Make a menu entry with the device name of the drive in the title menuentry "Chainload $drive" "$drive" { drive="$2" root="$drive" # Swap the drive currently designated as (hd0) with the drive we want to # chainload. Thus the drive we are about to chainload will appear to be the # first drive to the bootloader we chainload. drivemap -s "(hd0)" "$drive" chainloader +1 } done
然后只需保存文件就可以了。
当你启动时,如果有其他驱动器可以链式加载,你会看到它们的菜单条目(如果没有,你就不会)。 默认菜单项将保持不变,这意味着默认情况下Ubuntu应该启动,并且在此之前您将有5秒的超时。 由于您正在编辑/boot/grub/custom.cfg而不是/etc/grub.d/40_custom,因此您甚至不需要运行update-grub。
1。
从USB启动进入ubuntu。 打开终端。
2.1添加启动硬盘的条目
gksudo gedit /etc/grub.d/40_custom
在条目下面附上。 不要删除任何行。
menuentry "Boot From Hard disk" { set root=(hd0,1) chainloader +1 }
2.2更改默认条目以引导
gksudo gedit /etc/default/grub
将GRUB_DEFAULT=0
更改为GRUB_DEFAULT=X
此处X
是要启动的入口数减1。 如果要在引导加载程序中引导第3个条目,则X
应为2
(grub计数zero
)。
保存。
2.3更改超时以引导到默认操作系统
gksudo gedit /etc/default/grub
将GRUB_TIMEOUT=30
更改为GRUB_TIMEOUT=X
此处X
是引导到默认操作系统之前等待的秒数。 (我已经设定了3秒)
3。
sudo update-grub
4。
重启并选择Boot From Hard disk