# [SOLVED] Booting from SD card

## Massimo B.

Hi,

I can't get some grub2 booting from SD card.

Background is that I like to put the bootloader and the GPG-encrypted LUKS key on the SD card. The root system is stored on some large btrfs-on-luks. So I have the local harddrive as one huge luks-encrypted blockdevice. Booting requires 2 security levels that is the SD-Card (with bootloader and encrypted KEY file) and the GPG password to decrypt the KEY.

Installing grub2 on a USB pendrive, it works fine:

```
Model: Intenso Premium (scsi)

Disk /dev/sdc: 4043MB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags: 

Number  Start   End     Size    Type     File system  Flags

 1      2097kB  4042MB  4040MB  primary  ext2
```

The same installed on the SD card is not possible to boot eventhough the boot devices of the bios offers SD.

However the hardware can boot from SD-card, at least with some recent sysresccd installed. But this comes from some iso image, that required some isohybrid to be bootable from SD:

```
Error: Invalid partition table - recursive partition on /dev/mmcblk0.

Ignore/Cancel? I   

Model: SD SD02G (sd/mmc)

Disk /dev/mmcblk0: 1980MB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags: 

Number  Start  End  Size  Type  File system  Flags
```

```
# file systemrescuecd-x86-4.8.1.iso

systemrescuecd-x86-4.8.1.iso: ISO 9660 CD-ROM filesystem data 'sysrcd-4.8.1' (bootable)
```

----------

## NeddySeagoon

Massimo B.,

 *Quote:*   

> The same installed on the SD card is not possible to boot eventhough the boot devices of the bios offers SD.

 

Where does it go wrong?

Do you get a grub menu?

Does the kernel load ...

----------

## Massimo B.

It just skips very early and turns over to the default boot device as if there is no SD card inserted. No GRUB menu appearing. I would just guess that the hardware cannot boot from SD card if it wouldn't work successfully with the sysresccd image.

----------

## NeddySeagoon

Massimo B.

How is the MMC card partitioned and what filesystems does it contain?

Are you using BIOS or EFI mode?

----------

## Massimo B.

I format the SD card exactly like the USB pendrive I showed above. It works on USB but not on the SD-Card.

Currently I copied that sysresccd iso image via dd on that SD, so this does not seem to have a valid partition map but some ISO 9660. But it is booting without issues.

I just prefer the SD-Card over USB pendrive as security key, because of its small form factor, fitting in my portemonnaie.

----------

## Massimo B.

Not a single idea why booting from SD with the ISO 9660 works, but not with grub and msdos or gpt partition table?

How does ISO 9660 boot, is there grub also installed in that filesystem? Can I make my own SD-card like that?

----------

## snkmoorthy

may be you need to enable the 'boot' flag on the partition. Some BIOSes look for that specifically.(In fdisk use the 'a' option)

----------

## Massimo B.

I solved it, somehow I needed to use --force for grub-install as grub was not able to "embed" on the SD drive, no matter how much space I left in front of the first partition.

----------

## NeddySeagoon

Massimo B.

--force makes grub use block lists to load itself.  The block list is written when grub is installed to the MBR.

If you ever update grub on the SD card, you must reinstall it to the MBR too or the block lists will not point to the updated grub.

----------

## Massimo B.

Why do I need --force here at all, what about that blocklist mode and how can I avoid it?

As this is working:

```
 # grub-install --force --no-floppy /dev/mmcblk0 -v

grub-install: info: executing modprobe efivars 2>/dev/null.

grub-install: info: Looking for /sys/firmware/efi ...

grub-install: info: ... not found. Looking for /proc/device-tree ...

grub-install: info: ... not found.

Installing for i386-pc platform.

grub-install: info: cannot open `/boot/grub/device.map': No such file or directory.

grub-install: info: copying `/usr/lib/grub/i386-pc/acpi.mod' -> `/boot/grub/i386-pc/acpi.mod'.

grub-install: info: copying `/usr/lib/grub/i386-pc/adler32.mod' -> `/boot/grub/i386-pc/adler32.mod'.

grub-install: info: copying `/usr/lib/grub/i386-pc/affs.mod' -> `/boot/grub/i386-pc/affs.mod'.

grub-install: info: copying `/usr/lib/grub/i386-pc/afs.mod' -> `/boot/grub/i386-pc/afs.mod'.

