Running a July-2020 FreeBSD-13 build on the RPi4

Objective

  • Setup a current FreeBSD-13 running on an RPi4 using an external USB3 SSD

Background info

  • From https://wiki.freebsd.org/arm/Raspberry%20Pi we have the note that 
    “As of February 2020: If you encounter e.g. boot-problems from SD-card on the RPI4 try overwriting the whole overlay-folder from RPI-foundation to your SD-card's msdos-partition”. 
    Not sure if this is needed but will update when checking RPi4 bootloader version as a preventative measure (the eeprom bootloader needs to be recent in order to support USB booting)

Eventual approach

  • Make use of online disk images and not do any rebuilds (for now). This means a FreeBSD kernel with extra debugging is used.
  • Use current raspios to ensure that the RPi4 bootloader kept in eeprom is current.
  • Use FreeBSD image FreeBSD-13.0-CURRENT-arm64-aarch64-RPI3-20200723-r363439.img.xz (in this example) but with its MSDOSBOOT/overlays directory contents (located in the boot partition 1) overwritten by the latest boot/overlays directory contents provided by raspberrypi.org
  • Attach an external USB3 SSD to the RPi4, clone the microSD card image on to it, and adjust the FreeBSD loader.conf file on the microSD card to select the external USB3 SSD as the root file system 
    i.e. the kernel loading uses the microSD card (which can be updated by changing the card) but the final system is running off the external disk.

Items for next time

  • Should have left some disk space free for a swap area when using growfs (will have to add swapping to a file if needed).

Status

  • Have not performed a “make world” i.e. the system has not been stressed.
  • System is currently detecting only 1GB of the available 4GB of ram.
  • In July 2020, it is still a work in progress.

Preparation of RPi4

  • Update the RPi4 bootloader in eeprom
    • Download the latest raspios image https://www.raspberrypi.org/downloads/raspberry-pi-os/ 
      i.e. Raspberry Pi OS (32-bit) Lite 
      The “Minimal image based on Debian Buster” in the zip archive was 2020-05-27-raspios-buster-lite-armhf.img
      • It is possible to grab a copy of the latest overlays now by mounting the first partition of the card but we will use the card to boot the RPi4, ensure it is working, and then check get a copy before checking the bootloader version.
    • Attach wired network cable, HDMI screen (used connector adjacent to usb-c power), power (usb-c) and boot up
    • Login as pi/raspberry and save an archive of overlays: 
      cd /boot #cannot find keys like ~ or @ so use 2 commands 
      tar czvf ${HOME}/overlays.tgz overlays/ 
      cd 
      scp -Cp overlays.tgz me@myMainHost:
    • Confirm version of eeprom bootloader: 
      vcgencmd bootloader_version
    • If the version is not from June or later, follow the instructions at https://www.tomshardware.com/how-to/boot-raspberry-pi-4-usb using this latest raspios.
    • When all done: sudo shutdown now

Preparation for FreeBSD

  • After writing this image to the microSD card, mount the boot partition (an easy way might be to remove and reinsert the card adaptor if it is not already mounted) so overlays can be updated.
  • On myMainHost system, the boot partition is mounted at /Volumes/MSDOSBOOT so update by 
    cd /Volumes/MSDOSBOOT
    ls -l overlays/                                                     # view original DTBO files
    tar czvf ~/overlays_orig.tgz overlays    # save original DTBO files
    tar xzvpf ~/overlays.tgz overlays        # overwrite
    ls -l cd overlays/
    cd
    # unmount and remove 

Boot FreeBSD and configure

First Boot and Login

  • Insert the microSD card, attach a wired network, attach the screen to the micro hdmi socket next to the usb-c power socket, and then apply power
  • The system can be viewed booting up (ideally) and you will eventually the login invitation for host named generic
  • Try logging in via 
    ssh freebsd@generic 
    which will work if your DHCP server advertises the IP number for the default host name generic, otherwise check your DHCP server to identify the host IP number and login via 
    ssh freebsd@IPnumber #like ssh freebsd@192.168.1.123

