{"id":30,"date":"2010-02-11T01:04:45","date_gmt":"2010-02-11T01:04:45","guid":{"rendered":"http:\/\/www.irregular-expression.com\/?p=30"},"modified":"2012-06-25T04:04:07","modified_gmt":"2012-06-25T04:04:07","slug":"booting-debian-on-nexusone-with-x11wifi-from-sd-card","status":"publish","type":"post","link":"http:\/\/www.irregular-expression.com\/?p=30","title":{"rendered":"Booting Debian on NexusOne with X11\/Wifi from SD card."},"content":{"rendered":"<pre>This is a method to boot into Debian via fastboot on the nexus one from\r\nyour SD-card. This is NOT a chroot Debian image, it is honest to goodness\r\nDebian running directly on the hardware. This is completely non destructive to\r\nthe android OS. Connectivity to the device can be provided by adbd, ssh, or\r\nserial console. Wifi works perfectly. I have not tested bluetooth. Touchscreen\r\nworks, but needs tweaking. X11 works in framebuffer using the Debian\r\ntesting branch (squeeze). In order to get a full fledged X driver with\r\n3D acceleration we'll need the driver from\r\n<a href=\"https:\/\/www.codeaurora.org\/index.php?xwinp\">https:\/\/www.codeaurora.org\/index.php?xwinp<\/a> which I haven't been able to get\r\nto build. This doesn't mean it's broken. It just means I suck\r\nat cross compiling.\r\n\r\nTodo:\r\n-Tweak settings to make X more usable.\r\n-Get the CodeAurora MSM\/QSD X driver working.\r\n-Find decent method to input text.\r\n-Test bluetooth\r\n-Look into using the GSM radio.\r\n-Audio\r\n-Figure out how to configure adbd.\r\n\r\nThis how-to pulls heavily from the debian-arm install guide.\r\n<a href=\"http:\/\/www.debian.org\/releases\/stable\/arm\/index.html.en\">http:\/\/www.debian.org\/releases\/stable\/arm\/index.html.en<\/a>\r\n\r\nRequirements:\r\nadb (android-sdk)\r\nfastboot\r\nchroot (on your phone)\r\nsdcard with room for Debian - 2gigs seems to be sufficient for Debian + xfce.\r\nI Had about a gig leftover. For this guide, I'm starting fresh with a 4GB sdcard\r\nthat I'm devoting completely to Debian. According to the Debian install guide,\r\nyou need at least 32MB of memory and 500MB of hard disk space. The guide\r\nrecommends at least 5GB of storage for a comfortable install. But since I'm\r\nusing the lighter XFCE4 desktop I haven't had any space issues.\r\n<a href=\"http:\/\/www.debian.org\/releases\/stable\/arm\/ch03s04.html.en\">http:\/\/www.debian.org\/releases\/stable\/arm\/ch03s04.html.en<\/a>\r\n\r\n1. Re size the SD card\r\n(don't forget to backup your data before you go messing with partition tables!!)\r\n\t(optional) Instead of using a partition on your main SD card, you could\r\n\tsimply use another sdcard and dedicate the entire thing to Debian.\r\n\tNote: android didn't like me very much when I did this. I put in a\r\n\ttiny (30MB) vfat partition right at the beginning of the blank sdcard\r\n\tI mounted the sdcard on my Ubuntu system and used gparted to break\r\n\toff 2 gigs to use for Debian. Make sure you keep the normal android\r\n\tsdcard partition as the first partition otherwise android\r\n\twill not be able to find it.\r\n\tIf you're using apps to SD or anything else like that. Debian should\r\n\tprobably have the last partition. I'm not 100% sure on this since I\r\n\tdon't use my sdcard for anything else.\r\n\r\n2. Format the new partition.\r\n\text2 is probably best. (least abusive on the sdcard. ext3 &amp; 4 have\r\n\tjournaling which may be bad for the life of your sdcard)\r\n\tI used Gparted for this part as well.\r\n\r\n3. If you are installing from an Ubuntu or Debian desktop, install debootstrap\r\n\t$ sudo apt-get install debootstrap\r\n\tUsers of other distros may be able to get debootstrap but I'm not sure.\r\n\r\n4. Mount the sdcard on your desktop.\r\n\tanywhere will do just remember where you put it :-p\r\n\tex. mount \/dev\/sde2 \/mnt\/android\r\n\r\n5. debootstrap\r\n\trun debootstrap\r\n\tyou can change to a mirror closer to you if you don't want to use the\r\n\tUS mirror - <a href=\"http:\/\/www.debian.org\/misc\/README.mirrors\">http:\/\/www.debian.org\/misc\/README.mirrors<\/a>\r\n\tI'm using the Debian testing release (squeeze). I had issues getting\r\n\tX11 running in lenny, and have not tested sid.\r\n\t(lenny is stable, squeeze is testing, and sid is unstable)\r\n\t<a href=\"http:\/\/www.debian.org\/releases\/\">http:\/\/www.debian.org\/releases\/<\/a>\r\n\r\n\tdebootstrap --arch armel --foreign &lt;release&gt; &lt;\/path\/to\/debian&gt; &lt;mirror&gt;\r\n\t# debootstrap --arch armel --foreign squeeze \/mnt\/android \\\r\n           http:\/\/ftp.us.debian.org\/debian<\/pre>\n<pre>6. debootstrap(part2)\r\n\tUnmount the sdcard from your desktop.\r\n\tReboot the phone here since you've been mucking with the sdcard\r\n\tfile system. Android didn't like my sdcard until I did.\r\n\r\n\t$ adb shell\r\n\r\n\tmount the sdcard somewhere on the android file system.\r\n\tlook in \/dev\/block for the sdcard.\r\n\tTypically mmcblk0p# where # is the partition number.\r\n\tex. # mount -t ext2 \/dev\/block\/mmcblk0p2 \/data\/local\/mnt\r\n\r\n\tchroot\/debootstrap\r\n\r\n\t# chroot \/data\/local\/mnt\/ \/debootstrap\/debootstrap --second-stage\r\n\tthis will take a while especially if you have a slower sdcard.\r\n\r\n6. While that's working, now is a good time to get to work on your kernel\r\n\tI used the open source android kernel 2.6.29\r\n\t<a href=\"http:\/\/android.git.kernel.org\/\">http:\/\/android.git.kernel.org\/<\/a>\r\n\tStarted with mahimahi_defconfig (default nexus one kernel config from google)\u00c2\u00a0and starting customizing from there.<\/pre>\n<pre>\tThings to note.\r\n\t- file systems - don't forget to add support for whatever file systems\r\n\t  you need. Your root file system support cannot be built as a module.\r\n\t- wireless driver config - You may want to change the location the\r\n\t  kernel looks for your wifi firmware (this is different from the\r\n\t  kernel module).\r\n\t  I stuck mine in \/etc\/firmware, default is \/system\/etc\/firmware.\r\n\t  If you don't change this, you will have to put the firmware\r\n\t  in \/system\/etc\/firmware\r\n\t- wireless - Add in support for standard wifi extensions.\r\n\t- networking - standard tcp\/ip stuff... iptables if you want ect...\r\n\t- I wasn't able to get the kernel to boot into Debian until I turned\r\n\t  off initramfs support.\r\n\t  (note. this was before I discovered the 'noinitrd' kernel\r\n\t  kernel cmdline option. So disabling initrd may not be required)\r\n\t- If for some reason you are using ext4, it will fail to mount unless\r\n\t  you add in large devices and files support\r\n\t- Default kernel command string - has no effect.\r\n\t  This gets overwritten when you boot with fastboot or make a boot.img\r\n\t- Drivers - I left all the normal android drivers in.\r\n\t\t-Changed the firmware path for wifi.\r\n\t\t-Added in support for virtual terminal under character devices\r\n\t\t-Enabled MSM serial support (if you don't have a serial cable\r\n\t\t this is useless to you)\r\n\t\t-You can build the wifi driver into the kernel if you want.\r\n\r\n\tLink to the kernel config I used. Use at your own risk.\r\n\tIt works for me but I can't promise it's perfect or even good.\r\n\t<a href=\"http:\/\/irregular-expression.com\/tmp\/config\">http:\/\/irregular-expression.com\/tmp\/config<\/a>\r\n\tI would love input on building a better kernel config.\r\nIf you don't want to build your own kernel. You can download mine <a href=\"http:\/\/irregular-expression.com\/tmp\/zImage\">here.<\/a>\r\n\r\n7. Chroot and configure Debian.\r\n\tThere are still some things that need configuring before we reboot into\r\n\tDebian. Since fbconsole does not appear to be working, if you don't\r\n\thave a serial cable you will be flying blind until Debian is fully\r\n\tbooted and you can connect with ssh. Since there are still things to do\r\n\tbefore we reboot, we're going to chroot into Debian just like if we are\r\n\tusing a Debian chroot image.\r\n\r\n\tFor more information and examples of config files.\r\n\t<a href=\"http:\/\/www.debian.org\/releases\/stable\/arm\/apds03.html.en\">http:\/\/www.debian.org\/releases\/stable\/arm\/apds03.html.en<\/a>\r\n\r\n\tIt's probably best to use wifi for your data on the phone for this.\r\n\tIf you're on Linux and connected to the same router as the phone, copy\r\n\tover your resolv.conf\r\n\r\n\t$ adb push \/etc\/resolv.conf \/data\/local\/etc\/resolv.conf\r\n\r\n\tIf you are not in Linux or are not connected to wifi you will need to\r\n\tset up resolv.conf with something sane.\r\n\r\n\tex. from jay freeman's original Debian chroot.\r\n\t$ echo 'nameserver 4.2.2.2' &gt; \/data\/local\/etc\/resolv.conf\r\n\r\n\tpush wifi driver to the device\r\n\r\n\t$ adb push &lt;kernelroot&gt;\/drivers\/net\/wireless\/bcm4329\/bcm4329.ko \\\r\n\t  \/data\/local\/etc\/firmware\r\n\r\n\tcopy \/system\/etc\/firmware\/fw_bcm4329.bin to wherever you\r\n\tspecified in the kernel config.\r\n\r\n\t# cp \/system\/etc\/firmware\/fw_bcm4329.bin \/data\/local\/mnt\/etc\/firmware\/\r\n\r\n\tSetup environment variables, copy over adbd, and other stuff needed to\r\n\tmake things work. This should all be run from within an adb shell\r\n\r\n\t# cp \/sbin\/adbd \/data\/local\/mnt\/sbin\/adbd\r\n\t# sysctl -w net.ipv4.ip_forward=1\r\n\t# export PATH=\/usr\/bin:\/usr\/sbin:\/bin:$PATH\r\n\t# export TERM=linux\r\n\t# export HOME=\/root\r\n\r\n\tNext chroot and setup mount points\r\n\r\n\t# chroot \/data\/local\/mnt \/bin\/bash\r\n\t# mount -t devpts devpts \/dev\/pts\r\n\t# mount -t proc proc \/proc\r\n\t# mount -t sysfs sysfs \/sys\r\n\r\n\tWelcome to Debian chroot that we all know and love.\r\n\tLets finish configuring this thing.\r\n\r\n\tConfigure adbd to run on boot and create a symlink so\r\n\tadbd can find bash.\r\n\r\n\tEdit \/etc\/rc.local. Add adbd before exit 0\r\n\r\n\t#add this to \/etc\/rc.local\r\n\t\/sbin\/adbd &amp;\r\n\r\n\t# mkdir -p \/system\/bin\/\r\n\t# ln -s \/bin\/bash \/system\/bin\/sh\r\n\r\n\tNow we need to be able to install packages\r\n\tdon't forget if you are not using squeeze to change it here\r\n\r\n\t# echo 'deb http:\/\/ftp.us.debian.org\/debian squeeze main' \\\r\n\t   &gt;&gt; \/etc\/apt\/sources.list\r\n\t# apt-get update\r\n\r\n\tYou should see aptitude updating it's package list.\r\n\r\n\tInstall some needed packages\r\n\r\n\t# apt-get install wpasupplicant wireless-tools udev ssh\r\n\r\n\tOther packages\r\n\tAll up to your choice. Things like text editors, X, ect...\r\n\tsome suggested packages\r\n\r\n\t# apt-get install locales vi\r\n\r\n\tWifi driver\r\n\tWhen you try to load the wifi module, Linux will complain about not\r\n\tbeing able to parse modprobe.d. To fix this run depmod. If it complains\r\n\ta directory doesn't exist then create it.\r\n\r\n\t# depmod -a\r\n\r\n\tmove bcm4329.ko to \/lib\/modules\r\n\t# cp \/etc\/firmware\/bcm4329.ko \/lib\/modules\r\n\r\n\tEdit \/etc\/modules and add the bcm4329 module \r\n\r\n\t# \/etc\/modules: kernel modules to load at boot time.\r\n\t#\r\n\t# This file contains the names of kernel modules that should be loaded\r\n\t# at boot time, one per line. Lines beginning with \"#\" are ignored.\r\n\t# Parameters can be specified after the module name.\r\n\tbcm4329\r\n\r\n\tSetup fstab - critical: don't forget to configure the root file system\r\n\tor your system won't boot. If you like, mount your vfat sdcard partition\r\n\there too. Don't forget to mkdir for the mount point.\r\n\t*note* after boot the memory card is located at \/dev\/mmcblk0p#.\r\n\r\n\tHere is my \/etc\/fstab\r\n\r\n\t# \/etc\/fstab: static file system information.\r\n\t#\r\n\t# file system    mount point   type    options     dump pass\r\n\r\n\t\/dev\/block\/mmcblk0p2 \/ ext2 defaults 1 1\r\n\tproc \/proc proc defaults 0 0\r\n\t\/dev\/mmcblk0p1 \/media\/sdcard vfat defaults 0 0\r\n\r\n\tconfigure network\r\n\tThese two files will be tuned to what you need.\r\n\tHere are a couple examples.\r\n\r\n\t\/etc\/network\/interfaces\r\n\r\n\t\tauto lo\r\n\t\tiface lo inet loopback\r\n\r\n\t\tauto eth0\r\n\t\tiface eth0 inet dhcp\r\n\t\twpa-driver wext\r\n\t\twpa-conf \/etc\/wpa_supplicant.conf\r\n\r\n\t\/etc\/wpa_supplicant.conf\r\n\r\n\t\tctrl_interface=\/var\/run\/wpa_supplicant\r\n\r\n\t\tnetwork={\r\n        \tssid=\"myOpenNetwork\"\r\n        \tscan_ssid=1\r\n        \tkey_mgmt=NONE\r\n\t\t}\r\n\t\tnetwork={\r\n        \tssid=\"MyHomeNetwork\"\r\n        \tscan_ssid=1\r\n        \tkey_mgmt=WPA-PSK\r\n        \tpsk=\"MyWifiPassword\"\r\n\t\t}\r\n\t\tnetwork={\r\n        \tssid=\"MyFriendsWifi\"\r\n        \tscan_ssid=1\r\n        \tkey_mgmt=WPA-PSK\r\n        \tpsk=\"MyFriendsWifiPassword\"\r\n\t\t}\r\n\r\n\tinittab\r\n\tno need for getty so comment it out in \/etc\/inittab\r\n\tif you have a serial cable, configure it here. something like this.\r\n\tT0:23:respawn:\/sbin\/getty -L ttyMSM0 115200 linux\r\n\r\n\thostname\r\n\tconfigure your system's hostname - you can set this to whatever you like\r\n\t# echo DebianHostName &gt; \/etc\/hostname\r\n\r\n\tSet root password\r\n\t# passwd\r\n\r\n\tAdd user account\r\n\t# useradd -m yourusername -s \/bin\/bash\r\n\t# passwd yourusername\r\n\r\n8. Almost there!\r\n\tDouble check your configs and have your kernel handy.\r\n\tThe next step is to boot into Debian.\r\n\r\n9. Boot Debian\r\n\tput the device into fastboot mode\r\n\t$ adb reboot bootloader\r\n\tthe '-c' flag specifies arguments to pass to the kernel for boot.\r\n\tThis is probably the bare minimum.\r\n\r\n\tFormat is \"fastboot -c 'kernelcmdline' boot zImage\"\r\n\r\n$ fastboot -c 'root=\/dev\/mmcblk0p2 rw rootfs=ext2 init=\/sbin\/init \\<\/pre>\n<pre>rootwait noinitrd' boot zImage<\/pre>\n<pre>\tWait just a few minutes. DHCP is probably the longest part of this.\r\n\r\n10. Connect via ADB.\r\n\tIf everything went well you should be able to log into the\r\n\tphone via adb. adb push and pull work as well. \r\n\r\n\t$ adb shell\r\n\r\n11. Install X11\r\n\tFor a basic X11 install. This is probably not what you want.\r\n\t# apt-get install xserver-xorg\r\n\r\n\tYou can install whatever window manager\/desktop environment you like,\r\n\tI used XFCE. Most window managers likely depend on xserver-xorg so it\r\n\twill get pulled in when you install. \r\n\r\n\t# apt-get install xfce4 \r\n\r\n\tAfter I installed xfce4 I was able to get X on the main display by\r\n\tsimply running startxfce4\r\n\r\n\t# startxfce4\r\n\r\n\tBy default Debian is configured to only allow root to startx.\r\n\tIf you want to be able to run X as a user edit \/etc\/X11\/Xwrapper.config\r\n\t*note* even with this I haven't been able to run X as a normal user.\r\n\tOnly root.\r\n\r\n\tChange allowed_users=console\r\n\tto allowed_users=anybody\r\n\r\nCurrently touchscreen is a little weird. It feels almost like using a\r\nlaptop touchpad. The mouse moves much faster then your finger and tapping for\r\nclick isn't enabled by default but two finger tap will right click. You can\r\nalso move the mouse with the trackball. Clicking the trackball registers a\r\nclick. But you have to wiggle the trackball just a tiny bit after you click to\r\nmake it register. I am going to work on tweaking the fdi policy files to\r\nmake things a little more usable.\r\n\r\nText entry is a bit of a pain point currently. There are several on screen\r\nkeyboards out there. One interesting one I found is called cellwriter.\r\nThe touchscreen will need to be tweaked before it will work well with\r\nonscreen keyboards.\r\n\r\nFor other ideas on window managers and other software check out this link\r\n<a href=\"http:\/\/wiki.openmoko.org\/wiki\/Debian\">http:\/\/wiki.openmoko.org\/wiki\/Debian<\/a><\/pre>\n<pre>Screenies! <a href=\"http:\/\/picasaweb.google.com\/JairunCaloth\/Debian?feat=directlink\">http:\/\/picasaweb.google.com\/JairunCaloth\/Debian?feat=directlink<\/a><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a method to boot into Debian via fastboot on the nexus one from your SD-card. This is NOT a chroot Debian image, it is honest to goodness Debian running directly on the hardware. This is completely non destructive to the android OS. Connectivity to the device can be provided by adbd, ssh, or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,5],"tags":[7,6,8],"_links":{"self":[{"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=\/wp\/v2\/posts\/30"}],"collection":[{"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=30"}],"version-history":[{"count":0,"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.irregular-expression.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}