Files
test-repo/test.org
2021-11-14 16:31:48 +01:00

25 KiB

Démarrer le Ninkbox Raspberry 4 sans clavier ni écran

Attention: This guide if for owners of a GNU/Linux system. Not intended for Windows or MacOS users.

Attention: Ce guide est pour les utilisateurs GNU/Linux. Il n'est pas destiné aux utilisateurs Windows ou MacOS.

English

License

This document is (C) 2014-2020 Bruno Raoult and licensed under the Creative Commons Attribution Share Alike 4.0 International license.

Résumé

We will prepare the system to boot and connect to network.

Français

Licence

Ce document est (C) 2020 Bruno Raoult, sous licence Creative Commons Attribution Share Alike 4.0 International license.

DONE Introduction

Ce document explique comment démarrer le

DONE Download a debian image from beagleborg.org web site

You need to choose between these images :

Image Description
lxqt Everything, with full GUI, programming languages, etc. Maybe 3.5/4Gb size.
IoT Everything, but no GUI. Maybe 2Gb.
console Only console tools and networking. Maybe 1Gb size.
tiny I cannot find it anymore, but it was a console version, with busybox.

As IoT and lxqt versions contain stuff like javascript, python, node, cloud-9, etc., it is pretty difficult to strip down such images, and much easier to start from console version, and add what you need.

