使用syslinux制作启动U盘

来源:互联网 发布:明道办公软件网页版 编辑:程序博客网 时间:2024/05/20 05:09

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

插播一段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.cfg2013/01/08  10:32    <DIR>          backup2013/01/08  13:22            32,256 ldlinux.sys2013/06/21  07:15    <DIR>          autorun.inf2013/06/21  11:48               135 WINNT.XPE2006/11/11  10:00            47,564 NTDETECT.COM2003/01/01  04:02           297,584 NTLDR2008/03/01  16:54             1,024 LDNTLDR2004/08/17  20:00           322,730 BOOTFONT.BIN2013/06/21  11:48    <DIR>          winpe2013/06/21  13:10    <DIR>          puppy2011/04/19  05:24            56,164 menu.c322011/04/19  05:24           155,792 vesamenu.c322011/04/19  05:24               800 reboot.c322013/06/25  11:11    <DIR>          core2013/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.c32TIMEOUT 300MENU TITLE  MENU COLOR BORDER 30;44 #00000000 #00000000 noneLABEL winpeMENU LABEL [01] start Windows PE.KERNEL /ldntldrAPPEND initrd=/ntldr LABEL puppyMENU LABEL [02] start Wary Puppy Linux.KERNEL /puppy/vmlinuz PMEDIA=usbflashAPPEND initrd=/puppy/initrd.gzLABEL coreMENU LABEL [03] start Tiny Core Linux.KERNEL /core/vmlinuzAPPEND initrd=/core/core.gzLABEL guicoreMENU LABEL [04] start Tiny Core Linux with GUI.KERNEL /core/vmlinuzAPPEND initrd=/core/core.gz cdeLABEL rebootMENU LABEL [05] Reboot.KERNEL /reboot.c32

完成,设置U盘启动试试看吧。