Meego Wiki
Views

ARM/N900/Install/chroot

From MeeGo wiki
< ARM | N900 | Install(Difference between revisions)
Jump to: navigation, search
(Chrooting into a loopback image)
 
(24 intermediate revisions not shown)
Line 1: Line 1:
-
'''Under construction'''
+
'''NOTE!!! These instructions haven't been checked for a while, so they are likely to be broken. One known fault is that prebuilt MeeGo images use BTRFS nowadays and since Maemo 5 doesn't support it, creating an own image using ext3 is necessary.
-
Problem with chroot installation is finding space for it. SD card and Mydocs would have plenty of space but they use FAT32 so it can't be used directly. Solution is to mount loopback images. Easies way to get started is to use a prebuilt loopback image.
+
'''NOTE: These instructions cover the case where user wants to chroot to a MeeGo image on the Nokia N900, when Maemo 5 is already installed.'''
-
If a prebuilt loopback image is not yet available, you can create it from a provided tar ball.
+
'''Note: Following these instructions will get you chroot terminal, not MeeGo GUI. Applications can be run by typing their name but many of them will fail without other services started first.'''
-
== Creating a loopback image from a tar ball ==
+
 
-
Create 2GB image file
+
One issue with a chroot installation is finding space for it. The SD card and Mydocs have plenty of space, but they use FAT32 as a file system, so they can't be used directly. A solution is to mount loopback images. The easiest way to get started is to use a prebuilt loopback image.
 +
 
 +
If a prebuilt loopback image is not yet available, you can create it from a tarball.
 +
== Creating a loopback image from a tarball ==
 +
Create 2 GB image file.
  dd if=/dev/zero of=/home/user/MyDocs/meego-image bs=1024 count=2097152
  dd if=/dev/zero of=/home/user/MyDocs/meego-image bs=1024 count=2097152
-
Create filesystem on image file
+
Create filesystem on image file.
  mkfs.ext3 /home/user/MyDocs/meego-image
  mkfs.ext3 /home/user/MyDocs/meego-image
-
Create mount point and loopback mount the image
+
Create mount point and loopback mount the image.
  export MEEGO_ROOT="/mnt/meego_root"
  export MEEGO_ROOT="/mnt/meego_root"
  mkdir $MEEGO_ROOT
  mkdir $MEEGO_ROOT
  mount -o loop /home/user/MyDocs/meego-image $MEEGO_ROOT
  mount -o loop /home/user/MyDocs/meego-image $MEEGO_ROOT
-
Unpack Meego rootfs image there. You might get an error about invalid tar magic. There's some problem between GNU tar and Busybox tar. Solution is to install GNU tar from Maemo Extras (package name is tar-gnu)
+
Install GNU tar (Busybox tar and GNU tar have some unfortunate compatibility problems) from Maemo Extras repository.
-
  tar xzf <meego-image> -C $MEEGO_ROOT
+
apt-get install tar-gnu
 +
 
 +
Check if the Meego rootfs image has an extra /SOMEDIR at a beginning of the actual system files.
 +
  gtar -tzf <meego-image>
 +
 
 +
Unpack the Meego image.
 +
# If there was an extra /SOMEDIR at the beginning strip it away when unpacking
 +
gtar --strip-components 1 -xzf <meego-image> -C $MEEGO_ROOT
 +
 +
# otherwise just extract the image
 +
gtar -xzf <meego-image> -C $MEEGO_ROOT
-
Umount the image
+
Umount the image.
  umount $MEEGO_ROOT
  umount $MEEGO_ROOT
-
You now have a loopback image ready to be chrooted into
+
You now have a loopback image ready to be chrooted into.
== Chrooting into a loopback image ==
== Chrooting into a loopback image ==
-
Using a script to chroot into an image makes the process faster and safer.
+
Using a script to chroot into an image makes the process faster and safer. There is also a [[ARM/N900/Install/chroot_modular|modular way]].
Copy the code below to a meego_chroot.sh script and remember to chmod +x it.
Copy the code below to a meego_chroot.sh script and remember to chmod +x it.
-
Usage: ./meego_chroot.sh <path_to_meego-arm-n900-loop.img>
+
Usage: ./meego_chroot.sh <path_to_meego-arm-n900-loop.img> <offset>
-
You may always execute the commands below manually if you like. Changing the prompt is optional and you only need to do it once per image.  
+
Image downloaded from http://repo.meego.com/MeeGo/releases/1.0/core/images/meego-n900-open-armv7l/
 +
contains entire hard drive, not single partition. Partition offset from the beginning of the image can vary, so a fixed value is not possible. Offset can be found using Linux ''file'' command.
 +
 
 +
  # file meego-handset-armv7l-n900-daily-mmcblk0p.raw
 +
  meego-handset-armv7l-n900-daily-mmcblk0p.raw: x86 boot sector; partition 1: ID=0x83, starthead 0,
 +
  '''startsector 1''', 3125000 sectors; partition 2: ID=0x83, starthead 133, startsector 3125001, 500000 sectors,
 +
  code offset 0xb8
 +
 
 +
The part we're interested in ''file'' output is shown in bold. In this case, partition 1 starts from sector 1. To get the offset, this needs to be multiplied by 512. 512 x 1 = 512, so we should use 512 as offset in the above command line.
 +
 
 +
 
 +
You may always execute the commands below manually, if you like, just remember that in that case you have to export all variables used. For example, instead of line 'MEEGO_ROOT=/mnt/meego' write
 +
  export MEEGO_ROOT=/mnt/meego
 +
Changing the prompt is optional and you only need to do it once per image.  
   #!/bin/sh
   #!/bin/sh
 +
 
 +
  GRAPHICS_LIBS="\
 +
  /usr/lib/libIMGegl.so \
 +
  /usr/lib/libglslcompiler.so \
 +
  /usr/lib/libpvrPVR2D_DRI2WSEGL.so \
 +
  /usr/lib/libsrv_um.so \
 +
  /usr/lib/libOpenVGU.so \
 +
  /usr/lib/libpvrPVR2D_BLITWSEGL.so \
 +
  /usr/lib/libpvrPVR2D_FRONTWSEGL.so \
 +
  /usr/lib/libpvrPVR2D_FLIPWSEGL.so \
 +
  /usr/lib/libpvrPVR2D_X11WSEGL.so \
 +
  /usr/lib/libOpenVG.so \
 +
  /usr/lib/libEGL.so \
 +
  /usr/lib/libPVRScopeServices.so \
 +
  /usr/lib/libpvr2d.so \
 +
  /usr/lib/libGLESv2.so"
    
    
   ### Prepare and mount the image ###
   ### Prepare and mount the image ###
   MEEGO_IMAGE=$1
   MEEGO_IMAGE=$1
 +
  MEEGO_IMAGE_OFFSET=$2
   MEEGO_ROOT=/mnt/meego_root
   MEEGO_ROOT=/mnt/meego_root
 +
 
   mkdir -p ${MEEGO_ROOT}
   mkdir -p ${MEEGO_ROOT}
-
   mount -o loop ${MEEGO_IMAGE} ${MEEGO_ROOT}
+
    
 +
  # We can't loop mount directly if image requires offset
 +
  #  mount -o loop ${MEEGO_IMAGE} ${MEEGO_ROOT}
 +
 
 +
  # TODO This can fail if /dev/loop0 already exists
 +
  losetup /dev/loop0 ${MEEGO_IMAGE} -o ${MEEGO_IMAGE_OFFSET}
 +
 
 +
  mount /dev/loop0 ${MEEGO_ROOT}
    
    
   ### Mount system directories ###
   ### Mount system directories ###
Line 52: Line 104:
   mount -o bind /usr/share/fonts ${MEEGO_ROOT}/usr/share/fonts
   mount -o bind /usr/share/fonts ${MEEGO_ROOT}/usr/share/fonts
    
    
-
   mount -t tmpfs tmpfs ${MEEGO_ROOT}/tmp
+
   mount -o bind /tmp ${MEEGO_ROOT}/tmp
-
   mount -t tmpfs tmpfs ${MEEGO_ROOT}/var/run
+
   mount -o bind /var/run ${MEEGO_ROOT}/var/run
 +
  mount -o bind /home ${MEEGO_ROOT}/home
    
    
   ### Setup ###
   ### Setup ###
Line 62: Line 115:
   ln -s /proc/mounts ${MEEGO_ROOT}/etc/mtab
   ln -s /proc/mounts ${MEEGO_ROOT}/etc/mtab
    
    
-
   # Change the prompt - this is optional
+
   # Prepare .bashrc for setupping chroot environment
-
  # make sure this is added only once
+
   grep -q -s MeeGo ${MEEGO_ROOT}/root/.bashrc
   grep -q -s MeeGo ${MEEGO_ROOT}/root/.bashrc
   if [ "$?" -ne "0" ]; then
   if [ "$?" -ne "0" ]; then
-
     echo "export PS1=MeeGo-chroot:\\\w\\\\\$" >> ${MEEGO_ROOT}/root/.bashrc
+
     echo "# MeeGo" >> ${MEEGO_ROOT}/root/.bashrc
 +
    echo "source /tmp/session_bus_address.user" >> ${MEEGO_ROOT}/root/.bashrc
 +
   
 +
    # Change the prompt - this is optional
 +
    # echo "export PS1=MeeGo-chroot:\\\w\\\\\$" >> ${MEEGO_ROOT}/root/.bashrc
   fi
   fi
    
    
-
   # Copy graphics libraries from host
+
   # Setup .bashrc for cases when sudo is used
-
  GRAPHICS_LIBS="\
+
   grep -q -s MeeGo ${MEEGO_ROOT}/home/user/.bashrc
-
  /usr/lib/libIMGegl.so \
+
   if [ "$?" -ne "0" ]; then
-
   /usr/lib/libglslcompiler.so \
+
    echo "# MeeGo" >> ${MEEGO_ROOT}/home/user/.bashrc
-
   /usr/lib/libpvrPVR2D_DRI2WSEGL.so \
+
    echo "source /tmp/session_bus_address.user" >> ${MEEGO_ROOT}/home/user/.bashrc
-
  /usr/lib/libsrv_um.so \
+
   
-
  /usr/lib/libOpenVGU.so \
+
    # Change the prompt - this is optional
-
  /usr/lib/libpvrPVR2D_BLITWSEGL.so \
+
    # echo "export PS1=MeeGo-chroot:\\\w\\\\\$" >> ${MEEGO_ROOT}/home/user/.bashrc
-
  /usr/lib/libpvrPVR2D_FRONTWSEGL.so \
+
   fi
-
  /usr/lib/libpvrPVR2D_FLIPWSEGL.so \
+
-
  /usr/lib/libpvrPVR2D_X11WSEGL.so \
+
-
  /usr/lib/libOpenVG.so \
+
-
  /usr/lib/libEGL.so \
+
-
  /usr/lib/libPVRScopeServices.so \
+
-
  /usr/lib/libpvr2d.so \
+
-
   /usr/lib/libGLESv2.so"
+
    
    
 +
  # Copy graphics libraries from host 
   for lib in ${GRAPHICS_LIBS}; do
   for lib in ${GRAPHICS_LIBS}; do
     cp ${lib} ${MEEGO_ROOT}/usr/lib/
     cp ${lib} ${MEEGO_ROOT}/usr/lib/
   done
   done
 +
 
 +
  # Copy pulseaudio files from host
 +
  cp /usr/lib/libpulse* ${MEEGO_ROOT}/usr/lib/
    
    
   ### Start your engines ###
   ### Start your engines ###
Line 108: Line 161:
   umount ${MEEGO_ROOT}/tmp
   umount ${MEEGO_ROOT}/tmp
   umount ${MEEGO_ROOT}/var/run
   umount ${MEEGO_ROOT}/var/run
 +
  umount ${MEEGO_ROOT}/home
    
    
   umount ${MEEGO_ROOT}
   umount ${MEEGO_ROOT}
   echo
   echo
 +
 +
== Problems ==
 +
If the script fails for whatever reason, it is likely that cleanup is needed afterwards.
 +
# Check if any programs inside chroot are still running
 +
ps
 +
 +
# Check if anything is still mounted inside chroot
 +
mount
 +
 +
# Umount all the mounts inside chroot and remember the order
 +
# first 'umount /dev/pts' and only after that 'umount /dev'
 +
 +
# Check used loop device
 +
losetup
 +
 +
# Free the loop device, replace X with correct number
 +
losetup -d /dev/loopX
 +
 +
[[Category:N900]]

Latest revision as of 21:37, 22 June 2011

NOTE!!! These instructions haven't been checked for a while, so they are likely to be broken. One known fault is that prebuilt MeeGo images use BTRFS nowadays and since Maemo 5 doesn't support it, creating an own image using ext3 is necessary.

NOTE: These instructions cover the case where user wants to chroot to a MeeGo image on the Nokia N900, when Maemo 5 is already installed.

Note: Following these instructions will get you chroot terminal, not MeeGo GUI. Applications can be run by typing their name but many of them will fail without other services started first.

One issue with a chroot installation is finding space for it. The SD card and Mydocs have plenty of space, but they use FAT32 as a file system, so they can't be used directly. A solution is to mount loopback images. The easiest way to get started is to use a prebuilt loopback image.

If a prebuilt loopback image is not yet available, you can create it from a tarball.

Creating a loopback image from a tarball

Create 2 GB image file.

dd if=/dev/zero of=/home/user/MyDocs/meego-image bs=1024 count=2097152

Create filesystem on image file.

mkfs.ext3 /home/user/MyDocs/meego-image

Create mount point and loopback mount the image.

export MEEGO_ROOT="/mnt/meego_root"
mkdir $MEEGO_ROOT
mount -o loop /home/user/MyDocs/meego-image $MEEGO_ROOT

Install GNU tar (Busybox tar and GNU tar have some unfortunate compatibility problems) from Maemo Extras repository.

apt-get install tar-gnu

Check if the Meego rootfs image has an extra /SOMEDIR at a beginning of the actual system files.

gtar -tzf <meego-image>

Unpack the Meego image.

# If there was an extra /SOMEDIR at the beginning strip it away when unpacking
gtar --strip-components 1 -xzf <meego-image> -C $MEEGO_ROOT

# otherwise just extract the image
gtar -xzf <meego-image> -C $MEEGO_ROOT

Umount the image.

umount $MEEGO_ROOT

You now have a loopback image ready to be chrooted into.

Chrooting into a loopback image

Using a script to chroot into an image makes the process faster and safer. There is also a modular way.

Copy the code below to a meego_chroot.sh script and remember to chmod +x it.

Usage: ./meego_chroot.sh <path_to_meego-arm-n900-loop.img> <offset>

Image downloaded from http://repo.meego.com/MeeGo/releases/1.0/core/images/meego-n900-open-armv7l/ contains entire hard drive, not single partition. Partition offset from the beginning of the image can vary, so a fixed value is not possible. Offset can be found using Linux file command.

 # file meego-handset-armv7l-n900-daily-mmcblk0p.raw 
 meego-handset-armv7l-n900-daily-mmcblk0p.raw: x86 boot sector; partition 1: ID=0x83, starthead 0,
 startsector 1, 3125000 sectors; partition 2: ID=0x83, starthead 133, startsector 3125001, 500000 sectors,
 code offset 0xb8

The part we're interested in file output is shown in bold. In this case, partition 1 starts from sector 1. To get the offset, this needs to be multiplied by 512. 512 x 1 = 512, so we should use 512 as offset in the above command line.


You may always execute the commands below manually, if you like, just remember that in that case you have to export all variables used. For example, instead of line 'MEEGO_ROOT=/mnt/meego' write

 export MEEGO_ROOT=/mnt/meego

Changing the prompt is optional and you only need to do it once per image.

 #!/bin/sh
 
 GRAPHICS_LIBS="\
 /usr/lib/libIMGegl.so \
 /usr/lib/libglslcompiler.so \
 /usr/lib/libpvrPVR2D_DRI2WSEGL.so \
 /usr/lib/libsrv_um.so \
 /usr/lib/libOpenVGU.so \
 /usr/lib/libpvrPVR2D_BLITWSEGL.so \
 /usr/lib/libpvrPVR2D_FRONTWSEGL.so \
 /usr/lib/libpvrPVR2D_FLIPWSEGL.so \
 /usr/lib/libpvrPVR2D_X11WSEGL.so \
 /usr/lib/libOpenVG.so \
 /usr/lib/libEGL.so \
 /usr/lib/libPVRScopeServices.so \
 /usr/lib/libpvr2d.so \
 /usr/lib/libGLESv2.so"
 
 ### Prepare and mount the image ###
 MEEGO_IMAGE=$1
 MEEGO_IMAGE_OFFSET=$2
 MEEGO_ROOT=/mnt/meego_root
 
 mkdir -p ${MEEGO_ROOT}
 
 # We can't loop mount directly if image requires offset
 #  mount -o loop ${MEEGO_IMAGE} ${MEEGO_ROOT}
 
 # TODO This can fail if /dev/loop0 already exists
 losetup /dev/loop0 ${MEEGO_IMAGE} -o ${MEEGO_IMAGE_OFFSET}
 
 mount /dev/loop0 ${MEEGO_ROOT}
 
 ### Mount system directories ###
 echo "Mounting system directories inside the chroot environment..."
 mount -o bind /proc ${MEEGO_ROOT}/proc
 mount -o bind /sys  ${MEEGO_ROOT}/sys
 mount -o bind /dev ${MEEGO_ROOT}/dev
 mount -o bind /dev/pts ${MEEGO_ROOT}/dev/pts/
 
 mount -o bind /var/lib/dbus/ ${MEEGO_ROOT}/var/lib/dbus/
 mount -o bind /usr/share/fonts ${MEEGO_ROOT}/usr/share/fonts
 
 mount -o bind /tmp  ${MEEGO_ROOT}/tmp
 mount -o bind /var/run  ${MEEGO_ROOT}/var/run
 mount -o bind /home ${MEEGO_ROOT}/home
 
 ### Setup ###
 rm -f ${MEEGO_ROOT}/etc/resolv.conf
 cp /etc/resolv.conf ${MEEGO_ROOT}/etc/resolv.conf
 
 rm -f ${MEEGO_ROOT}/etc/mtab
 ln -s /proc/mounts ${MEEGO_ROOT}/etc/mtab
 
 # Prepare .bashrc for setupping chroot environment
 grep -q -s MeeGo ${MEEGO_ROOT}/root/.bashrc
 if [ "$?" -ne "0" ]; then
   echo "# MeeGo" >> ${MEEGO_ROOT}/root/.bashrc
   echo "source /tmp/session_bus_address.user" >> ${MEEGO_ROOT}/root/.bashrc
   
   # Change the prompt - this is optional
   # echo "export PS1=MeeGo-chroot:\\\w\\\\\$" >> ${MEEGO_ROOT}/root/.bashrc
 fi
 
 # Setup .bashrc for cases when sudo is used
 grep -q -s MeeGo ${MEEGO_ROOT}/home/user/.bashrc
 if [ "$?" -ne "0" ]; then
   echo "# MeeGo" >> ${MEEGO_ROOT}/home/user/.bashrc
   echo "source /tmp/session_bus_address.user" >> ${MEEGO_ROOT}/home/user/.bashrc
   
   # Change the prompt - this is optional
   # echo "export PS1=MeeGo-chroot:\\\w\\\\\$" >> ${MEEGO_ROOT}/home/user/.bashrc
 fi
 
 # Copy graphics libraries from host  
 for lib in ${GRAPHICS_LIBS}; do
   cp ${lib} ${MEEGO_ROOT}/usr/lib/
 done
 
 # Copy pulseaudio files from host
 cp /usr/lib/libpulse* ${MEEGO_ROOT}/usr/lib/
 
 ### Start your engines ###
 echo -e "chrooting to ${MEEGO_ROOT}...\n"
 cd ${MEEGO_ROOT}
 chroot ${MEEGO_ROOT} /bin/bash
 
 ### Cleanup ###
 echo "Cleaning mounts..."                                                                                      
 cd ~
 umount ${MEEGO_ROOT}/dev/pts
 umount ${MEEGO_ROOT}/dev
 umount ${MEEGO_ROOT}/sys
 umount ${MEEGO_ROOT}/proc
 
 umount ${MEEGO_ROOT}/var/lib/dbus/
 umount ${MEEGO_ROOT}/usr/share/fonts
 
 umount ${MEEGO_ROOT}/tmp
 umount ${MEEGO_ROOT}/var/run
 umount ${MEEGO_ROOT}/home
 
 umount ${MEEGO_ROOT}
 echo

Problems

If the script fails for whatever reason, it is likely that cleanup is needed afterwards.

# Check if any programs inside chroot are still running
ps

# Check if anything is still mounted inside chroot
mount

# Umount all the mounts inside chroot and remember the order
# first 'umount /dev/pts' and only after that 'umount /dev'

# Check used loop device
losetup

# Free the loop device, replace X with correct number
losetup -d /dev/loopX
Personal tools