您的位置:首页 > 运维架构 > Linux

使用syslinux制作启动U盘

2013-06-21 10:06 281 查看

1,下载syslinux

地址:https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-4.04.tar.gz

提取menu.c32, vesamenu.c32, reboot.c32到根目录备用。

2,分区

命令行:syslinux -mafi u:

3,激活

上面的-a参数就是表示激活的意思

4,准备puppylinux镜像

http://tinycorelinux.net/downloads.html

& damn samll linux
& puppy linux

TinyCore

插播一段vmware可以上网(telnet 也ok),但是无法ping google的问题,
http://www.cnblogs.com/karotte/archive/2013/03/24/vmware-ping.html

原来要关闭掉本机的网络连接共享。

解压iso文件得到vmlinuz和initrd.gz或者core.gz, 分配放置到
对于tinycore,放置到core目录,扩展放到cde目录
对于puppy,放置到puppy目录,sfs也放在puppy目录
至于syslinux.cfg的配置,可以参考iso里面的isolinux.cfg设置。

5,准备winpe镜像

参考这个文章《教你如何DIY WINPE系统》,可以改的“面目全非”
http://www.360doc.com/content/11/0104/10/1157314_83803846.shtml

参考这个帖子设置winpe。

http://lrxianed.diandian.com/post/2011-04-09/4710715

解压出winnt.xpe放置到根目录,

解压出NTDETECT.COM文件以及SETUPLDR.BIN放置到根目录,重命名SETUPLDR.BIN->NTLDR

下载ltntldr

ldntldr.bin.tgz

然后复制ldntldr.bin复制到根目录,修改为ltntldr

提取athlon.im_到winpe目录。

修改winnt.xpe指定wim文件的位置:

[SetupData]
BootDevice = "ramdisk(0)"
BootPath = "\WXPE\System32\"
OsLoadOptions = "/minint /fastdetect /rdpath=\WINPE\ATHLON.IM_"


看看最终的目录结构:

G:\>dir /a:H
驱动器 G 中的卷是 LIVETOOLS
卷的序列号是 F89A-2FF9

G:\ 的目录

2013/06/25  18:40               617 syslinux.cfg
2013/01/08  10:32    <DIR>          backup
2013/01/08  13:22            32,256 ldlinux.sys
2013/06/21  07:15    <DIR>          autorun.inf
2013/06/21  11:48               135 WINNT.XPE
2006/11/11  10:00            47,564 NTDETECT.COM
2003/01/01  04:02           297,584 NTLDR
2008/03/01  16:54             1,024 LDNTLDR
2004/08/17  20:00           322,730 BOOTFONT.BIN
2013/06/21  11:48    <DIR>          winpe
2013/06/21  13:10    <DIR>          puppy
2011/04/19  05:24            56,164 menu.c32
2011/04/19  05:24           155,792 vesamenu.c32
2011/04/19  05:24               800 reboot.c32
2013/06/25  11:11    <DIR>          core
2013/06/25  11:34    <DIR>          cde
10 个文件        914,666 字节
6 个目录     10,010,624 可用字节


插入一段驱动精灵里面的net.dll文件的解析代码:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <list>
#include <string>

typedef int uint32;
typedef struct {
char drvname [0x100]; // 原文件中每个驱动包的名字好像都不超过0x24
uint32 drvlen;
}drv_item;
/**
* 驱动文件集合的头部结构大概如此
*
* + count
* {
*    + zip file name length
*    + zip file file name( char array )
*    + zip file length
* }
* ... // 一共count个
* 第一个zip的文件内容
* 第二个zip的文件内容
* ...
* 第count个zip的文件内容
*
*/
typedef struct {
uint32 count;
drv_item items[1];
// ...
// zips' content
}net_drv_head;

int main(int argc, char * argv[])
{
int fsize = 0; struct stat st;
char * bufptr = 0; uint32 drvindex = 0;
FILE * drvf = fopen(argv[1], "rb");
if (!drvf) return -1;
if (stat(argv[1], &st)) return -1;
printf("file size : %d\n", st.st_size);
char * drvbuffer = (char *)malloc(st.st_size);
if (!drvbuffer) return -1;
if (st.st_size != fread(drvbuffer, 1, st.st_size, drvf))
return -1;

mkdir("zips", 0777);
bufptr = drvbuffer;
uint32 drvcount = *(uint32 *)bufptr; bufptr += sizeof(uint32);
printf("driver count : %d\n", drvcount);
net_drv_head * pHead = (net_drv_head*) malloc (sizeof(net_drv_head)
+ sizeof(drv_item) * (drvcount-1));
pHead->count = drvcount;
drv_item * pItem = &pHead->items[0];
for (drvindex = 0; drvindex < drvcount; drvindex++){
char drvname [0x100] = ""; uint32 drvfilelen = 0;
uint32 drvnamelen = *(uint32 *)bufptr; bufptr += sizeof(uint32);
memcpy(drvname, bufptr, drvnamelen); bufptr += drvnamelen;
drvname[drvnamelen] = '\0';
drvfilelen = *(uint32 *)bufptr; bufptr += sizeof(uint32);
printf("strlen: %d, str: %s, filelen: %d\n"
, drvnamelen
, drvname
, drvfilelen);
strcpy(pItem->drvname, "zips/"); strcat(pItem->drvname, drvname);
pItem->drvlen = drvfilelen;
pItem ++;
}
for (int i = 0; i < pHead->count; i++){
printf("%s, %d\n", pHead->items[i].drvname, pHead->items[i].drvlen);
FILE * zip = fopen(pHead->items[i].drvname, "wb");
fwrite(bufptr, 1, pHead->items[i].drvlen, zip);
bufptr += pHead->items[i].drvlen;
fclose(zip);
}
free(drvbuffer);
fclose(drvf);
return 0;
}

解析出来的zip都放置在zips文件夹下,tar出来看看。



6,修改syslinux.cfg

DEFAULT vesamenu.c32
TIMEOUT 300
MENU TITLE
MENU COLOR BORDER 30;44 #00000000 #00000000 none

LABEL winpe
MENU LABEL [01] start Windows PE.
KERNEL /ldntldr
APPEND initrd=/ntldr

LABEL puppy
MENU LABEL [02] start Wary Puppy Linux.
KERNEL /puppy/vmlinuz PMEDIA=usbflash
APPEND initrd=/puppy/initrd.gz

LABEL core
MENU LABEL [03] start Tiny Core Linux.
KERNEL /core/vmlinuz
APPEND initrd=/core/core.gz

LABEL guicore
MENU LABEL [04] start Tiny Core Linux with GUI.
KERNEL /core/vmlinuz
APPEND initrd=/core/core.gz cde

LABEL reboot
MENU LABEL [05] Reboot.
KERNEL /reboot.c32


完成,设置U盘启动试试看吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: