Skip to main content

Linux 引导加载程序与分区 (Bootloader & Partitioning)

cat /proc/partitions
cat /proc/version
lsusb -t

ESP (EFI System Partition)

Alpine Linux LVM & UEFI

dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda

创建 UEFI 启动 USB (Create UEFI Boot USB)

DEVICE=/dev/sdb
parted --script $DEVICE mklabel gpt
parted --script --align=optimal $DEVICE mkpart ESP fat32 1MiB 200MiB
parted --script $DEVICE set 1 boot on

gdisk -l /dev/sdb

# mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
mkfs.vfat -n Alpine ${DEVICE}1
mount -t vfat ${DEVICE}1 /mnt

wget https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.8/releases/x86_64/alpine-standard-3.8.0-x86_64.iso
cd /mnt && uniso < ~/alpine-standard-3.8.0-x86_64.iso

mkdir -p loader/entries

cat << CONF > loader/loader.conf
default alpine
timeout 4
CONF

# boot/syslinux/syslinux.cfg
cat << CONF > loader/entries/alpine.conf
title AlpineLinux-Vanilla
linux /boot/vmlinuz-vanilla
initrd /boot/initramfs-vanilla
options modules=loop,squashfs,sd-mod,usb-storage quiet nomodeset
CONF

cd ~ && umount /mnt

Partitioning Status

  • MBR: protective
  • BSD: not present
  • APM: not present
  • GPT: present

OVMF & QEMU

QEMU:

  • -L path: set the directory for the BIOS, VGA BIOS and keymaps

Parted & GPT

Parted commands:

mklabel msdos

unit MiB
mklabel gpt
mkpart 1 1 256
name 1 boot
set 1 legacy_boot on
mkpart 2 256 100%
set 2 lvm on

partprobe

Use sgdisk and parted:

# 转换为 GPT
parted -s /dev/sdb 'mklabel gpt'
# 编辑 GPT 分区
gdisk /dev/sdb
# 脚本操作 http://www.rodsbooks.com/gdisk/sgdisk-walkthrough.html
# -p 查看分区 -o 清除分区表 -g 转换 MBR 为 GPT -n 删除分区 -n 添加分区 -c 更改分区名
# -t 分区类型 -v 校验 -Z 清除分区数据,当需要从新分区的时候使用
sgdisk -og /dev/sdb

参考资料 (References)

Bootloader Features

FeatureSYSLINUXDas U-BootGRUB 2
Platformsx86 (PC)PPC, ARM, MIPS, x86, etc.x86, ARM, PowerPC, MIPS, SPARC
Filesystemsext2/3/4, btrfs, FAT16/32, NTFS, iso9660FAT, ext2/3/4, jffs2, ubifs, nfsext2/3/4, btrfs, zfs, xfs, FAT, NTFS, iso9660
OS SupportGNU/LinuxLinux, BSD, RTOS, Solaris, etc.Linux, BSD, Solaris, Multiboot
NetworkTFTPTFTP, NFS?