WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Headless non-persistent setup on first boot  (Read 2723 times)

Offline pidak

  • Newbie
  • *
  • Posts: 2
Headless non-persistent setup on first boot
« on: January 09, 2019, 03:26:16 PM »
Slowly and very very painfully getting there! (on RPi zero, piCore-9.0.3)

(Questions are further down!  ::) )

I'm a complete Linux newbie. And before that I used Windows for youtube and CAD. But I'm a curious and stubborn soul with little to no understanding about computers, so now I have my eyes set on Linux and, of course, I'm hitting brick walls at every turn.

Anyway, things are in motion and here is how it goes so far (gonna describe everything in detail when finally done):
1. dd piCore to microSD
2. Expand partition from Lubuntu using fdisk, fsck.ext2 -fv and resize2fs
3. Copy needed extensions to that partition
4. Plug-in to the TV to test wifi.sh, doesn't work, waste a few days wondering what's up with that.
5. Personal battle - create first own TCZ extension on Lubuntu, because the wifi dongle firmware is not quite as what is promised from the original extension
6. Test wifi.sh on TV - now it works. In the mean time Arch wiki tells me about this cool thing wpa_supplicant and it turns out that I, too, have it on my Lubuntu laptop.
7. I throw-in wpa_supplicant.conf in that extension, too. I do have the wifi.db file in there, as well. I did that in my early days (meaning before Christmas), thinking I need it, but I don't think I do anymore. Still, I haven't made a new one without wifi.db, so I never tested that theory.
8. This one took me probably a week to figure out: how to connect to internet from the CLI without using wifi.sh - just use wpa_supplicant. As it turns out wpa_supplicant only says 'hello' to the AP (from my understanding, but I'm very confused anyway). And who new one would need udhcpc from busybox to get the IP and connect to internet. In all honesty, I'm sure many people know. After a few days of cursing I had the genius idea of comparing the ps output before and after connecting through wifi.sh. There I saw another command right after wpa_supplicant:
Quote
udhcpc -n -i wlan0 -x hostname box
.
9. Also, around that time I learned about copy2fs, so that I don't have to redo all the step above every time I use wifi.sh and then my RPi auto-connects and I'm thinking I'm a computer genius. (but I still unmount from the CLI, should add this to bootlocal.sh, but see next step for that)
touch [/mnt/something_something/more_something]/tce/copy2fs.flg
10. Then on Lubuntu I copy mydata.tgz from the card:
Code: [Select]
tar -vxzf mygata.tgzThen I do:
Code: [Select]
tar -vcf mydata.tgz --gzip ./* # 3 folders in there - opt, bin and tcI compare the md5sum of original mydata.tgz and the one extracted and re-compressed with no change to content. Different values - I expected it wouldn't be so easy, but I did it out of curiosity and I had a little hope in my heart, you know, just in case. Despite the apparent failure, I try to give it a go - I do the same thing, but this time I add wpa_supplicant and udhcpc commands to the bootlocal.sh file.
11. Today I plug the Pi in the TV and it seems to be working! But it has its problems

Keep in mind, I'm at a level where I do ping google.com and I go: "All righty! It finally works!" And I have no idea what to do next, so I just turn it off and move on to reading about the next pressing matter and then I read some more and after that I mess with QTerminal on Lubuntu. I'm very keen on trying out everything, I get some grasp on, but until I completely figure out the headless setup, I'm very limited when it comes to experimenting.

And here come the questions:
I use these commands to connect to internet:
Code: [Select]
sudo wpa_supplicant -i wlan0 -D nl80211,wext -c /etc/wpa_supplicant.conf -B
sudo udhcpc -n -i wlan0 -x hostname box

Q1: When I write them manually in the CLI of the booted piCore, ping google.com works instantaneously and after adding them to bootlocal.sh, ping google.com waits 5-10seconds before starting to give the expected standard output. And I mean every time, waiting time doesn't go away after a while. Why does this happen? My gut tells me it's the lack of time break between commands causing this, but what is the "low-level" reason, so to speak. Secondary question: how to make udhcpc wait before executing?

Q2: If I use the -r option of udhcpc, why don't I get the requested IP (home network is the /24 type, so I know i request it within the limits. Or maybe I think I know. I used i.e. -r 192.168.1.11, but I always automatically go 192.168.1.7 while trying. I also tried .10; .111 and a few more)

Bonus questions - if no feedback, I'll revisit them later on in a new thread.
1.After extracting and recompressing mydata.tgz in Lubuntu (see No.10 above), tc user boots in the root folder, unable to cd ~; but able to cd /home; and only after running sudo su, I'm able to cd ~; I assume it has something to do with the permissions and I need to read on chmod, but right now I have little to no understanding, so I guess I don't really have a specific question. But if someone knows what is happening with the permissions after extract+recompress and how to bypass it, I'd happily try it out and tell you the results.
2.After unmount the microSD card I'm unable to tce-load -wi whatever.tcz, but tce-ab is able to find extensions and opens their descriptions, but it too doesn't download and install them. Soooo what's up with that? (haven't played with this one enough, so I only blame myself. Haven't even tried it before unmounting.)

Now if you'll excuse me, I'm going to get into SSH, VNC and that sort of things.  ;)

EDIT 1: USING piCore-9.0.3 with RPi zero
« Last Edit: January 09, 2019, 03:54:30 PM by pidak »

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: Headless non-persistent setup on first boot
« Reply #1 on: January 09, 2019, 07:11:03 PM »
Hi pidak,

I think you are making great progress! piCore is not easy as it is quite different to normal linux distributions.

I know you aren't doing an audio project but piCorePlayer has done all the things you are trying to do. It may help as you seem to like to reverse engineer. It works on all Raspberry Pi's, has headless setup, cli setup or web gui setup. It's all basic shell scripts.

BTW: wifi.sh/wifi.db has quite a few limitations.

regards
Greg

Offline pidak

  • Newbie
  • *
  • Posts: 2
Re: Headless non-persistent setup on first boot
« Reply #2 on: January 11, 2019, 05:58:18 PM »
Hi Greg,

thank you for you response! I've seen piCorePlayer being mentioned here and there on the forum, but I never had a look at it - I definitely will, though! I'm guessing I'll find a few concepts that would help me to move forward.

The reverse engineering is spot on! But also I kinda "must" do that, because I'm still unaware of too many things, so usually I don't even know what to search for. Right now my main purpose is to learn and understand. Busybox looks like a very adequate tool set to get a solid grasp on Linux in general, which makes Tiny Core quite fit for the purpose (also my reason to dismiss Raspbian).

And writing scripts is something I'd like to get to doing very soon. The idea is to implement installation + headless setup as my first script.

In the mean time, I could really use some help with the -r option of udhcpc (request IP from DHCP server, i.e. my router)!

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: Headless non-persistent setup on first boot
« Reply #3 on: January 11, 2019, 06:30:59 PM »
hi pidak,

I can't help with udhcpc -r

For a static IP's I usually map the MAC address to IP address on the DHCP server or avoid DHCP altogether.

regards
Greg