{"id":74,"date":"2014-11-06T13:41:40","date_gmt":"2014-11-06T05:41:40","guid":{"rendered":"http:\/\/blog.haostudio.net\/hwp\/?p=74"},"modified":"2017-07-25T00:21:34","modified_gmt":"2017-07-24T16:21:34","slug":"%e5%8b%95%e6%89%8b%e6%89%93%e9%80%a0debian-root-filesystem-for-arm-2","status":"publish","type":"post","link":"https:\/\/blog.haostudio.net\/hwp\/%e5%8b%95%e6%89%8b%e6%89%93%e9%80%a0debian-root-filesystem-for-arm-2\/","title":{"rendered":"\u52d5\u624b\u6253\u9020Debian root filesystem for ARM"},"content":{"rendered":"<!--more-->\n<h2>\u52d5\u624b\u6253\u9020Debian root filesystem for ARM<\/h2>\n<h3>\u4e00\u5207\u52d5\u529b\u7686\u4f86\u81ea\u65bc why ?<\/h3>\n<p>\u6bcf\u6b21\u90fd\u4f7f\u7528\u5225\u4eba\u505a\u597d\u7684image file \u4f86\u7528\u5728\u81ea\u5df1\u7684ARM \u958b\u767c\u677f\u4e0a. \u5c0d\u65bc\u5225\u4eba\u662f\u5982\u4f55\u505a\u51fa\u9019\u6a23\u7684image file \u611f\u5230\u597d\u5947.\n\u65bc\u662f\u82b1\u4e86\u4e00\u4e9b\u6642\u9593, \u60f3\u8981\u52d5\u624b\u6253\u9020\u81ea\u5df1\u958b\u767c\u677f\u4e0a\u5c08\u5c6c\u7684image file. \u4e0a\u7db2\u627e\u4e86\u4e00\u4e0b, \u539f\u672c\u662f\u60f3\u5f9e<a href=\"http:\/\/www.linuxfromscratch.org\/lfs\/\">Linux From Scratch<\/a>\u8457\u624b. \u89ba\u5f97LFS \u624d\u662f\u771f\u6b63\u5f9e\u5e95\u90e8\u6253\u9020\u8d77, \u4f46\u662f\u5f8c\u4f86\u60f3\u60f3, \u82e5\u67d0\u500b\u8edf\u9ad4\u6709bug, \u60f3\u8981\u66f4\u65b0\u6642, \u9084\u5f97\u5f9esouce code \u6293\u4e0b\u4f86, \u4e00\u500b\u500b\u88dc\u4e0a\u53bb, \u6211\u4f3c\u4e4e\u6c92\u8fa6\u6cd5\u6574\u5929\u90fd\u5728\u76ef\u8457\u8edf\u9ad4\u7684\u6f0f\u6d1e\u8dd1. \u6700\u5f8c\u6c7a\u5b9a\u63a1\u7528Debian Distribution, \u56e0\u70ba\u611f\u89ba\u4ed6\u6bd4\u8f03\u81ea\u7531. \u6709\u6f0f\u6d1e\u6642, \u53ea\u8981\u7528apt \u53bb\u66f4\u65b0\u5957\u4ef6\u5c31\u597d. \u56e0\u6b64\u52d5\u624b\u6253\u9020Debian \u7684Root File System \u5c31\u6210\u4e86\u7b2c\u4e00\u500b\u76ee\u6a19.<\/p>\n<h3>\u4e8b\u524d\u6e96\u5099<\/h3>\n<p>\u5728\u52d5\u624b\u4e4b\u524d, \u5148\u7528apt\u5148\u6e96\u5099\u4e0b\u5217\u5957\u4ef6<\/p>\n<pre><code># apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools\n<\/code><\/pre>\n<p>\u7136\u5f8c\u53c3\u8003<a href=\"https:\/\/launchpad.net\/gcc-arm-embedded\">\u9019\u88e1<\/a>\u88dd\u4e0aARM GNU toolchain (Cross compiler). \u5982\u679c\u4f60\u662f\u7528ubuntu \u597d\u50cf\u76f4\u63a5\u7528apt \u5c31\u53ef\u4ee5\u88dd<\/p>\n<pre><code># apt-get install crossbuild-essential-armhf\n<\/code><\/pre>\n<h3>(\u6b65\u9a5f 1) \u5efa\u7acb\u7a7a\u767d\u7684image file<\/h3>\n<p>\u5229\u7528dd \u5efa\u7acb\u4e00\u7684\u7a7a\u767d\u76841.9GB image file, \u9019\u500bimage \u662f\u70ba\u4e86\u4ee5\u5f8c\u53ef\u4ee5\u76f4\u63a5\u71d2\u5165\u5230SD Card \u6216TF Card.<\/p>\n<pre><code># dd if=\/dev\/zero of=rootfs.img  bs=1048576 count=1900\n<\/code><\/pre>\n<h3>(\u6b65\u9a5f 2) \u5728image file \u4e2d\u5efa\u7acbpartition.<\/h3>\n<p>\u5148\u7528losetup \u5c07\u6b64image file \u505a\u6210\u4e00\u500bloop device.<\/p>\n<pre><code># losetup -f --show rootfs.img\n\/dev\/loop0\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\u6211\u5011\u53ef\u4ee5\u628a\u9019\u500b\/dev\/loop0 \u7576\u4f5c\u662f\u4e00\u500b\u786c\u789f\u4f86, \u7528fdisk \u4f86\u5275\u9020partition. \u6211\u5c07\u5efa\u7acb2\u500bpartition, 1\u500b\u662fFAT\u683c\u5f0f\u7684, \u70ba\u4e86\u4ee5\u5f8c\u80fd\u653euboot \u53calinux kernel image file.\n\u53e6\u4e00\u500b\u662fext4\u683c\u5f0f, \u5b58\u653eDebian root filesystem. \u7b2c\u4e00\u500bpartition \u5927\u7d04\u53ea\u8981100MB \u5c31\u5920\u4e86.<\/p>\n<pre><code># fdisk \/dev\/loop0\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel\nBuilding a new DOS disklabel with disk identifier 0xbe3cb21f.\nChanges will remain in memory only, until you decide to write them.\nAfter that, of course, the previous content won&#039;t be recoverable.\n\nWarning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)\n\nCommand (m for help): n\nPartition type:\n   p   primary (0 primary, 0 extended, 4 free)\n   e   extended\nSelect (default p): p\nPartition number (1-4, default 1): 1\nFirst sector (2048-3891199, default 2048): \nUsing default value 2048\nLast sector, +sectors or +size{K,M,G} (2048-3891199, default 3891199): +100M\n\nCommand (m for help): t\nSelected partition 1\nHex code (type L to list codes): c\nChanged system type of partition 1 to c (W95 FAT32 (LBA))\n\nCommand (m for help): n\nPartition type:\n   p   primary (1 primary, 0 extended, 3 free)\n   e   extended\nSelect (default p): p\nPartition number (1-4, default 2): 2\nFirst sector (206848-3891199, default 206848): \nUsing default value 206848\nLast sector, +sectors or +size{K,M,G} (206848-3891199, default 3891199): \nUsing default value 3891199\n\nCommand (m for help): w\nThe partition table has been altered!\n\nCalling ioctl() to re-read partition table.\n\nWARNING: Re-reading the partition table failed with error 22: \u4e0d\u9069\u7528\u7684\u5f15\u6578.\nThe kernel still uses the old table. The new table will be used at\nthe next reboot or after you run partprobe(8) or kpartx(8)\n\nWARNING: If you have created or modified any DOS 6.x\npartitions, please see the fdisk manual page for additional\ninformation.\nSyncing disks.\n<\/code><\/pre>\n<p>fdisk \u5b8c\u5f8c\u8a18\u5f97\u5378\u8f09\/dev\/loop0<\/p>\n<pre><code># losetup -d \/dev\/loop0\n<\/code><\/pre>\n<h3>(\u6b65\u9a5f 3) \u683c\u5f0f\u5316partition<\/h3>\n<p>\u4f7f\u7528kpartx \u5c07image file \u4e2d\u7684\u5169\u500bpartition \u90fd\u639b\u6210loop device.<\/p>\n<pre><code># kpartx -va rootfs.img\nadd map loop0p1 (254:0): 0 204800 linear \/dev\/loop0 2048\nadd map loop0p2 (254:1): 0 3684352 linear \/dev\/loop0 206848\n1. 1. ls -al \/dev\/mapper\/loop0p?\n\/dev\/mapper\/loop0p1  \/dev\/mapper\/loop0p2\n<\/code><\/pre>\n<p>\u9019\u5169\u500bpartition \u5206\u5225\u639b\u6210\/dev\/mapper\/loop0p1, \u53ca\/dev\/mapper\/loop0p2<\/p>\n<p>\u5206\u5225\u5c07\u9019\u5169\u500bpartition \u683c\u5f0f\u5316\u6210FAT\u53caEXT4 filesystem<\/p>\n<pre><code># mkfs.vfat \/dev\/mapper\/loop0p1\n1. mkfs.ext4 \/dev\/mapper\/loop0p2\n<\/code><\/pre>\n<h3>(\u6b65\u9a5f 4) \u7b2c\u4e00\u968e\u6bb5\u5b89\u88ddDebian root filesystem<\/h3>\n<p>\u73fe\u5728\u958b\u59cb\u6e96\u5099\u5b89\u88dd\u6700\u57fa\u672cDebian system \u5230\/dev\/mapper\/loop0p2 \u4e0b.<\/p>\n<p>\u9996\u5148\u5efa\u7acb\u4e00\u500b\u76ee\u9304\u53ebrootfs,\u5c07\/dev\/mapper\/loop0p2 mount \u5230\u6b64\u76ee\u9304, \u7136\u5f8c\u4f7f\u7528debootstrap \u505a\u7b2c\u4e00\u968e\u6bb5\u5b89\u88dd.<\/p>\n<pre><code># mkdir -p \/root\/tmp\/rootfs\n1. mount \/dev\/mapper\/loop0p2 \/root\/tmp\/rootfs\n1. debootstrap --foreign --arch armhf wheezy \/root\/tmp\/rootfs http:\/\/http.debian.net\/debian\n<\/code><\/pre>\n<p>\u5c07qemu arm \u7684\u7a0b\u5f0f\u62f7\u8c9d\u5230rootfs \u4e2d\u7684\/usr\/bin \u88e1\u9762<\/p>\n<pre><code># cp \/usr\/bin\/qemu-arm-static \/root\/tmp\/rootfs\/usr\/bin\/\n<\/code><\/pre>\n<h3>(\u6b65\u9a5f 5) \u7b2c\u4e8c\u968e\u6bb5\u5b89\u88ddDebian root filesystem<\/h3>\n<p>\u63a5\u4e0b\u4f86\u505aDebian system \u7b2c\u4e8c\u968e\u6bb5\u5b89\u88dd<\/p>\n<pre><code># LANG=C chroot \/root\/tmp\/rootfs \/debootstrap\/debootstrap --second-stage\n<\/code><\/pre>\n<p>\u5efa\u7acb\u65b0Debian system \u4e2d \/etc\u76ee\u9304\u4e0b\u5fc5\u8981\u7684\u6a94\u6848<\/p>\n<pre><code># cat &lt;&lt; EOF &gt; \/root\/tmp\/rootfs\/etc\/apt\/sources.list\n&gt; deb http:\/\/http.debian.net\/debian wheezy main contrib non-free\n&gt; EOF\n\n1. cat &lt;&lt; EOF &gt; \/root\/tmp\/rootfs\/etc\/fstab\n&gt; proc            \/proc           proc    defaults        0       0\n&gt; \/dev\/mmcblk0p1  \/boot           vfat    defaults        0       0\n&gt; EOF\n\n1. echo &quot;bsms&quot; &gt; \/root\/tmp\/rootfs\/etc\/hostname\n\n1. cat &lt;&lt; EOF &gt; \/root\/tmp\/rootfs\/etc\/resolv.conf\n&gt; nameserver 8.8.8.8\n&gt; EOF\n\n1. cat &lt;&lt; EOF &gt; \/root\/tmp\/rootfs\/etc\/network\/interfaces\n&gt; auto lo\n&gt; iface lo inet loopback\n&gt;\n&gt; auto eth0\n&gt; allow-hotplug eth0\n&gt;\n&gt; iface eth0 inet dhcp\n&gt;\n&gt; EOF\n\n1. echo T0:2345:respawn:\/sbin\/getty -L ttyS0 115200 vt100 &gt;&gt; \/root\/tmp\/rootfs\/etc\/inittab\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u6a94\u6848\u5167\u5bb9\u53ef\u4ee5\u4f9d\u64da\u4f60\u81ea\u5df1\u7684\u9700\u6c42\u4f86\u505a\u4fee\u6539.<\/p>\n<h3>(\u6b65\u9a5f 6) \u7b2c\u4e09\u968e\u6bb5\u5b89\u88ddDebian root filesystem<\/h3>\n<p>\u63a5\u4e0b\u4f86\u505aDebian system \u7b2c\u4e09\u968e\u6bb5\u5b89\u88dd<\/p>\n<pre><code># export MALLOC_CHECK_=0\n1. export LC_ALL=C\n1. export DEBIAN_FRONTEND=noninteractive\n\n1. mount -t proc proc \/root\/tmp\/rootfs\/proc\n1. mount -o bind \/dev\/ \/root\/tmp\/rootfs\/dev\/\n1. mount -o bind \/dev\/pts \/root\/tmp\/rootfs\/dev\/pts\n\n1. cat &lt;&lt; EOF &gt; \/root\/tmp\/rootfs\/debconf.set\n&gt; console-common console-data\/keymap\/policy select Select keymap from full list\n&gt; console-common console-data\/keymap\/full select en-latin1-nodeadkeys\n&gt; EOF\n\n1. cat &lt;&lt; EOF &gt; \/root\/tmp\/rootfs\/third-stage\n&gt; #!\/bin\/bash\n&gt; apt-get update\n&gt; apt-get install locales locales-all\n&gt; locale-gen en_US.UTF-8\n&gt;\n&gt; debconf-set-selections \/debconf.set\n&gt; rm -f \/debconf.set\n&gt; apt-get update\n&gt; apt-get -y install git-core binutils ca-certificates initramfs-tools uboot-mkimage\n&gt; apt-get -y install locales console-common ntp less openssh-server nano git vim \n&gt; apt-get -y install wireless-tools wpasupplicant\n&gt; echo &quot;root:123456&quot; | chpasswd\n&gt; sed -i -e &#039;s\/KERNEL\\!=\\&quot;eth\\*|\/KERNEL\\!=\\&quot;\/&#039; \/lib\/udev\/rules.d\/75-persistent-net-generator.rules\n&gt; rm -f \/etc\/udev\/rules.d\/70-persistent-net.rules\n&gt; rm -f \/third-stage\n&gt; EOF\n\n1. chmod +x \/root\/tmp\/rootfs\/third-stage\n1. LANG=C chroot \/root\/tmp\/rootfs \/third-stage\n<\/code><\/pre>\n<h3>(\u6b65\u9a5f 7) \u6700\u5f8c\u52d5\u4f5c.<\/h3>\n<p>\u5176\u5be6\u5230\u4e86\u6b65\u9a5f6, \u5c31\u5df2\u7d93\u505a\u5b8cDebian root filesystem \u4e86.\n\u9996\u5148\u505c\u6b62qemu-arm-static \u9019\u500bprocess.<\/p>\n<pre><code># ps -ef | grep qemu-arm-static | awk &#039;{print $2}&#039; | xargs kill -9\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\u8981umount \u4e4b\u524d\u639b\u8f09\u7684\u76ee\u9304<\/p>\n<pre><code># umount \/root\/tmp\/rootfs\/proc\n1. umount \/root\/tmp\/rootfs\/dev\/pts\n1. umount \/root\/tmp\/rootfs\/dev\/   \n1. umount \/root\/tmp\/rootfs\n<\/code><\/pre>\n<p>\u6700\u5f8c\u5378\u4e0bloop device \u5373\u53ef.<\/p>\n<pre><code># kpartx -d rootfs.img\n<\/code><\/pre>\n<p>\u5927\u529f\u544a\u6210. \u9019\u500brootfs.img \u6a94\u5df2\u7d93\u5305\u542b\u4e86\u57fa\u672c\u7684Debian root filesystem \u4e86.<\/p>\n<h3>\u5f8c\u7e8c<\/h3>\n<p>\u4f46\u662f\u5225\u592a\u8208\u596e\u7684\u5c07\u9019\u500b\u6a94\u71d2\u5230SD Card \u6216TF Card. \u56e0\u70ba\u9019\u6a23\u9084\u4e0d\u80fd\u5920\u5c07 ARM \u7cfb\u7d71\u6b63\u5e38\u958b\u6a5f.<\/p>\n<p>\u4ed6\u9084\u7f3a2\u7684\u6771\u897f, uboot \u53cakernel. \u7531\u65bc\u9019\u5169\u7684\u6771\u897f\u8ddf\u4f60\u7684ARM \u958b\u767c\u677f\u6709\u7d55\u5c0d\u7684\u95dc\u4fc2,  \u56e0\u6b64\u4e0d\u540c\u5bb6\u7684\u677f\u5b50, \u5176\u4f5c\u6cd5\u90fd\u6709\u4e9b\u4e0d\u540c\n\u4e0b\u6b21\u6709\u6a5f\u6703, \u518d\u4f86\u8a0e\u8ad6\u5982\u4f55\u5c07uboot \u53cakernel \u6574\u5408\u5230\u9019\u500brootfs.img \u6a94\u4e2d, \u4f7f\u5b83\u80fd\u5920\u771f\u6b63\u7684\u5728ARM \u677f\u5b50\u4e0a\u958b\u6a5f\u8d77\u4f86.\n\u95dc\u65bc\u5982\u4f55\u5efa\u7acbCubieboard \u7684uboot, \u53calinux kernel \u8acb\u53c3\u8003<a href=\"http:\/\/blog.haostudio.net\/hwp\/%E5%BE%9Esource-code-%E9%96%8B%E5%A7%8B%E6%89%93%E9%80%A0%E6%9C%80%E5%9F%BA%E6%9C%AC%E7%9A%84debian-linux-system\/\">\u9019\u7bc7\u6587\u7ae0<\/a><\/p>\n<h3>\u81ea\u52d5\u5316\u5efa\u7acbroot filesystem \u7684script<\/h3>\n<p>\u505a\u4e86\u4e0a\u9762\u90a3\u9ebc\u591a\u7684\u52d5\u4f5c\u5f8c, \u61c9\u8a72\u6703\u89ba\u5f97\u5f88\u7d2f\u4e86. \u56e0\u6b64\u6211\u5beb\u4e86\u4e00\u500b\u81ea\u52d5\u5316\u7684script \u8b93\u4e0a\u9762\u7684\u6240\u6709\u6b65\u9a5f\u4e00\u6c23\u5475\u6210.\u53ef\u4ee5\u8b93\u7701\u4e0b\u8a31\u591a\u6642\u9593\u53bb\u559d\u676f\u5496\u5561\u5427.<\/p>\n<p>\u8acb\u5230<a href=\"https:\/\/github.com\/haotseng\/DebianRootFS4ARM\">\u9019\u88e1<\/a>\u6293\u53d6\u9019\u500b\u81ea\u52d5\u5316\u7684script.<\/p>\n<hr \/>\n<h3>\u53c3\u8003\u8cc7\u6599<\/h3>\n<ol>\n<li><a href=\"http:\/\/blog.xuite.net\/maxkerr\/blog\/19123624\">Ubuntu &#8211; \u5efa\u7acb ARM Toolchain (Cross Compiler)<\/a><\/li>\n<li><a href=\"https:\/\/launchpad.net\/gcc-arm-embedded\">GNU Tools for ARM Embedded Processors<\/a><\/li>\n<li><a href=\"https:\/\/wiki.debian.org\/Debootstrap\">Debootstrap<\/a><\/li>\n<li><a href=\"http:\/\/docs.kali.org\/armel-armhf\/kali-linux-arm-chroot\">Preparing a Kali Linux ARM chroot<\/a><\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,2],"tags":[31,9,32],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-embedded-system","category-linux","tag-arm","tag-debian","tag-root-filesystem"],"_links":{"self":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":6,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":412,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/74\/revisions\/412"}],"wp:attachment":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}