- Using Interfaces (GPIO, UART, SPI, ...)
- Building an initial ramdisk without root permission
- Creating a JFFS2 image from a directory structure
- SAM-BA : Flashing taskit's ARM-based boards
- Flashing new u-boot on Portux920T / Portux Panel-PC
- Implementing an own boot-logo for Panel-Card
- Nano-X with tslib support
- Using Watchdog on Stamp9G20 or PortuxG20
- Development with Eclipse
- Installing Debian/GNU Linux on Stamp9G20 and PortuxG20
- Using Xenomai on PortuxG20/Stamp9G20
- Installing a rootfs on SD card
- Using Power Management Features
- Using the NAND flash on NanosG20
- Using the buzzer on PortuxG20 rev. 2 and NanosG20
Building an initial ramdisk without root permission
Last edited by cglindkamp on Fri, 12/12/2008 - 14:03
Introduction
Building an initrd as described in our Linux guide needs root permission to mount an empty image, set correct ownership and create special files. This is inconvenient and not always possible. This guide describes how you can build root filesystems without the need for root permission.
Requirements
You need the following tools:
- genext2fs
- fakeroot
Procedure
Installation of the needed tools
On Debian and derived distributions just enter
apt-get install genext2fs fakeroot
with root rights.
Generating an initrd from a complete directory structure
If you already have all the files you need for the rootfs in a directory, use the following command:
genext2fs -d rootfs -b 8192 initrd.img
This creates an 8MiB sized ext2 image called initrd with the contents of the directory rootfs. If you need the root squashing feature (making all files owned by root as described in the Linux guide) add the option “-U”
genext2fs -d rootfs -b 8192 -U initrd.img
Do not use this feature, if the contents already have the correct ownership, i.e. you used the instructions from the next section to build the rootfs contents or create the image from the contents of an SD card/USB flash drive using the OpenEmbedded based system.
Now just compress the image with gzip:
gzip -9 < initrd.img > initrd.bin
You can now flash the image initrd.bin.
Changing permissions and create special files without root rights
The last section has shown you, how to create an image from files which already have correct ownership or just making everything owned by root. But this does not work, when you need finer permissions or special files in your rootfs. The last one is needed, if you build an rootfs for the kernels later than 2.6.12. To do this you have to start the tool fakeroot. Just enter
fakeroot
From now on, everything you do looks to the tools you are using as if you had root rights. So all files you create are owned by root, you can create special files and so on. The files you create are not really owned by root, fakeroot just overrides some system calls to track file creation and permission changes and fakes these for all programs. This means that after leaving and reentering the fakeroot environment, special files aren't special files anymore and files with an ownership different from root are now owned by root. So using this method, you have to recreate these files or their permissions after each invocation of fakeroot or use parameters -i and -s to save and restore the environment on each invocation of fakeroot. For further details consult the fakeroot man page.
After you have finished your work in the fakeroot environment, leave it with Ctrl-D or the exit command.
Bringing it all together
So a complete workflow to build a rootfs from scratch without root rights would look like that:
- Enter the fakeroot environment
- Fill your rootfs directory with the contents
- Adjust the permission with chown and chmod
- Generate the image with genext2fs and gzip
- Leave the fakeroot environment
