Raspberry Pi : Linux
System Architecture
The Raspberry Pi is an ARM-based device and therefore needs binaries compiled for this architecture.- ARMv6 (BCM2835): Raspberry Pi Model A, A+, B, B+, Zero, Zero W
- Architecture: ARMv6
- Processor: Broadcom BCM2835 700MHz
- RAM: 512MB
- SD:Full SD
- USB:2
- Ethernet:10/100
- ARMv7 (BCM2836): Raspberry Pi 2 (based on Model B+) The Raspberry Pi 2 is the successor to the Raspberry Pi. It builds upon the original model B+ upgrading to 1 GB of RAM, and replacing the aged ARMv6 single-core with an ARMv7 Cortex-A7 quad-core.
- Architecture: ARMv7 Cortex-A7
- Processor: Broadcom BCM2836 900MHz
- RAM: 1GB
- SD: Micro SD
- USB: 4
- Ethernet: 10/100
- ARMv8 (BCM2837): Raspberry Pi 3 The Raspberry Pi 3 is the successor to the Raspberry Pi 2. It builds upon the Pi 2 by upgrading the ARM cores to Cortex-A53 and adding an onboard single-band 2.4GHz-only wireless chipset.
- Architecture: ARMv8 Cortex-A53
- Processor: Broadcom BCM2837 1.2GHz
- RAM: 1GB
- SD: Micro SD
- USB: 4
- Ethernet: 10/100
- Wireless: B/G/N, Bluetooth
Linux Kernel
The Raspberry Pi kernel is stored in GitHub and can be viewed at github.com/raspberrypi/linux
Updating your kernel
If you use the standard Raspbian update/upgrade process,
sudo apt update sudo apt full-upgradethis will automatically update the kernel to the latest stable version.
Building a new kernel
Local building
- install Git and the build dependencies
sudo apt install git bc bison flex libssl-dev make sudo apt install libssl-dev
git clone --depth=1 https://github.com/raspberrypi/linux--depth=1 will download the current active branch and ignore the history of all branches.
- Raspberry Pi 1, Pi Zero, Pi Zero W, and Compute Module
cd linux KERNEL=kernel make bcmrpi_defconfig
cd linux KERNEL=kernel7 make bcm2709_defconfig
cd linux KERNEL=kernel7l make bcm2711_defconfig
CONFIG_LOCALVERSION="-v7l-MY_CUSTOM_KERNEL"You can change it while configure the kernel manually. It is located in "General setup" => "Local version - append to kernel release".
make -j4 zImage modules dtbs sudo make modules_install sudo cp arch/arm/boot/dts/*.dtb /boot/ sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/ sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/ sudo cp arch/arm/boot/zImage /boot/$KERNEL.img
Cross-compiling
- Install toolchain
git clone https://github.com/raspberrypi/tools ~/tools echo PATH=\$PATH:~/tools/arm-bcm2708/arm-linux-gnueabihf/bin >> ~/.bashrc source ~/.bashrcIf you are using a 32-bit Linux system, then you may need to install an additional set of libraries:
sudo apt install zlib1g-dev:amd64
git clone --depth=1 https://github.com/raspberrypi/linux
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
- Pi 1, Pi Zero, Pi Zero W, or Compute Module
cd linux KERNEL=kernel make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig
cd linux KERNEL=kernel7 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
cd linux KERNEL=kernel7l make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfigThen, build:
make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
- mount partitions
mkdir mnt mkdir mnt/fat32 mkdir mnt/ext4 sudo mount /dev/sdb6 mnt/fat32 sudo mount /dev/sdb7 mnt/ext4
sudo env PATH=$PATH make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=mnt/ext4 modules_install
sudo cp mnt/fat32/$KERNEL.img mnt/fat32/$KERNEL-backup.img sudo cp arch/arm/boot/zImage mnt/fat32/$KERNEL.img sudo cp arch/arm/boot/dts/*.dtb mnt/fat32/ sudo cp arch/arm/boot/dts/overlays/*.dtb* mnt/fat32/overlays/ sudo cp arch/arm/boot/dts/overlays/README mnt/fat32/overlays/ sudo umount mnt/fat32 sudo umount mnt/ext4
Another option is to copy the kernel into the same place, but with a different filename, you can then edit the config.txt file to select the kernel that the Pi will boot into:
kernel=kernel-myconfig.img
Getting the kernel headers
These provide the various function and structure definitions required when compiling code that interfaces with the kernel.
sudo apt install raspberrypi-kernel-headers
Installing Linux Distribution for Raspberry Pi
Installing Arch Linux ARM
Raspberry Pi 2
- Start fdisk to partition the SD card:
- At the fdisk prompt, delete old partitions and create a new one:
- Type o. This will clear out any partitions on the drive.
- Type p to list partitions. There should be no partitions left.
- Type n, then p for primary, 1 for the first partition on the drive, press ENTER to accept the default first sector, then type +100M for the last sector.
- Type t, then c to set the first partition to type W95 FAT32 (LBA).
- Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.
- Write the partition table and exit by typing w.
- Create and mount the FAT filesystem:
- Create and mount the ext4 filesystem:
- Download and extract the root filesystem (as root, not via sudo):
- Move boot files to the first partition:
- Unmount the two partitions:
- Insert the SD card into the Raspberry Pi, connect ethernet, and apply 5V power.
- Use the serial console or SSH to the IP address given to the board by your router.
- Login as the default user alarm with the password alarm.
- The default root password is root.
fdisk /dev/sdX
mkfs.vfat /dev/sdX1 mkdir boot mount /dev/sdX1 boot
mkfs.ext4
/dev/sdX2
mkdir root
mount /dev/sdX2 root
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C root
sync
mv root/boot/* boot
umount boot root
DEBIAN + PIXEL: RASPBERRY PI OS FOR MAC AND PC
The Raspberry Pi Foundation announced a new operating system for Mac and PC computers. It’s called Debian + PIXEL.
The new software enables you to install a Raspberry Pi-like OS on your computer. It boots from a DVD, USB Thumb drive or inside a virtual environment.
With Debian + PIXEL you carry on using your regular operating system. But can boot into the coding environment when you want to experiment with coding, Linux or software development.
The OS has most of the software that comes with Raspbian. Like the Raspberry Pi, it’s ideal for makers and coders.
Only now, you don’t even need to buy Raspberry Pi hardware to discover the learning environment. It’s also going to make life easier for code clubs and teachers.
It’s a “live” distribution so can be run from a DVD or USB stick without needing to change your current OS. This is great for using the environment without the headache of dual booting or dedicating the device to PIXEL permanently.
Download Image
Click here to download a copy of Debian + PIXELThe image is a standard ISO file so can be written to a DVD or USB drive using your favourite utility.
Burn Image
Etcher
To write SD/USB images I use Etcher using this guide : Write SD Card Images Using Etcher On Windows, Linux & Mac.Etcher can be downloaded from http://www.etcher.io/ and is available for Windows, Linux and Mac.
You browse to the image file and select a drive. The list of drives provides a nice set of information so it should be clearer exactly what physical device you are selecting.
When selecting image files you can select IMG and ISO files as expected but also Zip files. This allows you to burn Raspberry Pi images without even extracting them from the source Zip files.
Depending on the state of the SD card you are using you may need to format it first. On Windows I always use the official SD Formatter application.
Rawrite32
The Rawrite32 application has a simple interface.Make sure that you have inserted a blank USB drive into your computer.
Click the "open" button and navigate to the downloads folder and find the Fedora image that you downloaded earlier on.
Click on the target dropdown list and choose the drive letter for your USB drive.
Boot
The exact process to boot the image will depend on your hardware.
You need modify the Bios settings to allow the system to boot from a USB drive.
If your machine has a standard BIOS (i.e. not UEFI, although technically speaking UEFI is becoming more standard) then all you need to do to boot into a live version of Fedora is to reboot your computer with the USB drive still plugged in.
Virtual Machines
It is also possible to run this ISO image as a Virtual Machine.
I can load this iso image within Oracle’s VirtualBox on my MacbookAir .
Unfortunately any changes you make or save will be lost when you next reboot, so next we need to setup persistence to allow us to configure the operating system and save any files.
My workaround is to overlap possible changed folders:
- Create disk partitions
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 22527 20480 10M 83 Linux
/dev/sda2 22528 227327 204800 100M 83 Linux
/dev/sda3 227328 432127 204800 100M 83 Linux
/dev/sda4 432128 50331647 49899520 23.8G 5 Extended
/dev/sda5 434176 17211391 16777216 8G 83 Linux
/dev/sda6 17213440 48670719 31457280 15G 83 Linux
/dev/sda7 48672768 49287167 614400 300M 83 Linux
/dev/sda8 49289216 50331647 1042432 509M 83 Linux
/dev/sda1 8887 3038 5133 38% /etc
/dev/sda2 95054 10571 77315 13% /sbin
/dev/sda3 95054 11821 76065 14% /bin
/dev/sda5 8125880 4666924 3023144 61% /usr
/dev/sda7 289293 99204 170633 37% /opt
/dev/sda8 496548 74144 392248 16% /home
Adding Persistence
As the virtual machine boots from a DVD image it is unable to save any changes to the disk. To overcome this limitation we can use virtual hard disk drive that we created earlier which will be used to save any data or changes to the operating system. These files will then be made available when the virtual machine starts.
During the setup you will have created the virtual hard disk, but the disk will need preparing and formatting before it can be used. First create a disk partition using cfdisk. Start a terminal and after checking you are on the correct system (the prompt will say pi@raspberrypi) enter:
sudo cfdisk /dev/sda
Accept the first option of using the disk as a gpt disk. Now check the details are as expected - in particular that it does not show any partitions that are in use and that it matches the size of the disk created previously.
Choose "New" to create a new partition, accept the default of using the full disk drive as a single partition.
As you can see the file system type has defaulted to Linux, so use the right arrow to select "Write". Type yes to write the changes and then choose Quit.
The new partition is called sda1. It can now be formatted with the ext4 file system which is commonly used by Linux. This is done by running:
sudo mkfs.ext4 /dev/sda1
Now give the disk the name "persistence" using the elabel command.
sudo e2label /dev/sda1 persistence
You will now need to add a persistence.conf file to the disk. Enter the following commands to mount the disk on a temporary mount point:
sudo mkdir /mnt/temp
sudo mount /dev/sda1 /mnt/temp
Add the file using:
sudo leafpad /mnt/temp/persistence.conf
Add the following on the top line:
/ union
Also create a blank second line (as I found that it did not work without it). Save the file and quit from the editor.Now reboot the virtual machine and persistence will be enabled.
Run Raspberry Pi Desktop on a virtual machine
Raspberry Pi Desktop
Debian with Raspberry Pi Desktop is the Foundation’s operating system for PC and Mac. You can create a live disc, run it in a virtual machine, or even install it on your computer.
Download "Debian Buster with Raspberry Pi Desktop"
Run Raspberry Pi on VirtualBox
Create the virtual machine
Install
This will help you to install the system on the created Virtual Box drive.
Run with persistent storage
After run with persistent storage, the storage and partitions are:
Unfortunately any changes you make or save will be lost when you next reboot, so we need to setup persistence to allow us to configure the operating system and save any files.
We need to create partitions to replace the folders which may be changed after the software installation or executions:
bin /dev/sda1 100M
etc /dev/sda2 100M
sbin /dev/sda5 1G
opt /dev/sda6 1G
usr /dev/sda7 8G
home /dev/sda9 5.6G
留言