Difference between revisions of "Tutorials Linux opt on loopback"

From WebOS Internals
Jump to navigation Jump to search
(Undo revision 3800 by UltraBlack (Talk))
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Background & Purpose=
+
= Background & Purpose =
  
 
The Palm Pre's 8GB HD is configured with three partitions:
 
The Palm Pre's 8GB HD is configured with three partitions:
Line 26: Line 26:
 
'''NOTE:''' The /dev/store/update is mounted when you run the Update process. It would seem that the updates are stored here (at least some of them) prior to installation.
 
'''NOTE:''' The /dev/store/update is mounted when you run the Update process. It would seem that the updates are stored here (at least some of them) prior to installation.
  
=Requirements=
+
= Requirements =
  
 
You must have access to the Linux shell to perform this process. It is assumed that you followed the procedure to install Optware apps in /var/opt and linked /var/opt to /opt with the "mount -o bind /var/opt /opt" command and there is an equivalent entry in the /etc/fstab file.
 
You must have access to the Linux shell to perform this process. It is assumed that you followed the procedure to install Optware apps in /var/opt and linked /var/opt to /opt with the "mount -o bind /var/opt /opt" command and there is an equivalent entry in the /etc/fstab file.
  
=Procedure for Creating a Linux Virtual file system=
+
=Procedure for Creating a Linux Virtual File System=
  
 
Do '''NOT''' do this if you want to connect your Pre to your computer in the USB Drive or Media Sync modes.
 
Do '''NOT''' do this if you want to connect your Pre to your computer in the USB Drive or Media Sync modes.
Line 40: Line 40:
  
 
#  Create a 1GB file (adjust size (bs*count) as needed, the minimum size should be 256MB)
 
#  Create a 1GB file (adjust size (bs*count) as needed, the minimum size should be 256MB)
dd if=/dev/zero of=/media/internal/vfs/Optware.img bs=1024 count=1024k
+
dd if=/dev/zero of=/media/internal/vfs/optware.img bs=1024 count=1024k
  
 
# Create linux ext3 file system
 
# Create linux ext3 file system
mkfs.ext3 -F /media/internal/vfs/Optware.img
+
mkfs.ext3 -F /media/internal/vfs/optware.img
  
 
# Create a temporary mount point
 
# Create a temporary mount point
Line 49: Line 49:
  
 
# Mount newly created virtual file system
 
# Mount newly created virtual file system
mount -o loop /media/internal/vfs/Optware.img  /tmp/opt
+
mount -o loop /media/internal/vfs/optware.img  /tmp/opt
  
 
# Populate new virtual file system.
 
# Populate new virtual file system.
Line 65: Line 65:
 
# If no errors, mount virtual file system on /opt
 
# If no errors, mount virtual file system on /opt
 
# otherwise skip
 
# otherwise skip
mount -o loop /media/internal/vfs/Optware.img /opt/
+
mount -o loop /media/internal/vfs/optware.img /opt
  
 
# Add the following line to /etc/fstab to automount (without the #).
 
# Add the following line to /etc/fstab to automount (without the #).
# /media/internal/vfs/Optware.img     /optext3   loop,noatime   1       2
+
# /media/internal/vfs/optware.img /opt ext3 loop,noatime 1 2
 
#
 
#
 
# Comment out the /var/opt entry, should be similar to next line
 
# Comment out the /var/opt entry, should be similar to next line
#/var/opt /opt bind     defaults,bind         0       0
+
#/var/opt /opt bind defaults,bind 0 0
 
#
 
#
 
# reboot your phone, if error noted when attempting to unmount /opt
 
# reboot your phone, if error noted when attempting to unmount /opt
Line 81: Line 81:
 
</source>
 
</source>
  
=Caveat=
+
= Caveats =
  
 
Currently this procedure will disable USB Drive and Media Sync modes.
 
Currently this procedure will disable USB Drive and Media Sync modes.
Line 87: Line 87:
 
A method to safely unmount Virtual file system when selecting USB Drive and Media Sync modes is under development.
 
A method to safely unmount Virtual file system when selecting USB Drive and Media Sync modes is under development.
  
See the start/stop script below for now. In the future this should be wrapped inside a homebrew GUI.
+
See the start/stop script below for now. The script needs to be run from a non-ssh terminal (ie novaproxy or novaterm). In the future this should be wrapped inside a homebrew GUI.
  
==Workaround: Start/Stop Script==
+
== Caveat Workaround: Mount/Unmount Script ==
  
A work in progress. Needs to be bullet-proofed. Ideally should be wrapped around a WebOS GUI app. This script is a work-a-round to allow using the Palm Pre's USB Drive and Media Sync modes.
+
This script will start/stop (mount/unmount) the virtual file system, thus functioning as a work-a-round to allow using the Palm Pre's USB Drive and Media Sync modes. It is a work in progress and needs to be bullet-proofed. Ideally it should be wrapped around a WebOS GUI app—we are working on this. This script should be saved to a file (i.e. /home/root/vfs), made executable (i.e. chmod 750 /home/root/vfs and then run (i.e. with /home/root/vfs on or /home/root/vfs off). '''Do not save the script to an /opt path.''' Make sure you're running the script to toggle the virtual file system on or off when /media/internal is not mounted as a USB drive and the Media Sync mode is not enabled, otherwise the script will fail.
 +
 
 +
=== Note: We need this put in a Java service ===
 +
 
 +
''This means we need to translate it to Java the Pre can understand! This will be for front-end GUI to toggle the VFS. Please [http://gitorious.org/webos-internals/applications/trees/master/optloopservice look into this if you have the knowledge, on Gitorious]. The source is there.''
 +
 
 +
==== The Script Itself ====
  
 
<source lang="bash">
 
<source lang="bash">
Line 97: Line 103:
 
#
 
#
 
# List of Optware applications to start/stop
 
# List of Optware applications to start/stop
# in conjunction with mounting/unmounting VFS
+
# in conjunction with mounting/unmounting VFS.
# Edit to suit environment
+
#
APPS="Optware-openssh Optware-dropbear"
+
# Check to make sure /media/internal is
 +
# mounted
 +
FSINT=`/bin/df|/bin/grep "/dev/mapper/store-media"`
 +
if [ "$FSINT" = "" ]
 +
then
 +
echo "USB Drive not mounted. Exiting"
 +
exit 1
 +
fi
 +
 
 +
# OpenSSH and Dropbear are most common.
 +
# Edit to suit environment.
 +
APPS="optware-openssh optware-dropbear"
  
# An entry in /etc/fstab must exist filename
+
# An entry in /etc/fstab must exist for the VFS
 +
# Grab and parse entry
 
FSVFS=`/bin/grep "/opt" /etc/fstab|grep loop`
 
FSVFS=`/bin/grep "/opt" /etc/fstab|grep loop`
 
if [ "$FSVFS" != "" ]
 
if [ "$FSVFS" != "" ]
Line 107: Line 125:
 
  # Complete FileName of VFS to mount/unmount
 
  # Complete FileName of VFS to mount/unmount
 
  LVFSFN=`echo $FSVFS|/usr/bin/awk '{print $1}'`
 
  LVFSFN=`echo $FSVFS|/usr/bin/awk '{print $1}'`
  # VFS Mount Point
+
  # VFS Mount Point (ie /opt)
 
  LVFSMP=`echo $FSVFS|/usr/bin/awk '{print $2}'`
 
  LVFSMP=`echo $FSVFS|/usr/bin/awk '{print $2}'`
  # VFS file system Type
+
  # VFS file system Type (ie ext3)
 
  LVFSTP=`echo $FSVFS|/usr/bin/awk '{print $3}'`
 
  LVFSTP=`echo $FSVFS|/usr/bin/awk '{print $3}'`
 
else
 
else
Line 120: Line 138:
 
if [ "$VFSMTD" != "" ]
 
if [ "$VFSMTD" != "" ]
 
then
 
then
 +
# Loopback device associated with VFS (ie /dev/loop0)
 
  LVFSDV=`echo $VFSMTD|/usr/bin/awk '{print $1}'`
 
  LVFSDV=`echo $VFSMTD|/usr/bin/awk '{print $1}'`
 
fi
 
fi
Line 156: Line 175:
 
         echo '**** Unmounting Linux VFS'
 
         echo '**** Unmounting Linux VFS'
 
         /bin/umount "$LVFSMP"
 
         /bin/umount "$LVFSMP"
 +
        # Work-a-round to disassociate VFS from loopback device
 
         /sbin/losetup -d $LVFSDV
 
         /sbin/losetup -d $LVFSDV
 
         echo '**** Linux VFS Disabled'
 
         echo '**** Linux VFS Disabled'
Line 169: Line 189:
 
</source>
 
</source>
  
=Credits=
+
= Credits =
  
 
<pre>
 
<pre>
PuffTheMagic - Initial process
+
PuffTheMagic - Devised the initial process
1lnxraider  - Expanded and modified tutorial, is working on fixing caveats
+
1lnxraider  - Expanded, modified, & published tutorial
ultraBlack  - Found and had confirmed the major caveat that disables Media Sync and USB modes
+
            - Helped ultraBlack troubleshoot toggle script
NetWhiz      - Gave additional warning that this process disables USB Drive/Media Sync
+
            - Confirmed caveat
 +
ultraBlack  - Found & had confirmed the major caveat which disables Media Sync & USB modes
 +
            - Devised plan for front-end 'Toggle VFS' GUI, envisioning it as a way to also easily create it
 +
rwhitby      - Provided skeleton & basic methods for front-end GUI's Opt Loop Service
 +
NetWhiz      - Gave additional warning that this process disables Media Sync and USB modes
 
</pre>
 
</pre>

Latest revision as of 07:01, 15 August 2009

Background & Purpose

The Palm Pre's 8GB HD is configured with three partitions:

1) /dev/mmcblk0p1 defined as a Linux/PA-RISC boot partition is only 4MB
2) /dev/mmcblk0p2 defined as a Linux partition and is 32MB mounted as /boot
3) /dev/mmcblk0p3 defined as a Linux LVM partition is 7.62GB

The /dev/mmcblk0p3 partition is a Linux Volume Group that is sliced into six Logical Volumes:

/dev/store/root mounted on / (root) 456 MB
/dev/store/var mounted on /var 256MB
/dev/store/update mounts on /var/lib/update 56MB (not mounted)
/dev/store/log/ mounted on /var/log 40MB
/dev/store/media mounted /media/internal 6.69GB
/dev/store/swap Linux swap 128MB

It has been observed that if /var or / (root) usage is greater than or equal to 90% than the FAILED_NOT_ENOUGH_INSTALL_SPACE error is generated. "Builtin" applications reside on the root file system in /usr/palm/applications. Downloaded apps and those installed with palm-install reside on the /var file system in /var/usr/palm/applications. Also for so-called "rooted" Pre's the Optware Linux-based apps are stored in /var/opt.

One fix for a rooted Pre is to create a virtual Linux file system using a portion of the space allocated to /media/internal using a procedure similar to this one:

Linux Online - Using a file instead of a partition

Then mount the virtual file system on /opt vs binding /var/opt to /opt. Then relocating the files/directories under /var/opt to the new virtual file system.

NOTE: The /dev/store/update is mounted when you run the Update process. It would seem that the updates are stored here (at least some of them) prior to installation.

Requirements

You must have access to the Linux shell to perform this process. It is assumed that you followed the procedure to install Optware apps in /var/opt and linked /var/opt to /opt with the "mount -o bind /var/opt /opt" command and there is an equivalent entry in the /etc/fstab file.

Procedure for Creating a Linux Virtual File System

Do NOT do this if you want to connect your Pre to your computer in the USB Drive or Media Sync modes.

The following commands will move all of your Optware packages to an ext3 1GB loopback image that resides on /media/internal. <source lang="bash">

  1. Create a directory on the USB drive portion to hold the virtual file system

mkdir /media/internal/vfs

  1. Create a 1GB file (adjust size (bs*count) as needed, the minimum size should be 256MB)

dd if=/dev/zero of=/media/internal/vfs/optware.img bs=1024 count=1024k

  1. Create linux ext3 file system

mkfs.ext3 -F /media/internal/vfs/optware.img

  1. Create a temporary mount point

mkdir /tmp/opt

  1. Mount newly created virtual file system

mount -o loop /media/internal/vfs/optware.img /tmp/opt

  1. Populate new virtual file system.
  2. Must be in the source directory.

cd /opt tar cvf - . | (cd /tmp/opt; tar xf -) cd /

  1. Unmount virtual file system

umount /tmp/opt

  1. Unbind /var/opt from /opt

umount /opt

  1. If no errors, mount virtual file system on /opt
  2. otherwise skip

mount -o loop /media/internal/vfs/optware.img /opt

  1. Add the following line to /etc/fstab to automount (without the #).
  2. /media/internal/vfs/optware.img /opt ext3 loop,noatime 1 2
  3. Comment out the /var/opt entry, should be similar to next line
  4. /var/opt /opt bind defaults,bind 0 0
  5. reboot your phone, if error noted when attempting to unmount /opt

reboot

  1. If no errors noted with the Optware apps,
  2. remove files/directories from /var/opt

rm -r /var/opt </source>

Caveats

Currently this procedure will disable USB Drive and Media Sync modes.

A method to safely unmount Virtual file system when selecting USB Drive and Media Sync modes is under development.

See the start/stop script below for now. The script needs to be run from a non-ssh terminal (ie novaproxy or novaterm). In the future this should be wrapped inside a homebrew GUI.

Caveat Workaround: Mount/Unmount Script

This script will start/stop (mount/unmount) the virtual file system, thus functioning as a work-a-round to allow using the Palm Pre's USB Drive and Media Sync modes. It is a work in progress and needs to be bullet-proofed. Ideally it should be wrapped around a WebOS GUI app—we are working on this. This script should be saved to a file (i.e. /home/root/vfs), made executable (i.e. chmod 750 /home/root/vfs and then run (i.e. with /home/root/vfs on or /home/root/vfs off). Do not save the script to an /opt path. Make sure you're running the script to toggle the virtual file system on or off when /media/internal is not mounted as a USB drive and the Media Sync mode is not enabled, otherwise the script will fail.

Note: We need this put in a Java service

This means we need to translate it to Java the Pre can understand! This will be for front-end GUI to toggle the VFS. Please look into this if you have the knowledge, on Gitorious. The source is there.

The Script Itself

<source lang="bash">

  1. !/bin/sh
  2. List of Optware applications to start/stop
  3. in conjunction with mounting/unmounting VFS.
  4. Check to make sure /media/internal is
  5. mounted

FSINT=`/bin/df|/bin/grep "/dev/mapper/store-media"` if [ "$FSINT" = "" ] then

echo "USB Drive not mounted. Exiting"
exit 1

fi

  1. OpenSSH and Dropbear are most common.
  2. Edit to suit environment.

APPS="optware-openssh optware-dropbear"

  1. An entry in /etc/fstab must exist for the VFS
  2. Grab and parse entry

FSVFS=`/bin/grep "/opt" /etc/fstab|grep loop` if [ "$FSVFS" != "" ] then

# Complete FileName of VFS to mount/unmount
LVFSFN=`echo $FSVFS|/usr/bin/awk '{print $1}'`
# VFS Mount Point (ie /opt)
LVFSMP=`echo $FSVFS|/usr/bin/awk '{print $2}'`
# VFS file system Type (ie ext3)
LVFSTP=`echo $FSVFS|/usr/bin/awk '{print $3}'`

else

echo "**** No /etc/fstab entry"
exit 1

fi

  1. Determine if VFS is mounted

VFSMTD=`/bin/df|/bin/grep "$LVFSMP"|/bin/grep "^/dev/loop"` if [ "$VFSMTD" != "" ] then

# Loopback device associated with VFS (ie /dev/loop0)
LVFSDV=`echo $VFSMTD|/usr/bin/awk '{print $1}'`

fi

case $1 in

 "on" )
       if [ -e "$LVFSFN" -a -d "$LVFSMP" -a "$VFSMTD" = "" ]
       then
        echo '**** Mounting Linux VFS'
        /bin/mount "$LVFSFN"
        echo '**** Starting Applications'
        for x in $APPS
          do
           if [ -f /etc/event.d/"$x" ]
           then
           /sbin/initctl start "$x"
           fi
        done
        echo '**** Linux VFS Enabled'
       else
        echo '**** Error mounting VFS'
        exit 1
       fi
       ;;
 "off" )
       if [ "$VFSMTD" != "" -a "$LVFSDV" != "" ]
       then
        echo '**** Stopping Applications'
        for x in $APPS
          do
           if [ -f /etc/event.d/"$x" ]
           then
           /sbin/initctl stop "$x"
           fi
        done
        echo '**** Unmounting Linux VFS'
        /bin/umount "$LVFSMP"
        # Work-a-round to disassociate VFS from loopback device
        /sbin/losetup -d $LVFSDV
        echo '**** Linux VFS Disabled'
       else
        echo '**** Error unmounting VFS'
        exit 1
       fi
       ;;
 * )
       echo "Usage: `/usr/bin/basename $0` on|off"
       ;;

esac </source>

Credits

PuffTheMagic - Devised the initial process
1lnxraider   - Expanded, modified, & published tutorial
             - Helped ultraBlack troubleshoot toggle script
             - Confirmed caveat
ultraBlack   - Found & had confirmed the major caveat which disables Media Sync & USB modes
             - Devised plan for front-end 'Toggle VFS' GUI, envisioning it as a way to also easily create it
rwhitby      - Provided skeleton & basic methods for front-end GUI's Opt Loop Service
NetWhiz      - Gave additional warning that this process disables Media Sync and USB modes