WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Custom OS for Raspberry Pi Zero  (Read 716 times)

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Custom OS for Raspberry Pi Zero
« on: July 06, 2020, 03:16:27 PM »
Hi,

Amazing project, congratulations to everyone who has been contributing to the project. I have been trying to build a custom linux OS using buildroot to build an air-gapped specific-purpose device, when I discovered TinyCore linux & its default behavior is exactly what I want.

I want an immutable OS instance completely loaded into memory, with the support of ejecting bootable media after boot up. Run my self-contained binary, interact with it and power off by simply switching off the power directly.

I have read the TinyCore Book to understand how a lot of things work but still can use some help :)

I understand the bare minimum OS is the one that contains a kernel file & initrd file, with additional extensions in a tce directory, especially tce/optional, which can be auto-loaded into memory by creating a copy2fs.flg file & my own program can be launched by adding a launch command in /opt/bootlocal.sh script.

Q1) Does that sound accurate conceptually?

This is my first time attempting to build a custom linux OS, but I think Raspberry Pi doesn't need a MBR (Master Boot Record) like x86 arch, it simply needs a config.txt file with the information as to where the kernel file is and where the initrd file is.

Q2) Would you say that is correct?

Similarly cmdline.txt file for specifying boot codes?

Q3) Am I right about that?

Q4) How do I find details about the extensions that are listed on http://tinycorelinux.net/11.x/armv6/tcz/? Is there a page with details such as name, functionality, dependencies etc?

I only need x-server for display & webcam support to begin with.

Thank you so much in advance!
« Last Edit: July 06, 2020, 03:32:08 PM by ashfame »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8120
Re: Custom OS for Raspberry Pi Zero
« Reply #1 on: July 06, 2020, 05:30:29 PM »
Hi ashfame
Welcome to the forum.
... I understand the bare minimum OS is the one that contains a kernel file & initrd file, with additional extensions in a tce directory, especially tce/optional, which can be auto-loaded into memory by creating a copy2fs.flg file & my own program can be launched by adding a launch command in /opt/bootlocal.sh script.

Q1) Does that sound accurate conceptually? ...
Yes. Be aware, if your program requires the GUI or network to be up, it should be launched from  ~/.X.d/.

Quote
... Q2) Would you say that is correct? ...

 ----- Snip -----

 ... Q3) Am I right about that? ...
I don't use Pi so I can't answer with 100% certainty, but I believe that is correct. I'm sure one of the smart kids will correct me if I'm wrong.


Quote
... Q4) How do I find details about the extensions that are listed on http://tinycorelinux.net/11.x/armv6/tcz/? Is there a page with details such as name, functionality, dependencies etc? ...
Once you have a GUI up and running on the Pi the  Apps  utility can be used for that. If necessary, you can use your web browser too.

For example, if you go to  http://tinycorelinux.net/11.x/armv6/tcz/  and want some information about  Xorg.tcz.

This is the  .info  file. It may be sparse or contain additional information on using the program. It varies by extension:
http://tinycorelinux.net/11.x/armv6/tcz/Xorg.tcz.info

These are the extensions that are direct dependencies:
http://tinycorelinux.net/11.x/armv6/tcz/Xorg.tcz.dep

This shows the entire dependency tree which includes all dependencies:
http://tinycorelinux.net/11.x/armv6/tcz/Xorg.tcz.tree

This is the list of all files contained in the extension:
http://tinycorelinux.net/11.x/armv6/tcz/Xorg.tcz.list

This is the extensions MD5 (checksum) file:
http://tinycorelinux.net/11.x/armv6/tcz/Xorg.tcz.md5.txt

This is the extension itself:
http://tinycorelinux.net/11.x/armv6/tcz/Xorg.tcz

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Custom OS for Raspberry Pi Zero
« Reply #2 on: July 07, 2020, 12:49:15 AM »
Hi Rich, thanks for the welcome :)

Quote
Yes. Be aware, if your program requires the GUI or network to be up, it should be launched from  ~/.X.d/.

Good point!

Quote
Once you have a GUI up and running on the Pi the  Apps  utility can be used for that. If necessary, you can use your web browser too.

