Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

10/29/2022

ISA LAB, NATIONAL SCHOOL OF APPLIED SCIENCES ENSA, IBN TOFAIL UNIVERSITY UIT, KENITRA ISA LAB, NATIONAL SCHOOL OF APPLIED SCIENCES ENSA, IBN TOFAIL UNIVERSITY UIT, KENITRA
UNIVERSITY SEASON 2021-2022 UNIVERSITY SEASON 2021-2022

INTRODUCTION TO INTERNET OF THINGS IOT


APPLYING IA & CYBERSECURITY BLOCKCHAIN TO IOT
CONNECTED AUTOMOTIVE EMBEDDED SYSTEMS INTRODUCTION TO INTERNET OF THINGS IOT
INDUSTRIAL INTERNET OF THINGS/ IDUSTRY 4.0 APPLYING IA & CYBERSECURITY BLOCKCHAIN TO IOT
AUTONYMOUS DRIVING VEHICLE CONNECTED AUTOMOTIVE EMBEDDED SYSTEMS
Presented by Pr A. BAJIT INDUSTRIAL INTERNET OF THINGS/ IDUSTRY 4.0
AUTONYMOUS DRIVING VEHICLE
MAIN TOPICS OF THE COURSE Presented by Pr A. BAJIT
INTRODUCTION TO EMBEDDING LINUX KERNEL
SECTION I. EMULATING RASPBIAN OS ON QEMU IN ARM PROCESSORS
FIRST PART. EMBEDDED SYSTEMS SECOND PART
 INTRODUCTION TO LINUX KERNEL;  CONFIGURING RASPBAIN AND MOSQUITTO BROKER IN
AGENDA
 CONFIGURING LINUX KERNEL; THE RASPBERRY PI3; CHAPTER I. QEMU EMULATION
 EMULATING THE RASPBERRY PI OS  CONFIGURING MQTT CLIENTS;  Raspberry Pi OS Emulation
 INTRODUCTION TO IOT/MQTT PROTOCOL/CLOUD COMPUTING &  PROGRAMMING ESP8266 MCU NODE & ESP8266 ESP-01;
CLOUD STORAGE;  APPLICATION IOT PLATFORMS.  Starting Emulation
 INTRODUCTION TO PRTG NETWORK MONITOR AND DASHBOARD.
CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy
 Platform Developement
Pr. Abderrahim BAJIT
 Associate Professor Researcher in Embedded Electronic Systems
 Professor of Embedded Operating Systems Engineering, On-Board Computing Systems,
RealTime Embedded Systems Engineering, Automotive/Avionic Embedded Systems,
Industrial Intelligent Sensor Networks IOT.
 Department of Electriical & Automotive Mechatronic Engineering –GMA-
 Applied Sciences National School -ENSA- of Kénitra Morocco/International University
of Rabat UIR-Rabat, Natinal Institute Of Communication Technologies INPT Rabat.
Pr. ABDERRAHIM BAJIT INTRODUCTIONTOAUTOMOTIVEENGINEERING Pr. ABDERRAHIM BAJIT 2 INTRODUCTIONTOAUTOMOTIVEENGINEERING

AGENDA
Introduction EMBEDDED KERNEL. Emulating the RASPBERRY Pi
Introduction OS ON QEMU

I. INTRODUCTION TO QEMU/LIBVIR CHAPTER I. QEMU EMULATION


I. Introducing QEMU/LIBVIR MÉTHODOLOGIE D’EMBARQUEMENT D’UN SYSTÈME  Raspberry Pi OS Emulation
D’EXPLOITATION  Starting Emulation
Structure générale des systèmes d’exploitation (Cas Linux) ;
Mise en place d'un système Linux embarqué CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy
SYSTEMES EMBARQUES
Plateforme de développement Embarquée  Platform Developement
Développement d’applications pour systèmes embarqués

II. Emulating RASPBERRY Pi OS On QEMU II. EMULATING RASPBERRY PI OS ON QEMU


