efi转bios详细说明

前言

  制作好的efi格式的ubuntu15.10系统放到服务器主板上启动不了,于是将其改为bios格式,发现问题解决了,成功登入系统。下面是操作过程的一个记录。

测试环境

目标环境

系统: Ubuntu15.10

硬件: x86平台,服务器主板

宿主环境

系统: Ubuntu15.10

硬件: x86平台,普通主板

详细步骤

  • 第一步,将要修改的磁盘连接到额外的ubuntu系统的电脑上(我是通过sata转usb连接到笔记本上);
  • 第二步,分区修改。efi启动模式的磁盘会有一个efi分区,文件系统为fat32,我们需要将其格式化为boot分区的文件系统,可以是ext4。我采用gparted来完成的,细节就不细说了,我这里还通过管理标志界面去掉esp标志;
  • 第三步,进入要修改的磁盘环境,修改必要信息。依次执行下面命令,注意,替换sdd为自己外接的磁盘名,另外,这里的sdd2是指根分区,sdd1是指boot,也就是之前的efi分区,请根据自己的情况替换;
挂载根分区
$ sudo mount /dev/sdd2 /mnt
挂载boot分区
$ sudo mount /dev/sdd1 /mnt/boot/
挂载proc
$ sudo mount -o bind /proc/ /mnt/proc/
挂载sys
$ sudo mount -o bind /sys/ /mnt/sys
挂载dev
$ sudo mount -o bind /dev/ /mnt/dev
切入到外接磁盘(要修改的磁盘)环境
$ sudo chroot /mnt /bin/bash

如果前面指令全部成功执行,这时应该已经进入需要修复的磁盘环境里了。执行下面命令来卸载掉grub-efi-amd64(我这里是64位系统,32位系统的efi包肯定不同,需要根据情况修改)

$ sudo apt-get purge grub-efi-amd64 grub-common

,卸载完后我们就要安装BIOS version的grub了,执行下面命令即可:

$ sudo apt-get install grub-pc

注意: 可能需要配置dns,否则因为不能联网,导致apt-get install 失败,我这里临时配置一下(我的网关为192.168.1.1),于是我将dns指向它了。另外安装grub-pc时需要根据界面提示做相应动作,总之要指定安装到磁盘对应的设备名中,而不是对应的分区名中,如sdd,而不是sdd1。

$ sudo echo "nameserver 192.168.1.1" > /etc/resolv.conf
  • 第四步,修改fstab。去掉之前efi分区的挂载,我们这里用boot分区的uuid来替换掉它,要知道uuid,可以通过下面命令获取:
root@mcu-MacBookAir:/# sudo blkid /dev/sdd*
/dev/sdd: PTUUID="7e8d3b3a-6696-4dd2-8625-a1693ecf543e" PTTYPE="gpt"
/dev/sdd1: UUID="066f81f6-a4f5-43e5-ab8c-bb6fceb20de0" TYPE="ext4" PARTLABEL="EFI System Partition" PARTUUID="b1bb909b-ddcb-4ea4-a500-075e02bc3e01"
/dev/sdd2: UUID="d9ecfe99-05eb-4c79-939f-8e3c7a165d28" TYPE="ext4" PARTUUID="f450ba20-b922-4352-8eef-37113fcbfd70"
/dev/sdd3: UUID="ad15ce5a-53ac-4f25-b5b1-b33334e75159" TYPE="swap" PARTUUID="acaf2808-7db5-4b27-900b-52439688c66a"

修改前的fstab文件:

root@mcu-MacBookAir:/# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=d9ecfe99-05eb-4c79-939f-8e3c7a165d28 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=A663-8A43  /boot/efi       vfat    umask=0077      0       1
# swap was on /dev/sda3 during installation
UUID=ad15ce5a-53ac-4f25-b5b1-b33334e75159 none            swap    sw              0       0

修改后的fstab文件:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=d9ecfe99-05eb-4c79-939f-8e3c7a165d28 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=066f81f6-a4f5-43e5-ab8c-bb6fceb20de0  /boot       ext4    errors=remount-ro 0       1
# swap was on /dev/sda3 during installation
UUID=ad15ce5a-53ac-4f25-b5b1-b33334e75159 none            swap    sw              0       0

可以看到,主要是修改了第二个挂载条目,即之前的efi条目;

  • 最后一步,完善boot分区的内容。我从之前的boot目录(它里面存放了内核文件)拷贝内核文件到当前的boot分区,于是先卸载掉boot分区,将文件考出,然后再挂载boot分区,将内核文件考入
root@mcu-MacBookAir:/# umount /boot/
root@mcu-MacBookAir:/# cp /boot/vmlinuz-4.2.0-16-generic  .
root@mcu-MacBookAir:/# mount /dev/sdd1 /boot/
root@mcu-MacBookAir:/# mv vmlinuz-4.2.0-16-generic /boot/

执行完这行操作了,执行更新grub配置文件和生成initrd

root@mcu-MacBookAir:/# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.2.0-16-generic
root@mcu-MacBookAir:/# update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.2.0-16-generic
Found initrd image: /boot/initrd.img-4.2.0-16-generic
Found Ubuntu 15.10 (15.10) on /dev/sda6
done

剩下的就是收尾工作了, 退出当前环境,卸载所有和要修复磁盘相关的分区

exit
cd ~
sudo umount /mnt/*
sudo umount /mnt

,然后拔出磁盘,插入到目标主机启动就可以了。

如果哪位遇到相关问题,欢迎留言讨论!

完!
2016年5月

原文地址:https://www.cnblogs.com/rongpmcu/p/7662770.html