User avatar
mxcum167
Posts: 41
Joined: Sun Mar 04, 2012 11:56 am
Location: UK
Contact: Website

Simplifying booting between distros.

Mon Jun 04, 2012 6:25 pm

OK, I have been thinking of ways to switch between the three different distros that I am experimenting with on my RPi. Preferably without swapping SD Cards. This is my solution. I'm not suggesting this is the best way but it works for me.

First I got Debian working from an SD card. Then I connected a 250gb powered USB drive and partitioned it using gparted, as near as I could equally into 3. Formatting each partition ext4. This gave me /dev/sda1 (for Debian) /dev/sda2 (for Fedora) /dev/sda3 (for Raspbian)

Once I had copied the root filesystem for Debian to /dev/sda1, I changed the file /boot/cmdline.txt to allow Debian to use it, and rebooted. So far so good.

Next I booted from another SD card in with the Fedora distro on it and copied it's root filesystem to /dev/sda2, changed the /boot/cmdline.txt to allow this SD card mount /dev/sda2 as root, and rebooted. This also works no problem

Finally I did the same with an SD card with Raspbian on it, i.e. copied the root filesystem to /dev/sda3, again after reboot all works OK.

One thing I did notice whilst the Fedora and Raspbian distros seem to notice when an SD card is inserted or removed the Debian distro does not, maybe someone can advise me if there is a way to fix this.

At this point I have got 3 SD Cards with 3 distros, all mounting a different rootfs from a USB hard drive.

Next how to get it all using 1 SD Card.
Currently I have setup small scripts on each distro to copy the contents of the /boot on the SD Card to a subdirectory, just in case it has been updated, and then replace the files in /boot with the ones I need depending on what distro I want. Not the most elegant way, but again it works for me. If anyone's got a better idea I'll gladly try it.

I hope this helps someone

Martin.
Martin www.chez-cummings.com

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Simplifying booting between distros.

Mon Jun 04, 2012 6:38 pm

