注意:

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Difference between revisions of "User:Coffnix/Raspberry Pi 4"

From Funtoo
Jump to navigation Jump to search
(Adding doc changes for FL-10670 and fixing newlines for note admonitions)
 
(52 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Subpages|Advanced}}
== What you need ==
== What you need ==


# Raspberry PI 4
# Raspberry PI 4
# An existing Funtoo Linux install or Livecd (Livecd is a solid choice if you do not have funtoo installed on a hard drive)
# An existing Funtoo Linux install or Livecd (Livecd is a solid choice if you do not have funtoo installed on a hard drive)
# a 32GB or larger SD card
# a 32GB or larger microSD card, which will be {{c|/dev/mmcblk0}}, with partitions as {{c|/dev/mmcblk0p1}}, {{c|/dev/mmcblk0p2}}, etc.
 
Optional:
# A faster USB3 flash drive or external USB3 SSD drive to hold your root filesystem and swap to improve performance. If you use one, it will likely show up as {{c|/dev/sda}} when your Raspberry Pi boots, with partitions {{c|/dev/sda1}}, {{c|/dev/sda2}}, etc. You can use partition labels to make this easier to manage.


==Prepare your SD card==
==Prepare your SD card==
Target your drive as outlined in the official install. [[Install/Prepare_Disk]]


