Difference between pages "System resurrection" and "Funtoo Linux Installation on ARM"

From Funtoo
(Difference between pages)
Jump to: navigation, search
 
 
Line 1: Line 1:
Although it is always possible to resurrect a machine back to life by reinstalling it, it is not always suitable to reinstall from scratch. Sometimes the best approach is to try to repair, or "resurrect," a broken system so that is it fully functional again. This document will show you how to resurrect a broken Funtoo system without reinstalling everything from scratch.
+
Funtoo now provides [http://ftp.osuosl.org/pub/funtoo/funtoo-current/arm-32bit/ stage3 images] for arm platform. At this time are only armv6j_hardfp and armv7a_hardfp stages available. If you would like us to support other processors (see the list below), please fill a bug report on [http://bugs.funtoo.org].
+
== Building binary packages ==
+
  
The best approach for critical system repair is to boot on a SystemRescueCD or other similar LiveCD, and use this as working platform to resurrect your system.
 
  
For creating binary packages, you can use any of the following for a ''source environment'':
+
== List of ARM processor "flavors" ==
 +
* armv4l-unknown-linux-gnu (Rebel NetWinder, HP Armada and other devices having an ARMv4 processor, which is only capable of running the old ABI. Nevertheless it should work on newer CPUs)
 +
* armv4tl-softfloat-linux-gnueabi (OpenMoko FreeRunner and other devices using an ARMv4T processor. Uses the new ARM EABI and software floating point by default)
 +
* armv5tel-softfloat-linux-gnueabi (almost all ARM NAS, devices based on the Marvell Orion and Marvell Kirkwood, Marvell Sheevaplug, Marvell OpenRD, Guruplug, Dreamplug, QNAP TS109/TS209/TS409/TS119/TS219/TS419, Buffalo Linkstation/Kurobox PRO, HP mv2120, HP iPAQ, Linksys NSLU2 and other devices using an ARMv5TE processor. Uses the new ARM EABI and software floating point by default)
 +
* armv6j-unknown-linux-gnueabi ([[Raspberry Pi]], Nokia N800/N810, Smart Q7, OMAP2-based devices and other multimedia devices using an ARMv6 CPU and VFP. Uses the new ARM EABI and hardware floating point by default)
 +
* armv7a-unknown-linux-gnueabi (OMAP3-based devices(Beagleboard, IGEPv2, Devkit8000, AlwaysInnovating Touchbook, [[Nokia N900]]), OMAP4-based devices([[Pandaboard]]), Freescale i.MX515-based devices([[Efika MX]], Babbage Board, Lange Board…) Marvell Dove/Armada, Nvidia Tegra2-based devices(Toshiba AC100, Toshiba Folio), ST-Ericsson NOVA A9500-based devices(Snowball), Exynos 4412 ([[Odroid-X]], Odroid-Q, [[ODROID U2]]) and other devices using an ARMv7-A processor. Uses the new ARM EABI and generic(not NEON) hardware floating point by default
 +
* armv7a-hardfloat-linux-gnueabi (The same as armv7a-unknown-linux-gnueabi, but this one uses hardfloat instead of softfp. Read more about it here: http://wiki.debian.org/ArmHardFloatPort)
  
* Use the most recent Funtoo stage3 for your architecture
+
== Default installation of Funtoo on your platform/board ==
* If available, use a recent system backup (tar or cpio archive) or snapshot
+
This document is not a complete installation tutorial. Basic information about Funtoo Linux installation can be found on [[Funtoo Linux Installation]]. The goal of this document is to provide general information about installing Funtoo Linux on an ARM device, and highlight differences with a x86 installation.
  
On a working Linux system, which can be either your broken system booted with a LiveCD, or any type of Linux system on your network with similar processor, you will want to build a chroot environment using the "source environment" you selected above, and use this as a platform for building binary packages to restore your system. Once these packages are created, they can be copied to your broken system and installed using the steps later in this document.
+
The following notes are non-board specific. Other instructions can be found in the specific articles for the above mentioned devices.
  
The binary package creation environment would typically be set up as follows:
+
=== Overview ===
 +
Most of the ARM boards come with a SD card slot, so you will need an empty SD card (4GB is enough to get you started), in most cases the boards are also equipped with debug port which can be used with USB-to-serial cables, if you have one, you can use it to login to the machine without the need of connecting keyboards or displays. You will need a network connection to be able to download stages, kernel and update your portage tree.
  
<pre>
+
=== Kernel and bootloader setup ===
# install -d /mnt/rescue
+
Before you start you will need a kernel and a bootloader for your device. Some of the devices look for bootloader (in most cases U-Boot) on the SD along with the kernel.
# tar xpvf backup.tar.bz2 -C /mnt/rescue
+
# cp /etc/resolv.conf /mnt/rescue/etc
+
# mount --bind /proc /mnt/rescue/proc
+
# mount --bind /sys /mnt/rescue/sys
+
# mount --bind /dev /mnt/rescue/dev
+
# mount --bind /dev/pts /mnt/rescue/dev/pts
+
# chroot /mnt/rescue
+
# source /etc/profile
+
# env-update
+
</pre>
+
  
No matter of the way you jump in a functional Funtoo/Gentoo environment, the magic command to create a binary package archive once inside is to use the <tt>quickpkg</tt> command. <tt>quickpkg</tt> will capture the package in the exact form it is actually deployed on the environment and create an archive of it placed in <tt>/usr/portage/packages/<package-category>/<package-name>-<package-version>.tbz2</tt>.  
+
More information about the kernel and bootloader can be found on pages specific for your device.
  
In the following example capture everything installed within the "source environment" that is related <tt>sys-devel/gcc</tt> (4.4.5 is present on the system) is captured in a single archive named gcc-4.4.5.tbz2 located in <tt>/usr/portage/packages/sys-devel</tt>:
+
=== Installing Funtoo (overview) ===
  
<pre>
+
The installation on these devices differs from the normal installation procedure of booting an installation environment and chrooting from there to your new root, and can be little bit easier, but in some cases tricky.
# quickpkg sys-devel/gcc
+
</pre>
+
  
If you need to recompile a package instead of archiving an already deployed version (and of course without installing it on your "source environment"), just do:
+
Overview of the installation:
 +
* Extract stage3 to the 2nd partition of the SD card
 +
* Extract portage snapshot
 +
* Setup fstab
 +
* Setup root password
 +
* Configure hostname and networking (optional, but recommended)
 +
* Enable SSH access (optional, but recommended)
 +
* Enable serial console access (optional, but recommended)
 +
* Correct RTC "bug" with swclock
  
<pre>
+
==== Installing the Stage 3 tarball ====
# emerge --buildpkgonly sys-devel/gcc
+
</pre>
+
  
== Restoring the binary packages on the broken system ==
+
ARM stage3 tarballs can be found on [http://ftp.osuosl.org/pub/funtoo/funtoo-current/arm-32bit/]. Use the subarchitecture that suits best your device.
  
There are a couple of methods that can be used to restore binary packages to a broken system.
+
Mount the partition that will hold your rootfs of the SD card and extract the stage3 you have downloaded.
  
=== Chroot/Emerge Method ===
+
<console>
 +
# ##i##mkdir /mnt/SD_root
 +
# ##i##mount /dev/sdcard-device-px /mnt/SD_root
 +
</console>
  
This first approach can be used for lightly damaged systems that still have a functional Portage and to which you can still <tt>chroot</tt> and perform all basic Linux commands. To use this method, you would mount your broken system to <tt>/mnt/broken</tt> using steps similar to the way we set up <tt>/mnt/rescue</tt>, above.
+
Extract the stage3 (it may take a while).
 +
<console>
 +
# ##i##tar xapf stage3-armv7a_hardfp-xxxx.tar.xz -C /mnt/SD_root
 +
</console>
  
Before or after chrooting, copy the binary packages created in the step above in the exact same location on your broken system (e.g. in <tt>/usr/portage/packages/'''sys-devel'''</tt> in the case of <tt>'''sys-devel'''/gcc</tt>).
+
==== Extracting a portage snapshot ====
  
Once chrooted inside your system, you will be able to merge your packages using <tt>emerge</tt> as follows:
+
Now, download the portage snapshot from [http://ftp.osuosl.org/pub/funtoo/funtoo-current/snapshots/], and extract it to your partition.
  
<pre>
+
<console>
# emerge -k  sys-devel/gcc
+
# ##i##tar xapf portage-latest.tar.xz -C /mnt/SD_root/usr
</pre>
+
</console>
  
=== Tbz2 Extract Method ===
+
==== Setup fstab ====
 +
Edit the <tt>/mnt/SD_root/etc/fstab</tt> file to look like this:
  
This alternate method for installing binary packages is simpler and does not require the use of the <tt>chroot</tt> command. To prepare for using this approach, you just need to mount all key filesystems to <tt>/mnt/broken</tt> as follows -- and bind mounts are not necessary:
+
{{File
 +
|/mnt/SD_root/etc/fstab|<pre>
 +
/dev/mmcblk0p1 /boot vfat noauto,noatime 1 2
 +
/dev/mmcblk0p2 / ext4 noatime 0 1
 +
</pre>}}
  
<pre>
+
Adjust the partition devices and types to suit your needs.
# install -d /mnt/broken
+
# mount /dev/sdaX /mnt/broken
+
# mount /dev/sdaY /mnt/broken/usr
+
</pre>
+
  
Then, use the following commands to extract the .tbz2 archive to your broken filesystem that you mounted at <tt>/mnt/broken</tt>:
+
==== Setting the default root password ====
  
<pre>
+
{{fancywarning|Don't skip this step. This part differs from the standard installation procedure, as the root password must be set outside of a chroot environment. Skipping this step will result in an impossibility to login.}}
# tar xjpvf gcc-4.4.5.tbz2 -C /mnt/broken
+
 
 +
Normally, for setting the password, one has to be able to run passwd. However that's not possible in this case since an x86 system can't run ARM binaries. Therefore, it is needed to modify the file that contains the passwords (<tt>/etc/shadow</tt>) to set a default root password.
 +
 
 +
===== Clearing the root password =====
 +
This will allow to login with a blank password for the root user.
 +
<console>
 +
# ##i##nano -w /mnt/SD_root/etc/shadow
 +
</console>
 +
 
 +
Modify the line beginning by "root" to match the following:
 +
 
 +
{{File
 +
|/mnt/SD_root/etc/shadow|<pre>
 +
root::10770:0:::::
 
</pre>
 
</pre>
  
You will see a note about the trailing garbage at the end of the file being ignored. This is normal -- tar is ignoring the Portage .tbz2 metadata that is tacked on to the end of the file.
+
{{fancywarning|After initial login, remember to change the root password using the passwd command.}}
  
At this point, you can set up bind mounts (see <tt>/mnt/rescue</tt> example earlier in this document for those steps), <tt>chroot</tt> inside <tt>/mnt/broken</tt>, and perform a few tests to determine if your issue has been resolved.
+
===== Choosing a root password (alternative) =====
  
= Fixing broken portage =
+
First, generate a password. The output of this command will be used to modify the shadow file.
sometimes <tt>sys-apps/portage</tt> may fail and the above <tt>binpkg</tt> mentioned way to ressurect system will not work because of portage being broken itself. To fix portage manually the following steps required:
+
 
<console>
 
<console>
# cd /tmp
+
# ##i##openssl passwd -1
tmp # wget https://www.github.com/funtoo/portage-funtoo/tarball/funtoo-2.3.3-r4
+
or
tmp # tar xf funtoo-2.3.3-r4
+
# ##i##python -c "import crypt, getpass, pwd; print crypt.crypt('password', '\$6\$SALTsalt\$')"
tmp # cd funtoo-portage-funtoo-84fe4a7
+
funtoo-portage-funtoo-84fe4a7 # rm -rf /usr/lib/portage/*
+
funtoo-portage-funtoo-84fe4a7 # cp -a bin pym /usr/lib/portage/
+
funtoo-portage-funtoo-84fe4a7 # ln -s /usr/lib/portage/bin/emerge /usr/bin/emerge
+
 
</console>
 
</console>
This will back a working portage again. To ensure everything is consistent re-emerge portage itself immediately.
+
 
 +
Then, edit the shadow file and use the output of the last command to replace "YOUR_PASSWORD_MD5".
 +
 
 
<console>
 
<console>
# emerge portage </console>
+
# ##i##nano -w /mnt/SD_root/etc/shadow
File collision warning, if any, can be skipped at this point.
+
</console>
= Critical System Packages =
+
  
 +
{{File
 +
|/mnt/SD_root/etc/shadow|<pre>
 +
root:YOUR_PASSWORD_MD5:14698:0:::::
 +
</pre>}}
  
Several packages at the heart of your Funtoo system, these mainly are:
+
==== Setup hostname and networking ====
  
{| {{Table}}
+
Please read the [[Funtoo Linux Networking]] to configure your network.
|-
+
!Component
+
!Package
+
!Functional role
+
|-
+
|GNU Binutils
+
|sys-devel/binutils
+
|Binutils are a set a tools (linker, assembler...) used behind the scene by the GNU Compiler Collection to produce executable files.
+
|-
+
|GNU Compiler collection (GCC)
+
|sys-devel/gcc
+
|GCC is a collection of compilers for several languages (FORTRAN, Java, C and C++, plus some libraries like the Standard Template Library or ''STL''). A wide spectrum of software in a Funtoo system is written in C/C++.
+
|-
+
|C Library
+
|sys-libs/glibc
+
|The C library contains an implementation of a wide range of commonly needed functionalities like memory allocation, strings manipulation, I/O operations and so on. It is maybe one of the most critical system components as nearly everything on a Funtoo system depends on this component (including the Python interpreter which executes the vairous Python scripts at the heart of the Funtoo core utilities and package management system).
+
|-
+
|Z library
+
|sys-libs/zlib
+
|This library contain several lossless compression/decompression routines.It is used by many other components on a Funtoo system like the bzip2/bunzip2 commands (app-arch/bzip2) for example (xz archive utilities depends on another standalone set of libraries).
+
|-
+
|Python
+
|dev-lang/python
+
|The Python interpreter is the heart of Portage as is written in Python (the same is also true for various second line utilities).
+
|}
+
  
= Various weird issues =
 
  
'''P1:''' I have a local distfiles mirror and wget complains about not being able to resolve 'localhost'. <br>
+
==== Using swclock ====
'''S1:''' libnss (which handles name resolution) is probably damaged or suffers of inconsistencies, in your /etc/make.conf, change 'localhost' in GENTOO_MIRRORS for 127.0.0.1 (IPv4) or ::1 (IPv6)<br>
+
One of the problems some of the devices have, is that they don't have a battery to save the clock time. To mitigate this, on Funtoo we have an option in our init system called swclock which sets the date of the system upon boot from a last modified date of a file.
 +
 
 +
 
 +
First, add swclock to the boot runlevel.
 +
<console>
 +
# ##i##ln -sf /etc/init.d/swclock /mnt/SD_root/etc/runlevels/boot
 +
</console>
 +
 
 +
Then, remove hwclock from the startup because it sets the date from the RTC, which is 2000-01-01 upon startup and overrides swclock's date.
 +
<console>
 +
# ##i##rm /mnt/SD_root/etc/runlevels/boot/hwclock
 +
</console>
 +
 
 +
swclock uses the <tt>/lib/rc/cache/shutdowntime</tt> modification time to set the date, therefore we update it to have the current date and time.
 +
<console>
 +
# ##i##touch /mnt/SD_root/lib/rc/cache/shutdowntime
 +
</console>
 +
 
 +
Although this doesn't fix the issue, at least helps to set a sane date and time.
 +
Note: Consider using NTP, documented on the next chapter
 +
 
 +
 
 +
==== Enabling SSH access (optional) ====
 +
Adding sshd to the default runlevel will enable access to the device using ssh (if network has been configured).
 +
 
 +
<console>
 +
# ##i##ln -sf /etc/init.d/sshd /mnt/SD_root/etc/runlevels/default
 +
</console>
 +
 
 +
If no network has been configured yet, it might be a good idea to add dhcpcd in the default runlevel as well.
 +
 
 +
<console>
 +
# ##i##ln -sf /etc/init.d/dhcpcd /mnt/SD_root/etc/runlevels/default
 +
</console>
 +
 
 +
==== Enabling serial console access (optional) ====
 +
By default the ttyS0 port is configured at 9600 bps. However, almost all of the ARM devices run the serial port at 115200 bps. Also, the port device names differ (ttyO2 for Pandaboard, ttySAC1 for Odroid-X ...). So edit your /etc/inittab file:
 +
 
 +
<console>
 +
# ##i##nano -w /mnt/SD_root/etc/inittab
 +
</console>
 +
 
 +
(For example for Pandaboard: )
 +
<pre>
 +
s0:12345:respawn:/sbin/agetty 115200 ttyO2 vt100
 +
</pre>
 +
 
 +
 
 +
=== Finishing the installation and booting up the new system ===
 +
Let's unmount the SD card.
 +
<console>
 +
# ##i##umount /mnt/SD_root
 +
</console>
  
'''P2:''' Same problem as described in P1 but I use another machine on my network or a public mirror on the Internet  <br>
+
Once you have the card ready, put it into your device, and you should be able to boot it. If you have a debug port you will be able to see the boot process using minicom or similar program on another PC connected with the debug cable.
'''S2:''' See the solution given in S1 but with providing the IP of the machine you are downloading for.
+
  
[[Category:Internals]]
 
[[Category:Portage]]
 
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
 +
[[Category:ARM]]

Revision as of 17:48, 28 January 2014

Funtoo now provides stage3 images for arm platform. At this time are only armv6j_hardfp and armv7a_hardfp stages available. If you would like us to support other processors (see the list below), please fill a bug report on [1].


List of ARM processor "flavors"

  • armv4l-unknown-linux-gnu (Rebel NetWinder, HP Armada and other devices having an ARMv4 processor, which is only capable of running the old ABI. Nevertheless it should work on newer CPUs)
  • armv4tl-softfloat-linux-gnueabi (OpenMoko FreeRunner and other devices using an ARMv4T processor. Uses the new ARM EABI and software floating point by default)
  • armv5tel-softfloat-linux-gnueabi (almost all ARM NAS, devices based on the Marvell Orion and Marvell Kirkwood, Marvell Sheevaplug, Marvell OpenRD, Guruplug, Dreamplug, QNAP TS109/TS209/TS409/TS119/TS219/TS419, Buffalo Linkstation/Kurobox PRO, HP mv2120, HP iPAQ, Linksys NSLU2 and other devices using an ARMv5TE processor. Uses the new ARM EABI and software floating point by default)
  • armv6j-unknown-linux-gnueabi (Raspberry Pi, Nokia N800/N810, Smart Q7, OMAP2-based devices and other multimedia devices using an ARMv6 CPU and VFP. Uses the new ARM EABI and hardware floating point by default)
  • armv7a-unknown-linux-gnueabi (OMAP3-based devices(Beagleboard, IGEPv2, Devkit8000, AlwaysInnovating Touchbook, Nokia N900), OMAP4-based devices(Pandaboard), Freescale i.MX515-based devices(Efika MX, Babbage Board, Lange Board…) Marvell Dove/Armada, Nvidia Tegra2-based devices(Toshiba AC100, Toshiba Folio), ST-Ericsson NOVA A9500-based devices(Snowball), Exynos 4412 (Odroid-X, Odroid-Q, ODROID U2) and other devices using an ARMv7-A processor. Uses the new ARM EABI and generic(not NEON) hardware floating point by default
  • armv7a-hardfloat-linux-gnueabi (The same as armv7a-unknown-linux-gnueabi, but this one uses hardfloat instead of softfp. Read more about it here: http://wiki.debian.org/ArmHardFloatPort)

Default installation of Funtoo on your platform/board

This document is not a complete installation tutorial. Basic information about Funtoo Linux installation can be found on Funtoo Linux Installation. The goal of this document is to provide general information about installing Funtoo Linux on an ARM device, and highlight differences with a x86 installation.

The following notes are non-board specific. Other instructions can be found in the specific articles for the above mentioned devices.

Overview

Most of the ARM boards come with a SD card slot, so you will need an empty SD card (4GB is enough to get you started), in most cases the boards are also equipped with debug port which can be used with USB-to-serial cables, if you have one, you can use it to login to the machine without the need of connecting keyboards or displays. You will need a network connection to be able to download stages, kernel and update your portage tree.

Kernel and bootloader setup

Before you start you will need a kernel and a bootloader for your device. Some of the devices look for bootloader (in most cases U-Boot) on the SD along with the kernel.

More information about the kernel and bootloader can be found on pages specific for your device.

Installing Funtoo (overview)

The installation on these devices differs from the normal installation procedure of booting an installation environment and chrooting from there to your new root, and can be little bit easier, but in some cases tricky.

Overview of the installation:

  • Extract stage3 to the 2nd partition of the SD card
  • Extract portage snapshot
  • Setup fstab
  • Setup root password
  • Configure hostname and networking (optional, but recommended)
  • Enable SSH access (optional, but recommended)
  • Enable serial console access (optional, but recommended)
  • Correct RTC "bug" with swclock

Installing the Stage 3 tarball

ARM stage3 tarballs can be found on [2]. Use the subarchitecture that suits best your device.

Mount the partition that will hold your rootfs of the SD card and extract the stage3 you have downloaded.

# mkdir /mnt/SD_root
# mount /dev/sdcard-device-px /mnt/SD_root

Extract the stage3 (it may take a while).

# tar xapf stage3-armv7a_hardfp-xxxx.tar.xz -C /mnt/SD_root

Extracting a portage snapshot

Now, download the portage snapshot from [3], and extract it to your partition.

# tar xapf portage-latest.tar.xz -C /mnt/SD_root/usr

Setup fstab

Edit the /mnt/SD_root/etc/fstab file to look like this:

{{{name}}}
{{{body}}}

Adjust the partition devices and types to suit your needs.

Setting the default root password

Warning: Don't skip this step. This part differs from the standard installation procedure, as the root password must be set outside of a chroot environment. Skipping this step will result in an impossibility to login.

Normally, for setting the password, one has to be able to run passwd. However that's not possible in this case since an x86 system can't run ARM binaries. Therefore, it is needed to modify the file that contains the passwords (/etc/shadow) to set a default root password.

Clearing the root password

This will allow to login with a blank password for the root user.

# nano -w /mnt/SD_root/etc/shadow

Modify the line beginning by "root" to match the following:

{{File

|/mnt/SD_root/etc/shadow|
root::10770:0:::::
Warning: After initial login, remember to change the root password using the passwd command.
Choosing a root password (alternative)

First, generate a password. The output of this command will be used to modify the shadow file.

# openssl passwd -1
or
# python -c "import crypt, getpass, pwd; print crypt.crypt('password', '\$6\$SALTsalt\$')"

Then, edit the shadow file and use the output of the last command to replace "YOUR_PASSWORD_MD5".

# nano -w /mnt/SD_root/etc/shadow
{{{name}}}
{{{body}}}

Setup hostname and networking

Please read the Funtoo Linux Networking to configure your network.


Using swclock

One of the problems some of the devices have, is that they don't have a battery to save the clock time. To mitigate this, on Funtoo we have an option in our init system called swclock which sets the date of the system upon boot from a last modified date of a file.


First, add swclock to the boot runlevel.

# ln -sf /etc/init.d/swclock /mnt/SD_root/etc/runlevels/boot

Then, remove hwclock from the startup because it sets the date from the RTC, which is 2000-01-01 upon startup and overrides swclock's date.

# rm /mnt/SD_root/etc/runlevels/boot/hwclock

swclock uses the /lib/rc/cache/shutdowntime modification time to set the date, therefore we update it to have the current date and time.

# touch /mnt/SD_root/lib/rc/cache/shutdowntime

Although this doesn't fix the issue, at least helps to set a sane date and time. Note: Consider using NTP, documented on the next chapter


Enabling SSH access (optional)

Adding sshd to the default runlevel will enable access to the device using ssh (if network has been configured).

# ln -sf /etc/init.d/sshd /mnt/SD_root/etc/runlevels/default

If no network has been configured yet, it might be a good idea to add dhcpcd in the default runlevel as well.

# ln -sf /etc/init.d/dhcpcd /mnt/SD_root/etc/runlevels/default

Enabling serial console access (optional)

By default the ttyS0 port is configured at 9600 bps. However, almost all of the ARM devices run the serial port at 115200 bps. Also, the port device names differ (ttyO2 for Pandaboard, ttySAC1 for Odroid-X ...). So edit your /etc/inittab file:

# nano -w /mnt/SD_root/etc/inittab

(For example for Pandaboard: )

s0:12345:respawn:/sbin/agetty 115200 ttyO2 vt100


Finishing the installation and booting up the new system

Let's unmount the SD card.

# umount /mnt/SD_root

Once you have the card ready, put it into your device, and you should be able to boot it. If you have a debug port you will be able to see the boot process using minicom or similar program on another PC connected with the debug cable.