OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 1:17 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 6:05 am 
Offline

Joined: Tue Dec 09, 2014 9:57 am
Posts: 5
Dear Developers,

I would like to learn how to write a bootloader for USB sticks and how it works. Preferably in a deeper way (e.g. machine code).

I have a few questions:
- Is there a good tutorial about this?
- Is this bootloader rewriteable?

Thanks in advance,

Z0q :)


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 6:56 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
z0q wrote:
- Is there a good tutorial about this?
Any tutorial that covers writing a bootloader for a floppy disk or hard disk using BIOS int 0x13 is equally applicable to USB flash drives. The BIOS will choose to emulate your flash drive as either a floppy disk or hard disk based on its contents. Floppy disk emulation may not allow you to access the entire flash drive, so you should use hard disk emulation. In order to use hard disk emulation, your flash drive must have a valid partition table with one bootable partition.

Alternately, you may choose to write a UEFI bootloader instead of a BIOS bootloader. This only requires a FAT32 filesystem on the flash drive, from which the UEFI firmware will load your bootloader file.

z0q wrote:
- Is this bootloader rewriteable?
Is your USB flash drive rewritable?


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 7:22 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:59 am
Posts: 543
Location: Shahpur, Layyah, Pakistan
A USB drive boot loader works same as a either a hard disk boot loader or either a floppy boot loader. You can start as writing floppy boot loader. A good step by step tutorial of writing floppy boot loader is at http://www.brokenthorn.com/Resources/OSDevIndex.html in assembly language. Which is same for USB drive.


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 8:48 am 
Offline

Joined: Tue Dec 09, 2014 9:57 am
Posts: 5
Thank you for your replies :)

Yes, it is rewriteable, but I have to write in the special Boot sector right? I remember that I could throw away floppies after writing to their boot sectors with a work in progress bootloader.

How can I write to the boot sector of the USB stick?


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 9:06 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
z0q wrote:
I remember that I could throw away floppies after writing to their boot sectors with a work in progress bootloader.
This is because you overwrote the FAT12 BPB. That data is necessary for operating systems to read and write files from a FAT12-formatted floppy disk. Reformatting the floppy disk will restore its original functionality, but erase your bootloader.

If your flash drive bootloader doesn't include the necessary data structures, the same thing will happen when you put it on the flash drive. Just like the floppy disk, reformatting the flash drive will restore its original functionality and erase your bootloader.


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 9:10 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
Is there a good tutorial about this?

The Wiki has a page on Beginner Mistakes, and the second item reads:
Quote:
Is there a tutorial on..?

Because this place can not and does not cater for beginner developers, the question for some other place that does provide a tutorial, good explanations or easy to understand reading is often requested. However, they do not exist. Difficult subjects can not be described with light prose, just like there are enough things that are too complicated for a monkey to properly learn. If you have trouble reading official documentation, this would be a good time to practice.


You might want to read the rest of the wiki as well considering you have missed the basics.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 9:16 am 
Offline
Member
Member

Joined: Sun Mar 07, 2010 2:12 am
Posts: 65
Mike Gonta has written some stuff about usb booting:

USB Booting Secrets: http://board.flatassembler.net/topic.php?t=12389

more USB Booting Secrets: http://board.flatassembler.net/topic.php?t=12469

Regards
M2004


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 9:29 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
M2004 wrote:
Mike Gonta has written some stuff about usb booting:
"USB Booting Secret # 3" is wrong, BIOSes in floppy disk emulation mode will typically not provide LBA access. This is why hard disk emulation is the preferred mode for USB booting.


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Dec 10, 2014 9:33 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:59 am
Posts: 543
Location: Shahpur, Layyah, Pakistan
z0q wrote:
Thank you for your replies :)

Yes, it is rewriteable, but I have to write in the special Boot sector right? I remember that I could throw away floppies after writing to their boot sectors with a work in progress bootloader.

How can I write to the boot sector of the USB stick?

You can write boot sector to the first sector of USB drive (without partitioning) with special disk image utilities such as "dd" in Linux. dd on Windows is also available (using some tools).


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Tue Mar 17, 2015 3:26 pm 
Offline

Joined: Tue Dec 09, 2014 9:57 am
Posts: 5
Thank you all. My USB stick does now boot like a floppy.

I would like it to boot like a hard disk. Where do I start?

Sincerely :)


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Tue Mar 17, 2015 5:02 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 10:35 pm
Posts: 39
Location: Eagle, ID (USA)
To treat your flash drive as hard disk emulation, you must have a valid partition file and one Bootable partition.

_________________
"I think it may be time for some guru meditation"
"Barbarians don't do advanced wizardry"


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Tue Mar 17, 2015 5:31 pm 
Offline
Member
Member

Joined: Thu Sep 20, 2012 5:11 am
Posts: 69
Location: germany hamburg
Image http://hp-usb-disk-storage-format-tool.en.softonic.com/


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Mar 18, 2015 5:58 am 
Offline

Joined: Tue Dec 09, 2014 9:57 am
Posts: 5
How do I add my bootloader after formatting with HP USB Disk Storage Format Tool?

I have formatted my USB stick to FAT32 and manually edited the boot sector in HxD and overwrote the boot code with mine in binary. Now it boots and the drive is still accessible in Windows.

Would that be a good approach? I haven't reached the part of loading a kernel yet.

Thank you :)


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Mar 25, 2015 12:48 pm 
Offline

Joined: Tue Dec 09, 2014 9:57 am
Posts: 5
Bump!


Top
 Profile  
 
 Post subject: Re: Is there a tutorial for booting from USB?
PostPosted: Wed Mar 25, 2015 4:01 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Any tool that will write sectors to a disk can be used - the "dd" command is probably the easiest way. Using a hex editor to manually edit the codes is probably the hardest, and most error-prone, way to accomplish this task.

If you lack the knowledge to manipulate disk sectors in this way, and don't have the ability to use Google to find the answer, you are going to find OS development a very frustrating hobby. Do yourself a favour and learn how to research topics with the aid of Google. Everything that you have asked here is easily found.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot] and 74 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group