Versions du Noyau  Required Tools
EMU is a generic and open source machine emulator and virtualizer.
Configuration du Noyau et Modification de ses Paramètres: Au QEMU can be used in several different ways. The most common is for “system emulation”, where it provides a virtual model of an entire machine (CPU,
cours et après démarrage du système memory and emulated devices) to run a guest OS. In this mode the CPU may be fully emulated, or it may work with a hypervisor such as KVM, Xen, Hax
Construction et Mise a jour d’un Noyau or Hypervisor.Framework to allow the guest to run directly on the host CPU.
Gestion des Modules du Noyau
The second supported way to use QEMU is “user mode emulation”, where QEMU can launch processes compiled for one CPU on
another CPU. In this mode the CPU is always emulated.
III. Virtualizing A Network On LIBVIRT III. VIERTUALIZING A NETWORK ON LIBVIRT
Etude de cas d’un système LINUX DEBIAN QEMU also provides a number of standalone commandline utilities, such as the qemu-img disk image utility that allows you to create, convert and
Téléchargement du code source, configuration et Installation du noyau modify disk images.
Personnalisation des paramètres du noyau
Gestion des Modules du Noyau
Conclusion
Conclusion
Pr. ABDERRAHIM BAJIT 3 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT 4 INTRODUCTIONTOLINUXOPERATINGSYSTEM

1
10/29/2022

EMBEDDED KERNEL. Emulating the RASPBERRY Pi EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU OS ON QEMU
CHAPTER I. QEMU EMULATION CHAPTER I. QEMU EMULATION
 Raspberry Pi OS Emulation  Raspberry Pi OS Emulation
 Starting Emulation  Starting Emulation

CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy  LibVirt Librariy
 Platform Developement  Platform Developement

 PLATFORM SPECIFICATIONS  PLATFORM SPECIFICATIONS


Let’s start setting up a Lab VM. We will use Ubuntu and emulate our desired ARM versions inside of it. Inside your Ubuntu VM, create a new folder:

First, get the latest Debian/Ubuntu version and run it in a VM: https://www.ubuntu.com/download/desktop $ mkdir ~/qemu_vms/

For the QEMU emulation you will need the following: Download and place the Raspbian Jessie image to ~/qemu_vms/.
 A Raspbian Image: http://downloads.raspberrypi.org/raspbian/images/raspbian-2017-04-10/ (other versions
might work, but Jessie is recommended) Download and place the qemu-kernel to ~/qemu_vms/.
 Latest qemu kernel: https://github.com/dhruvvyas90/qemu-rpi-kernel
$ sudo apt-get install qemu-system
$ unzip <image-file>.zip
$ fdisk -l <image-file>

Pr. ABDERRAHIM BAJIT 5 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT 6 INTRODUCTIONTOLINUXOPERATINGSYSTEM

EMBEDDED KERNEL. Emulating the RASPBERRY Pi EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU OS ON QEMU
CHAPTER I. QEMU EMULATION CHAPTER I. QEMU EMULATION
 Raspberry Pi OS Emulation  Raspberry Pi OS Emulation
 Starting Emulation  Starting Emulation

CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy  LibVirt Librariy
 Platform Developement  Platform Developement

 File Componnents  Mounting the .img2 file system and Configuring the file ld.so.preload
We apply the following command to experience the image file components : You see that the filesystem (.img2) starts at sector 137216. Now take that value and multiply it by 512, in this case it’s 512 * 137216 =
$ fdisk -lu <image-file> 70254592 bytes. Use this value as an offset in the following command to mount the image system in the folder /mnt/raspbian:
Doing that, you should see something like this:
Disk 2017-03-02-raspbian-jessie.img: 4.1 GiB, 4393533440 bytes, 8581120 sectors $ sudo mkdir /mnt/raspbian
Units: sectors of 1 * 512 = 512 bytes $ sudo mount -v -o offset=70254592 -t ext4 ~/qemu_vms/<your-img-file.img> /mnt/raspbian
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes $ sudo nano /mnt/raspbian/etc/ld.so.preload
Disklabel type: dos
Disk identifier: 0x432b3940 Comment out every entry in that file with ‘#’, save and exit with Ctrl-x » Y.

Device Boot Start End Sectors Size Id Type


2017-03-02-raspbian-jessie.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
2017-03-02-raspbian-jessie.img2 137216 8581119 8443904 4G 83 Linux

Pr. ABDERRAHIM BAJIT 7 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT 8 INTRODUCTIONTOLINUXOPERATINGSYSTEM

2
10/29/2022

EMBEDDED KERNEL. Emulating the RASPBERRY Pi EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU OS ON QEMU
CHAPTER I. QEMU EMULATION CHAPTER I. QEMU EMULATION
 Raspberry Pi OS Emulation  Raspberry Pi OS Emulation
 Starting Emulation  Starting Emulation

CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy  LibVirt Librariy
 Platform Developement  Platform Developement

 Unmounting the image file system  Starting the RASPBERRY PI OS Emulation on QEMU
Then open the filesystem configuration file, fstab using the following commands. Now you can emulate it on Qemu in a ARM based processors by using the following command and managing the qemu kernel, cpu, memory size,
$ sudo nano /mnt/raspbian/etc/fstab raspberry pi os image,:

