Changes between Version 12 and Version 13 of BuildingImages

Show
Ignore:
Timestamp:
06/23/09 01:41:46 (15 months ago)
Author:
ppronchery (IP: 83.236.217.161)
Comment:

Completed merge of strap:1 paper

Legend:

Unmodified
Added
Removed
Modified
  • BuildingImages

    v12 v13  
    132132=== Packages configuration === 
    133133 
    134 The configuration of packages is found [http://trac.hackable1.org/trac/browser/trunk/build/packages here]. There is one file per package, and they are sourced after the extraction process if they are installed. They can have a different logic depending on the target platform and actual purpose of the image. 
    135  
    136 == Known problems == 
    137  
    138 === Dependency resolving is not perfect === 
    139  
    140 Dependencies are not resolved recursively at the moment. They rely on proper information from the `Packages.gz` files. 
    141  
    142 === Installation hook scripts are not executed === 
    143  
    144 There's no simple way around this one. It needs to be duplicated in the configuration files as described above. 
     134As packages are simply extracted into the staging directory before 
     135building the actual image, they are configured with their default 
     136settings, or sometimes not at all. Each package can be configured inside 
     137the packages directory, within a shell script of the same name. 
     138 
     139These shell scripts rely on a number of variables. The options defined 
     140above can be used to alter the behaviour of the scripts, and hence the 
     141final configuration of the images to be generated (eg the 
     142VENDOR-MODEL-PURPOSE profile). 
     143 
     144Other essential commands are available, and can be overriden as well: 
     145 
     146||'''Variable'''||'''Description'''|| 
     147||AR||Create, analyze and extract archives|| 
     148||CHMOD||Change the permissions of files and directories|| 
     149||CHOWN||Change the ownership of files and directories|| 
     150||CP||Copy files and directories|| 
     151||CUT||Process text data on the command-line|| 
     152||DU||Query the disk space used by files and directories|| 
     153||GREP||Look for given text patterns in files or on the command-line|| 
     154||GUNZIP||Decompress files|| 
     155||LN||Create and modify hard and symbolic links|| 
     156||MKDIR||Create directories|| 
     157||MKNOD||Create device nodes|| 
     158||MV||Rename and move files and directories|| 
     159||RMDIR||Delete directories|| 
     160||RM||Delete files and directories|| 
     161||SED||Replace content in files or on the command-line|| 
     162||STRIP||Remove debugging|| 
     163||TAR||Create, analyze and extract archives|| 
     164||TOUCH||Create files and alter timestamps|| 
     165||WGET||Download files over HTTP or FTP|| 
     166 
     167Some examples follow. 
     168 
     169Within packages/base-passwd: 
     170 
     171{{{ 
     172#/etc/passwd 
     173$SUDO$MKDIR "$DESTDIR/home/$USERNAME"                           || exit 2 
     174$SUDO$CHMOD 0750 "$DESTDIR/home/$USERNAME"                      || exit 2 
     175$SUDO$CHOWN 1000:1000 "$DESTDIR/home/$USERNAME"                 || exit 2 
     176${SUDO}sh -c "cat > \"$DESTDIR/etc/passwd\"" << EOF 
     177root:x:0:0:root:/root:/bin/sh 
     178$USERNAME:x:1000:1000:Hackable1 user:/home/hackable1:/bin/sh 
     179EOF 
     180}}} 
     181 
     182Within packages/bluez-utils: 
     183 
     184{{{ 
     185#/etc/rc?.d/S25bluetooth 
     186for i in 2 3 4 5; do 
     187        $SUDO$MKDIR "$DESTDIR/etc/rc$i.d"                       || exit 2 
     188        $SUDO$LN -s "../init.d/bluetooth" 
     189"$DESTDIR/etc/rc$i.d/S25bluetooth" \ 
     190                                                                || exit 2 
     191done 
     192}}} 
     193 
     194Within packages/fakeroot: 
     195 
     196{{{ 
     197#/usr/bin/fakeroot 
     198$SUDO$MKDIR "$DESTDIR/etc/alternatives" "$DESTDIR/usr/bin"      || exit 2 
     199$SUDO$LN -s "/usr/bin/fakeroot-tcp" "$DESTDIR/etc/alternatives/fakeroot" \ 
     200                                                                || exit 2 
     201$SUDO$LN -s "/etc/alternatives/fakeroot" "$DESTDIR/usr/bin/fakeroot" \ 
     202                                                                || exit 2 
     203}}} 
     204 
     205 
     206== Generating images == 
     207 
     208The operational mode of strap1 is fairly simple, and can be decomposed 
     209this way: 
     210 
     211 1. Resolve and cache dependencies 
     212 1. Extract the required packages 
     213 1. Create the device nodes 
     214 1. Configure the packages installed 
     215 1. Clean up the filesystem as required 
     216 1. Generate the final image 
     217 
     218 
     219=== Packages dependencies === 
     220 
     221Debian packages repositories contain a Packages file, gathering the 
     222meta-data from the different packages in one convenient place. This is 
     223particularly welcome when resolving dependencies, and therefore listing 
     224the packages to be installed. There are a few relevant parameters there: 
     225 
     226 * priorities: the essential packages have a particular "Priority" header, like "required", "important" or "standard"; if it matches PACKAGES_PRIORITY, the packages gets selected; 
     227 * dependencies: the "Depends", "Pre-Depends" and "Recommends" headers are also used to select packages. 
     228 
     229Two files are created during this process: 
     230 
     231 * depends/VENDOR-MODEL-PURPOSE.Depends 
     232 * depends/VENDOR-MODEL-PURPOSE.Packages 
     233 
     234The "Depends" file contains the list of the packages selected for 
     235inclusion, while the "Packages" file gathers all of the meta-data in one 
     236file. The latter resembles dpkg's "available" file. 
     237 
     238 
     239=== Packages extraction === 
     240 
     241Debian packages consist of an ar archive, with a meta-data archive 
     242member, and an optional archive to decompress. The extraction is 
     243performed without the dpkg tool, using the ar, gzip, bzip2 and tar 
     244utilities as required. 
     245 
     246The packages database is completed at the same time, always appending 
     247information to the "available" database, and appending information to 
     248the "status" database for the packages extracted. The list of files 
     249extracted, and the package meta-data is also placed in 
     250"/var/lib/dpkg/info". Minor modifications to ar's output are also 
     251necessary to format the "package.list" file properly. 
     252 
     253 
     254=== Device nodes creation === 
     255 
     256At this stage, device nodes are created. The regular device node 
     257creation script from Debian is used in this process, with the 
     258appropriate architecture specified on the command line. 
     259 
     260This phase is only performed if the sbin/MAKEDEV script was installed on 
     261the target platform. Otherwise, it has to be performed from within the 
     262packages configuration scripts. 
     263 
     264This phase is the only one currently known not to be portable. It is 
     265automatically skipped by Debian's device node creation script when it 
     266detects a non-Linux system. 
     267 
     268 
     269=== Configure the packages installed === 
     270 
     271As packages get extracted, they also need to be configured in the 
     272context of the image generated. Many packages also actually require some 
     273scripts and executables to be ran right before or after extraction. 
     274 
     275Unfortunately, in the case of hackable:1, the staging filesystem is 
     276often compiled for a different architecture than the native host. It is 
     277therefore impossible to run the configuration scripts. Instead, the 
     278necessary steps are reproduced within the "packages" directory. 
     279 
     280For each configuration script found in the "packages" directory, it is 
     281checked if the package of the same name was actually installed on the 
     282filesystem (by testing the presence of the 
     283"/var/lib/dpkg/info/package.list" file). If it is the case, the 
     284configuration script is sourced from within the build.sh script. 
     285 
     286It is possible to reproduce this phase at will, using the "config" 
     287target of the build.sh script. Beware that this can only work if the 
     288packages database information was kept (eg without the CLEAN_APT option 
     289set to "yes"). 
     290 
     291=== Clean up the filesystem as required === 
     292 
     293Some operations can then be conducted in order to gain space. They were 
     294mentioned in the 2.2 section: 
     295 
     296||'''Variable'''||'''Description'''|| 
     297||CLEAN_APT||Deletes everything in /var/lib/dpkg|| 
     298||CLEAN_DEVEL||Deletes /usr/include, /usr/lib/pkgconfig, /usr/lib/*.a...|| 
     299||CLEAN_DOC||Deletes /usr/share/doc, /usr/share/man...|| 
     300||CLEAN_KERNEL||Deletes /boot|| 
     301||CLEAN_LOCALES||Deletes /usr/share/locales|| 
     302||CLEAN_STRIP||Strips all the binaries found in /usr/bin, /usr/lib...|| 
     303 
     304 
     305=== Generate the final image === 
     306 
     307Lastly, the filesystem is either saved as a compressed tar archive (the 
     308"archive" target), or packed as a ready-to-flash software image (the 
     309"image" target). Unfortunately, this phase is currently hard-coded 
     310within the build.sh script. 
     311 
     312 
     313== Comparison with debootstrap == 
     314 
     315In fact, strap1 implements parts of deboostrap, and extends it in some 
     316regards. 
     317 
     318=== Why debootstrap is not enough === 
     319 
     320deboostrap is also useful to create Debian systems from scratch, without 
     321requiring dpkg or apt either. It is actually used by the Debian 
     322installer to initialize the system being installed. debootstrap consists 
     323of several thousands of lines of perl, of which cdebootstrap is an 
     324alternative implementation in C. 
     325 
     326However, both assume that the installer will resume the installation by 
     327chrooting to the target system, and then install and configure packages 
     328using the native tools. In many cases, this is not likely during 
     329embedded development. 
     330 
     331 
     332=== Limitations of debootstrap === 
     333 
     334First, in Debian packages the configuration process is relying on the 
     335possibility to run native binary programs from within the target system. 
     336This is used to either automatically detect, or ask the user 
     337specifically the settings to apply. 
     338 
     339Moreover, debootstrap can not conveniently be used to generate systems 
     340from multiple source repositories. It is also not able to initialize the 
     341packages database as well as apt does itself. 
     342 
     343Finally, debootstrap stops at the packages extraction phase. It does not 
     344provide filesystem images ready to flash, nor a way to conveniently 
     345automatically reproduce images from updated packages. 
     346 
     347 
     348=== Advantages of strap1 === 
     349 
     350strap1 addresses some of these issues already: 
     351 
     352 * it can use multiple package repositories at once 
     353 * it can generate valid packages databases, almost as complete as what apt does itself 
     354 * it can configure packages cross-platform 
     355 * it can generate final images. 
     356 
     357It is also very portable, and easy to extend: it consists only of a 
     358simple core script, along with individual profiles and configuration files. 
     359 
     360 
     361== Remaining issues == 
     362 
     363=== Incomplete dependencies === 
     364 
     365Dependencies are not resolved recursively at the moment (this problem is 
     366also found in debootstrap). The images generated may therefore be 
     367incomplete in some cases. 
     368 
     369=== Device nodes creation === 
     370 
     371Device nodes creation is not portable across Unix systems. This can 
     372sometimes be work-arounded with a tar archive of the necessary nodes, 
     373however it cannot be conveniently forced during the process at the moment. 
     374 
     375=== Not always embedded === 
     376 
     377The stock Debian packages may not always fit in an embedded environment. 
     378More cooperation with the Emdebian project is certainly desirable. 
     379 
     380=== Performance === 
     381 
     382The overall performance could be improved.