Tiny Core Linux

Tiny Core Base => TCB Talk => Topic started by: lemming on July 22, 2014, 03:55:43 AM

Title: How to install grub2 to /dev/mmcblk0?
Post by: lemming on July 22, 2014, 03: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?
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: theYinYeti on July 23, 2014, 04: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
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on July 23, 2014, 04: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".
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: Misalf on July 23, 2014, 04:58:47 AM
Is the boot flag set?
You can use cfdisk or gparted to toggle it.
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on July 23, 2014, 05: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.
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on July 24, 2014, 03: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?
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: Juanito on July 24, 2014, 04:02:40 AM
The idea is that you create grub.cfg yourself
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: theYinYeti on July 25, 2014, 03: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…
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on July 25, 2014, 07: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. 
 
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: theYinYeti on July 25, 2014, 08: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 ;)
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on July 25, 2014, 08: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?
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: Juanito on July 26, 2014, 12:27:18 AM
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
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: Rich on July 26, 2014, 02:05:39 AM
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.
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: coreplayer2 on July 26, 2014, 02:27:33 AM
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
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: coreplayer2 on July 27, 2014, 05: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 (http://www.rodsbooks.com/gdisk/gdisk.html)
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on August 15, 2014, 12:08:45 AM
Thanks coreplayer2. I have used gdisk to create the partitions and it has left a MB before the UEFI-GPT partition It looks like the others are aligned on MiB boundaries.

I am still struggling on a couple of fronts. One is that my Intel NUC PC does not show the UEFI partition in the part of BIOS setup where you select the boot disk under UEFI. I'm sorting this out with Intel (who surprise me with their helpfulness).

The other part is the grub.cfg file.
In one post by Juanito he gives the example thus:

search --no-floppy --fs-uuid --set=root 74d071dc-a992-4493-8b54-168fb79897dd

menuentry "rootfs64" {
  linux /boot/vmlinuz64 quiet noswap tce=UUID=74d071dc-a992-4493-8b54-168fb79897dd waitusb=10:UUID=74d071dc-a992-4493-8b54-168fb79897dd tz=GMT-4 blacklist=bcma blacklist=ssb blacklist=b43 text
  initrd /boot/rootfs.gz /boot/modules64.gz
}

In the help/description of the UEFI grub module in tce-ab it has the following:

menuentry "core" {
  linux (hd1,gpt2)/boot/vmlinuz64 quiet noswap tce=sdb2 tz=GMT-4 blacklist=bcma blacklist=ssb blacklist=b43 t
ext
  initrd (hd1,gpt2)/boot/corepure64.gz
}

Which is the best way to go with a /dev/mmcblk0?
In the Juantio example, is the UUID of the GPT partition, or the linux partition holding the kermel and disk image, or the whole device?   
Is this UUID got from using "blkid" or using gdisk.  Gdisk produces five different IDs as listed below

gdisk -l
Disk identifier (GUID): 3E7C2A8E-AE5D-4DC4-A137-B8F03BB6E418

gdisk -i option

first partition
Partition GUID code: C12A7328-F81F-11D2-BA4B-00A0C93EC93B (EFI System)
Partition unique GUID: 0859BC6C-FAEE-431F-BF79-EBA98A19222E

second partition
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 3B29B2C3-4BC6-473A-B18B-E8429D52A3B8

Then there is the sixth one given by blkid.

Which one should I use?

In the line, " initrd (hd1,gpt2)/boot/corepure64.gz" above (which I think defines /dev/sdb2) what would be the equivalent for the second partition of /dev/mmcblk0 ?

Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: Juanito on August 15, 2014, 02:41:38 AM
In the Juantio example, is the UUID of the GPT partition, or the linux partition holding the kermel and disk image, or the whole device?   
Is this UUID got from using "blkid" or using gdisk.

It's the uuid of the linux partition from blkid.
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on August 17, 2014, 07:56:59 AM
Too many variables with the Intel NUC so I have switched to a laptop with a USB stick instead as apparently others have had success with this setup. Once I get this going I will go back to the NUC.

Using the following grub.cfg:

menuentry "core" {
linux (hd0,2)/boot/vmlinuz64 noswap tce=sdb2 tz=GMT-4 blacklist=bcma blacklist=ssb blacklist=b43 text
initrd (hd0,2)/boot/corepure64.gz
}

I get the grub menu, but when I select the "core" option, the screen clears and I get:

error: no suitable video mode found.
Booting in blind mode.

And then it freezes.

I just want to run in text mode with no X so what do I need to add to the menuentry above to get it to work? I thought the "text" at the end of the kernel line would set the video mode to something basic.

EDIT I've since tried inserting vga=791 to no avail.


Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: Juanito on August 17, 2014, 11:48:38 AM
You could try:
Code: [Select]
loadfont unicode
insmod efi_gop
set gfxterm=auto
terminal_output gfxterm

..before the "menuentry" line.

Note that you'll need to copy /usr/local/share/grub/unicode.pf2 to /mnt/wherever/EFI/BOOT/grub/fonts
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on August 18, 2014, 02:37:49 AM
Thanks Juanito. Its up and going now. The unicode.pf2 was already there so I did not need to copy it.

I have been experimenting with the different menuentry methods such as the "(hd0,2)" vs the UUID method.
In one of your previous posts you had the line, "search --no-floppy --fs-uuid --set=root e94de7a3-149b-4554-bc02-6129467534a9"

Is the "--set=root e94d...." correct or should the equals sign be the other side of "root", i.e.  "--set root=e94d..."

Also some posts have had the the partition listed as "(hd1,gpt2)" or "(hd1,msdos5)".  Where does the name gpt2 or msdos5 come from?
I have tried labelling my partitions and using the label instead of numbers but that doesn't work.

Is there a http server for Corepure64?


Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: Juanito on August 18, 2014, 03:35:43 AM
"--set root=e94d..."

..is the correct one - well spotted :)

"gpt2" or "msdos5" are the partition name, not the label - I recall coreplayer2 had made a couple of posts on now to use labels with grub2. You could also take a look at the documentation for more details:

http://www.gnu.org/software/grub/manual/grub.html

I don't believe there's an http server extension for corepure64
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: lemming on August 19, 2014, 12:09:37 AM
Thanks Juanito.
I've had a bit more of a look around and it seems that you were right with the "--set=root e94d...." as other sites have this layout. It just looks odd.

Re the gpt2 and msdos5; I thought that it was something that the user set on the partition like a label. I cannot find these partition names anywhere in parted, gparted or gdisk. It would seem that only grub can "see" these names on the partitions. My pure Ubuntu laptop (partitioned and formatted with Ubuntu utils) shows up with msdosx partitions even though it has never had a MS OS on it. The only way to know which partition is which is to do an ls, in grub, on each one.

I was trying to use this nomenclature in grub.cfg for my mmcblk0 drive and assumed that gpt and msdos only applied to /dev/sda..sdx drives. I now see that the mmcblk0p1 and 2 are showing up as gpt1 and gpt2 respectively. Although ls in grub shows only (hd0), (hd0,gpt1) and (hd0,gpt2) I can use (hd0,1) and (hd0,2), respectively, instead for these same partitions. 
Title: Re: How to install grub2 to /dev/mmcblk0?
Post by: gerald_clark on August 19, 2014, 12:24:09 AM
the blkid command will show you the partition UUID.