...

grub-install: info: Partition 0 starts from 4096.

grub-install: info: drive = 0.

grub-install: info: the size of hostdisk//dev/mmcblk0 is 3866624.

grub-install: info: guessed root_dev `hostdisk//dev/mmcblk0' from dir `/boot/grub/i386-pc'.

grub-install: info: setting the root device to `hostdisk//dev/mmcblk0,msdos1'.

grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels.  This is not supported yet..

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..

grub-install: info: will leave the core image on the filesystem.

grub-install: info: opening the core image `/boot/grub/i386-pc/core.img'.

grub-install: info: saving <428840,0,24576>.

grub-install: info: saving <428888,0,4096>.

grub-install: info: opening the core image `/boot/grub/i386-pc/core.img'.

Installation finished. No error reported.
```

...while this is failing:

```

# grub-install /dev/mmcblk0 -v

grub-install: info: executing modprobe efivars 2>/dev/null.

grub-install: info: Looking for /sys/firmware/efi ...

grub-install: info: ... not found. Looking for /proc/device-tree ...

grub-install: info: ... not found.

Installing for i386-pc platform.

grub-install: info: cannot open `/boot/grub/device.map': No such file or directory.

grub-install: info: copying `/usr/lib/grub/i386-pc/acpi.mod' -> `/boot/grub/i386-pc/acpi.mod'.

grub-install: info: copying `/usr/lib/grub/i386-pc/adler32.mod' -> `/boot/grub/i386-pc/adler32.mod'.

grub-install: info: copying `/usr/lib/grub/i386-pc/affs.mod' -> `/boot/grub/i386-pc/affs.mod'.

...

grub-install: info: Scanning for mdraid09 devices on disk hostdisk//dev/mmcblk0.

grub-install: info: Scanning for dmraid_nv devices on disk hostdisk//dev/mmcblk0.

grub-install: info: Scanning for ldm devices on disk hostdisk//dev/mmcblk0.

grub-install: info: scanning hostdisk//dev/mmcblk0 for LDM.

grub-install: info: no LDM signature found.

grub-install: info: Scanning for lvm devices on disk hostdisk//dev/mmcblk0.

grub-install: info: no LVM signature found.

grub-install: info: Partition 0 starts from 4096.

grub-install: info: drive = 0.

grub-install: info: the size of hostdisk//dev/mmcblk0 is 3866624.

grub-install: info: guessed root_dev `hostdisk//dev/mmcblk0' from dir `/boot/grub/i386-pc'.

grub-install: info: setting the root device to `hostdisk//dev/mmcblk0,msdos1'.

grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels.  This is not supported yet..

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..

grub-install: error: will not proceed with blocklists.
```

----------

## NeddySeagoon

Massimo B.,

```
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels.  This is not supported yet..

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
```

It looks like you now use an MSDOS partition table but at one time, that SD card held a GPT partition table.

This makes grub go very carefully. Its quite possible you still have two complete but different partition tables. One MSDOS, one GPT.

Sometime, there was a GPT partition table on the device.  When you make a GPT partition table, you get an MSDOS partition table with one entry of partition type 0xEE.

This is a warning that GPT is in use.

There are two copies of the GPT partiton table, one starting just after the MBP at LBA 1 and the other at the end of the drive.

At this time, you have two different partition tables but one has a label to say its a fake.  This works, GPT is used.

Some time later, you either make a new partition table with a tool that does not understand GPT, so the old GPT partition table is left behind.

Certainly, the copy at the end of the drive is still there, even if its data is now inside the filesystem space.

You may have used a partition table tool that does not understand GPT, to delete the single MSDOS partition that carried the 0xEE warning flag and just made new partitions.

However it happened, grub can see both partition tables and is playing safe.  Embedding would overwrite the primary copy of GPT partition table.  That would be a very bad thing if GPT was really in use as it would be restored from the secondary copy next boot.

Choose which disk label you want to use. Copy the data off the SD card, make a new disk label with a GPT aware tool, restore the data then reinstall grub to the MBR.

If you choose GPT, you must make at least two partitions.  Embedding is not passible, so grub will look for a BIOS Boot partition, about 2Mb in size.  The grub embedding stuff goes here.  If you choose MSDOS, embedding is possible and your GPT disk label will be correctly destroyed.

----------