For example, if you go to  http://tinycorelinux.net/11.x/armv6/tcz/  and want some information about  Xorg.tcz.

The only ARM device I have the moment is the Raspberry Pi Zero (non-W), so no network capabilities. I specifically looked for this unit cuz of my use-case of an air-gapped device, so I can't run TinyLinux on it and customize it using Apps utility. I must do this on a regular linux box. Thanks for the links though, that's quite helpful, but I am still left wondering about packages like:

flwm.tcz vs flwm_topside.tcz - which one should I use? what's the diff?

Also essentially while choosing & copying over tcz files manually, I must check their dependencies and copy them over too. Also, check dependencies of dependencies as well, right? Can write a script for that.


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8120
Re: Custom OS for Raspberry Pi Zero
« Reply #3 on: July 07, 2020, 04:30:46 AM »
Hi ashfame
... flwm.tcz vs flwm_topside.tcz - which one should I use? what's the diff? ...
flwm  has the titlebar and and buttons on the left edge of the windows. flwm_topside has them on the top edge where they belong. ;D

Quote
... Also essentially while choosing & copying over tcz files manually, I must check their dependencies and copy them over too. Also, check dependencies of dependencies as well, right? Can write a script for that.
Look over here:
http://forum.tinycorelinux.net/index.php/topic,23034.msg144013.html#msg144013

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Custom OS for Raspberry Pi Zero
« Reply #4 on: July 07, 2020, 05:13:50 AM »
Hi ashfame
flwm  has the titlebar and and buttons on the left edge of the windows. flwm_topside has them on the top edge where they belong. ;D
oh damn, haha.

Quote
Look over here:
http://forum.tinycorelinux.net/index.php/topic,23034.msg144013.html#msg144013

That's perfect, thanks much! :)

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Custom OS for Raspberry Pi Zero
« Reply #5 on: July 07, 2020, 04:14:50 PM »
Hi ashfame

Hi @Rich

Based on my understanding how things should be, I tried making a custom OS by using bits from piCore11

I mounted both the partitions from the img file, took a look at all the files and then copied over certain files from first partition to a `custom` directory and tce folder from second partition along with X-org tcz files that I downloaded using the bash script you gave me earlier.

BTW, I used this command to mount:
Code: [Select]
mount -o loop,ro,offset=$((512*startblock)) piCore-11.0.img /mnt/tmp
Contents of `custom` directory now looks like:

Code: [Select]
root@localhost:/mnt/custom# ll
total 13M
drwxr-xr-x 3 root root 4.0K Jul  7 22:46 ./
drwxr-xr-x 6 root root 4.0K Jul  7 22:27 ../
-rwxr-xr-x 1 root root 3.4M Jul  7 19:56 11.0.gz*
-rwxr-xr-x 1 root root 1.3M Jul  7 19:56 4.19.81-piCore.gz*
-rwxr-xr-x 1 root root  52K Jul  7 22:27 bootcode.bin*
-rwxr-xr-x 1 root root  130 Jul  7 19:56 cmdline.txt*
-rwxr-xr-x 1 root root 2.1K Jul  7 22:27 config.txt*
-rwxr-xr-x 1 root root 4.8M Jul  7 19:56 kernel41981.img*
-rwxr-xr-x 1 root root 2.9M Jul  7 22:46 start.elf*
drwxr-xr-x 4 root root 4.0K Jul  7 20:50 tce/

I then proceeded to make an iso by running:

Code: [Select]
mkisofs -o piCoreXorg.iso custom but that didn't work and etcher complained about no partition table being there. I tried writing it to SD card anyway, because RaspberryPi's site explains they work off a config.txt file instead of BIOS. Didn't even get a boot (no led light action). I used `dd` and got same results.

I dug back into the book and tried `mkisofs` command with additional parameters to create partition correctly:

Code: [Select]
mkisofs -l -J -r -V PiCoreXorg -no-emul-boot -boot-load-size 4 -boot-info-table -b bootcode.bin -c boot.cat -o picorexorg.iso custom but didn't get lucky. Same results like before. No boot, no led lighting up.

