当前位置: 首页 > 工具软件 > PE-Linux > 使用案例 >

grub2引导iso镜像启动U盘制作(引导Fedora-Workstation-Live,kali-linux-2020.2-live,WIN10PE)

袁赞
2023-12-01

ENV:

[root@Fedora32 ~]#uname -r
5.6.16-300.fc32.x86_64
[root@Fedora32 ~]#cat /etc/redhat-release 
Fedora release 32 (Thirty Two)

之前心血来潮突然想重新玩玩引导U盘,结果操作不当,先前做好的启动U盘废了,只好重新再做了一次,上次操作的过程有一部分记录,但是最主要的grub.cfg文件的内容没有存,杯具就开始了。新的内容重新做吧!并把这次的操作过程详细记录并发出来(主要是自己的电脑有的备份说不定什么时候就被我操作没了^v^)

前注:因为grub2的命令要求root管理员操作,为了方便,直接切换到的root

准备工作:

一个U盘(16G以上的最好,我的U盘还是几年前的,将就用了)

iso镜像下载(自行下载)

  • Fedora-Workstation-Live-x86_64-32-1.6.iso 

  • kali-linux-2020.2-live-amd64.iso

  • WIN10PEBASE.iso

  • WIN10PENET.iso

另外就是linux的操作系统,我的主要工具(不要问为什么不使用windows的,我现在使用的操作系统就是linux)

下面开始吧!!!由于都是之前操作过在文档中记录的,主要展示的还是记录的操作过程。想学习的请耐心看。

一、U盘分区

主要分两个分区,一个分区放linux操作系统镜像,一个分区放windows的系统镜像。

16G的U盘,一个分6G,一个分9G,其实大小无所谓的,分区的多少也无所谓,主要看自己想怎么用。

[root@Fedora32 ~]#lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 298.1G  0 disk 
├─sda1   8:1    0     1G  0 part /boot
├─sda2   8:2    0    16G  0 part [SWAP]
└─sda3   8:3    0 281.1G  0 part /
sdb      8:16   0 465.8G  0 disk 
├─sdb1   8:17   0   150G  0 part /mnt/NTFS/NTFS1
├─sdb2   8:18   0   150G  0 part /mnt/NTFS/NTFS2
└─sdb3   8:19   0 165.8G  0 part /mnt/NTFS/NTFS3
sdc      8:32   1    15G  0 disk 
[root@Fedora32 ~]#fdisk /dev/sdc

Welcome to fdisk (util-linux 2.35.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-31457279, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-31457279, default 31457279): +6G

Created a new partition 1 of type 'Linux' and of size 6 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (2-4, default 2): 
First sector (12584960-31457279, default 12584960): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (12584960-31457279, default 31457279): 

Created a new partition 2 of type 'Linux' and of size 9 GiB.
Partition #2 contains a ntfs signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Command (m for help): p
Disk /dev/sdc: 15 GiB, 16106127360 bytes, 31457280 sectors
Disk model: Flash Disk      
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xdfded8a3

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdc1           2048 12584959 12582912   6G 83 Linux
/dev/sdc2       12584960 31457279 18872320   9G 83 Linux

Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 2 will be wiped.

//注:这里的a是给分区启用引导,如果没有这个操作,U盘怎么能算引导盘呢?
Command (m for help): a
Partition number (1,2, default 2): 1

The bootable flag on partition 1 is enabled now.

Command (m for help): p
Disk /dev/sdc: 15 GiB, 16106127360 bytes, 31457280 sectors
Disk model: Flash Disk      
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xdfded8a3

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdc1  *        2048 12584959 12582912   6G 83 Linux
/dev/sdc2       12584960 31457279 18872320   9G 83 Linux

Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 2 will be wiped.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

二、格式化分区。

  linux的镜像用ext4格式,windows的镜像用ntfs格式。

[root@Fedora32 ~]#mkfs.ext4 /dev/sdc1
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 1572864 4k blocks and 393216 inodes
Filesystem UUID: 434d6717-8427-46f4-85f1-75f4a19509df
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

//注:这里在的-f参数一定要用,要不然会等相当长的时间的
[root@Fedora32 ~]#mkfs.ntfs -f /dev/sdc2
Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.

三、挂载刚格式化好的U盘分区

[root@Fedora32 ~]#mkdir -p upan/linux
[root@Fedora32 ~]#mkdir -p upan/win
[root@Fedora32 ~]#mount /dev/sdc1 upan/linux/
[root@Fedora32 ~]#mount /dev/sdc2 upan/win/

四、grub2操作