I would assume the goal is to get it all on one SD card - (since we don't have a "boot manager" capability) this implies that the "switch distros" method is of the "change some files on the SD card, then reboot" variety. So, it doesn't seem like there should be any problem having just one boot SD card - since the card will only contain the "boot" files.

Now, something I'd not thought about until now: do the "boot" files vary by distro? I would assume not, although I've never seen this topic addressed. If they don't, then the whole process becomes quite simple indeed.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
mxcum167
Posts: 41
Joined: Sun Mar 04, 2012 11:56 am
Location: UK
Contact: Website

Re: Simplifying booting between distros.

Mon Jun 04, 2012 6:43 pm

Joe Schmoe wrote:I would assume the goal is to get it all on one SD card - (since we don't have a "boot manager" capability) this implies that the "switch distros" method is of the "change some files on the SD card, then reboot" variety. So, it doesn't seem like there should be any problem having just one boot SD card - since the card will only contain the "boot" files.
Yes, that's it. Simple scripts just move the correct files to /boot
Joe Schmoe wrote:Now, something I'd not thought about until now: do the "boot" files vary by distro? I would assume not, although I've never seen this topic addressed. If they don't, then the whole process becomes quite simple indeed.
That thought also crossed my mind, when I get a chance I might experiment using different rootfs with a single set of boot files.
Martin www.chez-cummings.com

itimpi
Posts: 1090
Joined: Sun Sep 25, 2011 11:44 am
Location: Potters Bar, United Kingdom
Contact: Website

Re: Simplifying booting between distros.

Mon Jun 04, 2012 6:44 pm

Joe Schmoe wrote:I would assume the goal is to get it all on one SD card - (since we don't have a "boot manager" capability) this implies that the "switch distros" method is of the "change some files on the SD card, then reboot" variety. So, it doesn't seem like there should be any problem having just one boot SD card - since the card will only contain the "boot" files.

Now, something I'd not thought about until now: do the "boot" files vary by distro? I would assume not, although I've never seen this topic addressed. If they don't, then the whole process becomes quite simple indeed.
I would think that the GPU files are probably the same, but that the kernel images are distro specific? Also some of the configuration files (config.txt and cmdline.txt) are likely to vary.

A number of people are working on 'bare metal programmimg' of the Pi. I would think that this type of work might lead to something which could be used as a boot manager so that the user could select more dynamically. However that is just a guess as there may be technical barriers that woud stop it being possible.

User avatar
hexelpdkk
Posts: 177
Joined: Fri Feb 24, 2012 4:40 pm

Re: Simplifying booting between distros.

Mon Jun 04, 2012 7:11 pm

At the moment, as everyone is using the rpi-update program, they all have the same kernel, gpu code, start.elf etc. At some point, the kernels may start to split - certainly raspbian is looking at getting a 3.2.18 debian kernel patched.

Even if the kernels do deviate, you can do all of this from one SD card - set a kernel line in config.txt, and specify the rootfs in cmdline.txt (I have just read this on the e-linux page http://elinux.org/RPi_config.txt, and not tried it myself). You could then switch OS with a very simple bash script to modify these on the boot partition.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Simplifying booting between distros.

Mon Jun 04, 2012 7:15 pm

This is also something I've been thinking about doing (but haven't got round to yet). I was planning on having a python script which could automatically partition a large SD card into multiple partitions, and then write the relevant files from the .img files directly to the SD partitions.
Regarding sharing the /boot files - I asked Hexxeh (author of rpi-update) whether his rpi-update tool (which updates start.elf/kernel.img/etc.) works cross-distro, and he tells me he's tested it to work fine with Debian, Arch and Raspbian. But of course there may still be differences in cmdline.txt and config.txt between distros? Have a look at http://www.raspberrypi.org/phpBB3/viewt ... 559#p91559 and http://www.raspberrypi.org/phpBB3/viewt ... 027#p88027 to get some ideas for how to handle multiple config files :)
I did some investigation of my own and found that Fedora does indeed have a custom kernel (and it's /opt/vc/ files are in a different location too).

Without some modification, rpi-update won't work correctly with a 'shared' /boot because once you've updated it from one distro, the files in /boot will be up-to-update, but the kernel modules and /opt/vc/ files on the 'other' distros' rootfs will still be out of date. I'd planned to make the necessary rpi-update modifications at the same time as writing my python script :)

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Simplifying booting between distros.

Mon Jun 04, 2012 7:19 pm

...and it's not something I've looked at in detail, but if somebody wanted a 'boot manager' rather than a "switch cmdline & reboot" approach, using kexec would probably be the best approach.

obarthelemy
Posts: 1410
Joined: Tue Aug 09, 2011 10:53 pm

Re: Simplifying booting between distros.

Mon Jun 04, 2012 8:33 pm

I seem to remember seeing on this forum that you can chain-load a kernel form another kernel. ie, we could have the Pi booting off the same files for all distros, then chain-loading a specific kernel and rootfs, only by tweaking the initial kernel's "then chain-load" parameter. I'll look that up once I have my Pi set up, unless someone answers promptly.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Simplifying booting between distros.

Mon Jun 04, 2012 11:16 pm

obarthelemy wrote:I seem to remember seeing on this forum that you can chain-load a kernel form another kernel
Yeah, that's the kexec I was talking about above :D

heimi
Posts: 1
Joined: Thu Jun 06, 2013 9:44 pm

Re: Simplifying booting between distros.

Thu Jun 06, 2013 10:18 pm

the switch can also be realised with a single card without additional media:

this is what i've done, read till the end to get the idea:

- Use a 4 Gig SD Card
- Install the rapberry debian with dd -- should end up with a dos partition (raspboot), and and 2gib ext4 (raspfs) (and 2Gig unused space)
- do not expand the filesystem to the full sd size.
- mount each filesystem in ubuntu or whatever you like and create one tar file for each (could also be managed by ssh)
- Install Archlinux image with dd (same card if you like, gives nearly the same layout as before -- again: do not expand)
- create a third partion with the remaining space and format as ext4
- create a rasp folder on the vfat part and extract the raspboot.tar there
- extract the raspfs.tar to the mounted newly created partition
- in arch the /boot is normally mouted ro so do a "mount -o remount,rw /boot" to make it writable
- create an arch directory and copy the kernel.img, cmdline.txt and config.txt from /boot into this folder.
- create a script in /boot which will copy this three files either from the rasp folder or the arch folder into the root of the boot partition (mounted as /boot normally)
- in the rasp folder, edit config.txt: exchange the root=/dev/mmcblk0p2 with ....3
- on the rasp part in /etc/fstab also use /dev/mmcblk0p3 for the root "/" mountpoint
thats it
It seems enough to exchange this three files. on my tests i realized that it was even possible to use the rasp kernel to mout the arch toor an vice versa, but than no additional modules could be found (different versions)
You can mount the other filesystem easily for exchange data / config if you like.

Hope it helps.

there are some optimization possible: instead of installing the rasp image just for the purpose of creating the tar you can try using losetup on a local filesystem without accessing an sd card....

Return to “Advanced users”