WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to install grub2 to /dev/mmcblk0?  (Read 19434 times)

Offline lemming

  • Newbie
  • *
  • Posts: 37
How to install grub2 to /dev/mmcblk0?
« on: July 22, 2014, 12:55:43 AM »
I am trying to install microcore to an Intel NUC PC using the manual method as outlined at "http://tinycorelinux.net/install_manual.html".
The NUC has 4GB flash memory (limited writes) as a built in hard drive so Microcore is an ideal OS not to burn it out.

I am using "grub-install --boot-directory=/mnt/mmcblk0p1/ /dev/mmcblk0" and other variations but get the warning "your embedding area is unusually small. core.img won't fit in it..." then some more about using blocklists(?) but they are unreliable. Also "Filesystem 'ext2' doesn't support embedding" (my file system is ext4!). It then aborts.

I have done all the other steps in the weblink above but am now stuck.

The flash memory is 4GB and formatted as a single ext4 primary partition (heaps of space).

Can anyone see where I have gone wrong?

I have a UEFI bios. Should it be set to legacy instead?
« Last Edit: July 22, 2014, 01:52:13 AM by lemming »

Offline theYinYeti

  • Full Member
  • ***
  • Posts: 177
    • YetI web site
Re: How to install grub2 to /dev/mmcblk0?
« Reply #1 on: July 23, 2014, 01:01:40 AM »
Probably you did not leave enough free space between the start of the drive and the start of the partition. You should leave at least 1MB.

Edit: see also http://www.gnu.org/software/grub/manual/grub.html#BIOS-installation
« Last Edit: July 23, 2014, 01:03:28 AM by theYinYeti »

Offline lemming

  • Newbie
  • *
  • Posts: 37
Re: How to install grub2 to /dev/mmcblk0?
« Reply #2 on: July 23, 2014, 01:48:12 AM »
Thanks Yin. I have been trying different things since my last post and have  left 1 Mb before the primary partition. Still wasn't having any joy when I discovered that Grub2 does not work with ext2. Have reformatted with ext4 and the grub-install command worked without a hitch, reporting "no errors" when it finished. However the pc still won't boot. I have been playing with the BIOS settings using UEFI then disabling it and using legacy boot. To no avail. I'm still not sure how grub sees the flash memory; as a floppy, SD card, USB stick or HDD? My original install parameters were wrong too so I changed the command to: "grub-install --boot-directory=/mnt/mmcblk0p1/boot  /dev/mmcblk0".
« Last Edit: July 23, 2014, 01:53:24 AM by lemming »

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: How to install grub2 to /dev/mmcblk0?
« Reply #3 on: July 23, 2014, 01:58:47 AM »
Is the boot flag set?
You can use cfdisk or gparted to toggle it.
Download a copy and keep it handy: Core book ;)

Offline lemming

  • Newbie
  • *
  • Posts: 37
Re: How to install grub2 to /dev/mmcblk0?
« Reply #4 on: July 23, 2014, 02:26:17 AM »
it was set but I will check again as I may have "unset" it with my experimentation. Thanks for the tip.

EDIT:  It was not set but I have reset it, but still no cigar.
« Last Edit: July 23, 2014, 04:01:04 AM by lemming »

Offline lemming

  • Newbie
  • *
  • Posts: 37
Re: How to install grub2 to /dev/mmcblk0?
« Reply #5 on: July 24, 2014, 12:55:44 AM »
I have been checking the installation of grub2 and discovered that grub-install command under TinyCore does not produce and boot/grub/grub.conf file. A whole lot of other grub files are there and I ran grub-install as root so it doesn't seem to be a permissions problem.

Is this a bug with this implementation or doesn't the TinyCore need a grub.conf/grub.cfg?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: How to install grub2 to /dev/mmcblk0?
« Reply #6 on: July 24, 2014, 01:02:40 AM »
The idea is that you create grub.cfg yourself

Offline theYinYeti

  • Full Member
  • ***
  • Posts: 177
    • YetI web site
Re: How to install grub2 to /dev/mmcblk0?
« Reply #7 on: July 25, 2014, 12:22:11 AM »
lemming: It is normal that Grub2 install does not create the menu file. The latter is supposed to be created by running a command, taking numerous config files into account.

But TC being minimalist, you will probably create the file by hand, as many others do ;-)
My article here may give some useful hints to you:
http://yalis.fr/cms/index.php/post/2013/05/09/Bootable-flash-drive-for-both-Linux-and-Windows%3A-part-2

But don't stay too close to the given _commands_ in this article, because to my knowledge the Grub2 version in TC is much older than the version in Arch Linux, and the files layout is initially a bit different; you may organize them the same way as I did in the end, though, if you wish so…

Offline lemming

  • Newbie
  • *
  • Posts: 37
Re: How to install grub2 to /dev/mmcblk0?
« Reply #8 on: July 25, 2014, 04:57:07 AM »
Thanks Yin, I will have a read.

Quote
The idea is that you create grub.cfg yourself

I had read the GNU grub-install webpage which states,

Quote
Note that grub-install is actually just a shell script and the real task is done by grub-mkimage and grub-setup. Therefore, you may run those commands directly to install GRUB, without using grub-install. Don’t do that, however, unless you are very familiar with the internals of GRUB. Installing a boot loader on a running OS may be extremely dangerous.

I took that to mean that grub-install ran grub-mkimage which produces the grub.cfg. Not so in TinyCore (and other Linuxes?).

I also  read that the /etc/grub.d directory has the files that grub-mkimage draws upon to create the grub.cfg. Not so in TinyCore as theYinYeti points out.

I read that a separate  EFI System partition of 200-512MB (depending on which website you read)  formatted to fat32 with a  gdisk type of EF00 is required. Or is this not the case with TC?

