LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 04-14-2008, 04:01 PM   #1
shogun1234
Member
 
Registered: May 2004
Posts: 165

Rep: Reputation: 15
bootstrap problem


I follow the tutorial at http://linuxgazette.net/issue77/krishnakumar.html and then want to copy the boot image to floppy disk. However, due to having no floppy disk so I change the destination of c programme (i.e. /dev/fd0 -> ./boot.img).
Code:
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
        char boot_buf[512];
        int file_desc, floppy_desc;

        file_desc = open("./boot", O_RDONLY);
        read(file_desc, boot_buf, 510);
        close(file_desc);

        boot_buf[510] = 0x55;
        boot_buf[511] = 0xaa;

        floppy_desc = open("xxx.img", O_RDWR);
        lseek(floppy_desc, 0, SEEK_CUR);
        write(floppy_desc, boot_buf, 512);
        close(floppy_desc);

        printf("finished writing to image file!\n");
        exit(0);
}

But seemingly the image file is not generated. What might cause this problem? And how to solve it?

Thanks in advice,
 
Old 04-15-2008, 02:26 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 492

Rep: Reputation: 50
Hello,

/dev/fd0 (as all /dev content) isn't a true file, it's a device! You can't use true file the same way you use device file...
After a quick show to the code, when "xxx.img" is replaced by a block device, it's just to install a boot code at its beginning. Quite strange to do this with a C program when dd command does the job.
 
Old 04-19-2008, 03:09 PM   #3
shogun1234
Member
 
Registered: May 2004
Posts: 165

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jf.argentino View Post
Hello,

/dev/fd0 (as all /dev content) isn't a true file, it's a device! You can't use true file the same way you use device file...
After a quick show to the code, when "xxx.img" is replaced by a block device, it's just to install a boot code at its beginning. Quite strange to do this with a C program when dd command does the job.

Hi,

Thanks your reply. Now I solve the problem. I checked the return code of open(), it return -1. The problem comes from that it requires a file to be opened first. Then I create a file by 'touch xxx.img' so that the image can be created. Next, mount the image in the virtualbox and launch the box; that would print the letter on the screen.
 
Old 07-08-2008, 04:42 PM   #4
arkinrome
LQ Newbie
 
Registered: Mar 2008
Location: México
Distribution: Slackware
Posts: 15

Rep: Reputation: 1
booting from a usb pen key

Hello,

I used the same example as above but I'm trying to boot from a usb pen key, my question is, is it the same as a floppy disk,I mean is the boot sequence the same, look for the first 0x55 0xaa in the 511 and 512 bytes, because I cannot make it work.

Any hints?

Thanks in advance.

Ghst
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LFS 6.3 Chapter 5.4.1 - problem with "make bootstrap" vipernicus42 Linux From Scratch 3 04-21-2008 08:58 PM
problem running "make bootstrap" on GCC Zaneyard Linux From Scratch 1 01-28-2008 09:28 PM
make bootstrap chipymunk Linux From Scratch 1 06-30-2005 09:44 PM
Bootstrap? Ossar Linux - Software 3 10-10-2004 10:00 AM
A problem of bootstrap leihsun Linux - General 0 07-12-2002 04:15 AM


All times are GMT -5. The time now is 08:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration