Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Sony Reader > Sony Reader Dev Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 01-25-2012, 08:37 AM   #1
uboot
Evangelist
uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.
 
Posts: 416
Karma: 75216
Join Date: Nov 2011
Location: old europe
Device: Kobo Mini, Sony PRS T1
Question HOWTO: e2fsck on init, fix_permissions afterwards

Hi folks, especially the devs,

I am desperately trying to get e2fsck fix my data and system partitions before mount and also run fix_permissions on every boot.

Both filesystems may get corrupted on a crash or cold reset. (I know that system is mounted read only normally, but it can be remounted rw for tweaking purposes, you know? )

The result of such a corruption are lots of force close popups and apps forgetting about their settings which many of us occassionally run into. (http://www.mobileread.com/forums/sho...d.php?t=164020 http://www.mobileread.com/forums/sho...d.php?t=164564)


Anyways, I already got a working e2fsck binary and found out that the whole boot process is done by the /init binary running the /init.rc script.

Read here for details: http://www.kandroid.org/online-pdk/guide/bring_up.html

So, the first thing to be done is integrating e2fsck commands into init.rc. But this requires the e2fsck binary to be available at this stage. Any ideas?

The best thing would be a busybox binary with integrated e2fsck. But I haven't found one for ARM yet... The one I have is statically linked to EXT2FS library, got it from here: http://sites.google.com/site/juanjosec/android

But how to make it available during init? Integrate to uboot / initial ramdisk?


The second goal - running the fix_permissions script - could be achieved by putting an exec call to /etc/install-recovery.sh, which is automatically called by /init.rc when the "on init" section is finished.

I tried many different ways to make install-recovery.sh run fix_permissions, but no success:
Code:
/bin/fix_permissions
exec /system/bin/fix_permissions
exec /system/bin/sh /system/bin/fix_permissions
The I tried to track this down by adding dummy echo commands to install-recovery.sh, but still nothing happens:
Code:
echo test > /mnt/sdcard/test.log
/system/bin/busybox echo test > /mnt/sdcard/test.log
write  /mnt/sdcard/test.log test
None of these commands did create the logfile.
uboot is offline   Reply With Quote
Old 01-25-2012, 08:53 AM   #2
m3l7d0wN
Zealot
m3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolate
 
Posts: 102
Karma: 33708
Join Date: Apr 2011
Device: Sony PRS-T1
hi, in a linux system, you can set the frequency of checking the filesystems with fsck, if it is what you mean, with tune2fs and -c option..
i.e. tune2fs -c 1 /dev/block/mmcblk2p10 (1 or 0, I don't remember)
the setting should be written in the partition, so you can launch the command only one time wherever you want.

does dmesg say something about install_recovery?

I don't understand why you have to run fsck on every boot. It should be enough to run it one time only.
m3l7d0wN is offline   Reply With Quote
 
Enthusiast
Old 01-25-2012, 08:57 AM   #3
uboot
Evangelist
uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.
 
Posts: 416
Karma: 75216
Join Date: Nov 2011
Location: old europe
Device: Kobo Mini, Sony PRS T1
The point is: on some android devices, especially the T1, there will NEVER be fsck done, regardless of the sanity state of the filesystems!

This is because:

1.) There are no fsck binaries for ext2/3/4 installed
2.) There are no fsck calls in init.rc

So, dmesg says something like
Code:
<4>EXT4-fs (mmcblk2p10): warning: mounting unchecked fs, running e2fsck is recommended
uboot is offline   Reply With Quote
Old 01-25-2012, 10:29 AM   #4
m3l7d0wN
Zealot
m3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolate
 
Posts: 102
Karma: 33708
Join Date: Apr 2011
Device: Sony PRS-T1
well,
it seems that sdcard is not accessible when install-recovery is launched.
Try this (for me it works):

mkdir /tmp
echo test > /tmp/test

