╰─# gdisk /dev/sdb GPT fdisk (gdisk) version 0.8.8
Partition table scan: MBR: protective BSD: not present APM: not present GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? forhelp): n Partition number (3-128, default 3): First sector (34-31266782, default = 31264768) or {+-}size{KMGTP}: Last sector (31264768-31266782, default = 31266782) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): EF02 Changed type of partition to 'BIOS boot partition'
Command (? forhelp): p Disk /dev/sdb: 31266816 sectors, 14.9 GiB Logical sector size: 512 bytes Disk identifier (GUID): 42BF9B08-57CA-4F18-8CB5-C3B06668B141 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 31266782 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name 1 2048 526335 256.0 MiB EF00 2 526336 31264767 14.7 GiB 0700 3 31264768 31266782 1007.5 KiB EF02 BIOS boot partition
Command (? forhelp): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully.
安装grub到U盘
1 2 3 4 5 6 7 8 9 10 11
$ sudo mount /dev/sdb1 /mnt -o uid=$USER,gid=$USER# 没什么好说的,挂载U盘使用,加上uid和gid参数只是为了编辑文件不需要sudo而已
# grub安装到MBR $ sudo grub2-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdb Installing for i386-pc platform. Installation finished. No error reported.
# grub安装到ESP,特别注意--removable参数,安装到移动设备上一定要用这个参数 $ sudo grub2-install --target x86_64-efi --efi-directory /mnt --boot-directory=/mnt/boot --removable Installing for x86_64-efi platform. Installation finished. No error reported.
# path to the partition holding ISO images (using UUID) probe -u $root --set=rootuuid set imgdevpath="/dev/disk/by-uuid/$rootuuid"
# lsblk -f to find your UUID for data device set ntfs_data_uuid="71E161DA3EB70972" set ext4_data_uuid="50a92fdb-4e11-47b8-889c-02f430d3a780"
# define globally (i.e outside any menuentry) insmod search_fs_uuid search --no-floppy --set=isopart --fs-uuid $ntfs_data_uuid search --no-floppy --set=centos_iso_part --fs-uuid $ext4_data_uuid# centos no ntfs set isopath=/iso # 定义iso文件存放的路径
# 定义各种要启动的iso镜像名 set ubuntu=ubuntu-16.04.1-desktop-amd64.iso # ubuntu桌面版镜像,支持12.04-16.04 set ubuntuserver=ubuntu-16.04.1-server-amd64.iso # ubuntu服务器版镜像,支持14.04-16.04 set debianlive=debian-live-8.6.0-amd64-gnome-desktop.iso # debian livecd镜像,支持debian8 set deepin15=deepin-15.3-amd64.iso # deepin15镜像 set linuxmint=linuxmint-18.1-kde-64bit.iso # linuxmint镜像,支持17-18 set ubuntukylin=ubuntukylin-16.04.1-desktop-amd64.iso # ubuntukylin镜像,支持14.04-16.04 set centosdvd=CentOS-7-x86_64-DVD-1511.iso # centos DVD版镜像,包括DVD/Everything/Minimal/Netinstall镜像,支持6-7 set centoslive=CentOS-7-x86_64-LiveGNOME-1511.iso # centos livecd镜像,包括livecd/livedvd,支持7(6似乎不支持直接引导ISO,期待PR解决) set opensuse=openSUSE-Leap-42.1-DVD-x86_64.iso # opensuse DVD安装镜像
# grub模块配置 loadfont unicode set lang=zh_CN insmod all_video insmod gfxterm insmod gettext insmod gfxmenu insmod png insmod ext2 insmod part_msdos insmod xfs insmod ntfs insmod loopback insmod iso9660 terminal_output gfxterm set menu_color_normal=cyan/blue set menu_color_highlight=white/blue gfxmode keep set vt_handoff=vt.handoff=7
# 主题配置 set gfxmode=auto set timeout_style=menu settimeout=10 set theme=$prefix/themes/Tuxkiller2/theme.txt export theme
menuentry '从本地硬盘启动' --class harddrive { set root=(hd1) chainloader +1 }
if [ -f "($isopart)$isopath/$linuxmint" ]; then menuentry "linuxmint-18.1-kde-64" --class linuxmint --class gnu-linux --class gnu --class os { set isofile="$isopath/$linuxmint" loopback loop ($isopart)$isofile echo'载入Linux Mint ...' linux (loop)/casper/vmlinuz file=/cdrom/preseed/linuxmint.seed boot=casper iso-scan/filename=$isofile noeject noprompt splash locale=zh_CN.UTF-8 -- echo'载入初始化内存盘 ...' initrd (loop)/casper/initrd.lz } fi
if [ -f "($isopart)$isopath/$ubuntu" ]; then menuentry "Ubuntu Desktop ISO" --class ubuntu --class gnu-linux --class gnu --class os { set isofile="$isopath/$ubuntu" loopback loop ($isopart)$isofile echo'载入Ubuntu Desktop ...' linux (loop)/casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper iso-scan/filename=$isofile noeject noprompt splash locale=zh_CN.UTF-8 -- echo'载入初始化内存盘 ...' initrd (loop)/casper/initrd.lz } fi
if [ -f "($isopart)$isopath/$ubuntukylin" ]; then menuentry "UbuntuKylin Desktop ISO" --class ubuntukylin --class gnu-linux --class gnu --class os{ set isofile="$isopath/$ubuntukylin" loopback loop ($isopart)$isofile echo'载入UbuntuKylin Desktop ...' linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile noeject noprompt splash locale=zh_CN.UTF-8 -- echo'载入初始化内存盘 ...' initrd (loop)/casper/initrd.lz } fi
# 特别注意: Ubuntu Server会出现安装的时候检测不到光驱的现象 # 此时手工进入shell下,将iso镜像挂载在/cdrom继续即可 # mount /dev/sdb1 /media # mount -o loop /media/boot/iso/ubuntu-*-server-*.iso /cdrom if [ -f "($isopart)$isopath/$ubuntuserver" ]; then menuentry "Ubuntu Server ISO" --class ubuntu --class gnu-linux --class gnu --class os{ set isofile="$isopath/$ubuntuserver" loopback loop ($isopart)$isofile set gfxpayload=keep echo'载入Ubuntu Server ...' linux (loop)/install/vmlinuz file=/cdrom/preseed/ubuntu-server.seed iso-scan/filename=$isofile quiet --- echo'载入初始化内存盘 ...' initrd (loop)/install/initrd.gz } fi
if [ -f "($isopart)$isopath/$deepin15" ]; then menuentry "Deepin 15 ISO" --class deepin --class gnu-linux --class gnu --class os{ set isofile="$isopath/$deepin15" loopback loop ($isopart)$isofile echo'载入Deepin ...' linux (loop)/live/vmlinuz.efi boot=live config findiso=$isofile noeject noprompt locales=zh_CN.UTF-8 -- echo'载入初始化内存盘 ...' initrd (loop)/live/initrd.lz } fi
if [ -f "($isopart)$isopath/$debianlive" ]; then menuentry "Debian LiveCD ISO" --class debian --class gnu-linux --class gnu --class os{ set isofile="$isopath/$debianlive" loopback loop ($isopart)$isofile echo'载入Debian LiveCD ...' linux (loop)/live/vmlinuz boot=live config findiso=$isofile noeject noprompt locales=zh_CN.UTF-8 -- echo'载入初始化内存盘 ...' initrd (loop)/live/initrd.img } fi
if [ -f "($centos_iso_part)$isopath/$centosdvd" ]; then menuentry "CentOS-7-x86_64-DVD-1511" --class centos --class gnu-linux --class gnu --class os{ set isofile="$isopath/$centosdvd" loopback loop ($centos_iso_part)$isofile echo'载入CentOS DVD ...' linux (loop)/isolinux/vmlinuz inst.stage2=hd:UUID=$ext4_data_uuid:/$isofile inst.lang=zh_CN.UTF-8 rhgb echo'载入初始化内存盘 ...' initrd (loop)/isolinux/initrd.img } fi
if [ -f "($isopart)$isopath/$opensuse" ]; then menuentry 'openSUSE-42.1-DVD-x86_64' --class opensuse --class gnu-linux --class gnu --class os{ set isofile="$isopath/$opensuse" loopback loop ($isopart)$isofile linux (loop)/boot/x86_64/loader/linux install=hd:$isofile initrd (loop)/boot/x86_64/loader/initrd } fi
if [ -f "($isopart)$isopath/$centoslive" ]; then menuentry "CentOS LiveCD ISO" --class centos --class gnu-linux --class gnu --class os{ set isofile="$isopath/$centoslive" loopback loop ($isopart)$isofile echo'载入CentOS LiveCD ...' probe -l -s isolable (loop) linux (loop)/isolinux/vmlinuz0 boot=isolinux root=live:LABEL="$isolable" iso-scan/filename=$isofile rd.live.image LANG=zh_CN rd.locale.LANG=zh_CN rhgb echo'载入初始化内存盘 ...' initrd (loop)/isolinux/initrd0.img } fi
menuentry '关闭系统' --class halt { echo'关机中 ...' halt }