Building a pure Debian armhf rootfs

来源:互联网 发布:java public 编辑:程序博客网 时间:2024/06/06 04:07

There are lots of filesystems images for various Debian flavours on ARM developer boards like the Cubietruck floating about. Most of these images are large binary files of unknown providence and even compressed take a while to download. There is a better way of making a root image for your new ARM board, just build it on your own normal workstation directly from the Debian repos with debootstrap using the magic of QEMU.

First install the support packages on your workstation:

sudo apt-get install qemu-user-static debootstrap binfmt-support

You will need about 500MB of space in a directory for the image, choose the version of Debian in this case we are building a wheezy image.

targetdir=rootfsdistro=wheezy

Lets get going building the first stage of the rootfs image from the Debian mirrors, this will take a few minutes and downloads about 200MB.

mkdir $targetdirsudo debootstrap --arch=armhf --foreign $distro $targetdir

Next copy the the qemu-arm-static binary into the right place for the binfmt packages to find it and copy in resolv.conf from the host.

sudo cp /usr/bin/qemu-arm-static $targetdir/usr/bin/sudo cp /etc/resolv.conf $targetdir/etc

We now have a very basic armhf rootfs in a directory, the next stages take place inside a chroot of that directory.

sudo chroot $targetdir

Inside the chroot we need to set up the environment again

distro=wheezyexport LANG=C

Now we need to complete the second stage of debootstrap to install the packages downloaded earlier

/debootstrap/debootstrap --second-stage

Once the package installation has finished, setup some basic support files

cat <<EOT > /etc/apt/sources.listdeb http://ftp.uk.debian.org/debian $distro main contrib non-freedeb-src http://ftp.uk.debian.org/debian $distro main contrib non-freedeb http://ftp.uk.debian.org/debian $distro-updates main contrib non-freedeb-src http://ftp.uk.debian.org/debian $distro-updates main contrib non-freedeb http://security.debian.org/debian-security $distro/updates main contrib non-freedeb-src http://security.debian.org/debian-security $distro/updates main contrib non-freeEOTcat <<EOT > /etc/apt/apt.conf.d/71-no-recommendsAPT::Install-Recommends "0";APT::Install-Suggests "0";EOT

Pull in the latest apt database from the Debian mirrors

apt-get update

Install the locales package otherwise dpkg scripts, note in jessie you may need to install the dialog package as well.

apt-get install locales dialogdpkg-reconfigure locales

Install some additional packages inside the chroot, an ssh server for network access and ntp because many boards don’t have a functional RTC.

apt-get install openssh-server ntpdate

Set a root password so you can login via ssh or the console

passwd

Build a basic network interfaces file so that the board will DHCP on eth0

echo <<EOT >> /etc/network/interfacesallow-hotplug eth0iface eth0 inet dhcpEOT

Set the hostname

echo debian-armhf > /etc/hostname

Enable the serial console, Debian sysvinit way

echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> /etc/inittab

We are done inside the chroot, so quit the chroot shell

exit

Tidy up the support files

sudo rm $targetdir/etc/resolv.confsudo rm $targetdir/usr/bin/qemu-arm-static

You now have a root file system for pretty much any armhf machine but next you need to make a bootable sd card image. I’ll cover that in thenext post, there are other howtos to assemble the bootable card.


Debootstrap可以快速建立一套Debian或Ubuntu的rootfs。支持多种CPU。

主要步骤:

  1. 准备工作:在debian系统下安装用aptitude安装debootstrap;将一个新磁盘mount到/mnt/rootfs/下;
  2. 运行debootstrap –arch=i386 squeeze /mnt/rootfs/ http://mirrors.163.com/debian;运行完成后,会在/mnt/rootfs/下生成一个较小的rootfs;
  3. chroot /mnt/rootfs/进入rootfs进行配置,用passwd root命令修改密码; 
    下面对生成的rootfs进行测试:
  4. 添加核心:可以拷贝一个完整debian系统的/boot、/lib/modprobe.d、/lib/modules到生成的rootfs下;
  5. 用grub-install命令安装grub到新磁盘,修改grub.cfg文件;启动新磁盘上的系统。

备注:

  1. 生成的rootfs(未安装kernel),大小约为234M,出去/usr/share和/var/apt下可删除的文件后,能够轻松裁剪到100M以内。
  2. 自己曾经从debian的netinstall进行裁剪,要裁剪到100M以内,要花数倍于用Debootstrap的精力。

0 0