obviously the file is accessible only until the T1 is rebooted again
m3l7d0wN is offline   Reply With Quote
Old 01-25-2012, 04:09 PM   #5
S3raph
Member
S3raph began at the beginning.
 
Posts: 14
Karma: 20
Join Date: Dec 2011
Device: Sony Reader PRS-T1
I think the best way would be to add e2fsck to the ramdisk and create an entry in the init.rc config.
S3raph is offline   Reply With Quote
Old 01-25-2012, 04:30 PM   #6
m3l7d0wN
Zealot
m3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolate
 
Posts: 102
Karma: 33708
Join Date: Apr 2011
Device: Sony PRS-T1
yeah, but it requires to flash p1 or p2 partitions (they're read only), which is quite dangerous.. the best way is to use a script that is stored in the /system (ext4) partition, so we can modify easily with adb.
install-recovery works fine for me
m3l7d0wN is offline   Reply With Quote
Old 01-25-2012, 04:40 PM   #7
S3raph
Member
S3raph began at the beginning.
 
Posts: 14
Karma: 20
Join Date: Dec 2011
Device: Sony Reader PRS-T1
yeah but in order to run e2fsck successfully it needs to be executed before the /system /data etc partition are mounted otherwise it wont work, so imho the only option is to put in init.rc of the ramdisk.
S3raph is offline   Reply With Quote
Old 01-25-2012, 04:42 PM   #8
m3l7d0wN
Zealot
m3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolate
 
Posts: 102
Karma: 33708
Join Date: Apr 2011
Device: Sony PRS-T1
oh, you are right.. I didn't think of that :P
m3l7d0wN is offline   Reply With Quote
Old 01-25-2012, 04:56 PM   #9
S3raph
Member
S3raph began at the beginning.
 
Posts: 14
Karma: 20
Join Date: Dec 2011
Device: Sony Reader PRS-T1
However for the fix_permissions script install-recovery.sh is the best location.

Adding
"sh /system/bin/fix_permissions 2>&1 > /data/fix_permissions.log"

to install-recovery.sh works like a charm

Last edited by S3raph; 01-27-2012 at 10:42 AM.
S3raph is offline   Reply With Quote
Old 01-25-2012, 06:55 PM   #10
rupor
Addict
rupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toysrupor shares his or her toys
 
rupor's Avatar
 
Posts: 208
Karma: 5658
Join Date: Jul 2007
Location: USA
Device: PRS 500,505,900,650,T1,T2, Nook ST, Kindle PW2
Quote:
Originally Posted by S3raph View Post
yeah but in order to run e2fsck successfully it needs to be executed before the /system /data etc partition are mounted otherwise it wont work, so imho the only option is to put in init.rc of the ramdisk.
What permissions are you fixing if /system and /data are not mounted? Am I missing something?

Or you are talking about fixing file systems only?
rupor is offline   Reply With Quote
Old 01-25-2012, 07:00 PM   #11
m3l7d0wN
Zealot
m3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolatem3l7d0wN is generous with chocolate
 
Posts: 102
Karma: 33708
Join Date: Apr 2011
Device: Sony PRS-T1
e2fsck fix the file system, not the permissions. For the permission part, we have to run fix_permissions after the system and data are mounted
m3l7d0wN is offline   Reply With Quote
Old 01-26-2012, 04:00 AM   #12
uboot
Evangelist
uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.uboot seems famous, but is in fact legendary.
 
Posts: 416
Karma: 75216
Join Date: Nov 2011
Location: old europe
Device: Kobo Mini, Sony PRS T1
Thanks @S3raph!!

@rupor: install_recovery is run as a service and at the point where services are started, everything is mounted
uboot is offline   Reply With Quote
Old 01-26-2012, 12:11 PM   #13
S3raph
Member
S3raph began at the beginning.
 
Posts: 14
Karma: 20
Join Date: Dec 2011
Device: Sony Reader PRS-T1
Your welcome

by the way I asked porkupan the correct parameters to build a "new" ramdisk

Code:
find . -print | cpio -o -H newc | gzip -v9 > ../ramdisk-adb.gz
mkimage -A ARM -O Linux -T ramdisk -C gzip -a 0x70308000 -e 0x70308000 -n "Normal Rootfs" -d ramdisk-adb.gz ramdisk-adb.uimg
as soon as I have some spare time I'm building a new ramdisk with e2fsck support.
S3raph is offline   Reply With Quote
Old 01-27-2012, 07:57 AM   #14
j0534ng31
Connoisseur
j0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheesej0534ng31 can extract oil from cheese
 
Posts: 83
Karma: 1224
Join Date: Dec 2011
Location: Gijon (Spain)
Device: Sony PRS-T1 black
Post

¿What do you think about this approach?

In init.rc, 'preload' is mounted before 'system' and 'data':
Code:
# mount ext4 partitions
    mount ext4 /dev/block/mmcblk2p6 /ebook/dic ro
    mount ext4 /dev/block/mmcblk2p8 /ebook/preload ro

    mount ext4 /dev/block/mmcblk2p10 /system
    mount ext4 /dev/block/mmcblk2p10 /system ro remount

    # We chown/chmod /data again so because mount is run as root + defaults
    mount ext4 /dev/block/mmcblk2p9 /data nosuid nodev
    chown system system /data
    chmod 0771 /data
    chown system system /data/app
Then, I think we can put our tools (e2fsck) into a new directory in 'preload' and change the PATH variable; and so, system and data can be automatically checked at boot time, just before mounting them.

As there is no free space in preload, but there is unused space in /dev/block/mmcblk2p8, first of all we have to resize the filesystem.

While booted in normal mode:
Code:
/ # # Just for your information, to see my actual busybox version
/ # # It's a full version, completely installed in '/system/xbin'
/ # busybox
BusyBox v1.20.0.git (2011-12-11 18:10:48 CET) multi-call binary.

/ # # To see actual size of preload and free space
/ # df
Filesystem           1K-blocks      Used Available Use% Mounted on
...
/dev/block/mmcblk2p8     36708     36697        11 100% /ebook/preload
...

/ # # Making a image of preload
/ # dd if=/dev/block/mmcblk2p8 of=/extsd/mmcblk2p8.img
81968+0 records in
81968+0 records out
41967616 bytes (40.0MB) copied, 14.361208 seconds, 2.8MB/s

/ # # Just to be sure
/ # stat -c %s /extsd/mmcblk2p8.img
41967616

/ # # Umount preload to resize fs
/ # umount /ebook/preload

/ # # Resizing the preload fs to partition size
/ # resize2fs /dev/block/mmcblk2p8
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/block/mmcblk2p8 to 40984 (1k) blocks.
The filesystem on /dev/block/mmcblk2p8 is now 40984 blocks long.

/ # # Remount the new preload
/ # mount /dev/block/mmcblk2p8 /ebook/preload

/ # # To see actual size of preload and free space
/ # df  &&  df -h
Filesystem           1K-blocks      Used Available Use% Mounted on
...
/dev/block/mmcblk2p8     40947     36697      4250  90% /ebook/preload
...
/dev/block/mmcblk2p8     40.0M     35.8M      4.2M  90% /ebook/preload
...
So, now we have 4.2MB... to save our tools and perhaps some scripts.

We just have to:
  1. Remount '/ebook/preload' as read/write
    mount -o remount,rw /dev/block/mmcblk2p8

  2. Create a new directory '/ebook/preload/bin'
    mkdir /ebook/preload/bin

  3. Copy there our 'e2fsck' tool
    cp -p $(which e2fsck) /ebook/preload/bin
    chmod 755 /ebook/preload/bin/e2fsck

  4. Option 1: Call 'e2fsck' from 'init.rc' using absolute path, to check filesystems at boot.

    - If needed, not forced, seems right to me:
    /ebook/preload/bin/e2fsck -py /dev/block/mmcblk2p9
    /ebook/preload/bin/e2fsck -py /dev/block/mmcblk2p10

    - Always, forced, seems of little use to me:
    /ebook/preload/bin/e2fsck -pyf /dev/block/mmcblk2p9
    /ebook/preload/bin/e2fsck -pyf /dev/block/mmcblk2p10

  5. Option 2: Add '/ebook/preload/bin' to the PATH variable (in 'init.rc') and let the system to decide when to do the check
    So, new PATH=/sbin:/system/sbin:/system/bin:/system/xbin:/ebook/preload/bin
    mount -o remount,rw /
    sed -i '/export PATH/ s@$@:/ebook/preload/bin@' /init.rc

  6. We can also change the automatic check frequency:
    tune2fs -c max_mounts_count /dev/block/mmcblk2p9
    tune2fs -c max_mounts_count /dev/block/mmcblk2p10

  7. Write pending changes to disk and reboot in normal mode:
    sync && $(which chgboot) normal && reboot


Just for the sake of completeness, right here are the tools I'm using (ready to download):
  • e2fsck
  • resize2fs
  • tune2fs
  • busybox (used for every other command)
    Install it, or replace every busybox depending 'command' by 'busybox command'
  • parted (NOT USED: I owe it to uboot!)



PS1:

I've used the same 'stat' + 'tune2fs' approach to extend the system partition.
(but, from recovery mode, to can umount the 'system' filesystem.)

It seems to me a 'cleaner' method than creating a new image, copying old system to new image,...


PS2:

I'm doing a great effort of documenting every procedure used to modify the PRS-T1 in a thread of my spanish forum...
I'm explaining how to use the android SDK, a bit of Linux, and a lot of interesting procedures like how to do a manual rooting, what is and how to install busybox,...
It needs to be borne in mind that it is a non-technical people forum; many of them are only book lovers,... so the information is written kinda adapted to their comprehesion skills.

It's in spanish language but using english is quite in order, so there is no need to translate with to post.
Those interested in taking part can find it HERE. You are very welcome!

Last edited by j0534ng31; 01-27-2012 at 08:02 AM.
j0534ng31 is offline   Reply With Quote
Old 01-27-2012, 10:32 AM   #15
S3raph
Member
S3raph began at the beginning.
 
Posts: 14
Karma: 20
Join Date: Dec 2011
Device: Sony Reader PRS-T1
great idea j0534ng31 I didn't thought about that, however the probably greatest advantage of the ramdisk solution is its simplicity.

I attached my modified ramdisk, its the "normal" ramdisk with a modified init.rc and includes the e2fsck binary.

Code:
# check filesystem
    exec /sbin/e2fsck -py /dev/block/mmcblk2p1
    exec /sbin/e2fsck -py /dev/block/mmcblk2p9
    exec /sbin/e2fsck -py /dev/block/mmcblk2p10
credits go to porkupan for the flash script/tools and all his great work.


[EDIT]
IF YOU HAVE DOWNLOADED ANY OF THE FILES DONT FLASH IT, IT WILL BRICK YOUR READER/RAMDISK.

YOU CAN RESTORE IT WITH THE SD-RESCUE METHOD
[EDIT]

Last edited by S3raph; 01-29-2012 at 11:36 AM.
S3raph is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot edit init.rc sjkevin Nook Developer's Corner 4 02-15-2011 06:44 PM
web2disk - howto? urbane_gorilla Calibre 3 03-29-2010 04:48 AM
SmartQ5 - modem init string and login data saving Drakon Rider Alternative Devices 4 09-27-2009 05:09 AM
Howto open case? Flolo HanLin eBook 7 06-25-2009 04:11 AM
update howto m-s-s iRex 5 07-01-2007 03:52 PM


All times are GMT -4. The time now is 07:38 AM.


MobileRead.com is a privately owned, operated and funded community.