Boot from SD-card | New Method [2.6.32]

Search This thread

gr0gmint

Senior Member
Feb 23, 2008
64
7
To make the HTC Desire boot from a 1gb file on your SD-card:

Instead of having to partition the SD-card to make this work,there is another solution; that is to make a "virtual" EXT2 partition as a file on the FAT32 partition.

You can make this file as big as you want. 1gb is a fitting size though. .. you will probably need a linux box to make this work.... The file has to be called altboot.ext2 and lie at the root of the SD-card

NOTE: The initfiles and the modified kernel in this guide is 2.6.32 ONLY. I understood this may be an inconvenience for some. This kernel also disabled the "Android Paranoid Networking" feature, which is a useless pain-in-the-ass feature.


1. To make a 1GB empty file, issue dd if=/dev/zero of=altboot.ext2 bs=1M count=1000
2. Make a EXT2 filesystem on the file: mkfs.ext2 altboot.ext2
3. Mount the file as a loopdevice: mount -o loop -t ext2 altboot.ext2 <mountpoint>
4. Copy files from the attached initfiles.zip to <mountpoint>
5. Copy all files from a rom of your choice to <mountpoint>
6. Issue a chmod -R 0755 <mountpoint>
7. Issue umount <mountpoint>
8. Copy altboot.ext2 to the root of the SD-card
9. Flash my kernel image
10. Reboot your phone, and press the Home key repeatedly

Good luck :D


The source code changes for this kernel can be found at http://github.com/gr0gmint/kernel_msm
(Here is the source code for the two "special" init files)

executable in the ramdisk:
Code:
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <linux/loop.h>
#include <fcntl.h>

#define BB_LOOP_SET_STATUS LOOP_SET_STATUS64
#define BB_LOOP_GET_STATUS LOOP_GET_STATUS64
typedef struct loop_info64 loop_info;


int main (int argc, char * argv[]) {
    int dfd,ffd;
    loop_info loopinfo;

    mknod("/sd2" , S_IFBLK|S_IRUSR| S_IWUSR, makedev(179,1) );
    mknod("/lo5" , S_IFBLK|S_IRUSR| S_IWUSR, makedev(7,5) );


    mkdir("/sd", 0755);
    sleep(7);
    mount("/sd2","/sd", "vfat",0, NULL) ;
    
  
    ffd = open("/sd/altboot.ext2", O_RDWR);
    dfd = open("/lo5", O_RDWR);
    
	ioctl(dfd, LOOP_SET_FD, ffd);
	memset(&loopinfo, 0, sizeof(loopinfo));
	strcpy((char *)loopinfo.lo_file_name, "/sd/altboot.ext2");
	ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo);
    mkdir("/chrootenv", 0755);
    if (mount("/lo5", "/chrootenv","ext2", 0, NULL) != 0 ) {
	    execv("/init", argv);
	}
    execv("/chrootenv/altinit", argv);
}

executable on the SD-card:
Code:
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/mount.h>
int main (int argc, char * argv[]) {
	
	if (chroot("/chrootenv/") == 0) {
	chdir("/");

	execv ("/init", argv);
	}
		


}
 

Attachments

  • initfiles.zip
    163.3 KB · Views: 594
  • altboot-kernel.zip
    2.3 MB · Views: 640
Last edited:

gr0gmint

Senior Member
Feb 23, 2008
64
7
Any error on execution?

Yes it reboots, and resumes with a normal boot. I made some error checking, and it seems the init binary gets executed, but there's trouble with mounting the SD-card. I will try with manually mknod'ing in a moment.

EDIT: That didn't help either.
 
Last edited:

kubino99

Senior Member
Apr 14, 2008
244
28
I'm not sure but when you do chroot you propably lost system folders. Maybe you can try this :

Code:
#include <unistd.h>
#include <sys/stat.h>
#include <sys/stat.h>

int main (int argc, char * argv[]) {

    mkdir("/dev", 0755);
    mkdir("/dev/block", 0755);
    mknod("/dev/block/mmcblk0p2" , S_IFBLK|S_IRUSR| S_IWUSR, makedev(179,2) );

    mkdir("/mnt", 0755);
    mkdir("/mnt/sdcard", 0755);
    mount("/dev/block/mmcblk0p2","/mnt/sdcard", "ext2",0, NULL);
    chroot("/mnt/sdcard");

    mkdir("/dev", 0755);
    mkdir("/proc", 0755);
    mkdir("/sys", 0755);
    mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755");
    mkdir("/dev/pts", 0755);
    mkdir("/dev/socket", 0755);
    mount("devpts", "/dev/pts", "devpts", 0, NULL);
    mount("proc", "/proc", "proc", 0, NULL);
    mount("sysfs", "/sys", "sysfs", 0, NULL);
    execv("/init", argv);
}

Edit : of course you need to firstly create special file /dev/block/mmcblk0p2
Edit2 : tryed to add code for creating /dev/block/mmcblk0p2, not sure if it will works I didn't test that ;-)
 
Last edited:

gr0gmint

Senior Member
Feb 23, 2008
64
7
I'm not sure but when you do chroot you propably lost system folders. Maybe you can try this :

Code:
#include <unistd.h>


int main (int argc, char * argv[]) {

    mkdir("/dev", 0755);
    mkdir("/mnt", 0755);
    mkdir("/mnt/sdcard", 0755);
    mount("/dev/block/mmcblk0p2","/mnt/sdcard", "ext2",0, NULL);
    chroot("/mnt/sdcard");

    mkdir("/dev", 0755);
    mkdir("/proc", 0755);
    mkdir("/sys", 0755);
    mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755");
    mkdir("/dev/pts", 0755);
    mkdir("/dev/socket", 0755);
    mount("devpts", "/dev/pts", "devpts", 0, NULL);
    mount("proc", "/proc", "proc", 0, NULL);
    mount("sysfs", "/sys", "sysfs", 0, NULL);
    execv("/init", argv);
}

Edit : of course you need to firstly create special file /dev/block/mmcblk0p2