IF you see anything with mmcblk0 in fstab, then: $ qemu-system-arm -kernel ~/qemu_vms/<your-kernel-qemu>
-cpu arm1176
Replace the first entry containing /dev/mmcblk0p1 with /dev/sda1 -m 256
Replace the second entry containing /dev/mmcblk0p2 with /dev/sda2, save and exit -M versatilepb
-serial stdio
Then unmount the image from its mount folder using the following commands.
-append "root=/dev/sda2 rootfstype=ext4 rw"
$ cd ~
-hda ~/qemu_vms/<your-jessie-image.img>
$ sudo umount /mnt/raspbian
-redir tcp:5022::22
-no-reboot

Pr. ABDERRAHIM BAJIT 9 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT 10 INTRODUCTIONTOLINUXOPERATINGSYSTEM

EMBEDDED KERNEL. Emulating the RASPBERRY Pi EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU OS ON QEMU
CHAPTER I. QEMU EMULATION CHAPTER I. QEMU EMULATION
 Raspberry Pi OS Emulation  Raspberry Pi OS Emulation
 Starting Emulation  Starting Emulation

CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy  LibVirt Librariy
 Platform Developement  Platform Developement

 Exploiting the RASPNERRY PI OS  Exploiting the RASPNERRY PI OS


If you see GUI of the Raspbian OS, you need to get into the terminal. Use Win key to get the menu, then navigate with arrow keys until you find Terminal Now you can SSH into it from your host system with (default password – raspberry):
application as shown below.
$ ssh pi@127.0.0.1 -p 5022

For a more advanced network setup see the “Advanced Networking” paragraph below.

Pr. ABDERRAHIM BAJIT 11 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT 12 INTRODUCTIONTOLINUXOPERATINGSYSTEM

3
10/29/2022

ISA LAB, NATIONAL SCHOOL OF APPLIED SCIENCES ENSA, IBN TOFAIL UNIVERSITY UIT, KENITRA
UNIVERSITY SEASON 2021-2022
EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU
INTRODUCTION TO INTERNET OF THINGS IOT
APPLYING IA & CYBERSECURITY BLOCKCHAIN TO IOT CHAPTER I. QEMU EMULATION
CONNECTED AUTOMOTIVE EMBEDDED SYSTEMS  Raspberry Pi OS Emulation
INDUSTRIAL INTERNET OF THINGS/ IDUSTRY 4.0  Starting Emulation
AUTONYMOUS DRIVING VEHICLE

Presented by Pr A. BAJIT CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION


 LibVirt Librariy
 Platform Developement
SECTION II. TROUBLESHOOTING and RESIZING the RASPBERRY Pi OS ARM
AGENDA
CHAPTER I. QEMU EMULATION  Troubleshooting the emulation
 Raspberry Pi OS Emulation If SSH doesn’t start in your emulator at startup by default, you can change that inside your Pi terminal with:
$ sudo update-rc.d ssh enable
 Starting Emulation
If your emulated Pi starts the GUI and you want to make it start in console mode at startup, use the following command inside your Pi terminal:
CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION $ sudo raspi-config
 LibVirt Librariy >Select 3 – Boot Options
>Select B1 – Desktop / CLI
 Platform Developement >Select B2 – Console Autologin

If your mouse doesn’t move in the emulated Pi, click <Windows>, arrow down to Accessories, arrow right, arrow down to Terminal, enter.

Pr. ABDERRAHIM BAJIT 13 INTRODUCTIONTOAUTOMOTIVEENGINEERING Pr. ABDERRAHIM BAJIT 14 INTRODUCTIONTOLINUXOPERATINGSYSTEM

EMBEDDED KERNEL. Emulating the RASPBERRY Pi EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU OS ON QEMU
CHAPTER I. QEMU EMULATION CHAPTER I. QEMU EMULATION
 Raspberry Pi OS Emulation  Raspberry Pi OS Emulation
 Starting Emulation  Starting Emulation

CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy  LibVirt Librariy
 Platform Developement  Platform Developement

 Troubleshooting the emulation  Troubleshooting the emulation


Once you are done with the setup, you are left with a total of 3,9GB on your image, which is full. To enlarge your Raspbian image, follow these steps on Now start the original raspbian with enlarged image as second hard drive:
your Ubuntu machine: $ qemu-system-arm -kernel ~/qemu_vms/<your-kernel-qemu>
-cpu arm1176
 Create a copy of your existing image:
-m 256
$ cp <your-raspbian-jessie>.img raspbian.img -M versatilepb
 Run this command to resize your copy: -serial stdio