[root@Fedora32 ~]#mkdir upan/linux/boot  
//建立boot文件夹是为了看着明白的,要不然下面的boot-directory参数会直接在/root/upan/linux/下建立grub2文件夹的
//下面这个操作参数很多,之前操作常出错,我就把这些参数都加上了,在最后的/dev/sdc是整个U盘的设备,不是sdc1,也不是sdc2,要注意,每个人操作的设备名也可能不同,要根据自己的设备操作,不要直接搬用。
[root@Fedora32 ~]#grub2-install --root-directory=/root/upan/linux/ --boot-directory=/root/upan/linux/boot --no-floppy /dev/sdc
Installing for i386-pc platform.
Installation finished. No error reported.
//看到No error就是好消息了

 

五、拷备之前准备的iso镜像到U盘里

[root@Fedora32 ~]#mkdir upan/linux/iso
[root@Fedora32 ~]#mkdir upan/win/iso
[root@Fedora32 ~]#cp /usr/share/syslinux/memdisk upan/win/iso/
[root@Fedora32 ~]#cp /mnt/NTFS/NTFS3/iso/linux/Fedora-Workstation-Live-x86_64-32-1.6.iso upan/linux/iso/
[root@Fedora32 ~]#cp /mnt/NTFS/NTFS3/iso/linux/kali-linux-2020.2-live-amd64.iso upan/linux/iso/
[root@Fedora32 ~]#cp /home/fedora/Documents/winpe/* upan/win/iso/
[root@Fedora32 ~]#syncs

文件存放位置

[root@Fedora32 ~]#ls upan/linux/iso/
Fedora-Workstation-Live-x86_64-32-1.6.iso  kali-linux-2020.2-live-amd64.iso
[root@Fedora32 ~]#ls upan/win/iso/
memdisk  WIN10PEBASE.iso  WIN10PENET.iso

 

六、grub.cfg文件(这是最重要的一步,之前我就是因为这步出问题,折腾了一天才算是搞定,这里的文件是我调整好的,如操作的和我一样,可直接使用的,亲自开机U盘启动进入live没问题的)

进入grub2文件夹,直接vim grub.cfg(手动建立文件)

[root@Fedora32 ~]#cd upan/linux/boot/grub2/
[root@Fedora32 grub2]#pwd
/root/upan/linux/boot/grub2
[root@Fedora32 grub2]#vim grub.cfg
=================grub.cfg===============

set timeout=10
set default=0
loadfont /boot/grub2/fonts/unicode.pf2
set gfxmode=1024x768
set gfxpayload=keep
insmod gfxterm
insmod vbe
insmod loopback
insmod iso9660
terminal_output gfxterm
insmod jpeg
background_image /boot/grub2/background.jpg
setmenu_color_normal=white/black
setmenu_color_highlight=black/light-gray


set ntfs_data_uuid="57D4C7A22B597228"
set ext4_data_uuid="434d6717-8427-46f4-85f1-75f4a19509df"

search --no-floppy --set=ntfs_iso_part --fs-uuid $ntfs_data_uuid
search --no-floppy --set=ext4_iso_part --fs-uuid $ext4_data_uuid


menuentry "Fedora-Workstation-Live 32" {
     set isofile="/iso/Fedora-Workstation-Live-x86_64-32-1.6.iso"
     insmod fat
     insmod ext2
     insmod ntfs
     search -s -f $isofile
     loopback loop ($ext4_iso_part)$isofile
     linux (loop)/isolinux/vmlinuz root=live:CDLABEL=Fedora-WS-Live-32-1-6 rootfstype=auto ro rd.live.image iso-scan/filename=$isofile
     initrd (loop)/isolinux/initrd.img
}


menuentry "KALI-linux-2020-amd64" {
     set isofile="/iso/kali-linux-2020.2-live-amd64.iso"
     insmod fat
     insmod ext2
     insmod ntfs
     search -s -f $isofile
     loopback loop ($ext4_iso_part)$isofile
     linux (loop)/live/vmlinuz boot=live findiso=$isofile noconfig=sudo username=kali hostname=kali
     initrd (loop)/live/initrd.img 
}


menuentry "Windows 10基础版" {
     set root='(hd0,msdos2)'
     insmod part_msdos
     insmod fat
     insmod ntfs
     echo "Loading Memdisk..."
     linux16 /iso/memdisk iso raw
     echo "Loading ISO..."
     initrd16 /iso/WIN10PEBASE.iso
}


menuentry "Windows 10网络版" {
     set root='(hd0,msdos2)'
     insmod part_msdos
     insmod fat
     insmod ntfs
     echo "Loading Memdisk..."
     linux16 /iso/memdisk iso raw
     echo "Loading ISO..."
     initrd16 /iso/WIN10PENET.iso
}


menuentry "reboot" {
    insmod reboot
    reboot
}

 
menuentry "halt" {
    insmod halt
    halt
}

 

到现在所有的操作都完成了,可以启动电脑放上U盘来玩一玩live了。

grub.cfg文件中有一些重要的内容,之后会单独写一篇来记录的,这里只展示U盘引导制作过程。

 

 类似资料: