1. Download our Official Android App: Forums for Android!

Tips Chrooted Ubuntu working on SGS2

Discussion in 'Android Devices' started by lotus49, Jun 23, 2011.

  1. lotus49

    lotus49 Android Expert
    Thread Starter
    Rank:
    None
    Points:
    153
    Posts:
    1,513
    Joined:
    May 9, 2011

    May 9, 2011
    1,513
    232
    153
    Male
    Yorkshire
    By using these instructions How to Install Ubuntu on Android! I have managed to install a chrooted Ubuntu on my SGS2.

    I had to make quite a few changes to the procedure (I'll write them up if anyone is interested) but it wasn't that hard. You would have to know Linux pretty well to debug the above instructions on the SGS2 though.

    I can now ssh into my Ubuntu installation from any other machine on my network including, of course, the SGS2 itself. Tomorrow I shall try to install a GUI. That's a little ugly, requiring VNC, but it looks simple enough.

    Perhaps someone will write an Android X server. Perhaps they already have, I shall have to investigate further.
     

    Advertisement

    Phik, NZtechfreak and Shanness like this.
  2. korg91

    korg91 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    6
    Joined:
    Jun 29, 2011

    Jun 29, 2011
    6
    0
    5
    Trento (Italy)
    Hi, I would really be grateful to you if you would explain the changes step by step...
    Thank you in advice
     
  3. lotus49

    lotus49 Android Expert
    Thread Starter
    Rank:
    None
    Points:
    153
    Posts:
    1,513
    Joined:
    May 9, 2011

    May 9, 2011
    1,513
    232
    153
    Male
    Yorkshire
    I thought I had replied to this yesterday but it appears not.

    Before you can do this you need to be able to log in to your phone as root. I was unable to do this using adb but was able to install a ssh server and since I have rooted my phone, I could then log in using ssh.

    If you confirm that you can do this, I'll write up the steps but if you saw my comment near the bottom of the page, I explained most of what I did there.

    I have subsequently made further changes as I realised that /proc and /dev should have been bound into the chrooted file system so I can post my bootubuntu file if that would be helpful. Debugging that file was the only hard bit of the process.
     
  4. korg91

    korg91 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    6
    Joined:
    Jun 29, 2011

    Jun 29, 2011
    6
    0
    5
    Trento (Italy)
    ok, i am in ;-)

    Maybe I can also tell you the reason why you didn't manage to get root with adb: maybe you didn't install "superuser" from the market (i did). Anyway if you install it, when you type "su" on adb you need to unlock your screen and allow the privileges for adb (you will see a popup).

    I also read your post on androlinux, but I didn't try it yet...could you explain me the remaining passages please?

    thank you very much
     
  5. lotus49

    lotus49 Android Expert
    Thread Starter
    Rank:
    None
    Points:
    153
    Posts:
    1,513
    Joined:
    May 9, 2011

    May 9, 2011
    1,513
    232
    153
    Male
    Yorkshire
    You are right, I didn't install "superuser" but since I had already rooted my phone and installed sshd, I was able just to ssh in as root.

    OK, there isn't all that much more to it. I decided, in the interests of saving space, to install ubuntu onto my SD card and the changes I made to the bootubuntu script reflect that.

    All you need to do in addition to the process as described in my link is to replace the file bootubuntu with my amended version BEFORE you run the ubuntu.sh script.

    This is what it looks like:

    Code (Text):
    1. #modprobe ext2
    2. mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
    3. export kit=/sdcard/external_sd/ubuntu
    4. export bin=/system/bin
    5. if ! test -d /data/local/ubuntu
    6. then
    7. mkdir /data/local/ubuntu
    8. fi
    9. export mnt=/data/local/ubuntu
    10. export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
    11. export TERM=linux
    12. export HOME=/root
    13. #mknod /dev/loop1 b 7 0
    14. losetup /dev/block/loop7 /sdcard/external_sd/ubuntu/ubuntu.img
    15. mount -t ext2 /dev/block/loop7 /data/local/ubuntu
    16. #mount -o loop,noatime -t ext2 $kit/ubuntu.img $mnt
    17. mount -o bind /proc $mnt/proc
    18. mount -o bind /dev $mnt/dev
    19. mount -t devpts devpts $mnt/dev/pts
    20. mount -t proc proc $mnt/proc
    21. mount -t sysfs sysfs $mnt/sys
    22. sysctl -w net.ipv4.ip_forward=1
    23. echo "Setting /etc/resolv.conf to Google Open DNS 8.8.8.8 and 8.8.4.4"
    24. echo "nameserver 8.8.8.8" > $mnt/etc/resolv.conf
    25. echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf
    26. echo "Setting localhost on /etc/hosts "
    27. echo "127.0.0.1 localhost" > $mnt/etc/hosts
    28. echo "READY TO ROCK AND ROLL BABY! "
    29. echo "Brought to you by NexusOneHacks.net and the open source community! "
    30. echo " "
    31. chroot $mnt /bin/bash
    32.  
    33. #After exit command is executed clear it all up
    34. echo " "
    35.  
    36. echo "Shutting down Ubuntu"
    37. umount $mnt/dev/pts
    38. umount $mnt/proc
    39. umount $mnt/sys
    40. umount $mnt
    41. losetup -d /dev/block/loop7
    The changes I made (and feel free to compare the two scripts yourself) were these:
    1. comment out the mknod line as there was already a usable loop device
    2. insert "external_sd/" into all the paths so that they pointed to the SD card
    3. use loop7 rather than loop1 (which was already in use)
    4. insert the two "mount -o bind..." lines, these should have been in the script already so that /proc and /dev were properly accessible after the chroot, I probably should have had one for /sys as well now that I think about it
    5. My phone barfed on the if [ ! -d ...] syntax so I changed it slightly so it does the same thing but with different syntax

    The version of ubuntu in ubuntu.img is rather old (Karmic). However, there is a link on that page explaining how to create a new image. The instructions worked first time with no changes on a Maverick system and Natty system. I am using the latest and although I haven't tested it a great deal (so many other things to play with on my snazzy new phone) it seems to work very well. If you don't already have a computer running ubuntu, you will struggle to do this bit and you'll have to resort to a VM or a live CD.

    I cannot promise to be able to fix any problem you have but I am an old hand at Unix since long before Linux was even thought of and I have been with Linux almost since its birth so I should be able to help.

    The usual warnings apply so if you manage to bugger up your phone, it's not my fault but I cannot really see how you could do that with this process. It adds to what's there already but changes nothing else so it should be completely safe.

    Oh, the last thing was that I kept getting Permission denied errors running scripts so just:
    Code (Text):
    1. # sh bootubuntu
    rather than just
    Code (Text):
    1. # bootubuntu
    if this happens to you.

    Have fun.
     
  6. korg91

    korg91 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    6
    Joined:
    Jun 29, 2011

    Jun 29, 2011
    6
    0
    5
    Trento (Italy)
    Thank you so much! IT WORKS! It's really AMAZING!

    Just a few things:

    Probably it's a stupid question (and it's because I didn't understand very well how it works) but...how can I shut ubuntu down? (and above all, is it necessary?)

    No problem for that, I am a strong linux supporter (unfortunately I'm not also a very powerful linux user :) )

    Anyway, I will surely try to build a natty image.

    I am very happy that you are a powerful linux/unix user. So I can ask you some question:

    - what terminal emulator do you use on the phone? I use android terminal emulator by Jack Palevich. It's not so bad, but there are some things that I would really like to have: colours (for example for "ls" different kind of files) and above all gestures. Did you ever use "mobile terminal" on the iphone? the gestures are really good (for example top-left swipe for Tab)

    - why the "Tab" key does not work on android terminal??? Nor in emulator, in adb and with ssh...

    - why the terminal is so...strange? for example, there isn't the classic "user@pc_name:~/folder$". It would be quite useful.

    - do you know a way to install many linux classic tools? for example nano,...


    Any advice for cool nerd stuff is really appreciated ;)

    Thank you very much again
     
  7. lotus49

    lotus49 Android Expert
    Thread Starter
    Rank:
    None
    Points:
    153
    Posts:
    1,513
    Joined:
    May 9, 2011

    May 9, 2011
    1,513
    232
    153
    Male
    Yorkshire
    When you log out of the shell in ubuntu it closes down as a result of that. You don't have to do anything else.

    I use ConnectBot and it does do colours. It won't allow you to change port, which is a bit annoying so I am looking for an alternative.

    When you refer to the strangeness of the environment it depends if you are talking about Android or Ubuntu. I presume you mean Android and the reason it seems unfriendly is that it's not meant for use directly. It's an OS powering a phone and it was designed to provide a minimal environment to enable a single-user GUI to run on top of it.

    Your best bet for installing additional software into Android is generally not to, but if you need say an editor, install busybox. Have a look at the free "BusyBox Installer" app in the marketplace. A recent version of busybox will provide an editor as well as a lot more.
     
  8. Rudedawg

    Rudedawg Android Expert
    Rank:
    None
    Points:
    98
    Posts:
    863
    Joined:
    Jun 24, 2011

    Jun 24, 2011
    863
    95
    98
    Security
    Southampton UK
    This thread is pure nerd porn. Well done though guys. :)
     
  9. korg91

    korg91 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    6
    Joined:
    Jun 29, 2011

    Jun 29, 2011
    6
    0
    5
    Trento (Italy)
    Some problems:

    I don't know why, but if I type "exit" in ubuntu (on android) shell it tells me:

    Code (Text):
    1. root@localhost:/# exit
    2. exit
    3.  
    4. Shutting down Ubuntu
    5. failed.
    6. losetup: /dev/block/loop7: Device or resource busy
    7. #
    8.  
    But then it exit anyway. But if I try to connect with VNC it's still there! Anyway I think it's kind of "freezed" when you don't use it, because my battery isn't draining at all.

    Another thing: I tried 2 VNC client but it seems that the keybord input works really badly: all the keys are wrong. Maybe it's necessary to choose the correct keyboard in ubuntu.
     
  10. lotus49

    lotus49 Android Expert
    Thread Starter
    Rank:
    None
    Points:
    153
    Posts:
    1,513
    Joined:
    May 9, 2011

    May 9, 2011
    1,513
    232
    153
    Male
    Yorkshire
    If you are using the ubuntu.img that you downloaded rather than building your own, I think the locale is set to German because when I tried to use apt-get the messages were in German. Try building your own and see if that helps.

    I shall look into the issue you describe about shutting down. I haven't done much testing of the script and I suspect that it had already been cobbled together before I started to hack it about too.
     
  11. sp33d_d3m0n

    sp33d_d3m0n Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 28, 2011

    Jul 28, 2011
    2
    0
    5
    Student
    Try creating your own ubuntu.img istead of downloading it(as the language and keymap is probably all messed up).
    The procedure is given on the following page:
    How to Build CHROOT ARM Ubuntu Images for Android!

    It works pretty fine for me except that i end up screwing the GUI cause of using ubuntu 11.04 (unity is not supported by vnc). So have to use lxde instead(which is frustrating).

    Also the error:

    root@localhost:/# exit
    exit

    Shutting down Ubuntu
    failed.
    losetup: /dev/block/loop7: Device or resource busy
    #

    does not affect the functioning of ubuntu. But still for some people who dont like any errors, you can run d "sh ubuntu.sh" command everytime you restart your phone.

    Also remember to type "vncserver -kill: 1(or your corresponding port/display number)" in ubuntu terminal before rebooting your device so that you dont have to change the port everytime you reboot your phone.

    All other scripts work fine. No need to edit those unless you know exactly wat you are doing or you want to end up getting a lot of errors.
     
  12. otester

    otester Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Aug 26, 2011

    Aug 26, 2011
    3
    0
    5
    I tried using the script above but after the "sh bootubuntu" bit I get this error:

    Code (Text):
    1.  
    2. # sh bootubuntu
    3. sh bootubuntu
    4.  failed: No such file or directoryk3 on /system
    5. bootubuntu: line 41: syntax error: unexpected end of file (expecting "then")
    6. # Killed
    7. / $
    Any ideas? :thinking:
     
  13. lotus49

    lotus49 Android Expert
    Thread Starter
    Rank:
    None
    Points:
    153
    Posts:
    1,513
    Joined:
    May 9, 2011

    May 9, 2011
    1,513
    232
    153
    Male
    Yorkshire
    That looks like a cut and paste error to me.

    Since the letters k3 do not appear in the script but do appear in the error message, I suspect that you have copied the script incorrectly.

    Have another go and report back.

    If that doesn't work, try:

    Code (Text):
    1. # sh -x bootubuntu
    and post the results so I can work out what the problem is.
     
  14. otester

    otester Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Aug 26, 2011

    Aug 26, 2011
    3
    0
    5
    I ended up going with Back Track 5 for Android, apparently they had a similar problem, after an update, worked perfectly.

    Thanks for posting though.
     
  15. Phik

    Phik Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 30, 2011

    Aug 30, 2011
    2
    0
    5
    Howdy. I'm getting a similar error to Otester. I grabbed the output of sh -x bootubuntu.


    Code (Text):
    1. export PATH=/data/local/bin:$PATH
    2. # export PATH=/data/local/bin:$PATH
    3. # cd /sdcard/external_sd/ubuntu
    4. # sh -x bootubuntu
    5. + mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
    6. mount: No such file or directory
    7. + export kit=/sdcard/external_sd/ubuntu
    8. + export bin=/system/bin
    9. bootubuntu: 38: Syntax error: end of file unexpected (expecting "then")
    10. #
    This is an exact copy/paste of the bootubuntu script im using

    Code (Text):
    1. #modprobe ext2
    2. mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
    3. export kit=/sdcard/external_sd/ubuntu
    4. export bin=/system/bin
    5. if ! test -d /data/local/ubuntu
    6. then
    7. mkdir /data/local/ubuntu
    8. fi
    9. export mnt=/data/local/ubuntu
    10. export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
    11. export TERM=linux
    12. export HOME=/root
    13. #mknod /dev/loop1 b 7 0
    14. losetup /dev/block/loop7 /sdcard/external_sd/ubuntu/ubuntu.img
    15. mount -t ext2 /dev/block/loop7 /data/local/ubuntu
    16. #mount -o loop,noatime -t ext2 $kit/ubuntu.img $mnt
    17. mount -o bind /proc $mnt/proc
    18. mount -o bind /dev $mnt/dev
    19. mount -t devpts devpts $mnt/dev/pts
    20. mount -t proc proc $mnt/proc
    21. mount -t sysfs sysfs $mnt/sys
    22. sysctl -w net.ipv4.ip_forward=1
    23. echo "Setting /etc/resolv.conf to Google Open DNS 8.8.8.8 and 8.8.4.4"
    24. echo "nameserver 8.8.8.8" > $mnt/etc/resolv.conf
    25. echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf
    26. echo "Setting localhost on /etc/hosts "
    27. echo "127.0.0.1 localhost" > $mnt/etc/hosts
    28. echo "READY TO ROCK AND ROLL BABY! "
    29. echo "Brought to you by NexusOneHacks.net and the open source community! "
    30. echo " "
    31. chroot $mnt /bin/bash
    32.  
    33. #After exit command is executed clear it all up
    34. echo " "
    35.  
    36. echo "Shutting down Ubuntu"
    37. umount $mnt/dev/pts
    38. umount $mnt/proc
    EDIT:
    Turns out to be an encoding problem. DON'T USE WINDOWS TO EDIT THE bootubuntu FILE. Use linux to get the right file encoding on the script. Works a charm that way.
    Thanks a heap to lotus49 for the script!
     
  16. lotus49

    lotus49 Android Expert
    Thread Starter
    Rank:
    None
    Points:
    153
    Posts:
    1,513
    Joined:
    May 9, 2011

    May 9, 2011
    1,513
    232
    153
    Male
    Yorkshire
    I'm glad you both worked it out.

    I rarely use Windows so I don't really experience problems like this. I probably should have pointed that out in my description.
     
  17. Phik

    Phik Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 30, 2011

    Aug 30, 2011
    2
    0
    5
    Has anyone managed to fix the Loop7 Device busy error?
    I edited the bootubuntu script so that it doesn't unmount the directories or attempt to remove the loop link when i quit the shell. I find running an SSH server in the background all the time handy and more than sufficient, but the ability to release the resources the ubuntu is using without rebooting my phone would be handy...
     
  18. kamathln

    kamathln Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Sep 4, 2011

    Sep 4, 2011
    1
    0
    5
    India

    Put this line right after the "export bin=/system/bin" line

    freeloop=$(expr 1 + $(ls /dev/block/loop* |cut -f 16- | sort -n|tail -n 1))

    and then replace all "loop7" in the script with "loop$freeloop"


    The thing is, loop7 wont be free if say, you have moved some apps to sd card .. the freeloop=line gets the next free loop device.

    Linux veterans might complain losetup -f should give the next free loop device .. but the problem is losetup looks at /dev/ for loop devices , while android seems to store them in /dev/block/ folder .. so losetup will report loop0 as the free loop, making necessary the above circus
     
  19. sp33d_d3m0n

    sp33d_d3m0n Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 28, 2011

    Jul 28, 2011
    2
    0
    5
    Student

Share This Page

Loading...