Multi-OS Installation
ISO Installer
What is an ISO File?
An ISO file, often called an ISO image, is a single file that's a perfect representation of an entire CD, DVD, or BD.The entire contents of a disc can be precisely duplicated in a single ISO file.
All ISO images end in the file extension .iso, and are often used to distribute large programs (such as OS) due to the fact that all of the program's files can be neatly contained as a single file.
Every single file required for whatever tool/OS to run is included in the single ISO image.
This makes the tool really easy to download an makes it super easy to burn to a disc or other device.
How to Extract ISO Files in Linux ?
Most compression/decompression software programs, like the free 7-Zip and PeaZip programs, will extract the contents of an ISO file to a folder.Extracting an ISO file copies all of the files from the image directly into a folder that you can browse through like any folder you'd find on your computer.
For example, let's say you've downloaded Microsoft Office as an ISO file, you could extract the installation files from the ISO and then install the program like you normally would any other program.
In Linux, there are couple ways do it.
- Mount or Extract ISO File in Linux
$ sudo mkdir /mnt/iso $ sudo mount -o loop ubuntu-16.10-server-amd64.iso /mnt/iso
$ sudo apt install p7zip-full p7zip-rar $ 7z x ubuntu-16.10-server-amd64.iso
$ isoinfo -i ../imgs/ubuntu-20.04.1-live-server-arm64.iso -lYou can extract a single file from an ISO image like so:
$ isoinfo -i ../imgs/ubuntu-20.04.1-live-server-arm64.iso -x MD5SUM.TXT > MD5SUM.TXT
How to Create ISO Files in Linux ?
genisoimage is a pre-mastering program to generate ISO9660/Joliet/HFS hybrid filesystems.It is capable of generating the System Use Sharing Protocol records (SUSP) specified by the Rock Ridge Inter‐change Protocol. This is used to further describe the files in the ISO9660 filesystem to a Unix host, and provides information such as long filenames, UID/GID, POSIX permissions, symbolic links, and block and character device files.
$ genisoimage -o cd.iso cd_dir
RepackBootableISO
What is a bootable ISO 9660 image ?
To be bootable by computer firmware, such an ISO image has to bear special entry points.The entry points on i386 and amd64 systems are: El Torito, MBR, GPT.
The entry point is normally the start of a bootloader system, which offers the user a menu of operating systems and is able to start the chosen one.
Grub2/ISOBoot
Ubuntu ISOs allow the user to boot and use the "Try Ubuntu" feature of the Ubuntu installation CD as well as to install Ubuntu directly from an ISO on the hard drive.
Exploring the ISO Contents
Viewing the folders and files contained in an ISO can help determine menuentry path designations.The most important files reside in the casper folder on a standard Ubuntu ISO.
The kernel link is vmlinuz and the image file is initrd.img.
LiveCDCustomizationFromScratch
A live CD (also live DVD, live disc, or live operating system) is a complete bootable computer installation including operating system.A Live CD allows users to run an operating system directly without installing it or making any changes to the computer's configuration.
Live CDs have being replaced by live USBs.
You can create a bootable Ubuntu LiveCd (along with the automatic hardware detection and configuration) from scratch.
You may wish to create an Ubuntu Remix and distribute it as a LiveCd.
Overview
The basic steps are to- Create a chroot and install your packages there.
- Compress the chroot system into a file.
- Create and configure the disk image which will have the bootloader (isolinux), the kernel, the compressed file-system image and some other stuff.
- Burn the Cd and test it out.
The Build Host System
This refers to the Ubuntu desktop you are running, the one the customised LiveCd is being built on.You will need to install the syslinux, squashfs-tools and genisoimage packages to be able to build the LiveCd Remix using the current system.
The Disk Image
Create a new folder to be the Disk-Image-Folder.- The isolinux bootloader binary (taken from the syslinux package) needs to be copied onto the disk image folder.
- The isolinux configuration file, which will allow the CD to show a boot-menu at boot time, needs to be copied into there too.
- You will also copy the kernel from the chroot onto the disk image folder.
The ChRoot Environment
This is the system that will eventually run from the CD.It does not need a kernel, nor a boot-loader unless you are planning on installing this system onto a hard disk (using Ubiquity).
The Casper package needs to be installed into the chroot.
Casper allows the Live System to perform hardware autoconfiguration and run from a live environment.
The chroot will be in the form of a squashed (compressed) file inside the disk image .
Cretae the ChRoot Environment
Debootstrap can be used to install Debian in a system without using an installation disk but can also be used to run a different Debian flavor in a chroot environment.Install debootstrap on the host system:
$ sudo apt install debootstrap $ mkdir -p work/chroot $ cd work $ sudo debootstrap --arch=$ARCH $SUITE chroot [ MIRROR [SCRIPT] ]The debootstrap command installs a bare Ubuntu system into work/chroot.
- $SUITE is the version of Ubuntu you intend to build an ISO for. The $SUITE may be a release code name (eg, sid, stretch, jessie, focal) or a symbolic name (eg, unstable, testing, stable, oldstable)
- $ARCH is the target processor architecture.
- For old 32 bit x86 systems use i386.
- For newer 64-bit x86 systems (also known as x64, x86_64, Intel 64, and AMD64) use amd64 (--arch=amd64).
- MIRROR The ubuntu.com archive will be used by default for downloading.
If downloading from the main archive is slow, use one of the alternatives from this list of mirrors by adding the URL to the end of the debootstrap command.
MIRROR can be an http:// or https:// URL, a file:/// URL, or an ssh:/// URL.
$ sudo debootstrap --arch=amd64 focal chroot [sudo] password for jerry: I: Retrieving InRelease I: Checking Release signature I: Valid Release signature (key id F6ECB3762474EDA9D21B7022871920D1991BC93C) I: Retrieving Packages I: Validating Packages I: Resolving dependencies of required packages... I: Resolving dependencies of base packages... I: Checking component main on http://archive.ubuntu.com/ubuntu... I: Retrieving adduser 3.118ubuntu2 I: Validating adduser 3.118ubuntu2 I: Retrieving apt 2.0.2 I: Validating apt 2.0.2 I: Retrieving apt-utils 2.0.2 I: Validating apt-utils 2.0.2 I: Retrieving base-files 11ubuntu5 ... I: Chosen extractor for .deb packages: dpkg-deb I: Extracting base-files... I: Extracting base-passwd... ... I: Configuring ca-certificates... I: Base system installed successfully.Now, copy some system files in your environment so that you can get some internet in the created chroot environment:
$ sudo cp /etc/hosts chroot/etc/hosts $ sudo cp /etc/resolv.conf chroot/etc/resolv.conf $ sudo cp /etc/apt/sources.list chroot/etc/apt/sources.listNote: If you are bootstrapping a release of Ubuntu other then the release you are currently running:
you should substitute the 'sudo cp /etc/apt/sources.list chroot/etc/apt/sources.list' command with the following.
sudo sed s/Release-You-Are-On/Release-You-Are-Bootstrapping/ < /etc/apt/sources.list > chroot/etc/apt/sources.listLaunchpad generates a unique key for each PPA and uses it to sign any packages built in that PPA.
This means that people downloading/installing packages from a PPA can verify packages' source.
You will need to add the PPA's key to your chroot's package manager.
On the PPA's overview page you'll see the PPA's OpenPGP key id. It'll look something like this: So , using the above as an example:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A9E345C0 #Substitute "A9E345C0" with the PPA's OpenPGP ID.For more detail, refer to "Introduction to Apt Authentication".
Now, enter the chroot system:
$ sudo chroot chroot # mount none -t proc /proc # mount none -t sysfs /sys # mount none -t devpts /dev/pts # export HOME=/root # export LC_ALL=CUpgrade packages:
# apt update # apt --yes upgrade # apt install --yes dbus # dbus-uuidgen > /var/lib/dbus/machine-id # dpkg-divert --local --rename --add /sbin/initctl Adding 'local diversion of /sbin/initctl to /sbin/initctl.distrib'Install packages needed for Live System:
$ sudo apt install --yes ubuntu-standard casper lupin-casper $ sudo apt install --yes discover laptop-detect os-prober $ sudo apt install --yes linux-genericNext, you may install more packages as you like.
Graphical installer, optional step
- For server systems
# apt install -y subiquity # sudo apt install snapd
$ sudo apt install ubiquity-frontend-gtk
$ sudo apt install ubiquity-frontend-kdeSo far, you have entered the chroot and installed packages, then clean up and leave.
# apt clean # rm -rf /tmp/* # rm /etc/resolv.conf # umount -lf /proc # umount -lf /sys # umount -lf /dev/pts # exit
Create the CD Image Directory and Populate it
There are 3 packages that need to be installed on the Host System which provide the tools to make the CD image.
- syslinux contains isolinux which makes the Cd bootable.
- squashfs-tools will compress the image.
- genisoimage provides mkisofs tool to turn a directory into a CD image.
$ sudo apt install syslinux squashfs-tools genisoimageCreate the image directory and the 3 required subdirectories:
$ mkdir -p image/{casper,isolinux,install}Copy the kernel and initrd from your chroot:
$ sudo cp chroot/boot/vmlinuz-5.4.0-72-generic image/casper/vmlinuz $ sudo cp chroot/boot/initrd.img-5.4.0-72-generic image/casper/initrdCopy the isolinux and memtest binaries from your host system:
cp /usr/lib/ISOLINUX/isolinux.bin image/isolinux/ $ cp /usr/lib/syslinux/modules/bios/ldlinux.c32 image/isolinux/ # for syslinux 5.00 and newer $ cp /boot/memtest86+.bin image/install/memtest
How to set up an Ubuntu 20.04 ISO image to auto-install a server
For actually modifying the ISO image, what I do is prepare a scratch directory, unpack the pristine ISO image into it with 7z (because we have 7z installed and it will unpack ISOs, among many other things), modify the scratch directory, and then build a new ISO image with:$ mkisofs -o jerry_arm64_ubuntu_20.04.iso \ -ldots -allow-multidot -d -r -l -J \ -e boot/grub/efi.img -no-emul-boot \ -boot-load-size 4 -boot-info-table \ scratch-dir
- -o iso.img sets the name of the new ISO image file.
- -e boot/grub/efi.img marks the file /boot/grub/efi.img in the ISO as EL Torito boot image for EFI. This enables booting from CD, DVD or BD media.
- -no-emul-boot is a necessary addtitional option to -e.
- -b isolinux/isolinux.bin marks the file /isolinux/isolinux.bin in the ISO as EL Torito boot image for legacy BIOS. This enables booting from CD, DVD or BD media.
- -c isolinux/boot.cat
$ isohybrid cslab_ubuntu_20.04.iso
To verify an ISO installer image for arm64 (AArch64) using QEMU and KVM
qemu-system-aarch64 \ -cpu cortex-a53 -M virt -m 4096 -nographic \ -drive if=pflash,format=raw,file=/home/work/imgs/QEMU_EFI.img \ -drive if=pflash,file=/home/work/imgs/varstore.img \ -drive if=virtio,file=/home/work/imgs/debian.img \ -drive if=virtio,format=raw,file=/home/work/imgs/ubuntu-20.04.1-live-server-arm64.isowhere
- QEMU_EFI.img A UEFI image for QEMU’s virt machine can be downloaded:
$ wget http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_GCC5/QEMU_EFI.img.gz $ gunzip QEMU_EFI.img.gz
$ qemu-img create -f qcow2 varstore.img 64M
$ qemu-img create -f qcow2 debian.img 128GIt’s generally better to make the debian.img too large rather than too small.
ISOLINUX
ISOLINUX is a boot loader for Linux/i386 that operates off ISO 9660/El Torito CD-ROMs in "no emulation" mode.
CustomizeLiveInitrd
At boot time, the boot loader loads the kernel and the initramfs image into memory and starts the kernel.The kernel checks for the presence of the initramfs and, if found, mounts it as / and runs /init.
The initrd contains all the programs and utilities the kernel needs in order to find the root partition.
The initrd is "given" to the kernel by the boot loader (often isolinux on CDs, or grub on hard drives).
The initrd used by an installed system is maintained by the mkinitramfs script, which is run automatically when for instance upgrading the kernel or any tool used inside the initrd.
The initrd used when booting a live cd ("Desktop CD") can be found in the casper directory of the CD.
Casper is a hook for initramfs-tools used to generate an initramfs capable to boot live systems( ISOs, netboot tarballs, and usb stick images and Ubuntu live CDs).
At boot time, live systems will look for a (read-only) media containing a "/casper" directory where a root filesystems (often a compressed squashfs) is stored.
If found, it will create a writable environment, using unionfs, for debian like systems to boot from.
- Generates an initramfs image The initramfs is a compressed cpio archive. The archive can be used on a different box of the same arch with the corresponding Linux kernel.
- Create an initramfs for current running kernel:
At boot time, the kernel unpacks initramfs into RAM disk, mounts and uses it as initial root file system.
$ mkinitramfs -o ~/tmp/initramfs-$(uname -r)
$ mkinitramfs -k -o ~/tmp/initramfs-2.6.21-686 2.6.21-686
$ lsinitramfs /mnt/casper/initrd
$ mkdir initrd $ cd initrd $ unmkinitramfs /mnt/casper/initrd . $ tree . -L 3 . ├── early │ └── kernel │ └── x86 └── microcode └── AuthenticAMD.bin ├── early2 │ └── kernel │ └── x86 └── microcode └── GenuineIntel.bin └── main ├── bin -> usr/bin ├── conf │ ├── arch.conf │ ├── conf.d │ ├── initramfs.conf │ ├── modules │ └── uuid.conf ├── cryptroot │ └── crypttab ├── etc │ ├── casper.conf │ ├── console-setup │ ├── default │ ├── dhcp │ ├── fstab │ ├── initiatorname.iscsi │ ├── ld.so.cache │ ├── ld.so.conf │ ├── ld.so.conf.d │ ├── lvm │ ├── mdadm │ ├── modprobe.d │ ├── motd │ ├── mtab -> /proc/mounts │ ├── nsswitch.conf │ ├── os-release │ ├── passwd │ ├── plymouth │ ├── ssl │ └── udev ├── init ├── lib -> usr/lib ├── lib32 -> usr/lib32 ├── lib64 -> usr/lib64 ├── libx32 -> usr/libx32 ├── run ├── sbin -> usr/sbin ├── scripts │ ├── casper │ ├── casper-bottom │ ├── casper-functions │ ├── casper-helpers │ ├── casper-premount │ ├── functions │ ├── init-bottom │ ├── init-premount │ ├── init-top │ ├── local │ ├── local-block │ ├── local-bottom │ ├── local-premount │ ├── local-top │ ├── lupin-helpers │ ├── nfs │ └── panic ├── usr │ ├── bin │ ├── lib │ ├── lib32 │ ├── lib64 │ ├── libx32 │ ├── sbin │ └── share └── var └── lib
Create Bootable Windows USB Sticks from Linux
WoeUSB is Linux tool for creating Windows USB stick installer from a real Windows DVD or an image.- woeusb is a CLI utility that does the actual creation of a bootable Windows installation USB storage device from either an existing Windows installation or a disk image.
- woeusbgui (as the name suggests,) is a woeusb GUI wrapper based on WxWidgets.
Install WoeUSB on Ubuntu
sudo add-apt-repository ppa:nilarimogard/webupd8 sudo apt update wget http://security.ubuntu.com/ubuntu/pool/universe/w/wxwidgets3.0/libwxgtk3.0-0v5_3.0.4+dfsg-3_amd64.deb sudo apt install ./libwxgtk3.0-0v5_3.0.4+dfsg-3_amd64.deb sudo apt install woeusb sudo woeusb --target-filesystem NTFS --device win10.iso /dev/sdbx
BIOS-Boot or EFI partition
BIOS-Boot partition(if your BIOS is set up in Legacy mode)
- Mount point none
- Type no filesystem
- Description the BIOS-boot partition contains GRUB 2's core.
- Size 1MB.
It is necessary if you install Ubuntu on a GPT disk, and if the firmware (BIOS) is set up in Legacy (not EFI) mode.
It must be located at the start of a GPT disk, and have a "bios_grub" flag.
EFI partition: if your BIOS is set up in EFI mode(if your BIOS is set up in EFI mode)
- Mount point /boot/efi (no need to set up this mount point as the installer will do it automatically)
- Type FAT (generally FAT32)
- Description the EFI partition (also called ESP) contains some boot files.
- Size 100~250MB
It is necessary if the firmware (BIOS) is set up to boot the HDD in EFI mode (which is default on more and more modern, > year 2011 computers).
It must be located at the start of a GPT disk, and have a "boot" flag.
EFI Boot manager
efibootmgr is a tool for managing UEFI boot entries.
Installation
CONFIG_EFI_VARS support needs to be enabled in kernel:Firmware Drivers --->l EFI (Extensible Firmware Interface) Support ---> <*> EFI Variable Support via sysfsInstall:
sudo apt install efibootmgr
Configuration
EFI vars
In order to successfully use efibootmgr the EFI variables filesystem must be accessible.When the system is in EFI mode, run the following command to check for the existence of efivarfs:
sudo mount | grep efivars
Listing boot entries
$ efibootmgr -v BootCurrent: 0000 Timeout: 1 seconds BootOrder: 0000,0002,0003 Boot0000* ubuntu HD(1,GPT,32d52b22-0e61-42ab-b9eb-afa549ffaa41,0x800,0xee000)/File(\EFI\UBUNTU\SHIMX64.EFI) Boot0002* UEFI: PXE IPv4 Intel(R) Ethernet Connection (10) I219-V PciRoot(0x0)/Pci(0x1f,0x6)/MAC(1c697a6e9412,0)/IPv4(0.0.0.00.0.0.0,0,0)..BO Boot0003* UEFI: PXE IPv6 Intel(R) Ethernet Connection (10) I219-V PciRoot(0x0)/Pci(0x1f,0x6)/MAC(1c697a6e9412,0)/IPv6([::]:<->[::]:,0,0)..BOThe asterisk (*) means the boot entry is active.
You can see the EFI system partition number, the partition table type (GPT), UUID of the EFI system partition and the boot loader file.
The above shows that the EFI system partition (ESP) is on the 1st partition of my hard disk (/dev/sda1). It’s a GPT partition table.
Install Kernel
linux-generic contains omplete Generic Linux kernel and headers.List currently installed linux images:
$ dpkg --list | grep linux-image ii linux-image-5.4.0-72-generic 5.4.0-72.80 amd64 Signed kernel image generic ii linux-image-generic 5.4.0.72.75 amd64 Generic Linux kernel image
Packages
linux-image
$ apt-file find vmlinuz-5.8.0-50-generic linux-image-5.8.0-50-generic: /boot/vmlinuz-5.8.0-50-generic linux-image-unsigned-5.8.0-50-generic: /boot/vmlinuz-5.8.0-50-genericSearch available kernel version:
$ apt-cache search linux-image
$ sudo apt install linux-image-5.8.0-50-generic $ sudo apt install linux-headers-5.8.0-50-generic
linux-image-extra
initramfs-tools
update-initramfs generates an initramfs image.The initramfs is a gzipped cpio archive.
At boot time, the kernel unpacks that archive into RAM disk, mounts and uses it as initial root file system.
- Update the initramfs of the newest kernel:
update-initramfs -u
update-initramfs -u -k `uname -r`
/usr/share/initramfs-tools |-- conf-hooks.d | `-- busybox-initramfs |-- conf.d |-- hook-functions |-- hooks | |-- amd64_microcode | |-- brltty | |-- compcache | |-- console_setup | |-- dmsetup | |-- fixrtc | |-- framebuffer | |-- fsck | |-- fuse | |-- intel_microcode | |-- kbd | |-- klibc-utils | |-- kmod | |-- lvm2 | |-- ntfs_3g | |-- plymouth | |-- resume | |-- thermal | |-- thin-provisioning-tools | |-- udev | |-- zz-busybox-initramfs | `-- zz-dhclient |-- init |-- modules |-- modules.d `-- scripts |-- functions |-- init-bottom | |-- lvm2 | |-- plymouth | `-- udev |-- init-premount | |-- brltty | |-- lvm2 | `-- plymouth |-- init-top | |-- all_generic_ide | |-- blacklist | |-- brltty | |-- console_setup | |-- framebuffer | `-- udev |-- local |-- local-block | `-- lvm2 |-- local-bottom | `-- ntfs_3g |-- local-premount | |-- fixrtc | |-- ntfs_3g | `-- resume |-- local-top | `-- lvm2 |-- nfs `-- panic |-- console_setup `-- plymouthBoot scripts are included in the initramfs image and normally executed during kernel boot in the early user-space before the root partition has been mounted.
Hook scripts are used when an initramfs image is created and not included in the image itself.
They can however cause files to be included in the image.
Hook scripts are executed under errexit.
Thus a hook script can abort the mkinitramfs build on possible errors (exitcode != 0).
Hooks can be found in two places:
- /usr/share/initramfs-tools/hooks
- /etc/initramfs-tools/hooks
Regenerating the initramfs:
$ sudo dpkg-reconfigure linux-image-5.4.0-92-generic Processing triggers for linux-image-5.4.0-92-generic (5.4.0-92.103) ... /etc/kernel/postinst.d/initramfs-tools: update-initramfs: Generating /boot/initrd.img-5.4.0-92-generic /etc/kernel/postinst.d/zz-update-grub: Sourcing file `/etc/default/grub' Sourcing file `/etc/default/grub.d/10-disableos-prober.cfg' Sourcing file `/etc/default/grub.d/50-cloudimg-settings.cfg' Sourcing file `/etc/default/grub.d/init-select.cfg' Generating grub configuration file ... Found linux image: /boot/vmlinuz-5.4.0-92-generic Found initrd image: /boot/initrd.img-5.4.0-92-generic Adding boot menu entry for UEFI Firmware Settings done
How To View Content Of initrd.img file?
To list the content:$ lsinitramfs /boot/initrd.img-5.11.0-43-generic > initrd.img-5.11.0-43-generic.lst
How To Modify Content Of initrd.img file?
Since initramfs usually needs to be customized for the particular hardware/device configuration and kernel version, they are not included as a part of any package, but are generated on the fly at kernel installation time.To create/recreate/update the initramfs file means to update the initrd.img-* ramdisk files in /boot.
- Create a totally fresh version
$ mkdir initrd $ cd initrd/ $ sudo update-initramfs -c -k $(uname -r) update-initramfs: Generating /boot/initrd.img-5.4.0-92-generic $ ls -l /boot/initrd.img* lrwxrwxrwx 1 root root 27 Jan 5 00:59 /boot/initrd.img -> initrd.img-5.4.0-92-generic -rw-r--r-- 1 root root 90027126 Jan 5 06:37 /boot/initrd.img-5.4.0-92-generic lrwxrwxrwx 1 root root 27 Jan 5 00:59 /boot/initrd.img.old -> initrd.img-5.4.0-92-generic
$ sudo apt remove mdadmor
$ sudo mv /usr/share/initramfs-tools/hooks/mdadm .
$ sudo update-initramfs -u
$ lsinitramfs /boot/initrd.img-5.4.0-92-generic |grep mdadm
grub2-common
Update GRUB menu:$ sudo update-grub
kernel-install
kernel-install is used to install/remove kernel and initramfs images to/from /boot.
kernel-install will execute the files located in the directory /usr/lib/kernel/install.d/ and the local administration directory /etc/kernel/install.d/.
/usr/lib/kernel/install.d ├── 00-entry-directory.install ├── 50-depmod.install ├── 85-initrd.install └── 90-loaderentry.install /etc/kernel/ ├── install.d ├── postinst.d │ ├── apt-auto-removal │ ├── initramfs-tools │ ├── unattended-upgrades │ ├── update-notifier -> /usr/share/update-notifier/notify-reboot-required │ └── zz-update-grub ├── postrm.d │ ├── initramfs-tools │ └── zz-update-grub └── preinst.d └── intel-microcodeFiles in /etc/kernel/install.d/ take precedence over files with the same name in /usr/lib/kernel/install.d/.
Executables must have the extension ".install"; other extensions are ignored.
An executable should return 0 on success.
COMMANDS
The following commands are understood:- add KERNEL-VERSION KERNEL-IMAGE kernel-install creates the directory /boot/MACHINE-ID/KERNEL-VERSION/ and copies KERNEL-IMAGE to /boot/MACHINE-ID/KERNEL-VERSION/linux.
- remove KERNEL-VERSION kernel-install removes the entire directory /boot/MACHINE-ID/KERNEL-VERSION/
It also creates a boot loader entry.
Update GRUB menu
$ sudo update-grub
Remove kernel
$ uname -a $ dpkg --get-selections | grep linux-image $ sudo apt purge linux-image-X.X.XX-XX-genericWhat is the difference between apt remove and apt purge?
- apt remove just removes the binaries of a package. It leaves residue configuration files.
- apt purge removes everything related to a package including the configuration files.
If you used apt remove to a get rid of a particular software and then install it again, your software will have the same configuration files.
BIOS boot partition
GNU GRUB Manual 2.04
深入指揮作業系統啟動 詳解GRUB開機管理程式
GRUB支援多個作業系統(Multi-boot)的啟動,對於無法啟動的作業系統如Windows和OS/2之類的系統,GRUB則是透過鏈式啟動(Chain Loading)的方式來支援。
所謂鏈式啟動,簡單講就是透過GRUB開機管理程式去啟動另一個作業系統自己的開機管理程式,例如GRUB就是透過啟動Windows系統開機管理程式(NTLDR)的方式支援Windows開機。
GRUB支援常見的UNIX檔案系統(File System),也支援Windows系統中使用的FAT和NTFS檔案系統。GRUB藉由支援這些檔案系統,讓使用者無須載入作業系統,便可以在GRUB開機時檢視GRUB所支援檔案系統裡檔案的內容。
GRUB的啟動載入過程分成三個階段.
階段1(Stage 1)
GRUB在安裝時,會將boot.img寫入到主要啟動磁區(MBR)內. BIOS載入MBR程式碼時,就是載入boot.img檔案的程式內容. boot.img取得主控權後的主要動作,就是緊接著載入第1.5階段所需的core.img檔案。
階段1.5(Stage 1.5)
主控權會由boot.img交給core.img. core.img會載入設定及所需的相關模組,特別是檔案系統模組,讓GRUB可以在之後提供使用者檢視各個磁碟檔案系統的功能。 core.img在載入設定與模組後,便會從設定中找出「/boot/grub」在磁碟中的位置,並讀取在「/boot/grub」內有關作業系統載入與開機的相關資訊
階段2(Stage 2)
使用者看到的便是在螢幕中的文字模式開機選項選單。此時,GRUB便處在等待使用者選擇選項開機或執行相關指令的狀態中。
boot.img嚴格占有446位元組的大小,並被寫入MBR(0磁區)。
如果可行(出於向下相容的原因第一個分割區起始於63磁區而非1磁區,但這不是強制的),core.img被寫入介於MBR和第一分割區之間的空磁區之中。
/boot/grub目錄可以放在單獨的分割區中,也可以放在根分割區中。
GRUB選單介紹
GRUB採用捲動螢幕選擇想要啟動的作業系統。通過向"menu.lst"(或grub.cfg)檔案中添加相關資訊,
- GRUB Legacy的設定檔為/boot/grub/menu.lst或/boot/grub/grub.conf。
- GRUB 2的設定檔為/boot/grub/grub.cfg。
編輯選項的e指令
進入GRUB命令列的c指令
載入作業系統前,在GRUB文字模式螢幕下鍵入c鍵可以進入GRUB命令列。
grub>然後用戶可以直接對GRUB下指令,
要離開GRUB提示符號回到選單,則按下〔ESC〕鍵。
進入GRUB命令提示模式,便表示可以忽略原本GRUB的設定,逕自對GRUB下指令來選擇要開機的方式及環境。
- help 列出GRUB所支援的指令, GRUB會自動對命令做分頁顯示,按下任意鍵就會顯示下一頁命令列表,help後面加上指令名稱,就會顯示指令的用法說明
- clear 清空畫面輸出
- set 列出環境變數設定
- echo $環境變數
- ls 列出目前GRUB所找到的磁碟機與分割資訊
- lsmod 顯示出目前GRUB已載入的模組名稱,以及其相關模組與參考資訊。 GRUB預設可能沒有載入GPT分割表模組,因此若要辨識GPT分割表,使用「insmod part_gpt」指令載入GPT分割表模組,便可辨識出GPT分割,在未載入part_gpt這個GPT分割表模組之前,只有顯示(hd1)磁碟機資訊。載入了ntfs模組便可列出NTFS檔案系統中的檔案與目錄資訊
- cat 列出系統中相關設定檔的內容. 在輸入指令時,可以像在bash一樣透過按下〔Tab〕鍵讓系統帶出可能的檔名建議或列表.
- configfile file Load file as a configuration file. If file defines any menu entries, then show a menu containing them immediately. Any environment variable changes made by the commands in file will not be preserved after configfile returns.
- probe [--set var] --driver|--partmap|--fs|--fs-uuid|--label device Retrieve device information. If option --set is given, assign result to variable var, otherwise print information on the screen.
圖中顯示了目前有磁碟機hd0,hd0裡有兩個以舊有MBR分割型態分割的磁碟分割,分別為msdos1及msdos2. 可以分別使用「ls (hd0,msdos1)」及「ls (hd0,msdos2)」指令來檢視分割表資訊,
從中觀察,msdos1顯示了檔案系統型態為xfs、分割的UUID編號以及分割的KB大小,但是第二個分割卻沒顯示檔案系統,為未知(No Known)無法辨識,只有顯示分割的大小。這是因為第二分割是lvm型態的檔案系統,因為GRUB相關的lvm模組未載入,所以無法辨識。 這時可以使用「insmod lvm」指令載入lvm模組,然後利用ls指令再檢視一次,便可成功顯示分割資訊. 除了顯示檔案系統資訊外,也可以使用ls指令列出可辨識檔案系統內相關檔案與目錄的資訊,例如執行「ls (hd0,msdos1)/」指令就可以列出msdos1這個分割裡面的根目錄下檔案根.既然能夠顯示根目錄,當然也就能顯示目錄下指定路徑的檔案及子目錄資訊.
找到相關Linux系統核心磁碟與檔案相關位置後,便可藉由執行指令的方式逕自進行開機。 例如在ubuntu 20.04 Installer的環境下,
grub>linux (cd0)/casper/vmlinuz grub>initrd (cd0)/casper/initrd grub>boot
- 設定GRUB所安裝的設備名稱與分割編號 (hd0,1)表示第一個硬碟的第一個分割
set root=(hd0,1)
linux
initrd
boot
認識GRUB設定檔
/boot/grub/grub.cfg
這是最後GRUB產生的選單設定檔案,一般不會直接更改這個檔案,而是更改相關設定檔後,執行「grub-mkconfig -o /boot/grub/grub.cfg」指令來更新grub.cfg。執行指令後,GRUB會讀取且執行相關設定檔來偵測位於「/boot」目錄下相關Linux系統核心檔案,之後將這些檔案設定加入到「/boot/grub/grub.cfg」檔案裡面,產生最後在開機看到的GRUB開機管理程式選單。
/etc/default/grub
- GRUB_DEFAULT 這是設定預設選單選項,如果是寫成「GRUB_DEFAULT=0」則預設開機選項會是第一項,若設為「GRUB_DEFAULT=1」則是第二項,以此類推。而如果寫成「GRUB_DEFAULT=saved」,則表示預設開機選項可以由grub2-set-default或是grub2-reboot這兩個指令來設定,在這兩個指令後面空格再直接指定是第幾項即可。
- GRUB_SAVEDEFAULT 若設為「GRUB_SAVEDEFAULT=true」,GRUB會將上次選擇的開機選項設為預設選項,不過「/boot」目錄如果位於LVM或RAID上,則做這個設定會沒有效用。
- GRUB_HIDDEN_TIMEOUT 設定GRUB選單隱藏的時間,單位是整數秒,當只有單一作業系統時,GRUB會直接由那個作業系統開機,而不顯示選單,若要顯示選單,可以按〔Shift〕鍵,若是多個作業系統,則GRUB預設為不隱藏選單,會一直顯示選單。
- GRUB_HIDDEN_TIMEOUT_QUIET 設定是否顯示倒數計時的數字,設定為「true」,表示不顯示。
- GRUB_TIMEOUT 設定在多少秒之後自動以預設的作業系統開機,值若設定為「-1」時,開機選單會持續顯示,直到使用者選擇選項。
/etc/grub.d/
目錄下有一些設定檔案,都是以Shell程式的方式寫成,grub-mkconfig才會去執行它們並產生設定檔內容
- 00_header 這是設定初始顯示項目的設定檔,包含圖形模式、預設選項、時間限制等設定,這些設定基本上都是由剛剛說明過的「/etc/default/grub」中的設定轉入,因此這個設定檔一般不直接更改,而是透過修改「/etc/default/grub」檔案的設定來更新00_header內的設定。
- 10_linux 此檔案是負責去搜尋root設備底下「 /boot」目錄裡Linux系統核心相關檔案,grub-mkconfig去搜尋Linux系統核心相關檔案的動作,便是由10_linux這個檔案來進行,因此一般也不會直接更改10_linux檔案,如果要拿掉一些Linux kernel選項,使用者將「/boot」底下相關的Linux kernel檔案刪除即可。
- 30_os-prober 此檔案是負責到其他磁碟找尋Windows、Linux、Mac OS/X、Minix或是Hurd等相關作業系統,並把這些位於其他磁碟機的作業系統加入開機選項中,這個檔案主要是讓grub-mkconfig呼叫使用,是系統寫好的偵測指令稿程式(Shell Script),因此沒有修改必要。
- 40_custom 看到custom檔名就知道這個檔案是讓使用者能夠修改加入自己所想設定的項目。因此,在「/etc/grub.d/」目錄下,唯一可以直接讓使用者修改的就是這個檔案,不過使用者必須熟悉Shell程式設計與GRUB相關設定。
如果GRUB沒安裝好,導致看不到開機畫面或只是看到GRUB這四個字系統就停住,那就需要另外的Linux開機救援光碟進入系統重新修復GRUB的安裝。
Chainloading: Another bootloader
Chainloading another bootloader to GRUB2 is fairly easy.
Something as simple as the following example is enough to boot another disk that uses a "Custom Super Bootloader".
Use /etc/grub.d/40_custom foo chainloading another bootloader:
menuentry "Custom Super Bootloader Example" { insmod part_msdos insmod chain chainloader (hd1,1) +1 }
If you see "Invalid EFI file path" after executing chainloader, you can try replacing the entry with something like the following:
menuentry "Windows 7" { insmod part_gpt insmod chain set root='(hd0,gpt5)' chainloader /EFI/Microsoft/Boot/bootmgfw.efi }If this still fails, this means your Windows is using the legacy MBR partition table.
Windows (MSDOS based boot loaders)
Microsoft Windows 8 (and above versions) are no longer installed using MSDOS partitions by default, however they do maintain backwards compatibility with BIOS MBR systems.
Sometimes it is necessary in the BIOS firmware configuration tool to disable UEFI mode completely in order to force BIOS MBR mode.
The simplest way to dual boot Windows (or MS-DOS) is to add an MBR menu entry to GRUB2's grub.cfg file for each Windows operating system installed.
For instance, to boot Windows 7, add the following to the grub.cfg file, modify /etc/grub.d/40 :
- Windows 7 example
menuentry "Windows 7 BIOS MBR" { insmod part_msdos insmod ntldr insmod ntfs ntldr (hd0,msdos1)/bootmgr }
menuentry "Windows XP BIOS MBR" { insmod part_msdos insmod ntldr insmod ntfs ntldr (hd0,msdos1)/ntldr }
menuentry "Windows 10" { insmod ntfs insmod ntldr insmod part_msdos insmod search_fs_uuid search --no-floppy --fs-uuid --set=root 1AECC5A1ECC57811 ntldr /bootmgr }The ntldr relies on legacy BIOS to do its job. On an UEFI system, you have a version of GRUB with the x86_64-efi architecture, which can only chainload other UEFI bootloaders. The ntldr module does not exist in the EFI version of grub2. Partition UUIDs can be obtained with blkid.
menuentry "Windows 7 Enterprise" { insmod ntfs insmod chain set root='(hd0,msdos1)' chainloader +1 }
How to use boot-repair to provide a "Bootinfo Summary"
- Install and run the Boot-Repair tool
sudo add-apt-repository ppa:yannubuntu/boot-repair sudo apt-get update sudo apt-get install -y boot-repair
boot-repair-4ppa124 [20200606_2045] ============================== Boot Info Summary =============================== => Windows 7/8/2012 is installed in the MBR of /dev/sda. => Grub2 (v2.00) is installed in the MBR of /dev/sdb and looks at sector 1 of the same hard drive for core.img. core.img is at this location and looks for (,msdos1)/boot/grub. It also embeds following components: modules --------------------------------------------------------------------------- fshelp ext2 part_msdos biosdisk --------------------------------------------------------------------------- => Windows 7/8/2012 is installed in the MBR of /dev/sdc. sda1: __________________________________________________________________________ File system: ntfs Boot sector type: Windows 7/2008: NTFS Boot sector info: No errors found in the Boot Parameter Block. Operating System: Boot files: /bootmgr /Boot/BCD sda2: __________________________________________________________________________ File system: ntfs Boot sector type: Windows 7/2008: NTFS Boot sector info: No errors found in the Boot Parameter Block. Operating System: Windows 7 Boot files: /Windows/System32/winload.exe sdb1: __________________________________________________________________________ File system: vfat Boot sector type: FAT32 Boot sector info: No errors found in the Boot Parameter Block. Operating System: Boot files: /efi/BOOT/fbx64.efi /efi/ubuntu/fwupx64.efi /efi/ubuntu/grubx64.efi /efi/ubuntu/mmx64.efi /efi/ubuntu/shimx64.efi /efi/ubuntu/grub.cfg sdb2: __________________________________________________________________________ File system: Extended Partition Boot sector type: Unknown Boot sector info: sdb5: __________________________________________________________________________ File system: ext4 Boot sector type: - Boot sector info: Operating System: Ubuntu 18.04.4 LTS Boot files: /boot/grub/grub.cfg /etc/fstab /etc/default/grub sdc1: __________________________________________________________________________ ... sdc2: __________________________________________________________________________ ... sdc5: __________________________________________________________________________ ... sdc3: __________________________________________________________________________ ... ================================ 2 OS detected ================================= OS#1: The OS now in use - Ubuntu 18.04.4 LTS CurrentSession on sdb5 OS#2: Windows 7 on sda2 ============================ Architecture/Host Info ============================ CPU architecture: 64-bit BOOT_IMAGE of the installed session in use: /boot/vmlinuz-5.3.0-53-generic root=UUID=fdbf84c2-25ea-48a7-8193-621d1b01f928 ro quiet splash vt.handoff=1 ===================================== UEFI ===================================== BIOS is EFI-compatible, and is setup in EFI-mode for this installed-session. SecureBoot disabled. efibootmgr -v BootCurrent: 0006 Timeout: 1 seconds BootOrder: 0006,0004,0005 Boot0004* Hard Drive BBS(HD,,0x0)..GO..NO........o.K.I.N.G.S.T.O.N. .S.A.4.0.0.S.3.7.2.4.0.G....................A...........................>..Gd-.;.A..MQ..L.0.5.2.0.B.6.6.7.6.7.1.0.9.A.6.B. . . . ........BO..NO........o.S.T.1.0.0.0.L.M.0.4.8.-.2.E.7.1.7.2....................A...........................>..Gd-.;.A..MQ..L. . . . . . . . . . . . .G.Z.1.S.R.R.E.H........BO..NO........o.W.D.C. .W.D.1.0.J.P.V.X.-.2.2.J.C.3.T.0....................A...........................>..Gd-.;.A..MQ..L. . . . .W. .-.D.X.W.1.M.8.E.A.3.K.F.5.N........BO Boot0005* CD/DVD Drive BBS(CDROM,,0x0)..GO..NO........I.P.I.O.N.E.E.R. .B.D.-.R.W. . . .B.D.R.-.2.0.9.M....................A..............................Gd-.;.A..MQ..L.P........BO Boot0006* ubuntu HD(1,MBR,0xfd195226,0x800,0x100000)/File(\EFI\Ubuntu\shimx64.efi)..BO bed45d1c9554cea09924d3814cb7c446 sdb1/BOOT/fbx64.efi b5698f2f88c3917bdf0c9f0f2a45d469 sdb1/ubuntu/fwupx64.efi 64a633007e3d5a9a5943e417442548d6 sdb1/ubuntu/grubx64.efi 4487628005555bfd4a4c0a47211e0700 sdb1/ubuntu/mmx64.efi f7a57b08bc7c1c85417ae4cea582d1d4 sdb1/ubuntu/shimx64.efi f7a57b08bc7c1c85417ae4cea582d1d4 sdb1/BOOT/BOOTX64.efi ============================= Drive/Partition Info ============================= Disks info: ____________________________________________________________________ sdb : notGPT, no-BIOSboot, has---ESP, not-usb, not-mmc, has-os, 2048 sectors * 512 bytes sda : notGPT, no-BIOSboot, has-noESP, not-usb, not-mmc, has-os, 2048 sectors * 512 bytes sdc : notGPT, no-BIOSboot, has-noESP, not-usb, not-mmc, no-os, 2048 sectors * 512 bytes Partitions info (1/3): _________________________________________________________ sdb5 : is-os, 64, apt-get, signed grub-pc grub-efi , grub2, grub-install, grubenv-ok, update-grub, farbios sda1 : no-os, 32, nopakmgr, no-docgrub, nogrub, nogrubinstall, no-grubenv, noupdategrub, not-far sda2 : is-os, 32, nopakmgr, no-docgrub, nogrub, nogrubinstall, no-grubenv, noupdategrub, farbios sdb1 : no-os, 32, nopakmgr, no-docgrub, nogrub, nogrubinstall, no-grubenv, noupdategrub, not-far sdc1 : no-os, 32, nopakmgr, no-docgrub, nogrub, nogrubinstall, no-grubenv, noupdategrub, farbios sdc3 : no-os, 32, nopakmgr, no-docgrub, nogrub, nogrubinstall, no-grubenv, noupdategrub, farbios sdc5 : no-os, 32, nopakmgr, no-docgrub, nogrub, nogrubinstall, no-grubenv, noupdategrub, farbios Partitions info (2/3): _________________________________________________________ sdb5 : isnotESP, fstab-has-goodEFI, no-nt, no-winload, no-recov-nor-hid, no-bmgr, notwinboot sda1 : isnotESP, part-has-no-fstab, no-nt, no-winload, no-recov-nor-hid, bootmgr, is-winboot sda2 : isnotESP, part-has-no-fstab, no-nt, haswinload, no-recov-nor-hid, no-bmgr, notwinboot sdb1 : is---ESP, part-has-no-fstab, no-nt, no-winload, no-recov-nor-hid, no-bmgr, notwinboot sdc1 : isnotESP, part-has-no-fstab, no-nt, no-winload, no-recov-nor-hid, no-bmgr, notwinboot sdc3 : isnotESP, part-has-no-fstab, no-nt, no-winload, no-recov-nor-hid, no-bmgr, notwinboot sdc5 : isnotESP, part-has-no-fstab, no-nt, no-winload, no-recov-nor-hid, no-bmgr, notwinboot Partitions info (3/3): _________________________________________________________ sdb5 : not-sepboot, with-boot, fstab-without-boot, not-sep-usr, with--usr, fstab-without-usr, std-grub.d, sdb sda1 : not-sepboot, no-boot, part-has-no-fstab, not-sep-usr, no---usr, part-has-no-fstab, std-grub.d, sda sda2 : not-sepboot, no-boot, part-has-no-fstab, not-sep-usr, no---usr, part-has-no-fstab, std-grub.d, sda sdb1 : not-sepboot, no-boot, part-has-no-fstab, not-sep-usr, no---usr, part-has-no-fstab, std-grub.d, sdb sdc1 : not-sepboot, no-boot, part-has-no-fstab, not-sep-usr, no---usr, part-has-no-fstab, std-grub.d, sdc sdc3 : not-sepboot, no-boot, part-has-no-fstab, not-sep-usr, no---usr, part-has-no-fstab, std-grub.d, sdc sdc5 : not-sepboot, no-boot, part-has-no-fstab, not-sep-usr, no---usr, part-has-no-fstab, std-grub.d, sdc fdisk -l (filtered): ___________________________________________________________ Disk sda: 223.6 GiB, 240057409536 bytes, 468862128 sectors Disk identifier: 0x818c62ac Boot Start End Sectors Size Id Type sda1 * 2048 206847 204800 100M 7 HPFS/NTFS/exFAT sda2 206848 468858879 468652032 223.5G 7 HPFS/NTFS/exFAT Disk sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors Disk identifier: 0xfd195226 Boot Start End Sectors Size Id Type sdb1 * 2048 1050623 1048576 512M ef EFI (FAT-12/16/32) sdb2 1052670 1953523711 1952471042 931G 5 Extended sdb5 1052672 1953523711 1952471040 931G 83 Linux Disk sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors ... blkid (filtered): ______________________________________________________________ NAME FSTYPE UUID PARTUUID LABEL PARTLABEL sda ├─sda1 ntfs 383AA4973AA45422 818c62ac-01 系統保留 └─sda2 ntfs 5EAEA624AEA5F4A5 818c62ac-02 sdb ├─sdb1 vfat E4A7-2619 fd195226-01 ├─sdb2 fd195226-02 └─sdb5 ext4 fdbf84c2-25ea-48a7-8193-621d1b01f928 fd195226-05 sdc ├─sdc1 ntfs 6AB87EB0B87E7B01 a299e4a4-01 程式集 ... . ===================== sdb1/efi/ubuntu/grub.cfg (filtered) ====================== search.fs_uuid fdbf84c2-25ea-48a7-8193-621d1b01f928 root hd1,msdos5 set prefix=($root)'/boot/grub' configfile $prefix/grub.cfg ====================== sdb5/boot/grub/grub.cfg (filtered) ====================== Ubuntu fdbf84c2-25ea-48a7-8193-621d1b01f928 Ubuntu, with Linux 5.3.0-53-generic fdbf84c2-25ea-48a7-8193-621d1b01f928 Ubuntu, with Linux 4.18.0-15-generic fdbf84c2-25ea-48a7-8193-621d1b01f928 ### END /etc/grub.d/30_os-prober ### System setup uefi-firmware ### END /etc/grub.d/30_uefi-firmware ### ========================== sdb5/etc/fstab (filtered) =========================== # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sdb5 during installation UUID=fdbf84c2-25ea-48a7-8193-621d1b01f928 / ext4 errors=remount-ro 0 1 # /boot/efi was on /dev/sdb1 during installation UUID=E4A7-2619 /boot/efi vfat umask=0077 0 1 /swapfile none swap sw 0 0 ======================= sdb5/etc/default/grub (filtered) ======================= GRUB_DEFAULT=0 GRUB_TIMEOUT=5 GRUB_HIDDEN_TIMEOUT_QUIET=false GRUB_TIMEOUT_STYLE=menu GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX="" ==================== sdb5: Location of files loaded by Grub ==================== GiB - GB File Fragment(s) 160.653255463 = 172.500119552 boot/grub/grub.cfg 3 4.478511810 = 4.808765440 boot/vmlinuz-4.18.0-15-generic 2 93.557353973 = 100.456443904 boot/vmlinuz-5.3.0-53-generic 1 4.478511810 = 4.808765440 vmlinuz 2 7.208553314 = 7.740125184 boot/initrd.img-4.18.0-15-generic 2 7.282760620 = 7.819804672 boot/initrd.img-5.3.0-53-generic 2 7.208553314 = 7.740125184 initrd.img 2 7.208553314 = 7.740125184 initrd.img.old 2 ===================== sdb5: ls -l /etc/grub.d/ (filtered) ====================== -rwxr-xr-x 1 root root 12693 二 8 2019 10_linux -rwxr-xr-x 1 root root 11298 二 8 2019 20_linux_xen -rwxr-xr-x 1 root root 12059 二 8 2019 30_os-prober -rwxr-xr-x 1 root root 1418 二 8 2019 30_uefi-firmware -rwxr-xr-x 1 root root 214 二 8 2019 40_custom -rwxr-xr-x 1 root root 216 二 8 2019 41_custom ======================== Unknown MBRs/Boot Sectors/etc ========================= Unknown BootLoader on sdb2 ... ================================= User choice ================================== Is sdb (ATA ST1000LM048-2E71) a removable disk? no Suggested repair: ______________________________________________________________ The default repair of the Boot-Repair utility would purge (in order to remove grub-efi) and reinstall the grub2 of sdb5 into the MBRs of all disks (except live-disks and removable disks without OS). Grub-efi would not be selected by default because: legacy-win no-win-efi Additional repair would be performed: unhide-bootmenu-10s win-legacy-basic-fix Blockers in case of suggested repair: __________________________________________ LegacyWindows detected. Please enable BIOS-compatibility/CSM/Legacy mode in your UEFI firmware, and use this software from a live-CD (or live-USB). Final advice in case of suggested repair: ______________________________________ Please do not forget to make your BIOS boot on sdb (ATA ST1000LM048-2E71) disk! The boot of your PC is in UEFI mode. You may want to retry after changing it to BIOS-compatibility/CSM/Legacy mode.
在不遺失資料的情況下, 將Windows* 安裝的硬碟從舊式MBR轉換為UEFI mode
說明將 SSD 從 MBR(主開機記錄)轉換到 GPT (GUID 磁碟分割表格)磁碟分割架構的方法。
確認 Windows 已安裝到 MBR 分割區中
- Log in Windows
- 開啟磁碟管理員。對於 Windows 10, 請同時按下 Windows 鍵和 X 鍵,然後按一下磁碟管理員。
- 找到主要系統開機磁碟分割。
- 用滑鼠右鍵按一下左側顯示為(磁碟 x、基本、容量、線上) 的磁碟 (在該映像中,表示磁碟 0 為範例)。
- 選取「內容」。
- 按一下磁碟區標籤。
- 在這裡您可以確認分割區樣式。
使用 MBR2GPT.exe 將磁碟分割表格從 MBR 轉換為 GPT
- 開啟具有管理員權限的命令提示字元。
- 發出以下命令:mbr2gpt.exe /convert /allowfullOS。
- 關閉並啟動到您的 BIOS。
- 將設定更改為 UEFI 模式。
MBR2GPT tool test guidance
MBR2GPT.EXE converts a disk from Master Boot Record (MBR) to GUID Partition Table (GPT) partition style without modifying or deleting data on the disk. The tool is designed to be run from a Windows Preinstallation Environment (Windows PE) command prompt but can also be run from the full Windows 10 operating system (OS).
Prior to running MBR2GPT:
- Run msinfo32 to verify the Machine is currently booted in BIOS mode
- Run msinfo32 to verify the Windows 64-bit OS is installed
- Make that the system disk has at most 3 primary partitions in MBR and at least one of the partitions is marked as Active.
- Make sure that the device’s firmware supports UEFI boot by looking for the relevant setting(s) in the firmware menu, or by checking with the PC/firmware manufacturer
How to Convert MBR to GPT without Data Loss in Windows 7/8/10 [Partition Manager]
Converting MBR to GPT without Data Loss in Windows 7 can be achieved by using MiniTool Partition Wizard
Free Edition is suitable to convert MBR to GPT free in Windows 7 if you only want to convert your data disk. If you need to convert OS disk to GPT, its Professional Edition could be a good choice since Free Edition doesn't support this.
Convert MBR Disk to GPT Disk by Disk Management
The data on the target will be lost.
Use Windows 7 Disk Management.(If there is any partition on the target disk, the function of "Convert to GPT Disk" will be grayed out.)
- Get into the disk management interface, select the target hard disk and delete all partitions in it with "Delete Volume".
- Right-click on the target hard disk and select "Convert to GPT Disk". Then you can discover that the MBR disk is converted to GPT disk successfully.
Convert Windows 7/8/10 Installation from Legacy to UEFI Without Data Loss (Simpler Method)
- Download gpt-fdisk for Windows
- Boot in Windows Recovery Environment
- Download Windows10 MediaCreationTool2004, then create Windows 10 Bootable USB stick from an ISO.
- Shutdown Windows7 and boot using this USB stick
- Entering the command mode Pressing Shift+10 or by Window Setup Wizard: "Repair your computer" --> "Trouble Shoot" --> "Advanced Option" --> "Command Prompt".
- Use diskpart to find out the disk number for your installed Windows7
diskpart list disk select disk x list par exit
cd /d f: gdisk64.exe -l x:Make sure the disk's partitions installed with Windows7.
gdisk64.exe x:Press 'Y' and 'w' to make the change.
- Shrink the bigger partition y to free space for creating the EFI partition
diskpart list disk select disk x sel par y shrink desired = 200 minimum = 200 create par efi format fs = fat32 quick assign letter = Z: exit
bcdboot W:\Windows /l en-us /s Z: /f ALL exit
sudo update-grubto update the system generated grub.cfg file in the /boot/grub/ directory.
Install Ubuntu
How To Install Ubuntu Along With Windows
This guide covers system with BIOS.
- Create a bootable USB stick/burn a DVD Now let’s download the Ubuntu 18.04 .iso image of Ubuntu. Go to this link. Burn the .iso image on DVD. If you are using USB stick then use Rufus to make a bootable USB stick. If your machine uses BIOS mode then use Universal USB Installer. If it uses UEFI mode then use Rufus and use the MBR (or GPT partion scheme, depending on your hard drive partitioning type) partition scheme to make a bootable USB stick. Actually Rufus can be used both for BIOS and UEFI.
- Restart your computer Restart your computer and press one of the Del/Esc/F11/F12 keys to enter into your BIOS setup utility. In the boot priorities menu select the USB as the first boot device and then click Save changes and reboot. Wait for the computer to load the OS in RAM. A GRUB menu will appear.
- Install Ubuntu After the installation process ends press the Restart Now button. The computer will reboot into the GRUB menu, where for ten seconds, you will be able to select which OS you wish to boot, either Ubuntu 18.04 or Windows 7.
留言