qi-emdebian

README.txt

15:a453943c42de
2016-11-26 Paul Boddie Updated the documentation for Debian Jessie.
     1 {{infobox|This is currently a work in progress. The objective is to make a reliable set of instructions that can be used to provide a directly bootable Emdebian system. See the [[#Further Work|"Further Work"]] section for areas of improvement.}}
     2 
     3 [http://www.emdebian.org/ Emdebian] is a project that traditionally provided cross-compilation toolchains, tools for cross-building packages, and tools for making root filesystems for deployment on devices, particularly embedded devices with "foreign" architectures. Such tools permit the time-consuming and resource-intensive work of preparing a system image to be done on "normal" personal computers and workstations, with the finished result then being deployed on the target device. Many of the things developed under the Emdebian umbrella are now provided in Debian itself, and thus Emdebian is no longer really distinct from Debian and is certainly not a separate distribution (as it once was).
     4 
     5 The approach cultivated by Emdebian is to draw upon the extensive selection of Debian packages that are already available, up-to-date, and maintained for a selection of architectures, rather than to cross-build an entire distribution from scratch and either offer a monolithic result or one which offers less sophisticated methods for managing the deployed software. By building on Debian, it should be possible to benefit from the considerable effort invested in Debian packaging by the community and be able to obtain usable packages for specific technologies without being obliged to take on the work of tracking upstream development, dependency relationships, fixing portability issues, and performing packaging work just to be able to use some particular piece of software.
     6 
     7 == The Workflow ==
     8 
     9 Making an installable Emdebian system involves the following steps:
    10 
    11 # Obtain the necessary tools.
    12 # Obtain a kernel image.
    13 # Choose a suitable configuration.
    14 # Prepare a root filesystem.
    15 # Configure the installation.
    16 # Format the boot medium.
    17 # Complete the installation.
    18 # Boot into the new system.
    19 
    20 === Obtaining the Tools ===
    21 
    22 To prepare a root filesystem, the [http://wiki.debian.org/Multistrap multistrap] tool is needed. On Debian-based systems, this tool should be available from the usual package repository, and can thus be installed as follows:
    23 
    24  apt-get install multistrap
    25 
    26 Since multistrap is under active development, it may be the case that a later version of the tool is required. If this proves to be the case when following these instructions, you may need to enable the appropriate "backports" repository (using <code>/etc/apt/sources.list</code> and/or <code>/etc/apt/sources.d</code>), update the packaging system...
    27 
    28  apt-get update
    29 
    30 ...and then try to install such a newer version. If no readily available newer version exists in a usable repository, you may need to backport the package from a later Debian release. Such an activity is currently outside the scope of this document.
    31 
    32 ==== Downloads ====
    33 
    34 The scripts and files related to this activity are provided in the following archive:
    35 
    36 [[File:Qi-emdebian.tar.gz]]
    37 
    38 A [http://hgweb.boddie.org.uk/qi-emdebian repository] also provides the scripts and files in their different versions.
    39 
    40 === Obtaining a Kernel Image ===
    41 
    42 It can be easier to obtain an existing kernel image prepared by the [[Building Software Image|OpenWrt-based toolchain]], typically called <code>openwrt-xburst-qi_lb60-uImage.bin</code> and found in the [http://downloads.qi-hardware.com/software/images/NanoNote/Ben/ software image release folders].
    43 
    44 With the existing available kernels, there should be no need for any kernel modules to get started. However, the intention is to provide a more reliable way of obtaining the kernel and any additional modules using either the appropriate Debian packages or through other methods.
    45 
    46 === Choosing a Configuration ===
    47 
    48 The multistrap package and documentation provide several example configurations. However, a specific configuration for the NanoNote should look like this for the Debian Jessie release:
    49 
    50 <pre>
    51 [General]
    52 arch=mipsel
    53 cleanup=true
    54 noauth=false
    55 bootstrap=Debian
    56 aptsources=Debian
    57 
    58 [Debian]
    59 packages=sysvinit-core
    60 packages=udev busybox-static
    61 source=http://ftp.debian.org/debian
    62 keyring=debian-archive-keyring
    63 suite=jessie
    64 </pre>
    65 
    66 This minimal configuration installs a base system from Debian packages. (Previously, qi-emdebian used special Emdebian Grip packages which were meant to be smaller than conventional Debian packages, but the Emdebian project considered the effort of producing such packages for an arguably marginal benefit to be a costly distraction from other work.) In addition, the <code>udev</code> and <code>busybox-static</code> packages are added; this latter package is essential for the initial configuration of the system. Various other packages may be needed in practice, and so example files for various distributions are provided in the [http://hgweb.boddie.org.uk/qi-emdebian/file/tip/conf qi-emdebian distribution] for guidance.
    67 
    68 {{infobox|It is important to note that for Debian Jessie, systemd provides the init system. Where older kernels are used on the NanoNote, such as the default OpenWrt kernels, this will most likely cause the system to hang when booting because systemd requires kernel features that were not previously enabled. One solution is to specify <code>sysvinit-core</code> in the package list, thus continuing the use of the init system previously enabled by default in Debian.}}
    69 
    70 === Preparing a Root Filesystem ===
    71 
    72 With a suitable configuration file called, for example, <code>multistrap-jessie-mipsel.conf</code> a root filesystem can be constructed in a location such as <code>rootfs</code> as follows. Note that you must be <code>root</code> or use <code>sudo</code> for this to work properly. Multistrap may ask for elevated privileges.
    73 
    74  multistrap -f multistrap-jessie-mipsel.conf -d rootfs
    75 
    76 If this operation fails with errors related to repository public keys, you may need to install a newer version of multistrap as described above. A selection of configuration files can be found in the <code>conf</code> directory in the qi-emdebian distribution.
    77 
    78 === Configuring the Installation ===
    79 
    80 On its own, multistrap does not provide all the files required for a running system. Moreover, a filesystem prepared by the tool will not be configured, and any attempt to boot into such a filesystem will probably fail. Thus, additional configuration must be performed.
    81 
    82 ==== Conventional Configuration Files ====
    83 
    84 A number of configuration files, missing from the root filesystem, must be defined for the installation:
    85 
    86 * <code>/etc/fstab</code>
    87 * <code>/etc/hostname</code>
    88 * <code>/etc/network/interfaces</code>
    89 * <code>/etc/resolv.conf</code>
    90 
    91 Such files can be placed in a directory called, for example, <code>files</code> while retaining the necessary filesystem structure, so that <code>fstab</code> would reside at <code>files/etc/fstab</code>, and so on. This reflects their typical locations in a real system.
    92 
    93 ==== Pre-Initialisation Files ====
    94 
    95 Two additional files called <code>preinit</code> and <code>preinit-config</code> are required that "glue" the kernel to the Debian system on the first boot of the system. These files must reside in the current directory when running the script below. The <code>preinit</code> file is a convention apparently employed by the OpenWrt distribution used on the NanoNote, and where kernels from other origins are to be used, it is important that the appropriate conventions for invoking the system <code>init</code> program are followed. Thus, if you switch to a different kernel from another project, you may need to change the <code>qi-emdebian-postsetup</code> script to install these files into other locations, potentially giving them different names.
    96 
    97 {{infobox|It is important to realise that due to the state of various essential packages as deployed by multistrap, the init system cannot be run immediately: not even the default shell is configured at initial boot. Consequently, a means of running a shell is required for the package configuration process, and only then may the init process be started. The solution to this configuration problem is provided by installing the <code>busybox</code> package and having the shell it provides be the one to run the pre-initialisation scripts.}}
    98 
    99 ==== Running the Script ====
   100 
   101 With the missing files now defined, a script written to automate the remaining configuration activity can be run as follows. Again, it may help to be <code>root</code> or to use <code>sudo</code> to be able to copy the necessary files into the root filesystem:
   102 
   103  qi-emdebian-postsetup rootfs openwrt-xburst-qi_lb60-uImage.bin files
   104 
   105 Here, <code>rootfs</code> is the root filesystem created above, <code>openwrt-xburst-qi_lb60-uImage.bin</code> is the kernel image obtained above, and <code>files</code> is the directory containing the missing configuration files.
   106 
   107 === Formatting the Boot Medium ===
   108 
   109 Currently, only booting from a microSD card is described in these instructions. Eventually, installation to NAND may also be covered.
   110 
   111 The microSD card should first be made available to the computer performing this work. On a Linux-based system, it should then appear as a device like <code>/dev/sdb</code>. You should check and '''make absolutely sure''' that you know which device has been assigned to the microSD card, perhaps using the <code>dmesg</code> command to see what is reported when plugging in the card. For example:
   112 
   113 <pre>
   114 [25942.832101] sd 20:0:0:0: [sdb] Attached SCSI removable disk
   115 [25942.832148] sd 20:0:0:0: Attached scsi generic sg2 type 0
   116 </pre>
   117 
   118 With this information, you can now partition the card using <code>fdisk</code>. First, as <code>root</code> or using <code>sudo</code>, run the following to look for existing partitions:
   119 
   120  fdisk -l /dev/sdb
   121 
   122 If the microSD card already has partitions, you should check to see if they have been mounted by the system:
   123 
   124  mount
   125 
   126 If so, you must first unmount the corresponding devices as follows (as <code>root</code> or using <code>sudo</code>):
   127 
   128  umount /dev/sdb1
   129 
   130 To preserve existing partitions, you can copy them from the card to your system as follows (as <code>root</code> or using <code>sudo</code>):
   131 
   132  dd if=/dev/sdb1 of=sdb1.backup
   133 
   134 To add a new partition, run <code>fdisk</code>, use the <code>n</code> command to make a primary partition, and then the <code>w</code> command to write the partition table. Since <code>fdisk</code> will probably suggest a reasonable start of a partition, perhaps the biggest concern is the size of the partition. Choosing <code>+1024M</code> to indicate a partition of 1024MB or 1GB is not unreasonable for modern microSD cards and current Emdebian installations.
   135 
   136 It is also possible to accept the partition size suggested by <code>fdisk</code> and assign all the space on the card to a partition as well. This may not be sensible, however, since it may make some operations slower and hinder alternative uses for the space (like the creation of other partitions for purposes like backups).
   137 
   138 ==== Swap Partition ====
   139 
   140 Debian programs can use a lot of memory - more than the 32MB of program memory that the NanoNote has available - and so it becomes necessary to allocate additional swap memory so that all running programs can fit in memory. Making a swap partition is largely the same process as that described above for the root partition, but it is likely that you will want to choose a much smaller size. 128M is likely to be enough for the NanoNote: anything larger is probably entertaining a misplaced belief that the computer is powerful to efficiently run the kinds of programs needing such larger amounts of memory.
   141 
   142 If you create a swap partition, be sure to edit the <code>files/etc/fstab</code> file and to remove the comment marker for the line describing the <code>swap</code> partition.
   143 
   144 === Completing the Installation ===
   145 
   146 With a partition in place (<code>/dev/sdb1</code> in this case), you can now run the following helper script (as <code>root</code> or using <code>sudo</code>):
   147 
   148  qi-emdebian-install rootfs /dev/sdb1 --mkfs
   149 
   150 This will make a filesystem in the partition and copy the root filesystem to the card. You should then eject the card as follows (adjusting for the appropriate device name):
   151 
   152  eject sdb
   153 
   154 === Booting into the New System ===
   155 
   156 To boot into the newly prepared system, insert the microSD card into the NanoNote's card slot, then hold down the M key while pressing the power button. The device should now report that it is loading <code>"/boot/uImage" from mmc device</code>. With the conventional OpenWrt-based kernel, the boot splash-screen (or bootsplash) will take up most of the display, but messages will appear at the bottom of the screen.
   157 
   158 If everything goes according to plan, a few minutes will be required for the configuration of the system to be done by the device - this is an issue with installing and booting Debian for the first time - but eventually, a message at the bottom of the screen should read something like...
   159 
   160  nanonote login:
   161 
   162 This indicates that the system is now ready to allow you to log in. You should be able to do so as <code>root</code> without providing a password. It is then your responsibility to set a password using the <code>passwd</code> command.
   163 
   164 === Further Configuration ===
   165 
   166 To set the clock to a UTC time, run the following command:
   167 
   168  date -u -s '2015-06-17 13:08:00'
   169 
   170 To set the time zone, run the following:
   171 
   172  dpkg-reconfigure tzdata
   173 
   174 It may be easier to run this command via a secure shell (ssh) connection to the NanoNote from a computer with a larger screen.
   175 
   176 To set up a default locale or to change the locales and their settings, install the appropriate package and reconfigure it:
   177 
   178  apt-get install locales
   179  dpkg-reconfigure locales
   180 
   181 == Further Work ==
   182 
   183 Things to be added include...
   184 
   185 * A selection of sample configuration files plus other files like hostname, group, and so on
   186 * Network configuration
   187 * A proper way of getting a kernel and modules (perhaps using Debian-centric methods)
   188 * Information about essential packages already provided by the existing [[OpenWrt Software Image|software image]]
   189 * Package fixes, such as the use of integer-only libraries for Vorbis decoding, for example
   190 
   191 The initial configuration process should be improved to give nicer visual feedback. Currently, the screen is cleared and the configuration activity is reported to the console. It might be convenient to allow interactivity using the usual curses-based textual user interface that Debian uses when configuring packages.
   192 
   193 === Initial Root Filesystems ===
   194 
   195 Use of a separate [http://www.kernel.org/doc/Documentation/initrd.txt initial root filesystem] has been suggested. [http://www.mobileread.com/forums/showthread.php?t=99021 Installing a "normal" Debian ARMEL Linux on the Kindle] provides one recipe for making such a filesystem. There is also a Debian package - [http://packages.debian.org/jessie/initramfs-tools initramfs-tools] - which might be of interest, although it seems to be limited to copying files around for the same architecture. There is also [http://wiki.debian.org/InitrdReplacementOptions a comparison] between initramfs-tools and [http://packages.debian.org/sid/yaird yaird]. Another related tool is [http://packages.debian.org/jessie/debirf debirf].
   196 
   197 === Related Documents ===
   198 
   199 A document somewhat similar to this one, but employing debootstrap is [http://foxg20old.acmesystems.it/doku.php?id=debian:how_to_cross_compile_a_kernel_and_create_the_debian_root_file_store How to Cross Compile a Kernel and Create the Debian Root File Store]. Another similar document describing an initial root filesystem is [http://whiteboard.ping.se/Android/Debian How to run Debian or Ubuntu GNU/Linux on your Android]. And [http://cblfs.cross-lfs.org/index.php/Creating_an_Initramfs Creating an Initramfs] also provides some useful hints.
   200 
   201 [[Category:Ben NanoNote]]