Initial configure

  • System initial config for passwords and add a user account: 
    freebsd@generic:~ % passwd freebsd
    Changing local password for freebsd
    Old Password:
    New Password:
    Retype New Password:
    
    freebsd@generic:~ % su root
    Password: ____
    
    root@generic:/home/freebsd # passwd root
    Changing local password for root
    New Password: ____
    Retype New Password: ____
    
    root@generic:/home/freebsd # cat /etc/passwd # view the existing account details to see if uid 1000 is free for my account
    
    root@generic:/home/freebsd # adduser
    Username: *******
    Full name: ******* ********
    Uid (Leave empty for default): __1000__
    Login group [phillip]: __staff__
    Login group is staff. Invite phillip into other groups? []: __wheel__
    Login class [default]: 
    Shell (sh csh tcsh nologin) [sh]: 
    Home directory [/home/phillip]: 
    Home directory permissions (Leave empty for default): 
    Use password-based authentication? [yes]: 
    Use an empty password? (yes/no) [no]: 
    Use a random password? (yes/no) [no]: 
    Enter password: *****
    Enter password again: *****
    Lock out the account after creation? [no]: 
    Username   : *******
    Password   : *****
    Full Name  : ******* ********
    Uid        : 1000
    Class      : 
    Groups     : staff wheel
    Home       : /home/phillip
    Home Mode  : 
    Shell      : /bin/sh
    Locked     : no
    OK? (yes/no): __yes__
    adduser: INFO: Successfully added (phillip) to the user database.
    Add another user? (yes/no): __no__
    Goodbye!
    
    root@generic:/home/freebsd # cat /etc/group # confirm which users now have su ability 

USB disk setup

  • We first confirm the USB3 disk and its device entry
  • To identify 
    #insert disk
    dmesg | tail -22
    stack backtrace:
    #0 0xffff000000486ae4 at witness_debugger+0x64
    #1 0xffff000000487af4 at witness_warn+0x3f0
    #2 0xffff000000681f68 at uma_zalloc_debug+0x2c
    #3 0xffff0000006819d0 at uma_zalloc_arg+0x2c
    #4 0xffff0000003caef4 at getenv_string_buffer+0x40
    #5 0xffff0000003cb610 at getenv_quad+0x14
    #6 0xffff0000003cb5e0 at getenv_int+0x14
    #7 0xffff00000003ba94 at daregister+0x1b4
    #8 0xffff0000000131c4 at cam_periph_alloc+0x528
    #9 0xffff00000003b344 at daasync+0x260
    #10 0xffff00000001fc68 at xpt_async_process_dev+0x194
    #11 0xffff00000001bd84 at xpt_async_process+0x384
    #12 0xffff00000001c48c at xpt_done_process+0x300
    #13 0xffff00000001e19c at xpt_done_td+0xd8
    #14 0xffff0000003d952c at fork_exit+0x7c
    da0 at umass-sim0 bus 0 scbus0 target 0 lun 0
    da0: <JMicron Generic 8101> Fixed Direct Access SPC-4 SCSI device
    da0: Serial Number 0123456789ABCDEF
    da0: 400.000MB/s transfers
    da0: 476940MB (976773168 512 byte sectors)
    da0: quirks=0x2<NO_6_BYTE> 

    and, ignoring the extra kernel debug info, we see a 400MB/s device has been probed as da0 i.e. device /dev/da0

  • Copy microSD card contents onto USB disk (overwrite contents including partition details) 
     root@generic:/home/freebsd # dd if=/dev/mmcsd0 of=/dev/da0 bs=4m status=progress 
  • Check the BSD file system 
     root@generic:/home/freebsd # ls -l /dev/da0*
    crw-r-----  1 root  operator  0x6c Jul 31 12:33 /dev/da0
    crw-r-----  1 root  operator  0x6d Jul 31 12:33 /dev/da0s1
    crw-r-----  1 root  operator  0x6e Jul 31 12:33 /dev/da0s2
    crw-r-----  1 root  operator  0x70 Jul 31 12:25 /dev/da0s2a
    
    root@generic:/home/freebsd # fsck /dev/da0s2a
    ** /dev/da0s2a
    ** Last Mounted on 
    ** Phase 1 - Check Blocks and Sizes
    ** Phase 2 - Check Pathnames
    ** Phase 3 - Check Connectivity
    ** Phase 4 - Check Reference Counts
    ** Phase 5 - Check Cyl groups
    24089 files, 680359 used, 1182592 free (24 frags, 147821 blocks, 0.0% fragmentation)
    
    ***** FILE SYSTEM MARKED CLEAN ***** 
  • Resize /dev/da0s2a 
    We know that: the USB disk is da0, the first slice holds the original boot partition information (/dev/da0s1), the second slice contains the UFS file system (/dev/da0s2), the UFS file system is in device /dev/da0s2a
    • Mark the slice to resize 
       root@generic:/home/freebsd # gpart resize -i 1 /dev/da0s2
      da0s2a resized 
    • Grow the UFS file system and check it until it is marked clean 
       root@generic:/home/freebsd # growfs /dev/da0s2a
      It's strongly recommended to make a backup before growing the file system.
      OK to grow filesystem on /dev/da0s2a from 7.3GB to 466GB? [yes/no] yes
      
      root@generic:/home/freebsd # fsck /dev/da0s2a
      ** /dev/da0s2a
      ** Last Mounted on 
      ** Phase 1 - Check Blocks and Sizes
      ** Phase 2 - Check Pathnames
      ** Phase 3 - Check Connectivity
      ** Phase 4 - Check Reference Counts
      ** Phase 5 - Check Cyl groups
      CG 0: BAD CHECK-HASH 0xe501b67 vs 0x9d602865
      CG 12: BAD CHECK-HASH 0x27a0370c vs 0xf11ec7b4
      24089 files, 680359 used, 117568820 free (36 frags, 14696098 blocks, 0.0% fragmentation)
      
      ***** FILE SYSTEM IS CLEAN *****
      
      ***** FILE SYSTEM WAS MODIFIED *****
      
      root@generic:/home/freebsd # fsck /dev/da0s2a
      ** /dev/da0s2a
      ** Last Mounted on 
      ** Phase 1 - Check Blocks and Sizes
      ** Phase 2 - Check Pathnames
      ** Phase 3 - Check Connectivity
      ** Phase 4 - Check Reference Counts
      ** Phase 5 - Check Cyl groups
      24089 files, 680359 used, 117568820 free (36 frags, 14696098 blocks, 0.0% fragmentation)
      
      ***** FILE SYSTEM IS CLEAN ***** 
  • We have completed the copy of FreeBSD files and adjusted the UFS file system to use all the USB disk storage.

