Building a pure Debian armhf rootfs

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=rootfs
distro=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 $targetdir
sudo 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=wheezy
export 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.list
deb http://ftp.uk.debian.org/debian $distro main contrib non-free
deb-src http://ftp.uk.debian.org/debian $distro main contrib non-free
deb http://ftp.uk.debian.org/debian $distro-updates main contrib non-free
deb-src http://ftp.uk.debian.org/debian $distro-updates main contrib non-free
deb http://security.debian.org/debian-security $distro/updates main contrib non-free
deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free
EOT

cat <<EOT > /etc/apt/apt.conf.d/71-no-recommends
APT::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 dialog
dpkg-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/interfaces
allow-hotplug eth0
iface eth0 inet dhcp
EOT

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.conf
sudo 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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值