How to install and boot from an SD card

This page describes how to install on an SD card on systems where the BIOS cannot boot from SD (e.g. IBM/Lenovo ThinkPad). This can be useful e.g. to set up an older laptop which did have a SD card slot but not an SSD but a slower classic HD (may be with some worn out bad sectors after all those years, so you don't entirely trust that disk anymore?), or if you want to have an entire OS on a portable SD you can swap between computers. (If your laptop's BIOS CAN boot from SD cards like it can from harddisks and USBs, then no special instructions are needed, as it's a standard install.)

You’ll want to use a fast SD card for this purpose, maybe one you had lying around from a Raspberry Pi experiment? The SD card may likely be SLOWER than a SSD or even the original HDD. (Speed Class 10, see https://www.sdcard.org/developers/overview/speed_class/; an old SD card from a photo camera may or may not be fast enough for this approach to make sense in practice.)

Installation Instructions

The idea to get around the BIOS is to have just GRUB and /boot on either an internal HDD, or a USB stick you leave plugged in, and have the rest of the OS (maybe incl. /home etc.) on the SD card.

Start by doing a normal standard installation, but choose Installation type: Something else (You can create or resize partitions yourself, or choose multi...). Now put "/" on the SD (say as ext4 on /dev/mmcblk0p2, if you put a Swap /dev/mmcblk0p1 maybe) BUT make sure that /boot goes on say /dev/sda1 (or a USB stick device, slower than the SD), giving it 1 or few GBs. You may also want to use the rest of the space not needed for /boot on your HDD (or USB) to be e.g. /dev/sda2 on /media/hdd - in case you run out of space on that SD. As Device for boot loader installation, use /dev/sda (NOT /dev/sda1, and certainly NOT /dev/mmcblk - as your BIOS cannot boot from that).

You may try restarting now - but it won't work, yet... This is because while GRUB's initial stage IS loaded from the MBR on, and the Kernel CAN be loaded because /boot isn't on the SD, when that early initial Kernel which runs with the filesystem from /boot/initrd.img* wants to hand-over to our "real" filesystem on the SD, it gets stuck.

The trick is to add support for SD cards into initrd.img:

How to add additional modules to initrd.img

We need to chroot into the "real" OS from the Live CD (Repair) session, and to do that want to set up a “shadow” of it inside /mnt, so, similarly to what is explained on https://help.ubuntu.com/community/LiveCdRecovery:

We first take a look at how what’s mounted where in our “real” (non-LiveCD) running system:

$ cat /media/ubuntu/425.../etc/fstab

And mount that inside /mnt (which should be empty):

$ ls /mnt
$ sudo mount UUID=425... [or /dev/mmcblk0p2] /mnt
$ sudo mount UUID=03… [or /dev/sda2] /mnt/boot

We also have to have some of the special directories in /mnt before we chroot:

$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /proc /mnt/proc # OR: sudo mount -t proc proc /mnt/proc
$ sudo mount --bind /sys /mnt/sys   # OR: sudo mount -t sysfs sys /mnt/sys

You may want to set-up a few more things before you chroot, e.g. this is useful:

$ cp /etc/resolv.conf /mnt/etc/resolv.conf

$ dpkg-divert --local --rename --add /sbin/initctl
$ ln -s /bin/true /sbin/initctl

Now we’ll make /mnt our new root, so that we can run commands “as if” we weren’t on the LiveCD file systems anymore, but in the running “real” OS (which doesn’t boot yet / anymore):

$ sudo chroot /mnt

And now we can start fixing things in it, e.g. this is what we need to get the SD card to work during the initial early kernel which runs with the file system loaded from initrd (which in our case is on HDD/SSD/USB), before it hands over to our real filesystem (which in our case is on the SD) :

# echo "mmc_core" >> /etc/initramfs-tools/modules
# echo "mmc_block" >> /etc/initramfs-tools/modules
# echo "sdhci" >> /etc/initramfs-tools/modules
# echo "sdhci-pci" >> /etc/initramfs-tools/modules

And now we can finally rebuild our initrd.img* in /boot:

# update-initramfs -v
# ls -lh /boot/initrd.img*
# update-initramfs -u -k all
# ls -lh /boot/initrd.img*

And restarting now should get you booted from the SD!

Issues

SD suspend/resume issues

E.g. IBM/Lenovo ThinkPad have an issue wherein resuming from suspended state with OS on SD doesn't work (see http://www.thinkwiki.org/w/index.php?search=sd+card).

See Also

External Links


CategoryInstallation CategoryLive CategoryBootAndPartition CategoryBackupRecovery

BootFromSD (last edited 2014-12-22 09:15:59 by 178-16-145-98)