Does this mean  that my flash memory has to have a blank 1 MB at the start; 512MB fat32 EFI partition next and  the rest my ext2-ext4 for the system? What flags should I have set for each of these partitions?

It seems that there are a several departures of the TC grub2 from the standard grub2 and without documentation or guides, newbs like me (as well as the more experienced judging by the few TC threads on the topic) have a hard time piecing it all together. The threads I refer to also come from 2012 and there have been a few changes in grub2 with some web pages using "grub.conf" and "--root-directory" which further adds to the confusion. 
 
« Last Edit: July 26, 2014, 05:49:38 AM by lemming »

Offline theYinYeti

  • Full Member
  • ***
  • Posts: 177
    • YetI web site
Re: How to install grub2 to /dev/mmcblk0?
« Reply #9 on: July 25, 2014, 05:17:57 AM »
What I as pointing out was, actually, that the layout of the files installed on the target device (/boot/grub by default) is different in older versions of Grub2 than it is with a newer version. I was not talking about the package files.
However, the package files are indeed in a different place in TC, but for a different reason: the install prefix is simply /usr/local instead of /, which means that (/usr)/sbin is replaced by /usr/local/sbin, and /etc is replaced by /usr/local/etc, for example.
Apart from this different install prefix, TC's Grub2 is probably pretty close to upstream; just a slightly older version.

As for the partitions, a blank space before the first partition is only needed for a MBR-format device. For an GPT-format device, just create a 1MB+ Grub partition per the documentation:
Quote
When creating a BIOS Boot Partition on a GPT system, you should make sure that it is at least 31 KiB in size. (GPT-formatted disks are not usually particularly small, so we recommend that you make it larger than the bare minimum, such as 1 MiB, to allow plenty of room for growth.) You must also make sure that it has the proper partition type.
Using GNU Parted, you can set this using a command such as the following:

# parted /dev/disk set partition-number bios_grub on

If you are using gdisk, set the partition type to ‘0xEF02’. With partitioning programs that require setting the GUID directly, it should be ‘21686148-6449-6e6f-744e656564454649’.

As a side-note, AFAIK, from Grub2's perspective, ext2, ext3 or ext4 are more or less the same. Don't read too much into a message saying ext2 instead of ext4 ;)

Offline lemming

  • Newbie
  • *
  • Posts: 37
Re: How to install grub2 to /dev/mmcblk0?
« Reply #10 on: July 25, 2014, 05:34:05 PM »
Thanks again Yin

Quote
....the install prefix is simply /usr/local instead of /, which means that (/usr)/sbin is replaced by /usr/local/sbin, and /etc is replaced by /usr/local/etc, for example.

I will do some more reading as I seem to be missing the point. I haven't got a /usr/local directory on my target disk.

Quote
When creating a BIOS Boot Partition on a GPT system,

I am trying for a EUFI/GPT grub setup, not the hybrid BIOS/GPT type,  as EUFi is the standard for new motherboards and future installs of TC.  I was wondering what the disk setup for that should be.

On Arch and Ubuntu it seems that the the EFI partition, that I spoke of, is necessary. Is this so with TC? If so, what are the flags, type number and filesystem and size are necessary for TC?

Regarding ext2 vs ext4; as the TC setup that I want is the run-in-memory type with no writing to the disk (I am using 4GB flash memory built onto the motherboard which has a limited number of writes before failing). Seeing that I am only reading at startup would the ext2 be the simplest and fastest filesystem to run with or are there drawbacks?
« Last Edit: July 25, 2014, 05:35:39 PM by lemming »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: How to install grub2 to /dev/mmcblk0?
« Reply #11 on: July 25, 2014, 09:27:18 PM »
On Arch and Ubuntu it seems that the the EFI partition, that I spoke of, is necessary. Is this so with TC? If so, what are the flags, type number and filesystem and size are necessary for TC?

You need something like this:

Use gdisk to create 2 partitions:
Code: [Select]
$ gdisk -l /dev/sdb
GPT fdisk (gdisk) version 0.6.11
l
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sdb: 2006673 sectors, 979.8 MiB
Logical sector size: 512 bytes
Disk identifier (GUID): 7CF13D85-1AA7-427F-990C-F31663DCD1F0
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 2006639
Partitions will be aligned on 2-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34          245793   120.0 MiB   EF00  EFI System
   2          245794         2006639   859.8 MiB   0700  Linux/Windows data

and:
Code: [Select]
$ sudo mkfs.vfat /dev/sdb1
$ sudo mke2fs /dev/sdb2

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: How to install grub2 to /dev/mmcblk0?
« Reply #12 on: July 25, 2014, 11:05:39 PM »
Hi lemming
Quote
I haven't got a /usr/local directory on my target disk.
That's because you are not supposed to. That directory gets created in RAM every time the system boots.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: How to install grub2 to /dev/mmcblk0?
« Reply #13 on: July 25, 2014, 11:27:33 PM »
Another consideration for flash drives (or SSD's) require alignment based on MiB boundaries not sectors for best performance.

Most Intel based UEFI systems will boot using a 200MiB Fat partition with an offset of (starting at) 1MiB  (this provides correct alignment for flash based drives)
The format of the next partition is then determined for the desired operating system.

Another factor in this equation is the controller to which the flash drive is connected.

I think installing grub2 to a temporary medium like a USB drive might help determine if grub2 detects the flash drive and confirm the device is in fact mmcblk0p1 ??

Isn't it fun learning a new system..


Sent from my iPhone using Tapatalk

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: How to install grub2 to /dev/mmcblk0?
« Reply #14 on: July 27, 2014, 02:01:43 AM »
You may find this link useful reading, especially the section "Boot disks for EFI-based systems"

http://www.rodsbooks.com/gdisk/gdisk.html