Monday 9 June 2014

creating a backup bootable image(s) of your sdcard

One of things that you can be guaranteed to do is make mistakes.  Especially when your learning.  So having regular backups is essential.  One of the ways to do this is by making an image of your hard drive/flash drive/sd card that your operating system resides on.  Imaging creates an exact replica so that all of those packages and dependencies you setup will work again after you break it.

Backup:

The most helpful page I found in a brief search on the topic was here:


In case that link goes dead I've copied the steps I took away from this below.

Find out the name of the device you want to image through fdisk:

sudo fdisk -l                                                                               



In my case the device was at  \dev\sdc as I had my bootable sd card inserted in a usb reader.  When inserted the sd card has two partitions.  Make sure you record the file table.  Mine looked something like this.  You'll want to know the start, end and Id numbers for each partition.


   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *        2048       100351       ***    e  W95 FAT16 (LBA)
/dev/sdc2            100352     7741439      ***   83  Linux


The sd card is now ready to have an image taken of it using dd.  There is a lot of potential to screw up with dd so make sure you read the man page and understand what each flag is doing and avoid typos.  My command was as follows which takes /dev/sdc1 and 2 and puts it in an gzip'd bin file.  I did one image for each partition in this case.

sudo dd if=/dev/sdc1 bs=1024 | gzip > ~/bbbsdjun9boot.bin.gz                                                           

sudo dd if=/dev/sdc2 bs=1024 | gzip > ~/bbbsdjun9rootfs.bin.gz                                                         

I ended up with two files which can be extracted to an sd card to recover the system.

Recovery:

You will need to have the exact size partitions or larger of the original in order for this to work so make sure you write  it down above.  If you're booting up a new sd card instructions to do this can be found here:

http://www.armhf.com/boards/beaglebone-black/bbb-sd-install/

Essentially, you need to recreate the partition structure of the SD card you had before.  If you're using a larger card, in my case I have an 8 Gb card and my original was 4 Gb, you need to create the partition structure using the start and ends from before.

Now you can run:

gzip -dc ~/bbbsdjun9boot.bin.gz | dd of=/dev/sdc1 bs=1024

gzip -dc ~/bbbsdjun9rootfs.bin.gz | dd of=/dev/sdc2 bs=1024

Which can take a while depending on the write speed of your SD card.  Mine was getting around 1.7 Mb/s so the 50 Mb boot partition only took 30 sec, the ~4Gb rootfs partition took much longer.  Go get a coffee or something.

It is wise to follow through with checking your backup is viable before moving on to do whatever sketchy development you want to do next.  If you can't recover your system when the **** hits the fan you're going to be one sad panda.

Oh.  One note.  I had a bunch of problems with the dd command throwing an permissions error for /dev/sd1.  setting 'sudo -i' seemed to solve the problems.

Sunday 8 June 2014

Starting applications at boot

So by now you've likely written a few applications for your little BBB and you're thinking, 'hey, sure would be nice if these ran at boot'.

Here is some things I've found to make your life easier when doing this.

First off from this fellow:
http://stackoverflow.com/questions/7221757/run-automatically-program-on-startup-under-linux-ubuntu

you want to create an init script called 'yourscript' and put in init.d, make it excecutable and add it to the update-rc.d with default parameters as below

sudo mv /filename /etc/init.d/
sudo chmod +x /etc/init.d/filename 
sudo update-rc.d filename defaults 
If you've never created an init script before there is a template on github:
which details the adding and use.  
Once added these are helpful commands:
/etc/init.d/algorithms start
/etc/init.d/algorithms stop
/etc/init.d/algorithms status
Also anything you put on stdout and stderr should show up in the log files here:
 /var/log/scriptname.log and error output to /var/log/scriptname.err

Tuesday 3 June 2014

Load things at boot time

So one of the useful things you will likely want to be able to do is enable certain hardware configurations at boot.

Well for starters you can mess with the uEnv.txt file similar to this:


##To disable HDMI/eMMC...
optargs=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN capemgr.enable_partno=BB-UART1

You may also wish to run some scripts at boot.
add any scripts to rc.local.

sudo nano /etc/rc.local
 
you will need to make the scripts executable of course.