Tuesday, September 13, 2016

2. Installing 64-bit Fedora 24 on a Raspberry Pi-3

2016.09.13
Revised 2016.09.18


This post is a guide for installing 64-bit Fedora 23 or 24 on a µSD card for the Raspberry Pi-3B.  These instructions are modifications for 64-bit Fedora of the instructions created by Will Foster for 32-bit Fedora [ https://hobo.house/2016/03/13/installing-fedora-linux-on-the-raspberry-pi-3/ ]: all credit for intellectual content goes to him.  This page simply provides the modifications (and cautions) for the 64-bit Fedora install.  Please refer to that site for more information and for prior work on debugging the 64-bit install process.

Please let me know if there are errors or ambiguities in the instructions below and I will correct them as quickly as I can -- even quicker if you provide suggested language!  I think comments work on this blog site, but if not, email me at hdtodd@gmail.com.

Assumed working environment:

  1. A standard OSX Mac or Linux PC with SD slot and a SD adapter card for a µSD card, and a WiFi or Ethernet connection to the Internet.  You can use a Raspbian-based Raspberry Pi as the workstation for this if you have the USB port available and the µSD-USB adapter described under tools.  (I would think these instructions could be tailored for Windows, but I don't have a Windows systems and so couldn't document the process.)
  2. Comfort using command-line tools on Linux and/or Mac OSX. 
  3. A Raspberry Pi-3B (no earlier version will work) with power supply, keyboard, display, µSD disk.  Mouse optional (but required if you want to use a graphical display system).
  4. Ethernet connection and cable  to connect the Pi-3B to the Internet
  5. WiFi for the Pi is optional

Helpful tools:

  1. µSD (micro SD card) USB adapter that will allow you to insert your µSD card into the adapter, then insert the adapter into a USB port, and have the computer then be able to access that µSD card.

Warnings

As of 2016.09.12, there are problems with systems that result from updates to the Fedora 24 Raspberry Pi distribution after the initial install.  Those problems limit the functionality of the updated system (4.7.1 to 4.7.4, at last check).
  1. The 20160623 distribution (step 1 below) installs kernel 4.6.2-4-main.  That system functions reasonably well: WiFi works, xfce GUI desktop functions, etc.  Compilers, assemblers, linkers, etc all function.  Firefox and Thunderbird crash before they can bring up a window.  There may be problems in other applications.
  2. I understand from Kraxel that the RPi firmware is updated as part of the "dnf update" process. So doing "rpi-update" is not necessary.  I was concerned that it may, in fact, cause problems with some of the firmware as it supports Fedora.  So I've omitted the step of performing an "rpi-update".
  3. The 4.7.3-2-main  and subsequent updates fix the VA_BITS=48-->39 problem that caused polkit memory addressing crashes.  
  4. If you do a "dnf update", as of 2016.09.12, you'll update to kernel 4.7.3-1-main (or subsequent update).  That update breaks a number of things (as do previous updates I had tried earlier).  The VA_BITS=48-->39 .config parameter has been corrected, so "polkit" no longer crashes with memory addressing problems.  But other components continue to fail.  "systemctl default" fails; xfce4 simply hangs the system (and trying to boot with the graphical interface set as the default hangs without giving a prompt).  If you do the "dnf update" and get to the point where you can't boot into 4.7.x, boot back to 4.6.2-4-main. The instructions below will give you a system that puts up a boot menu so you can select the kernel you want to run.
  5. If you simply want to bring up 64-bit Fedora 24 with a GUI desktop that functions as a stable Fedora system, I would recommend not doing the "dnf update" in step 11.  Rather, perform the initial installation, then
    dnf groupinstall "xfce desktop"
    You can then use the GUI tools to configure your WiFi connection, and most of the Fedora functionality will be operating.  Watch the blogs to wait for others to signal that the updates no longer break key Fedora services.

Installation Procedure

  1. Download FC23 or FC24 64-bit OS distribution images from here: https://www.kraxel.org/repos/rpi2/images/ .  I used the file https://www.kraxel.org/repos/rpi2/images/arm64-rpi3-f24-mainline-20160623.raw.xz, but you should use a more recent version if there is one.  What you get is a .xz zip file.  You can unzip it with gunzip on the Mac to get a .raw file.  If you rename it to .img on the Mac and double click on it, OSX will open the vfat partition and mount it.  It can’t do that with the ext4 partition since it doesn’t know about them.  Or if you copy the image (or download it to) a Linux system, you can double-click the .img file to  mount both partitions in order to poke around and see what’s in them.  Dismount the partitions before the next step.  On the Mac, if you've mounted it and it's listed as disk2, use the command diskutil list to verify that!!), you can umount with the command:
    sudo diskutil unmountDisk disk2
  2. Copy the unzipped image file to the µSD drive.  You'll need to be administrator or root to do this.  On the Mac or Linux PC, install a blank µSD at least 8GB in capacity; note the device name (something like /dev/disk2 on the Mac or /dev/sdb on RPi — but be sure you get the drive identity correct before you do this step or you may blow away your Mac OS system!!), and then issue the command:
    sudo dd bs=1m if=arm64-rpi3-f24-mainline-20160623.raw \
       of=/dev/rdisk2
    Note the output is to "rdisk2" rather than "disk2".  Again, if you're on a Mac, it will auto-mount the first partition when the copy has been completed; you'll need to issue the following command to unmount the µSD:
    sudo diskutil unmountDisk disk2
  3. Three partitions on the µSD.  The result of this is that you will have 3 partitions on the µSD.  If you insert it into a Linux (RPi) system on which it is the second attached USB drive (hence is "sdb" rather than "sda"), you'll see:
    1. /dev/sdb1: a vfat partition that will be “/boot” when you start up the RPi
    2. /dev/sdb2: “/swap”
    3. /dev/sdb3: an ext4 partition that will be “/” when you start up the RPi
  4. Check and expand the µSD file system.  The third partition is only about a GB in size, corresponding to the size in the distribution version.   We need to expand it.   You will need to be on a RPi or other Linux system – OSX does not have the tools.  Insert the µSD into a Linux system (e.g., Raspbian, but it doesn’t need to be an RPi-3); don’t mount the partitions and umount them if they've been auto-mounted.  Use the following steps to check the file system and then expand “/” on the µSD to fill the remaining drive (I’m assuming it’s /dev/sdb, but check its identity on your system or you may blow away your operating system!):
  5. sudo e2fsck -f /dev/sdb3
    sudo resize2fs /dev/sdb3
  6. Boot your new Fedora system on the RPi-3.  Insert the µSD as the boot drive on a RPi-3 and boot it up.   It will boot up once, do some configuring, resize "/", and then reboot itself.   Don’t panic!  Just be patient … and it’s fairly fast.   It’ll quickly come back with a login prompt.
  7. Log in as “root”, password “pi”.
  8. Streamline the security environment.  As shipped, FC23 installs SELinux in “permissive” mode.  Selinux may cause problems with operation of some apps — at least it looked to be implicated in some things not running because they didn’t have permissions to access or modify files.  And Will Foster (hobo) reported that SELinux is known to interfere with operations in Fedora.  So on the first boot up, edit the configuration file to disable it:
    vi /etc/selinux/config and change “permissive” to “disabled”.  Exit vi (“:wq”) and reboot.  If you don’t know how to use vi, wait ’til you’ve installed a text editor you do know (eg, nano) and do it then.  And once your tools are all in place and the system is stabilized, you may want to go back and revert back to "permissive" .
  9. Set the host name of your system:
    echo MyHostName > /etc/hostname
    (use your preferred host name in place of “MyHostName”)
  10. Familiar tools aren't available yet.  A number of tools you’re likely to want to use aren’t installed in the distribution version.  But that’s OK: you need to update software to stabilize the system and then you can download apps and get the system you want.
  11. Manually configure your WiFi if necessary.  You will likely find it easier to simply plug into an Ethernet port to get started, but if that's difficult, you might try configuring WiFi manually.  This procedure is adapted from [ https://www.blackmoreops.com/2014/09/18/connect-to-wifi-network-from-command-line-in-linux/ ] and has worked for me, though I had to delete the manual configuration once I had the GUI interface working and wanted to manage via the network widget.
    1. Verify that you have a wlan device with the command:
      iw dev
    2. Check the wlan device status:
      ip link show wlan0
      Should be in the DOWN state
    3. Bring up the wlan0 interface:
      ip link set wlan0 up
      and then verify that it is up:
      ip link show wlan0
      should now show wlan0 in the UP state.
    4. Check the connection status -- shouldn't be connected:
      iw wlan0 link
    5. Scan to find the WiFi network you want.  Skip this step if you know the SSID of the network you want to join:
      iw wlan0 scan
    6. Assuming it's a WPA password protected network,
      wpa_passphrase YourNetworkSSID >> /etc/wpa_supplicant.conf
      (now type the password for that network -- no prompt for this)
      wpa_passphrase will create the network entries for your network, appending to any prior entries (not replacing). Verify by
      cat /etc/wpa_supplicant.conf
    7. Connect to the network:
      wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
    8. Verify that you've connected:
      iw wlan0 link
    9. Get an IP address through DHCP:
      dhclient wlan0
    10. And verify that you've gotten an IP and are connected to your wireless network and have your routing set up:
      ip addr show wlan0
      ifconfig wlan0
      ip route show
    11. Check it by pinging a large Internet host:
      ping 8.8.8.8
  12. Connect your RPi3 to the Internet via the Ethernet port.  If you’re skilled at getting WiFi configured via command line editing, go ahead and do that and see if you can get it to connect to the network, but the easiest way will likely be to plug the RPi3 into an Ethernet connection. If you do that, Fedora will tell you it found a link and made a connection.   Some times it even told me the IP address, but generally it doesn’t.  And “ifconfig” isn’t there yet.  But if you have a way of identifying the IP assigned to it (e.g., by looking at the DHCP assignments made by your router or by ssh'ing to another system and typing "who" to see your source IP), then you can ssh into it from another system (e.g., from another PC type ssh root@192.168.1.101, password is pi ). You may find it convenient to do much of the following work from another system, since you’ll spend a good deal of time waiting for downloads and installs to complete and you can do other things if you’re working from another system.  You'll probably want to sftp to some other host on your net and copy over the /etc/hosts file and install it in your RPi /etc directory so that you can connect to your other network hosts by name.
  13.  Install some essential tools.  Issue the commands:
    dnf install binutils nano net-tools wget
    dnf groupinstall "administration tools" "system tools"
    If you’re an emacs user, you can
    dnf install emacs-nox
    at this point, too, or other tools that you use frequently.
  14. Reboot.  Now many of the tools you might want are available. Your favorite editor should be there (or install it with dnf if it isn’t).  “ifconfig” should be there and will show that you have an Ethernet connection and that wlan0 is there and functioning (but not configured and so not connected to an access point).
  15. Secure your system and set up a user account.  Your preferences may vary, but at least log in as root, password=pi, and type:
    passwd
    And then enter a new password for root.  I prefer to set up a group and account for myself using the same uid/gid I use on other systems, to make nfs connections less troublesome:
    groupadd -g 502 YourUserGroup (your group id and group name as you prefer) useradd -b /home -g YourUserGroup -G root -m -s /bin/bash \
        -u 502 YourUserName
    (again, use your preferences for gid, shell, uid, and username).
    Type
    passwd YourUserName (your name here)
    and enter a password for your personal account.  And finally, I like to work in my own account but have easy access to su when I need it, so if you prefer to work that way, enter the command:
    visudo
    then arrow down to
    ## Allow root to run any commands anywhere
    root ALL=(ALL) ALL
    go to the next line (blank), type “i” to begin inserting, and type in
    YourUserName ALL=(ALL) ALL
    press the ESC key to end the insert, then type “:wq” to save the file and exit.  If you do this, you can now log in as yourself to do most of your work but issue a “sudo" to do a specific administrative task or “sudo -s” whenever you need to jump into root for longer periods.
  16. Install a GUI desktop.  There are now tools installed that would let you configure your WiFi connection from the command line, but you’re likely to want a GUI desktop interface anyway, so it may be easier to install that first.   Choose the one you want.  I found that xfce4 works pretty well — lightweight but familiar look.  You can see what’s available with the command:
    dnf group list
    which will show a number of different application suites as well as desktop systems.   Let’s say you would like to try xfce.  Issue the command:
    sudo dnf groupinstall "xfce desktop"
    After the download and install have finished, reboot.   It will come up with a graphical login screen.  Login as yourself.   For some reason, presumably distribution configuration, the system doesn’t start NetworkManager automatically initially, and as a result the WiFi configuration manager toolbar widget won’t start up.  So open a terminal window and issue the commands:
    sudo systemctl enable NetworkManager
    sudo systemctl start NetworkManager
    Now double-click the network widget icon in the upper right-hand toolbar.  It’ll bring up your connection options.  Ethernet should already be connected; Wifi won’t be.  Go to the left side of that toolbar, click “Applications” to bring down the menu, click “system”, and select “network”.  Now tell it you want to add a WiFi interface, wlan0 as the device, and fill in your SSID and authentication information and tell it to connect.  At this point, you should be able to manage your network connections through the icon on the right side of the top toolbar.

    If you prefer not to have a graphical login screen but want to stick with command line for most of your work, type: 
    sudo systemctl set-default multi-user.target
  17. Add your favorite programs.  Now you can load programs to tailor the system to your own needs. Use
    dnf list | grep MyFavoriteApp
    to identify a specific program that you’d like to install, then
    dnf install MyFavoriteApp
    to actually install it.   For larger packages that involve numerous programs, you can use
    dnf group list
    to identify other packages you’d like to install.   If you want C and associated development tools, for example, issue the command:
    dnf groupinstall "C Development Tools and Libraries"

Detritus

These are steps that we defer for now:
  1. Defer this step until the update doesn't break xfce.  Update the OS distribution.  You’ll use “dnf” — a YUM extension, equivalent to "apt" in Raspbian — to do the updates and installs.   Log in as root, password pi, either on the console or over the network. Issue the command:
    dnf update
    and respond "y" to let it install the updates.
  2. This step not recommended for now but left for possible future use.  Install the firmware updater and update the RPi firmware.  The RPi3 uses firmware in the /boot drive to actually load the OS, and that gets updated occasionally, too.   The tool to do that is called “rpi-update”.   We have to download and install it, first, since it’s not part of the Fedora distribution: 
    wget -O /usr/bin/rpi-update \
        https://raw.githubusercontent.com/Hexxeh/rpi-update/master/rpi-update
    chmod +x /usr/bin/rpi-update
    rpi-update
    Reboot

Rebooting to an attached USB drive

I have not been able to get the new booting process to boot Fedora directly from an attached USB drive (process as described in the MSB site (https://www.raspberrypi.org/blog/pi-3-booting-part-i-usb-mass-storage-boot/).  So if you want to install 64-bit Fedora on an external USB-attached hard drive or thumb drive, you'll need to have the boot process transfer from the µSD to the USB device.  The setup process isn’t terribly complicated, but there are too many variations and possible complications to give a single list of instructions, so I'll just sketch the ideas out here.  The description in this section assumes that you have some experience doing systems work in Linux — you know how to use fdisk, dd, and friends, for example, and you know that the results can be catastrophic if you screw up.   The general idea is to tell the booting firmware, which is located on the µSD (/dev/mmcblk0) to redirect its booting process to a partition on the USB thumb drive or USB-attached hard drive (/dev/sda, for example).   In Raspbian, you do that in /boot/cmdline.txt by changing the reference to “/dev/mmcblk0p3” to point to “/dev/sda3” (for example).  In Fedora (or maybe later versions of Raspbian … not sure where the change came from), you change that reference from mmcblk0p3 to sda3 in /boot/extlinux/extlinux.conf .  But before you do that, you need:
  1. fdisk /dev/sda (assuming that’s your new boot device) to create the partitions you want. I made a copy of /dev/mmcblk0p1 (the µSD /boot) to /dev/sda1 ; I made /dev/sda2 be “/swap”; I made /dev/sda3 be “/”.   There’s no real reason to have /boot on the hard drive (RPi boots its firmware from the µSD, and having /boot point anywhere other than /dev/mmcblk0p1 causes other problems when you update firmware … the real boot partition, on mmcblk0, doesn’t get updated by rpi-update, for example!).  But I use the hard-drive first partition /boot to keep an archival copy of a working /boot from mmcblk0p1.
  2. However you choose to set up your partitions, identify which one is going to be “/swap” (you probably really do want that to be on your hard drive!) and issue a mkswap /dev/sda2 (for example)
  3.  Identify which partition is going to be “/”, and create the file systems on it with "mkfs -t ext4 /dev/sda3" (for example)
  4.  Mount the hard drive “/” partition.  For example, mkdir /mnt/hdslash and then mount the partition with "mount /dev/sda3 /mnt/hdslash".   Copy the system from “/” on /dev/mmcblk0p3 to what will become the new “/” on /dev/sda3.  But if you try to copy the live version of “/” (as the system is in operation), you’ll get lots of error messages and likely (since I’ve never let it complete) to be unsuccessful.   This copying is best done by attaching the hard drive and your new FC23 µSD to a functioning Linux system and copying.  This is the tricky part.  If you get this wrong, you blow away your Linux OS or your new FC23 µSD drive.  (How might I know that, you ask?   Experience.  Typing “/dev/sda” instead of “/dev/sdb” can be a fatal mistake).   You need to be careful to identify your source and destination drives (they’re likely to be /dev/sda and /dev/sdb, but which is which? Better be sure!).
  5. The last change you’ll need to make is in the /etc/fstab on the hard drive to identify /boot, /swap, and /.   And confirm that the file /boot/extlinux/extlinux.conf (make sure it’s the one on /dev/mmcblk0p1) points to /dev/sda3 (for example) rather than /dev/mmcblk0p3.
  6. Put your µSD card in your RPi3, attach and turn on your hard drive, and power up your RPi3.  With any luck (or about the 5th time you try it), you’ll see the initial firmware boot off your µSD card, then see it load the OS from the hard drive.
  7. Remember: if you identify in /etc/fstab that /boot is on your hard drive, any software updates (dnf or rpi-update) will only update that version, not the one you actually boot from on /dev/mmcblk0p1.  After an update, you’ll need to copy the updated boot files back to that µSD partition.  And you can get version skew between /boot and the OS files in / on that µSD, so you have to be careful to keep things in sync.   While having /boot point to /dev/sda1 (for example) is manageable, I've found it's easiest to just leave /boot pointing to /dev/mmcblk0p1 and not mount the /dev/sda1 as /boot any more -- just use it to back up /boot.
  8. There are numerous variations in this process that you might choose, depending on how you intend to use your system, the capacity of your hard drive, etc.  One of the simplest would be to connect your hard drive to a Linux system and power it up; assuming it’s /dev/sda (CHECK THAT TWICE!), use the dd command and then the e2fsck and resize2fs commands from the beginning of these instructions to copy the repository distribution image to that hard drive.  Edit /dev/mmcblk0p1/boot/extlinux/extlinux.conf to refer to /dev/sda3 and edit the /dev/sda3/etc/fstab to mount /dev/sda2 as /swap and /dev/sda3 as /.  You’ll end up with a small swap space, and you’ll need to update and install software on that new hard drive since you won’t have copied the software from your µSD, but it’ll be a much faster process and less error prone.   I haven’t done it this way (yet), but I’ll try it on my next install and append to this if it’s as straightforward as I think it will be.
The instructions above assume you're installing on a µSD card, but a USB thumb drive or hard drive will work just fine.  If you use a USB drive, though, you'll still need a µSD card on which you can install the boot code for Fedora on the Pi -- a copy of the /dev/sda1 partition from the USB drive.  I have not (yet) been able to get the Pi-3B to boot off the USB drive directly, probably because the newly-implemented MSD boot mechanism is designed for Raspbian.

No comments:

Post a Comment