To begin, first download and install NOOBs onto the SD card you wish to install Fedora on. Once NOOBs is loaded onto the card, place the card into the raspberry_pi and install Raspbian normally. By doing this, the card will gain the file structure and partitions it needs to operate normally. Once it's finished, the card should have a boot partition, a swap partition, and root partition created. The boot and swap partitions will remain untouched, though we will modify the root partition a bit.
Once the installation is finished and you see the blue setup screen, the card is ready to get Fedora loaded onto it. Unplug the pi and take out the SD, and insert it into your computer again. From this point forward a Linux or Mac is recommended.
NOTE: For Windows users, install VirtualBox and setup a guest machine to access the SD card. Refer to this blog post for directions on accessing an SD card through VirtualBox.
In the machine where we will be installing Fedora onto the card, check the /mnt directory. We will be mounting two devices which we will use as a source of files for Fedora and as a destination for those files. It is recommended you create two directories in your /mnt folder for this purpose. As a suggestion, run the following two commands.
- mkdir /mnt/source
- mkdir /mnt/destin
Once the SD is in the machine, figure out which device in /dev it is mapped to. For instance, the main disk drive may be /dev/sda while the SD card may be /dev/sdb. Due to the installation process of Raspbian, the SD card will have multiple partitions on it. The root partition may be the 6th partition, so the actual device you need may be /dev/sdb6. We'll mount this partition to the /mnt/destin directory.
That partition is currently holding the root file system of Raspbian. As it stands, the system is fully bootable, but we want to run Fedora. In the boot partition, all the files required to boot the OS properly already exists now, since we did a standard install. If we remove that partition, and recreate one where we drop the Fedora root system into it we'll be able to run the OS of our choice. Before we do that though there are two things we will need to make a copy of.
- The current /etc/fstab file of Raspbian
- A modules folder under /libs/modules
- This folder will have '-v7+' at the end of the folder name
Now that we have those copies, the rest of the root filesystem is uneeded, so go ahead and use your favorite partition manager (e.g. fdisk, gparted, etc...) and delete the root filesystem partition and create a new one with a format of ext4.
Now comes the part where we load Fedora onto the SD card. You'll need to download a version of Fedora from their ARM project page. As of this writing, Fedora-Minimal-armhfp-22-3-sda.raw.xz was used to install the operating system. Whichever version you download they will be compressed with xz. To uncompress it, the simplest way is to issue a command with the following format
- xzcat Fedora-Minimal-armhfp-22-3-sda.raw.xz >> Fedora.raw
The 'Fedora.raw' file will contain multiple partitions as it is a file backup of an installed system. At this point it is recommended you install 'gdisk' as 'fdisk' will not always give the correct numbers needed, as will be explained in a bit. If you issue the command "gdisk -l Fedora.raw" you will receive output like the following
This displays the partitioning layout the .raw file is preserving. Right now, the important one we want is the third line listing. That partition holds the root filesystem that we will put on the SD card to run Fedora. But in order to access the data we will have to mount that partition as if it was a physical disk. Since it's a file though, we'll have to get a little crafty.
You'll notice two of the column headings are 'Start (sector)' and 'End (sector)'. We're looking at what is stored in the 'Start' column. Those numbers represent how many sectors into the hard disk the partition is 'physically' located. To mount it to gain access it, we will have to give a offset number so it knows to begin the mount at a certain point, otherwise it won't be able to work correctly. Before we can mount it though, we need to do a little math.
On a harddrive, there are a certain amount of sectors which can actually hold data, and in the file system each sector is 512 bytes apart. So in order to get the correct offset number, we have to multiple the starting sector number by 512 to find where the mount will have to 'begin' to find the data we're looking for. In this case:
- 1087488 * 512 = 556793856
- mount -o ro,loop,offset=556793856 Fedora.raw /mnt/source
- Read-Only. Makes it so we can only read from the source. Using 'rw' instead would allow us to write changes, but we don't need that for our purposes.
- mounts the file as a 'loop' device, otherwise the system would sequentially read through all the data and not know how to return to the beginning so we can read additional data out.
- Wikipedia Loop Device
- This is where we tell the machine where to begin looking for a file system inside the file.
- cp -R /mnt/source/* /mnt/destin
- umount /mnt/source
- umount /mnt/destin