Dirtbag's Blog

Change boot OS of a headless raspberrypi.

[ link: raspberrypiboot | tags: raspberrypi | updated: Fri, 17 Apr 2020 12:09:17 -0400 ]

When running the NOOBS image on a raspberrypi, you can install multiple OSs to run and multi boot the ones you choose. For instance, I boot openelec and raspbian. I needed to be able to switch between which one to boot without hooking up a monitor and keyboard to my pi.

So on my pi, I have the following disk layout.

 Disk /dev/mmcblk0: 7861 MB, 7861174272 bytes
4 heads, 16 sectors/track, 239904 cylinders, total 15353856 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001be8c

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048     2818359     1408156    e  W95 FAT16 (LBA)
/dev/mmcblk0p2         2826240    15288319     6231040   85  Linux extended
/dev/mmcblk0p3        15288320    15353855       32768   83  Linux
/dev/mmcblk0p5         2834432     3096575      131072    c  W95 FAT32 (LBA)
/dev/mmcblk0p6         3104768     7501823     2198528   83  Linux
/dev/mmcblk0p7         7503872     7626751       61440    c  W95 FAT32 (LBA)
/dev/mmcblk0p8         7634944    15280127     3822592   83  Linux

I have the option of booting raspbian (which is on mmcblk0p7) or openelec (which is on mmcblk0p5)
So in my case, what I have to do is mount up the mmcblk0p3 partition and you will see the following:

root@raspberrypi:~# mount /dev/mmcblk0p3 /mnt/
root@raspberrypi:~# ls /mnt/
installed_os.json  lost+found  noobs.conf

You should have the installed_os.json and noobs.conf file.. Look in the installed_os.json file and you should see something like:

root@raspberrypi:~# cat /mnt/installed_os.json 
  "description" : "OpenELEC is a fast and userfriendly XBMC Mediacenter distribution.",
  "folder" : "/mnt/os/OpenELEC",
  "icon" : "/mnt/os/OpenELEC/OpenELEC.png",
  "name" : "OpenELEC",
  "partitions" : [
  "release_date" : "2013-09-14"
  "description" : "A Debian wheezy port, optimised for the Raspberry Pi",
  "folder" : "/mnt/os/Raspbian",
  "icon" : "/mnt/os/Raspbian/Raspbian.png",
  "name" : "Raspbian",
  "partitions" : [
  "release_date" : "2014-01-07"

The first devices listed for each OS, i.e. the /dev/mmcblk0p5 and /dev/mmcblk0p7 are what you need to note:
Now edit the /mnt/noobs.conf file and edit the "default_partition_to_boot" part.

root@raspberrypi:~# cat /mnt/noobs.conf
default_partition_to_boot=7    <------- edit this

So in my case, I can set it to be 7 to boot raspbian or 5 to boot openelec. After you edit the file, save it and unmount the /dev/mmcblk0p3 partition and reboot.

root@raspberrypi:~# umount /mnt/
root@raspberrypi:~# reboot


Like this article? Buy me a beer!