Thanks for the input, but it still reboots:(
 

gr0gmint

Senior Member
Feb 23, 2008
64
7
dmesg | grep -i 'mmc'

EDIT: I can see i probably need to sleep a few seconds before i mount. Will try later

Code:
[    4.355255] bravo_init_mmc()+
[    4.355438] bravo_init_mmc()-
[    5.939910] mmc0: MMC_BUSCLK_PWRSAVE is enabled
[    5.940185] mmc0: Qualcomm MSM SDCC at 0x00000000a0300000 irq 24,0 dma 8
[    5.940185] mmc0: Platform slot type: Not defined
[    5.940185] mmc0: 4 bit data mode enabled
[    5.940216] mmc0: MMC clock 144000 -> 50000000 Hz, PCLK 64000000 Hz
[    5.940216] mmc0: Slot eject status = 1
[    5.940216] mmc0: Power save feature enable = 1
[    5.940246] mmc0: DM non-cached buffer at ffa06000, dma_addr 0x3b331000
[    5.940246] mmc0: DM cmd busaddr 0x3b331000, cmdptr busaddr 0x3b331300
[    5.940704] mmc1: MMC_BUSCLK_PWRSAVE is enabled
[    5.941192] mmc1: Qualcomm MSM SDCC at 0x00000000a0400000 irq 26,0 dma 8
[    5.941192] mmc1: Platform slot type: SD
[    5.941192] mmc1: 4 bit data mode enabled
[    5.941223] mmc1: MMC clock 144000 -> 50000000 Hz, PCLK 64000000 Hz
[    5.941223] mmc1: Slot eject status = 0
[    5.941223] mmc1: Power save feature enable = 1
[    5.941223] mmc1: DM non-cached buffer at ffa07000, dma_addr 0x3b335000
[    5.941253] mmc1: DM cmd busaddr 0x3b335000, cmdptr busaddr 0x3b335300
[    6.173095] mmc1: Command timeout (cmd= 5 mci_st=00000004)
[    6.179077] mmc1: Command timeout (cmd= 5 mci_st=00000004)
[    6.185119] mmc1: Command timeout (cmd= 5 mci_st=00000004)
[    6.191101] mmc1: Command timeout (cmd= 5 mci_st=00000004)
[    6.711578] mmc1: host does not support reading read-only switch. assuming write-enable.
[    6.711791] mmc1: new high speed SDHC card at address 673b
[    6.712432] mmcblk0: mmc1:673b SD16G 14.9 GiB 
[    6.712921]  mmcblk0: p1 p2
 

gr0gmint

Senior Member
Feb 23, 2008
64
7
It boots now, but is stuck at the HTC logo, although adbd runs.
Some of the errors it loops constantly:
Code:
E/FramebufferNativeWindow(  484): Couldn't get gralloc module

E/libEGL  (  484): eglGetDisplay:632 error 300c (EGL_BAD_PARAMETER)
E/libEGL  (  484): eglInitialize:646 error 3008 (EGL_BAD_DISPLAY)


I/Zygote  (  483): Exit zygote because system server (484) has terminated
I/ServiceManager(   55): service 'media.audio_flinger' died
I/ServiceManager(   55): service 'media.player' died
I/ServiceManager(   55): service 'media.camera' died
I/ServiceManager(   55): service 'media.audio_policy' died
I/ServiceManager(   62): Waiting for sevice SurfaceFlinger...


E/AudioHardwareQSD(  507): Cannot open /dev/audience_a1026 -1
I/AudioHardwareQSD(  507): set_tpa2018d1_parameters() not present

E/Zygote  (  512): setreuid() failed. errno: 17
 

kubino99

Senior Member
Apr 14, 2008
244
28
It boots now, but is stuck at the HTC logo, although adbd runs.
Some of the errors it loops constantly:
Code:
E/FramebufferNativeWindow(  484): Couldn't get gralloc module

E/libEGL  (  484): eglGetDisplay:632 error 300c (EGL_BAD_PARAMETER)
E/libEGL  (  484): eglInitialize:646 error 3008 (EGL_BAD_DISPLAY)


I/Zygote  (  483): Exit zygote because system server (484) has terminated
I/ServiceManager(   55): service 'media.audio_flinger' died
I/ServiceManager(   55): service 'media.player' died
I/ServiceManager(   55): service 'media.camera' died
I/ServiceManager(   55): service 'media.audio_policy' died
I/ServiceManager(   62): Waiting for sevice SurfaceFlinger...


E/AudioHardwareQSD(  507): Cannot open /dev/audience_a1026 -1
I/AudioHardwareQSD(  507): set_tpa2018d1_parameters() not present

E/Zygote  (  512): setreuid() failed. errno: 17

seems like you need to create special files in /dev folder check via adb which files are present.
 

kingchris

Senior Member
Apr 17, 2007
310
13
quick OT Question.
do you think it is possible to create a recovery which is bootable with this method?
 

myth1001

Senior Member
Nov 15, 2009
369
19
Kuala Lumpur
Though I have no idea what this is for, but GREAT WORK mate!
Great to see new breakthrough for our Desire!
Thanks for the hard work! :D
 

gr0gmint

Senior Member
Feb 23, 2008
64
7
Though I have no idea what this is for, but GREAT WORK mate!
Great to see new breakthrough for our Desire!
Thanks for the hard work! :D

Thanks ^^
It means you can have both Froyo and 2.1 on your Desire for example.
You basically have an extra ext2 partition on your SD card with another OS
 

StuMcBill

Senior Member
Feb 13, 2010
1,895
120
It's working! We can now do multibooting on Desire!
I will post a guide tomorrow with files!

Does this mean we can store /system on our SD card and choose between booting the SD card stored software or the software stored on the Flash of the device?

Dual-booting between Internal Flash and SD card essentially? So you could have Froyo (when released) on SD card and 2.1 on the device as normal?

Or could you have recovery stored on the SD card and run it from there?
 

gr0gmint

Senior Member
Feb 23, 2008
64
7
Does this mean we can store /system on our SD card and choose between booting the SD card stored software or the software stored on the Flash of the device?

Dual-booting between Internal Flash and SD card essentially? So you could have Froyo (when released) on SD card and 2.1 on the device as normal?

Or could you have recovery stored on the SD card and run it from there?

Yes. Only limitation (so far), is they have to share to same kernel.
And no. I don't think you will have write access to the system partition.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    It's working! We can now do multibooting on Desire!
    I will post a guide tomorrow with files!