I am pretty sure I lack understanding of partitions here to put all the conceptual information I gathered to work. Please advice.

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12402
Re: Custom OS for Raspberry Pi Zero
« Reply #6 on: July 07, 2020, 09:49:05 PM »
Maybe I'm missing something here, but if you wish to create a custom piCore and it will be booted from sd card then why not mount the piCore image, make your changes and then un-mount the image?

The modified image can then be written to sd card.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10273
Re: Custom OS for Raspberry Pi Zero
« Reply #7 on: July 08, 2020, 12:16:33 AM »
ISO image = CD. Rpi does not use cds, that's more of an x86 thing.

You write the image to a SD card using dd.
edit:
Code: [Select]
dd if=piCore-11.0.img of=/dev/sdd bs=1M
When running dd, make triple sure /dev/sdd is your SD card and not your hd.
« Last Edit: July 08, 2020, 12:19:00 AM by curaga »
The only barriers that can stop you are the ones you create yourself.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Custom OS for Raspberry Pi Zero
« Reply #8 on: July 08, 2020, 01:46:33 AM »
Maybe I'm missing something here, but if you wish to create a custom piCore and it will be booted from sd card then why not mount the piCore image, make your changes and then un-mount the image?

The modified image can then be written to sd card.

I am building an air-gap device, hence using Raspberry Pi Zero (non-W), so I have no networking capabilities on that thing. And that's the only ARM device I have got. Moreover, I want to be able to package this custom OS along with an application program and let others download & use it, so I guess I am simply looking for a way to put the customized piCore back together in a format (disk image or iso) that can be easily written to a SD Card. Does that explain my situation?

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Custom OS for Raspberry Pi Zero
« Reply #9 on: July 08, 2020, 01:49:14 AM »
ISO image = CD. Rpi does not use cds, that's more of an x86 thing.

You write the image to a SD card using dd.
edit:
Code: [Select]
dd if=piCore-11.0.img of=/dev/sdd bs=1M
When running dd, make triple sure /dev/sdd is your SD card and not your hd.

Right, that's what I did to write piCore to SD card and run it. I guess I don't know how to put that modified directory (modified piCore) back together as an IMG disk, that can be written to SD card?

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12402
Re: Custom OS for Raspberry Pi Zero
« Reply #10 on: July 08, 2020, 04:15:21 AM »
The situation is analogous to that of a hard disk.

You mount a hd, you write some data and you unmount the hd - the next time you mount the hd, the new data is there.

So, you mount the piCore image, you write some data and you unmount the image - the next time you dd the image to a sd card, the new data is there.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Custom OS for Raspberry Pi Zero
« Reply #11 on: July 08, 2020, 05:19:37 AM »
The situation is analogous to that of a hard disk.

You mount a hd, you write some data and you unmount the hd - the next time you mount the hd, the new data is there.

So, you mount the piCore image, you write some data and you unmount the image - the next time you dd the image to a sd card, the new data is there.

oh damn, really? I guess that makes sense, I just didn't know images can be modified like that. Is this only applicable for IMG files or even ISOs?
I am gonna try this out and report.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10273
Re: Custom OS for Raspberry Pi Zero
« Reply #12 on: July 08, 2020, 09:33:09 AM »
ISOs are read-only, but in general you can loop mount and edit all kinds of images. Floppies, zip disks, hard disks...
The only barriers that can stop you are the ones you create yourself.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Custom OS for Raspberry Pi Zero
« Reply #13 on: July 08, 2020, 11:06:39 AM »
The situation is analogous to that of a hard disk.

You mount a hd, you write some data and you unmount the hd - the next time you mount the hd, the new data is there.

So, you mount the piCore image, you write some data and you unmount the image - the next time you dd the image to a sd card, the new data is there.


ISOs are read-only, but in general you can loop mount and edit all kinds of images. Floppies, zip disks, hard disks...

It worked. Thanks a lot :)

My further questions would be about specific bits around customization, but I guess new topics/questions are better suited unless you folks recommend I continue with this topic.