This document is only about the latter option. But you will notice that console image is often not present on above URL. In fact, a better source starts from the Debian Beagleboard page, which gives access to useful links including Debian images. At the date this document is written, the image chosen is Debian 10.5 Buster Console Flasher Snapshot (please choose a flasher image, otherwise you will not be able to flash your device with the image - I lost hours because of this issue :-(

More images are available on : https://debian.beagleboard.org/images/ or https://rcn-ee.com/rootfs/bb.org/testing.

After the download, you will have a file looking like bone-eMMC-flasher-debian-10.5-console-armhf-2020-08-31-1gb.img.xz.

Let's immediately rename and uncompress it, to make this document easier to read from now on.

$ mv bone-eMMC-flasher-debian-10.5-console-armhf-2020-08-31-1gb.img.xz bone-debian.img.xz
$ xz -d bone-debian.img.xz
renaming/uncompressing image

From now on, we will work only with the bone-debian.img uncompressed image file.

DONE Test image file with a loop-mount (optional)

We can mount the image file, in order to make changes we need. To do so, we first need to find out what is its structure. I will use parted(1), you have the choice between many tools to do the job (fdisk(1), sfdisk(1), …)

$ parted bone-debian.img unit s print
WARNING: You are not superuser.  Watch out for permissions.
Model:  (file)
Disk /export/home/br/Downloads/bone-debian.img: 1843200s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start  End       Size      Type     File system  Flags
 1      8192s  1843199s  1835008s  primary  ext4         boot
image structure check

The real starting byte of partition in image is (sector_size * start_sector). Here sector_size=512, and start_sector=8192.

Note: We asked parted to output units in "sectors" (unit s). You will have to adjust calculation according to the unit you choose.

Now, we loop-mount the device:

$ mkdir /mnt/test
$ sudo mount bone-debian.img -o loop,offset=$((512*8192)) /mnt/test
image loop-mount

Now you can check what is in the image, and make some changes if you want.

$ ls -l /mnt/test
total 100
-rw-r--r--  1 root root  1359 May 18 18:52 bbb-uEnv.txt
drwxr-xr-x  2 root root  4096 May 18 12:23 bin
drwxr-xr-x  4 root root  4096 May 18 18:52 boot
drwxr-xr-x  4 root root  4096 May 18 12:14 dev
drwxr-xr-x 71 root root  4096 May 18 12:25 etc
drwxr-xr-x  3 root root  4096 May 18 12:25 home
-rw-r--r--  1 root root    55 May 18 18:52 ID.txt
drwxr-xr-x 13 root root  4096 May 18 12:23 lib
drwx------  2 root root 16384 May 18 18:52 lost+found
drwxr-xr-x  2 root root  4096 May 18 12:15 media
drwxr-xr-x  2 root root  4096 May 18 12:15 mnt
-rw-r--r--  1 root root  1008 May 18 18:52 nfs-uEnv.txt
drwxr-xr-x  5 root root  4096 May 18 18:52 opt
drwxr-xr-x  2 root root  4096 May  2 18:39 proc
drwx------  2 root root  4096 May 18 12:15 root
drwxr-xr-x  2 root root  4096 May  2 18:39 run
drwxr-xr-x  2 root root  4096 May 18 12:22 sbin
drwxr-xr-x  2 root root  4096 May 18 12:15 srv
drwxr-xr-x  2 root root  4096 May  2 18:39 sys
drwxrwxrwt  2 root root  4096 May 18 12:25 tmp
drwxr-xr-x 10 root root  4096 May 18 12:15 usr
drwxr-xr-x 11 root root  4096 May 18 12:15 var
image contents

Don't forget to unmount the partition when finished

$ sudo umount /mnt/test
un-mount image

DONE Build a bootable microSD

Links: elinux.org, and others.

Insert a µSD card, and find out the device (normally something like /dev/sdX), (you may use lsblk(1), or check /var/log/syslog). Example :

$ lsblk -o NAME,TYPE,FSTYPE,MOUNTPOINT,PARTLABEL,LABEL,SIZE,RO
NAME   TYPE FSTYPE MOUNTPOINT    PARTLABEL LABEL      SIZE RO
[...]
sdc    disk                                         931.5G  0
└─sdc1 part ext4                 porsche1  porsche1 931.5G  0
sdg    disk                                           7.3G  0
└─sdg1 part vfat                                      7.3G  0
find µSD card device

My 8Gb microSD device is therefore /dev/sdg, which contains a single VFAT partition.

Warning: Next step will overwrite the SD partition table, therefore all existing data.

Now, we can copy the image to the card with the command below. ATTENTION ! DO NOT COPY BELOW LINE AS-IS, USE YOUR OWN DEVICE !

$ sudo dd if=bone-debian.img of=/dev/sdg
copy image to µSD card

Once done, we can check the new SD card setup :

$ lsblk -o NAME,TYPE,FSTYPE,MOUNTPOINT,PARTLABEL,LABEL,SIZE,RO /dev/sdg
NAME   TYPE FSTYPE MOUNTPOINT PARTLABEL LABEL   SIZE RO
sdg    disk                                     7.3G  0
└─sdg1 part ext4                        rootfs  896M  0
µSD structure after image copy

As a precaution, it is better to perform a file system check :

$ sudo e2fsck -f /dev/sdg1
µSD file-system check

sdg1 contains a 900Mb ext4 partition, that we can grow a little bit, just in case we want to add something in it (in fact, the file system uses only 400Mb on the partition, as the e2fsck above showed).

DONE Grow partition (optional)

There is a script included in image file system to expand the file system partition size to use the full SD capacity. We will instead do it manually, and use only a portion of the SD card.

We start from the lsblk output above. We simply need to (1) expand the partition (sdg1 for me), and (2) grow the ext4 file system within the resized partition.

As an example, let's expand /dev/sdg1 to 2Gb. We will use parted(1) and resize2fs(1) :

$ sudo sudo parted  /dev/sdg resizepart 1 2048
Information: You may need to update /etc/fstab.

$ sudo resize2fs /dev/sdg1
resize2fs 1.45.5 (07-Jan-2020)
Resizing the filesystem on /dev/sdg1 to 498976 (4k) blocks.
The filesystem on /dev/sdg1 is now 498976 (4k) blocks long.
grow image system partition

Note: parted's resizepart argument are partition number and new size in Mb, in this order.

DONE Flash the board

DONE Confirm the Beaglebone can boot on µSD card (optional)

If you wish, you may try to boot the µSD image without flashing the eMMC. To do so, follow these steps.

Important: Before going further, you must confirm the image will not flash immediately the eMMC. We mount the ext4 partition and verify the end of the {mount-point}/boot/uEnv.txt :

$ mkdir /mnt/test
$ sudo mount /dev/sdg1 /mnt/test
$ df /mnt/test
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/sdg1        1946576 438880   1391528  24% /mnt/test
$ cd /mnt/test/boot
$ tail uEnv.txt
###U-Boot Overlays###

cmdline=coherent_pool=1M net.ifnames=0 lpj=1990656 rng_core.default_quality=100 quiet

#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M net.ifnames=0 lpj=1990656 rng_core.default_quality=100 quiet video=HDMI-A-1:1024x768@60e

##enable Generic eMMC Flasher:
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh
double check /boot/uEnv.txt

Ensure the last line (#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh) is commented-out (starting with #), do it if necessary, with your favorite editor.

Umount your partition, and insert the SD card in the unpowered Beaglebone.

Now, hold down the User Boot button (which is not far from the micro-SD slot), and plug the mini-USB to the Beaglebone and your desktop.

The board will turn-on, and the four on-board LEDs will light up for a few seconds, then they will start to blink. Now you can release the button.

The board is just booting from the µSD…

Open a terminal on your desktop, and repeat the following command until you new interfaces appearing (an alternative is to check /var/log/syslog) :

$ while true; do ifconfig -s; echo; sleep 5; done
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0      1500 16074852      0     87 0      15516809      0      0      0 BMRU
lo       65536   512399      0      0 0        512399      0      0      0 LRU
tun0      1500        0      0      0 0             0      0      0      0 MOPRU

[...]

Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0      1500 16074905      0     87 0      15516882      0      0      0 BMRU
eth1      1500        6      0      0 0            10      0      0      0 BMRU
lo       65536   512503      0      0 0        512503      0      0      0 LRU
tun0      1500        0      0      0 0             0      0      0      0 MOPRU
usb0      1500        6      0      0 0            10      0      0      0 BMRU

[...]
check for new interface on desktop

As you can see, new interface(s) appeared at some time. Here, we got eth1 and usb0.

Note : It is possible that your system shows only one interface, or two eth interfaces, depending on the image build.

You can now check the IP of one of them on your desktop :

$ ifconfig eth1
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.7.1  netmask 255.255.255.0  broadcast 192.168.7.255
        inet6 fe80::220:4035:e598:a13c  prefixlen 64  scopeid 0x20<link>
        ether 1c:ba:8c:a2:ed:6b  txqueuelen 1000  (Ethernet)
        RX packets 51  bytes 7226 (7.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 97  bytes 20058 (20.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
check eth1 address on desktop

Our address is either 192.168.6.1 or 192.168.7.1, depending on the interface. The Beaglebone will have the address 192.168.6.2 (or 192.168.7.2). Just ssh to it as user debian (the default password will be displayed, normally temppwd):

$ ssh debian@192.168.6.2
Debian GNU/Linux 10

BeagleBoard.org Debian Buster Console Image 2020-08-31

Support: https://bbb.io/debian

default username:password is [debian:temppwd]

debian@192.168.6.2's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
debian@beaglebone:~$ echo 'Hello BB !'
Hello BB !
debian@beaglebone:~$
connect to beaglebone as debian/temppwd

Voilà ! You can play with your system, and logout when finished.

DONE Flash the Beaglebone

Important: Before going further, you must confirm the image will flash the eMMC. You have to mount the ext4 partition on the desktop and verify the end of the {mount-point}/boot/uEnv.txt :

$ mkdir /mnt/test
$ sudo mount /dev/sdg1 /mnt/test
$ df /mnt/test
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/sdg1        1946576 438880   1391528  24% /mnt/test
$ cd /mnt/test/boot
$ tail uEnv.txt
###U-Boot Overlays###

cmdline=coherent_pool=1M net.ifnames=0 lpj=1990656 rng_core.default_quality=100 quiet

#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M net.ifnames=0 lpj=1990656 rng_core.default_quality=100 quiet video=HDMI-A-1:1024x768@60e

##enable Generic eMMC Flasher:
cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh
double check

Ensure the last line (cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh) has comment removed (not starting with #), remove the comment if necessary, with your favorite editor.

Umount your partition, and insert the SD card in the unpowered Beaglebone.

We do reboot just the same as before : unplug the mini-usb, and plug it again while pressing the User button until the four on-board LEDs start to blink after having lighted up together for a few seconds.

It will take a few minutes to flash the image on the board. The bank of 4 LED's will turn off when it is finished (some say they turn on).

When done, unplug the board, remove the µSD card to avoid flashing the board again by mistake, and power-on the board again.

Note : I strongly recommend to comment again last line of /boot/uEnv.txt on µSD partition, in case you would need to boot it for some reason.

DONE Change debian password

This is the first thing to do. Also, we will change /etc/motd, /etc/issue, and /etc/issue.net files.

$ ssh debian@192.168.6.2
Debian GNU/Linux 10

BeagleBoard.org Debian Buster Console Image 2020-08-31

Support: https://bbb.io/debian

default username:password is [debian:temppwd]

debian@192.168.6.2's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

debian@beaglebone:~$ sudo passwd root
[sudo] password for debian:
New password:
Retype new password:
passwd: password updated successfully

debian@beaglebone:~$ passwd
Changing password for debian.
Current password:
New password:
Retype new password:
passwd: password updated successfully
connect to beaglebone as debian/temppwd

For /etc/motd and /etc/issue, here are mine :

Welcome to idril !
/etc/motd
Debian GNU/Linux 10 \n \l

BeagleBoard.org Debian Buster Console Image 2020-08-31
/etc/issue
Debian GNU/Linux 10

BeagleBoard.org Debian Buster Console Image 2020-08-31
/etc/issue.net

Note : We could have changed the password before flashing the board, by I prefer to keep the SD card with an easy way to connect to, if case I need it.

DONE Networking

Note : There are not so many editors available by default : vi, vim.tiny, nano, nano-tiny, and obviously sed and cat > for non-interactive edition.

Until now, we did boot with USB networking. We will now setup RJ45 connectivity, so that we don't need the cables around the desktop anymore :)

We want the Beaglebone to have a static IP, and do not use any information from DHCP. Please ensure the chosen address is not in a range managed by your dhcp server.

The data I will use:

Hostname idril
IP address 192.168.0.120
Network 192.168.0.0/24
Netmask 255.255.255.0
Router 192.168.0.1
DNS servers 8.8.8.8 and 8.8.4.4

First login to the beaglebone as we did previously, with user debian : ssh debian@192.168.7.2 or ssh debian@192.168.6.2.

By default, network is managed by connman. I don't like it, JASS (Just another Systemd Syndrome - une usine à gaz in french). More: It is very difficult to configure an interface which is not yet known by connman. It happens we are now connected via USB, so ETH0 is not (yet) managed by connman. There are options, but I don't see the difference with a good "old/working/standard" /etc/network/interfaces method.

First, let us set basic information :

DONE /etc/hostname and /etc/hosts files

Change the contents of /etc/hostname with your chosen hostname :

idril
new /etc/hostname

Add the folliwing lines in /etc/hosts with your chosen hostname and IP address.

# local network address
192.168.0.120	idril
new lines in /etc/hosts

DONE connman-free method

Note : Here, we could also totally uninstall connman.

ask connman to forget about eth0

First, we ask connman not to manage eth0. Edit /etc/connman/main.conf and add eth0 on NetworkInterfaceBlacklist line :

NetworkInterfaceBlacklist=SoftAp0,usb0,usb1,eth0
blacklist eth0 in /etc/connman/main.conf

configure network interface

In /etc/network/interface, we add the following section :

# eth0 interface, not managed by connman
auto eth0
iface eth0 inet static
    address 192.168.0.120
    netmask 255.255.255.0
    gateway 192.168.0.1
new lines in /etc/hosts

configure DNS

By default, connman (again!) tries to handle DNS. It is likely /etc/resolv.conf is a symbolic link to some connman file (/var/run/connman/resolv.conf).

You need to remove /etc/resolv.conf and create a new one with your own name servers :

# DNS manual configuration
nameserver 8.8.8.8
nameserver 8.8.4.4
new /etc/resolv.conf

DONE connman method

CANCELED knowing connman eth0 naming

Will not use it, even if simpler and normal connman usage.

DONE without knowing eth0 connman name

Here, we create a kind of provisioning configuration, as we don't know yet how connman is going to handle eth0 (/var/lib/connman), eth0 being non-existent, as unplugged.

So we create a generic configuration in /var/lib/connman/idril.config. The filename must end with ".config".

[service_eth0]
Type = ethernet
IPv4 = 192.168.0.120/255.255.255.0/192.168.0.1
IPv6 = off
Nameservers = 8.8.8.8,8.8.4.4
connman: /var/lib/connman/idril.config

but the simplest is to use it… Here we can either disable (or uninstall) connman, either configure static IP within connman, as explained here :

First, we need to know which interface is known by connman:

debian@beaglebone:~$ echo idril | sudo tee /etc/hostname
debian@beaglebone:~$ sudo cp -p /etc/hosts{,.sav}
debian@beaglebone:~$ echo -e "192.168.0.120\tidril\t\t# localhost" | sudo tee -a /etc/hosts
contents of /etc/hostname
debian@beaglebone:~$ echo idril | sudo tee /etc/hostname
debian@beaglebone:~$ sudo cp -p /etc/hosts{,.sav}
debian@beaglebone:~$ echo -e "192.168.0.120\tidril\t\t# localhost" | sudo tee -a /etc/hosts
line to add in /etc/hosts
debian@beaglebone:~$ echo idril | sudo tee /etc/hostname
debian@beaglebone:~$ sudo cp -p /etc/hosts{,.sav}
debian@beaglebone:~$ echo -e "192.168.0.120\tidril\t\t# localhost" | sudo tee -a /etc/hosts

Then we add information for eth0 in /etc/network/interfaces:

debian@beaglebone:~$ sudo cp -p /etc/network/interfaces{,.sav}
debian@beaglebone:~$ cat << _EOF | sudo tee -a /etc/network/interfaces
auto eth0
iface eth0 inet static
    address 192.168.0.120
    netmask 255.255.255.0
    gateway 192.168.0.1
_EOF_
/etc/network/interfaces

By default connman is installed. I don't like it, JASS (Just another Systemd Syndrome), but the simplest is to use it… Here we can either disable (or uninstall) connman, either configure static IP within connman, as explained here :

First, we need to know which interface is known by connman:

$ connmanctl services
,*AO Wired                ethernet_1cba8cf070a7_cable

The network interface is ethernet_1cba8cf070a7_cable. We configure it with :

$ sudo connmanctl config ethernet_1cba8cf070a7_cable --ipv4 manual 192.168.0.120 255.255.255.0 192.168.0.1 --nameservers 8.8.8.8 8.8.4.4
$ sudo connmanctl --ipv6 off

WORKING access the beaglebone via its ethernet interface

We don't need the USB connection anymore, so we just plug the Beaglebone Black on a RJ45 hub/switch, where it will physically stay.

After adding idril address in desktop /etc/hosts (or local naming service if any):

192.168.0.120	idril              # neaglebone Black server
new line in /etc/hosts on desktop

Then we just login to it as following:

$ ssh debian@idril
Debian GNU/Linux 10

BeagleBoard.org Debian Buster Console Image 2020-08-31

Support: https://bbb.io/debian

default username:password is [debian:temppwd]

debian@idril's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Oct 27 00:21:12 2020 from 192.168.0.100
debian@idril:~$
access the BBB via its final IP address

ONGOING users

My purpose here is: to create a first user ("br", for me). I prefer to have an UID of 1000 so that there is no file permissions issues (or ID translation setup) when sharing my files between machines. By looking in /etc/passwd and /etc/group, it appears the debian user uses 1000 as UID and GID. I could either rename debian user/group in those files, but it does not sound very clean. Instead, I will change these IDs to 1100, and change debian home directory ownership.

change "debian" user UID/GID

We just need to replace 1000 with 1100 in /etc/passwd and /etc/group

with UID 1000
From now on, we don't need the USB link anymore. You can just plug the Beaglebone Black on a RJ45 hub/switch.
Given you add ~idril~ in desktop ~/etc/hosts~ file,

- change debian uid/gid and home ownership
- create 1st mainuser: adduser "user"
- check/change uid/gid/ownership

* WORKING system default locale/timezone and RTC

You can view current time/date configuration with ~timedatectl status~ command. The output will look like {{{input-file}}}:

#+name: zobi
#+begin_src example -n
               Local time: Fri 2020-10-02 11:10:08 CEST
           Universal time: Fri 2020-10-02 09:10:08 UTC
                 RTC time: Fri 2020-10-02 09:10:08
                Time zone: Europe/Paris (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
new line in /etc/hosts on desktop

Important are lines 4, 5, 6, 7. Only the fourth one is not configured. You can check check ntp(1)

$ sudo timedatectl set-timezone Europe/Paris
	(or: sudo ln -s /usr/share/zoneinfo/Europe/London /etc/localtime)

CANCELED Remove unused packages

As I will use the Beaglebone as a server, I don't need anything related to node.js, cloud9, and other funny stuff installed by default

$ sudo apt-get -f purge c9-core-installer
$ sudo apt-get -f purge nodejs
$ sudo apt-get purge bb-node-red-installer libnode-dev:armhf libnode64:armhf nodejs-doc
$ sudo apt-get purge alsa-utils bluealsa

$ sudo apt-get autoremove
$ sudo apt-get clean

Remove nginx, install apache.

$ sudo apt-get purge nginx nginx-common nginx-full
$ sudo apt-get install apache2