Switch FreeBSD to use the USB3 file system

  • The system boot from the microSD card is to be configured to use the USB disk after the kernel loads, by adjusting the loader.conf on the microSD card (not the USB disk)
  • The current contents is 
     root@generic:/home/freebsd # cat /boot/loader.conf
    # Configure USB OTG; see usb_template(4).
    hw.usb.template=3
    umodem_load="YES"
    # Multiple console (serial+efi gop) enabled.
    boot_multicons="YES"
    boot_serial="YES"
    # Disable the beastie menu and color
    beastie_disable="YES"
    loader_color="NO" 
  • Choose the switch of the root file system from the faster USB3 disk 
     echo root@generic:/home/freebsd # sh     #change to sh shell so a multiline text string can be entered
    
    # echo '
    > 
    > # Switch to da0 root
    > #
    > vfs.root.mountfrom="ufs:/dev/da0s2a"' >> /boot/loader.conf
    # exit
     root@generic:/home/freebsd # cat /boot/loader.conf # check 

    and the text 
    vfs.root.mountfrom=“ufs:/dev/da0s2a” 
    should now be appended to this loader.conf file.

  • Reboot and the kernel load will use the microSD card but then the system will use the faster disk 
      root@generic:/home/freebsd # reboot 

Notes on further use

  • Shutdown: the system can do a clean shutdown by using halt i.e. 
     root@generic:/home/freebsd # sync; sync; sync; halt 

    and waiting 10 seconds before power down. Using the shutdown command was found unreliable.

  • Time zone: this can be set manually e.g. 
    # ln -s /usr/share/zoneinfo/Australia/Brisbane /etc/localtime 
  • Optional tools:
    su root
    # pkg install zile	#add an editor (and autoinstall the pkg support files)
    # pkg install bash      #preferred shell
    
    # pkg install sudo	#and enable sudo by a user who can skip pwd entry
    
    # diff /usr/local/etc/sudoers~ /usr/local/etc/sudoers
    
    < # %wheel ALL=(ALL) ALL
    ---
    > # %wheel ALL=(ALL) ALL
    > # phillip ALL=(ALL) NOPASSWD: ALL
    
    # pkg install openntpd	#read docs via ... MANPATH=/usr/local/man man ntpd
    # sh                    #enable
    echo 'openntpd_enable="YES"           # enable time via OpenNTP
    openntpd_flags="-s"
    ntpd_enable="NO"
    ' >> /etc/rc.conf
    exit
    
    # pkg install dnsmasq 

References

No comments: