grub-install error when trying to install to USB

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Mathyn
Posts: 13
Joined: Sun Jan 04, 2015 1:20 pm

grub-install error when trying to install to USB

Post by Mathyn »

So far I have only tested my simple OS using Qemu. Now I want to install it on a USB and try and run it the real way.

I've followed this tutorial: http://wiki.osdev.org/GRUB_2#USB_instructions

The first time I got an error saying no 'EFI folder' was found. I fixed this by adding the target parameter like this:

Code: Select all

sudo grub-install --target=i386-pc  --root-directory=/media/YourLabel --no-floppy --recheck --force /dev/sdc1
When executing this command I see the following in the terminal:

Code: Select all

Installing for i386-pc platform.
grub-install: warning: File system `fat' doesn't support embedding.
grub-install: error: embedding is not possible, but this is required for cross-disk install.
I formatted the USB as FAT32 (as the tutorials requires), but it looks like FAT32 is not supported when trying to install with my target?

Does anyone got an idea how I might fix this problem?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: grub-install error when trying to install to USB

Post by Combuster »

There's a difference between /dev/sdX and /dev/sdXY - or in other words, you didn't follow the tutorial in at least two places.
"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 ]
Mathyn
Posts: 13
Joined: Sun Jan 04, 2015 1:20 pm

Re: grub-install error when trying to install to USB

Post by Mathyn »

Ah right, that's probably it. I'm rather new to Linux so the difference wasn't that obvious to me.
Mathyn
Posts: 13
Joined: Sun Jan 04, 2015 1:20 pm

Re: grub-install error when trying to install to USB

Post by Mathyn »

I gave it another try and I managed to install grub on the USB. Thanks for pointing out my mistake, Combuster.
Testing the USB with Qemu using

Code: Select all

sudo qemu-system-x86_64 -hda /dev/sdf
Loads the OS like it should.

However, when I try to boot from the USB using an actual computer a black screen with a blinking cursor is shown. Could this mean the USB is not detected as bootable by the BIOS?

More details:
I first format the USB with:

Code: Select all

sudo mkfs.vfat -F 32 -n TicTacTOS -I /dev/sde
I then mount the USB to my own custom location with:

Code: Select all

sudo mount /dev/sde /mnt/TicTacTOS
Next I install Grub:

Code: Select all

sudo grub-install --target=i386-pc --root-directory=/mnt/TicTacTOS --no-floppy --recheck --force /dev/sde
The following is displayed in the console:

Code: Select all

Installing for i386-pc platform.
grub-install: warning: File system `fat' doesn't support embedding.
grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
Installation finished. No error reported.
I am not sure what these warnings mean, can anyone explain these to me?

Another thing I noted is that when I use:

Code: Select all

sudo fdisk -l
it displays the following in the terminal:

Code: Select all

WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sda: 252.0 GB, 252000000000 bytes
255 heads, 63 sectors/track, 30637 cylinders, total 492187500 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc14cbd8d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1   492187499   246093749+  ee  GPT

Disk /dev/sdf: 2002 MB, 2002780160 bytes
62 heads, 62 sectors/track, 1017 cylinders, total 3911680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
My HDD does show a device boot row but the USB does not. Does this mean the USB is not bootable?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: grub-install error when trying to install to USB

Post by BrightLight »

For USB sticks, Syslinux is easier to use than GRUB. It also has some nice modules and it can boot ELF kernels.
You can just install Syslinux with:

Code: Select all

sudo syslinux --mbr --install /dev/sdX
Of course, replace X with your USB stick name.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Mathyn
Posts: 13
Joined: Sun Jan 04, 2015 1:20 pm

Re: grub-install error when trying to install to USB

Post by Mathyn »

I forgot to mention this but maybe it might help you guys help me:

The contents of the USB now looks like this:

Code: Select all

boot
    grub
        fonts
        i386-pc
        locale
        grub.cfg
        grubenv
    myos.bin
The fonts, i386-pc and locale map are filled with a bunch of files. Let me know if you need more information about this.

myos.bin is the compiled kernel.
the contents of grub.cfg look like this:

Code: Select all

menuentry "myos"{
	multiboot /boot/myos.bin
}
Mathyn
Posts: 13
Joined: Sun Jan 04, 2015 1:20 pm

Re: grub-install error when trying to install to USB

Post by Mathyn »

omarrx024 wrote:For USB sticks, Syslinux is easier to use than GRUB. It also has some nice modules and it can boot ELF kernels.
You can just install Syslinux with:

Code: Select all

sudo syslinux --mbr --install /dev/sdX
Of course, replace X with your USB stick name.
Hellp omarrx024, thank you for your reply. I'll give Syslinux a try :)
Mathyn
Posts: 13
Joined: Sun Jan 04, 2015 1:20 pm

Re: grub-install error when trying to install to USB

Post by Mathyn »

Ok so I made a bootable USB with Syslinux and it worked on a real computer. Now I am trying to get my OS kernel booted. I have taken a look at the http://www.syslinux.org/wiki/index.php/ ... ERNEL_file but have so far not managed to get my own kernel running.

I use the following commands to build my kernel:

Code: Select all

#compile the boot loader
i686-elf-as ../boot.s -o boot.o

#compile the kernel
i686-elf-gcc -c ../kernel.c -o kernel.o -std=gnu99 -ffreestanding -Wall -Wextra

#link the boot loader and kernel
i686-elf-gcc -T ../linker.ld -o myos.bin -ffreestanding -nostdlib boot.o kernel.o -lgcc

#build the iso
mkdir isodir
mkdir isodir/boot
cp myos.bin isodir/boot/myos.bin
mkdir isodir/boot/grub
cp ../grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue /usr/lib/grub/i386-pc -o myos.iso isodir
After this I have a myos.bin file containing my kernel. The file myos.iso also contains the grub bootloader. I'm guessing I should use myos.bin as the kernel but how would I boot this using Syslinux?

What happens right now is the USB is bootable and the following is displayed on the screen:

Code: Select all

Booting from Hard Disk...
Now booting the kernel for TicTacTOS
Could not found kernel image: linux
boot: 
I enter the file name for my kernel (myos.bin) and after that the system hangs and shows a blinking cursor. I have tested this using Qemu btw.

I have also created syslinux.cfg which looks like this:

Code: Select all

DEFAULT linux
LABEL TicTacTOS
	SAY Now booting the kernel for TicTacTOS
Obviously I still need to edit this file so it selects the kernel right from the start.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: grub-install error when trying to install to USB

Post by BrightLight »

Your syslinux.cfg file should look something like this:

Code: Select all

LABEL YourOS
kernel /myos.bin
append 
When you have a "boot:" prompt, you can type YourOS. Syslinux works with the label names, not file names.
So for example, the screen output might look like:

Code: Select all

SYSLINUX Version X.XX

boot: YourOS
Loading /myos.bin ....
My OS is starting up (or whatever your start up message is)
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Mathyn
Posts: 13
Joined: Sun Jan 04, 2015 1:20 pm

Re: grub-install error when trying to install to USB

Post by Mathyn »

Thanks for the help :)! I followed your instructions and right now the following is shown on the screen:

Code: Select all

Booting from Hard Disk...
No DEFAULT or UI configuration directive found!
boot:
When I press tab the label defined in the config file is shown. Once I type this label in the boot prompt it looks like the computer is hanging e.g. the cursor is flashing but nothing else happens.

Maybe I misunderstand which format the kernel must be in for Syslinux to load it. In this case I followed the barebones tutorial and used the .bin file which is ultimately created. Just to be, the code posted below is the first thing that will run in my OS:

Code: Select all


.set ALIGN,    1<<0             # align loaded modules on page boundaries
.set MEMINFO,  1<<1             # provide memory map
.set FLAGS,    ALIGN | MEMINFO  # this is the Multiboot 'flag' field
.set MAGIC,    0x1BADB002       # 'magic number' lets bootloader find the header
.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot

.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM

.section .bootstrap_stack, "aw", @nobits
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

.section .text
.global _start
.type _start, @function
_start:
	movl $stack_top, %esp

	call kernel_main

	cli
	hlt
.Lhang:
	jmp .Lhang

.size _start, . - _start
Any ideas?
Post Reply