On the non-Raspberry Pi system, you will insert and prepare the microSD card. The card will likely show up as {{c|/dev/sdX}}, but when the Raspberry Pi 4 boots, the card will show up as {{c|/dev/mmcblk0}}.
Please note that the Raspberry Pi has a custom boot loader which uses a FAT32 partition, which will be the {{c|/boot}} partition just like a regular x86-64bit Funtoo
installation. This means we will simply make {{c|/boot}} FAT32 but use MBR. Without firmware changes, the {{c|/boot}} partition must reside on the microSD card, but the root and swap partitions can
reside on other disks.
Target your drive as outlined in the official install. [[Install/Prepare_Disk]]. Use the MBR method but make a FAT32 {{c|/boot}}:
*delete everything:
{{console|body=
{{console|body=
###i## cgdisk /dev/funtoo}}
###i## wipefs -a /dev/sdX
}}
 
Make a new MS-DOS disklabel. Add a new partition - this will be 128Mb for /boot
{{console|body=
###i## fdisk /dev/sdX
}}
{{console|body=
Command (m for help): ##i##n
Partition type
  p  primary (0 primary, 0 extended, 4 free)
  e  extended (container for logical partitions)
Select (default p): ##i##p
Partition number (1-4, default 1): 1
First sector (2048-15523839, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-15523839, default 15523839): +128M
}}


*delete everything:


*scroll down to the large chunk of free space:
Has created a new partition 1 of type 'Linux' and of size 128 MiB.
Add a 2G partition 2 for swap.
Put the remaining space in partition 3 for root.


Check with
{{console|body=
{{console|body=
Command: ##i##new ↵
Command (m for help): ##i##p
First sector: ##i##↵
Last sector: ##i##+256M ↵
Hex Code: ##i##EF02 ↵
Name: ##i##BOOT ↵
}}
}}


*scroll down to the large chunk of free space:
Using an 8G microSD card it should show
{{console|body=
Device        Boot    Start      End  Sectors  Size Id Type
/dev/sdX1    2048  264191  262144  128M 83 Linux
/dev/sdX2  264192  4458495  4194304    2G 83 Linux
/dev/sdX3  4458496 15523839 11065344  5.3G 83 Linux
}}


Set flags and partition types
Toggle the bootable flag on partition 1
{{console|body=
{{console|body=
Command: ##i##new ↵
Command (m for help): ##i##a
First sector: ##i##
Partition number (1-3, default 3): ##i##1
Last sector: ##i##↵
Hex Code: ##i## 8305 ↵
Name: ##i##FUNTOO ↵
}}
}}


The bootable flag on partition 1 is enabled now.
Mark partition 1 as FAT
{{console|body=
{{console|body=
                              Disk Drive: /dev/funtoo
Command (m for help): ##i##t
                            Size: 62333952, 29.7 GiB
Partition number (1-3, default 3): ##i##1
Partition type (type L to list all types): ##i##c


Part. #    Size        Partition Type            Partition Name
Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.
----------------------------------------------------------------
            1007.0 KiB  free space
  1        256.0 MiB  BIOS boot partition       BOOT
  2        29.5 GiB    Linux ARM64 root (/)     FUNTOO
}}
}}


{{note|The Pi checks the type of partition 1 in the partition table and will not boot if its 82}}
Mark partition 2 as swap
{{console|body=
{{console|body=
Command: ##i##write ↵
Command (m for help): ##i##t
Do you want to proceed? (Y/N): ##i##yes ↵
Partition number (1-3, default 3): ##i##2
Command: ##i##quit
Partition type (type L to list all types): ##i##82
 
Changed type of partition 'Linux swap / Solaris' to 'Linux swap / Solaris'.
}}
 
Check again.
{{console|body=
Device        Boot  Start      End  Sectors  Size Id Type
/dev/sdX1      *      2048  264191  262144  128M  c W95 FAT32 (LBA)
/dev/sdX2            264192  4458495  4194304    2G 82 Linux swap / Solaris
/dev/sdX3          4458496 15523839 11065344  5.3G 83 Linux
}}
 
Save the new partition table. Exit fdisk with either w or q
{{console|body=
w  write table to disk and exit
quit without saving changes
}}
}}


Line 54: Line 105:


{{console|body=
{{console|body=
###i## mkfs.vfat -F 32 /dev/funtoo1
###i## mkfs.vfat -F 32 /dev/sdX1
###i## fatlabel /dev/funtoo1 "BOOT"
###i## fatlabel /dev/sdX1 "BOOT"
###i## mkfs.ext4 /dev/funtoo2
###i## mkswap -L SWAP /dev/sdX2
###i## e2label /dev/funtoo2 "FUNTOO"
###i## mkfs.ext4 -F /dev/sdX3
###i## e2label /dev/sdX3 "FUNTOO"
}}
}}


Line 68: Line 120:
Mount your SD card:
Mount your SD card:
{{console|body=
{{console|body=
###i## mount /dev/funtoo2 /mnt/funtoo  
###i## mount /dev/sdX3 /mnt/funtoo  
###i## mkdir /mnt/funtoo/boot
###i## mkdir /mnt/funtoo/boot
###i## mount /dev/funtoo1 /mnt/funtoo/boot
###i## mount /dev/sdX1 /mnt/funtoo/boot
}}
}}


Line 88: Line 140:


===Pre-boot Configuration===
===Pre-boot Configuration===
*Edit your make.conf file to enable fchroot to compile:
{{console|body=
###i## nano /mnt/funtoo/etc/portage/make.conf
}}
{{file|name=/mnt/funtoo/etc/portage/make.conf|desk make.conf file|body=
FEATURES="-pid-sandbox"
}}
*Edit your fstab file so everything mounts correctly on boot:
*Edit your fstab file so everything mounts correctly on boot:
*Raspberry pi only supports partuuid and partlabel loading:
*Raspberry pi only supports partuuid and partlabel loading:
Line 105: Line 147:


{{file|name=/mnt/funtoo/etc/fstab|body=
{{file|name=/mnt/funtoo/etc/fstab|body=
LABEL=BOOT   /boot          vfat    defaults          0      2
LABEL=BOOT     /boot          vfat    noauto            0      2
LABEL=SWAP      none            swap    sw                0      0
LABEL=FUNTOO    /              ext4    defaults,noatime  0      1
LABEL=FUNTOO    /              ext4    defaults,noatime  0      1
tmpfs /var/tmp/portage tmpfs uid=portage,gid=portage,mode=775,noatime 0 0
}}
}}
{{Note|Rather than using the labels above, you can also simply use {{c|/dev/mmcblk0p1}}, {{c|/dev/mmcblk0p2}} and {{c|/dev/mmcblk0p3}} respectively.}}


==Chrooting into your new installation==
==Chrooting into your new installation==
===for a good time install [[Package:Fchroot]]===
 
If you are on an existing Funtoo system, you will need to {{c|emerge fchroot}}. If you are using our official LiveCD, {{c|fchroot}} is already available.


*Fchroot in:
*Fchroot in:
{{console|body=
{{console|body=
###i## emerge fchroot
###i## cd /mnt/funtoo
###i## cd /mnt/funtoo
###i## fchroot --cpu cortex-a72 . su --login
###i## fchroot --cpu cortex-a72 . su --login
###i## export PS1="FUNTOO $PS1"
###i## export PS1="FUNTOO $PS1"
%fchroot%
}}
}}


====set your pass====
=== Configure driver VC4 and screen resolution ===
* Create new user and set password:
 
Note that the Raspberry Pi 4 has two different video drivers. You have the option of using {{c|vc4-fkms-v3d}} or {{c|vc4-kms-v3d-pi4}}. Either way, you will want to make sure you are using HDMI port 1 on your device (on the Raspberry Pi 400, this is the one closest to the USB-C power connector) or you may not get any video. You should also see the "Setting Video Modes" section if you have a finicky monitor and find
you need to explicitly set a video mode to get the Raspberry Pi to select a display mode that your monitor accepts.
 
==== vc4-fkms-3d ====
 
{{console|body=
{{console|body=
###i## echo -e "root\nroot" {{!}} passwd root
%fchroot%##i## nano /boot/config.txt
###i## useradd funtoo && echo -e "funtoo\nfuntoo" {{!}} passwd  funtoo
###i## usermod -a -G wheel funtoo
###i## echo "funtoo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
}}
}}


use '''dtoverlay=vc4-fkms-v3d''':


=== Sync tree ===
{{file|name=/boot/config.txt|body=
{{console|body=
gpu_mem=256
###i## ego sync
disable_overscan=1
dtparam=audio=on
dtoverlay=vc4-fkms-v3d
max_framebuffers=2
arm_64bit=1
}}
}}


=== compile in ram ===
{{console|body=
###i## mkdir /var/tmp/portage
###i## chown portage:portage /var/tmp/portage
###i## mount /var/tmp/portage
}}


{{note|
On Raspberry PI 4 CM4 the above boot config does not enable the onboard USB.


=== Emerge necessary ebuilds ===
To ensure the USB ports are enabled when running RPi4 CM4's in headless mode AND providing the physical USB ports via a carrier board, simply instead use these two lines to the {{c|config.txt}}:
{{console|body=
{{file|name=/boot/config.txt|body=
###i## emerge raspberrypi-userland raspberrypi-firmware raspberrypi-image sys-firmware/raspberrypi-wifi-ucode
dtoverlay=dwc2
dr_mode=host
}}
}}
}}


==== vc4-kms-v3d-pi4 ====


{{console|body=
You can alternative use '''dtoverlay=vc4-kms-v3d-pi4''':
###i## nano /boot/config.txt
}}


{{file|name=/boot/config.txt|body=
{{file|name=/boot/config.txt|body=
disable_overscan=1
gpu_mem=256
dtparam=audio=on
dtoverlay=vc4-kms-v3d-pi4
dtoverlay=vc4-fkms-v3d
max_framebuffers=2
max_framebuffers=2
arm_64bit=1
arm_64bit=1
}}
}}


{{note|using dtoverlay '''vc4-kms-v3d-pi4''' can cause blank screen on both FrameBuffer and X server. Try setting CEA or DMT mode if you run into blank screen error on your monitor or TV}}
If you have a finicky monitor, you may need to use the following uptions, uncommented:
{{file|name=/boot/config.txt|body=
# CEA
#hdmi_group=1
#hdmi_mode=4
# DMT
hdmi_group=2
hdmi_mode=85
}}
==== Setting Display Modes ====
If your display is unhappy with your Raspberry Pi's default graphics mode, or you want to lower the resolution slightly for better performance if you have a 4K display, then use this table to find the “hdmi_mode” value for your resolution. CEA are "TV" modes. DMT are "computer monitor" modes. Your display may prefer one or the other.
[[Image:Modes_cea_dmt.png|650px]]
Configure kernel line:
{{console|body=
{{console|body=
###i## nano /boot/cmdline.txt
%fchroot%###i## nano /boot/cmdline.txt
}}
}}


{{file|name=/boot/cmdline.txt|body=
{{file|name=/boot/cmdline.txt|body=
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes usbhid.mousepoll=0 rootwait
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p3 rootfstype=ext4 fsck.repair=yes usbhid.mousepoll=0 rootwait consoleblank=0
}}
}}
{{Note|If you are using an external USB3 drive for your root filesystem, you will need to change the {{c|1=root=}} line above to match.}}


Set your timezone:
Set your timezone:
{{console|body=
{{console|body=
###i## ln -sf /usr/share/zoneinfo/America/Detroit /etc/localtime
%fchroot%##i## ln -sf /usr/share/zoneinfo/MST7MDT /etc/localtime
}}
}}


*Set Services:
{{Important|This following step should not be needed:}}
 
Regenerate locales:
{{console|body=
{{console|body=
###i## rc-update add dhcpcd default
%fchroot%##i## locale-gen
###i## rc-update add busybox-ntpd boot
###i## rc-update add swclock boot
###i## rc-update del hwclock boot
###i## rc-update del swap boot
}}
}}


=== Set Passwords, Exit from fchroot and boot your raspberry pi ===
Now, set your root password and create any necessary users. See [[Install/Finishing]]
{{Important|Did you set your root password? See above! If you are using GNOME or a DE, you will also need to create a regular user to log in.}}


=== Exit from fchroot and boot your raspberry pi ===
Make sure all buffers have been flushed and unmount the temp directories:
Make sure all buffers have been flushed and unmount the temp directories:


{{console|body=
{{console|body=
###i## exit
%fchroot%##i## exit
###i## sync
###i## sync
###i## cd /mnt ; umount -lR funtoo
###i## cd /mnt ; umount -lR funtoo
}}
}}


 
Now place the microSD card in your Raspberry Pi 4 and boot it up!
{{note|you should probably test that your pi boots at this point BEFORE emerging everything.}}
 
=== Update all system ===
{{console|body=
###i## emerge -avuND @world
}}
 
[[Install/Stage3_Desktop]]
 
 
Now you can follow the [[Funtoo Linux Installation|Funtoo Install documentation]] to continue configuring your system.  You'll definitely want to look into {{Package|sys-devel/distcc}} if you are going to be adding lots of software to your system.

Latest revision as of 07:21, November 7, 2022

Subpages:

What you need

  1. Raspberry PI 4
  2. An existing Funtoo Linux install or Livecd (Livecd is a solid choice if you do not have funtoo installed on a hard drive)
  3. a 32GB or larger microSD card, which will be /dev/mmcblk0, with partitions as /dev/mmcblk0p1, /dev/mmcblk0p2, etc.

Optional:

  1. A faster USB3 flash drive or external USB3 SSD drive to hold your root filesystem and swap to improve performance. If you use one, it will likely show up as /dev/sda when your Raspberry Pi boots, with partitions /dev/sda1, /dev/sda2, etc. You can use partition labels to make this easier to manage.

Prepare your SD card

On the non-Raspberry Pi system, you will insert and prepare the microSD card. The card will likely show up as /dev/sdX, but when the Raspberry Pi 4 boots, the card will show up as /dev/mmcblk0.

Please note that the Raspberry Pi has a custom boot loader which uses a FAT32 partition, which will be the /boot partition just like a regular x86-64bit Funtoo installation. This means we will simply make /boot FAT32 but use MBR. Without firmware changes, the /boot partition must reside on the microSD card, but the root and swap partitions can reside on other disks.

Target your drive as outlined in the official install. Install/Prepare_Disk. Use the MBR method but make a FAT32 /boot:

  • delete everything:
root # wipefs -a /dev/sdX

Make a new MS-DOS disklabel. Add a new partition - this will be 128Mb for /boot

root # fdisk /dev/sdX
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-15523839, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-15523839, default 15523839): +128M


Has created a new partition 1 of type 'Linux' and of size 128 MiB. Add a 2G partition 2 for swap. Put the remaining space in partition 3 for root.

Check with

Command (m for help): p

Using an 8G microSD card it should show

Device        Boot    Start      End  Sectors  Size Id Type
/dev/sdX1     2048   264191   262144  128M 83 Linux
/dev/sdX2   264192  4458495  4194304    2G 83 Linux
/dev/sdX3  4458496 15523839 11065344  5.3G 83 Linux

Set flags and partition types Toggle the bootable flag on partition 1

Command (m for help): a
Partition number (1-3, default 3): 1


The bootable flag on partition 1 is enabled now. Mark partition 1 as FAT

Command (m for help): t
Partition number (1-3, default 3): 1
Partition type (type L to list all types): c

Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.
   Note

The Pi checks the type of partition 1 in the partition table and will not boot if its 82

Mark partition 2 as swap

Command (m for help): t
Partition number (1-3, default 3): 2
Partition type (type L to list all types): 82

Changed type of partition 'Linux swap / Solaris' to 'Linux swap / Solaris'.

Check again.

Device         Boot   Start      End  Sectors  Size Id Type
/dev/sdX1      *       2048   264191   262144  128M  c W95 FAT32 (LBA)
/dev/sdX2            264192  4458495  4194304    2G 82 Linux swap / Solaris
/dev/sdX3           4458496 15523839 11065344  5.3G 83 Linux

Save the new partition table. Exit fdisk with either w or q

w   write table to disk and exit
q   quit without saving changes

Create File Systems

Next, we need to create file systems on the partitions:

root # mkfs.vfat -F 32 /dev/sdX1
root # fatlabel /dev/sdX1 "BOOT"
root # mkswap -L SWAP /dev/sdX2
root # mkfs.ext4 -F /dev/sdX3
root # e2label /dev/sdX3 "FUNTOO"

Prepare Your Boot Partition

Make mount points for your boot and root partitions on the SD card:

root # mkdir /mnt/funtoo

Mount your SD card:

root # mount /dev/sdX3 /mnt/funtoo 
root # mkdir /mnt/funtoo/boot
root # mount /dev/sdX1 /mnt/funtoo/boot

Get the Funtoo Files Onto the SD Card

Download the Necessary Files

Grab the latest Arm64_generic stage 3 file: Subarches

root # cd /mnt/funtoo
root # wget https://area31.host.funtoo.org/stage3-raspi4-1.4-release-std-2022-05-19.tar.xz

Extract the stage 3:

root # tar --numeric-owner --xattrs --xattrs-include='*' -xpf stage3*

Pre-boot Configuration

  • Edit your fstab file so everything mounts correctly on boot:
  • Raspberry pi only supports partuuid and partlabel loading:
root # nano /mnt/funtoo/etc/fstab
   /mnt/funtoo/etc/fstab
LABEL=BOOT      /boot           vfat    noauto            0       2
LABEL=SWAP      none            swap    sw                0       0
LABEL=FUNTOO    /               ext4    defaults,noatime  0       1


   Note

Rather than using the labels above, you can also simply use /dev/mmcblk0p1, /dev/mmcblk0p2 and /dev/mmcblk0p3 respectively.

Chrooting into your new installation

If you are on an existing Funtoo system, you will need to emerge fchroot. If you are using our official LiveCD, fchroot is already available.

  • Fchroot in:
root # emerge fchroot
root # cd /mnt/funtoo
root # fchroot --cpu cortex-a72 . su --login
root # export PS1="FUNTOO $PS1"
fchroot #

Configure driver VC4 and screen resolution

Note that the Raspberry Pi 4 has two different video drivers. You have the option of using vc4-fkms-v3d or vc4-kms-v3d-pi4. Either way, you will want to make sure you are using HDMI port 1 on your device (on the Raspberry Pi 400, this is the one closest to the USB-C power connector) or you may not get any video. You should also see the "Setting Video Modes" section if you have a finicky monitor and find you need to explicitly set a video mode to get the Raspberry Pi to select a display mode that your monitor accepts.

vc4-fkms-3d

fchroot # nano /boot/config.txt

use dtoverlay=vc4-fkms-v3d:

   /boot/config.txt
gpu_mem=256
disable_overscan=1
dtparam=audio=on
dtoverlay=vc4-fkms-v3d
max_framebuffers=2
arm_64bit=1


   Note

On Raspberry PI 4 CM4 the above boot config does not enable the onboard USB.

To ensure the USB ports are enabled when running RPi4 CM4's in headless mode AND providing the physical USB ports via a carrier board, simply instead use these two lines to the config.txt:

   /boot/config.txt
dtoverlay=dwc2
dr_mode=host

vc4-kms-v3d-pi4

You can alternative use dtoverlay=vc4-kms-v3d-pi4:

   /boot/config.txt
gpu_mem=256
dtoverlay=vc4-kms-v3d-pi4
max_framebuffers=2
arm_64bit=1


   Note

using dtoverlay vc4-kms-v3d-pi4 can cause blank screen on both FrameBuffer and X server. Try setting CEA or DMT mode if you run into blank screen error on your monitor or TV

If you have a finicky monitor, you may need to use the following uptions, uncommented:

   /boot/config.txt
# CEA
#hdmi_group=1
#hdmi_mode=4
# DMT
hdmi_group=2
hdmi_mode=85

Setting Display Modes

If your display is unhappy with your Raspberry Pi's default graphics mode, or you want to lower the resolution slightly for better performance if you have a 4K display, then use this table to find the “hdmi_mode” value for your resolution. CEA are "TV" modes. DMT are "computer monitor" modes. Your display may prefer one or the other.

Modes cea dmt.png

Configure kernel line:

fchroot ## nano /boot/cmdline.txt
   /boot/cmdline.txt
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p3 rootfstype=ext4 fsck.repair=yes usbhid.mousepoll=0 rootwait consoleblank=0


   Note

If you are using an external USB3 drive for your root filesystem, you will need to change the root= line above to match.

Set your timezone:

fchroot # ln -sf /usr/share/zoneinfo/MST7MDT /etc/localtime
   Important

This following step should not be needed:

Regenerate locales:

fchroot # locale-gen

Set Passwords, Exit from fchroot and boot your raspberry pi

Now, set your root password and create any necessary users. See Install/Finishing

   Important

Did you set your root password? See above! If you are using GNOME or a DE, you will also need to create a regular user to log in.

Make sure all buffers have been flushed and unmount the temp directories:

fchroot # exit
root # sync
root # cd /mnt ; umount -lR funtoo

Now place the microSD card in your Raspberry Pi 4 and boot it up!