$ qemu-img resize raspbian.img +6G -append "root=/dev/sda2 rootfstype=ext4 rw"
-hda ~/qemu_vms/<your-jessie-image.img>
 Now start the original raspbian with enlarged image as second hard drive: -redir tcp:5022::22
$ sudo qemu-system-arm -kernel ~/qemu_vms/<kernel-qemu> -cpu arm1176 -m 256 -M versatilepb -serial stdio -append -no-reboot
"root=/dev/sda2 rootfstype=ext4 rw" -hda ~/qemu_vms/<your-original-raspbian-jessie>.img -redir tcp:5022::22 -no-reboot -hdb -hdb raspbian.img
raspbian.img

Pr. ABDERRAHIM BAJIT 15 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT 16 INTRODUCTIONTOLINUXOPERATINGSYSTEM

4
10/29/2022

EMBEDDED KERNEL. Emulating the RASPBERRY Pi EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU OS ON QEMU
CHAPTER I. QEMU EMULATION CHAPTER I. QEMU EMULATION
 Raspberry Pi OS Emulation  Raspberry Pi OS Emulation
 Starting Emulation  Starting Emulation

CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION
 LibVirt Librariy  LibVirt Librariy
 Platform Developement  Platform Developement

 Troubleshooting the emulation  Troubleshooting the emulation


Once you are done with the setup, you are left with a total of 3,9GB on your image, which is full. To enlarge your Raspbian image, follow these steps on You can now start your QEMU VM with this command:
your Ubuntu machine: $ sudo qemu-system-arm -kernel ~/qemu_vms/<kernel-qemu>
-cpu arm1176
 Login and run:
-m 256 -M versatilepb
$ sudo cfdisk /dev/sdb
-serial stdio
 Delete the second partition (sdb2) and create a New partition with all available space. Once new partition is creates, use Write to commit the changes. -append "root=/dev/sda2 rootfstype=ext4 rw"
Then Quit the cfdisk. Resize and check the old partition and shutdown. -hda ~/qemu_vms/rasbian.img
$ sudo resize2fs /dev/sdb2 -net nic -net tap,ifname=tap0,script=no,downscript=no
$ sudo fsck -f /dev/sdb2 -no-reboot
$ sudo halt
When the QEMU VM starts, you need to assign an IP to it’s eth0 interface with the following command:
 Now you can start QEMU with your enlarged image: $ sudo ifconfig eth0 172.16.0.2/24
$ sudo qemu-system-arm -kernel ~/qemu_vms/<kernel-qemu> -cpu arm1176 -m 256 -M versatilepb -serial stdio -append
If everything went well, you should be able to reach open ports on the GUEST (Raspbian) from your HOST (Ubuntu) system. You can test this with a
Pr. ABDERRAHIM BAJIT 17 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT netcat (nc) tool (see an example below). 18 INTRODUCTIONTOLINUXOPERATINGSYSTEM

ISA LAB, NATIONAL SCHOOL OF APPLIED SCIENCES ENSA, IBN TOFAIL UNIVERSITY UIT, KENITRA
UNIVERSITY SEASON 2021-2022
EMBEDDED KERNEL. Emulating the RASPBERRY Pi
OS ON QEMU
INTRODUCTION TO INTERNET OF THINGS IOT
CHAPTER I. QEMU EMULATION APPLYING IA & CYBERSECURITY BLOCKCHAIN TO IOT
 Raspberry Pi OS Emulation CONNECTED AUTOMOTIVE EMBEDDED SYSTEMS
 Starting Emulation INDUSTRIAL INTERNET OF THINGS/ IDUSTRY 4.0
AUTONYMOUS DRIVING VEHICLE
CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION Presented by Pr A. BAJIT
 LibVirt Librariy
 Platform Developement
SECTION III. VIRTUALIZING NETWORK USING RASPBERRY Pi OS LIBVIRT
AGENDA
 Troubleshooting the emulation CHAPTER I. QEMU EMULATION
If everything went well, you should be able to reach open ports on the GUEST (Raspbian) from your HOST (Ubuntu) system. You can test this with a  Raspberry Pi OS Emulation
netcat (nc) tool (see an example below).
 Starting Emulation

CHAPTER II. QEMU/LIBVIRT NETWORK VIRTULIZATION


 LibVirt Librariy
 Platform Developement

Pr. ABDERRAHIM BAJIT 19 INTRODUCTIONTOLINUXOPERATINGSYSTEM Pr. ABDERRAHIM BAJIT 13 INTRODUCTIONTOAUTOMOTIVEENGINEERING

You might also like