2013-03-17 02:41:10 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2013-03-28 15:28:27 +01:00
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
echo "This script must be run as root" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-03-28 18:04:29 +01:00
|
|
|
ls /usr/bin/qemu*arm*
|
|
|
|
if [ -z $? ]; then
|
2013-03-28 15:28:27 +01:00
|
|
|
echo "You need qemu user static binaries." 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-03-17 02:41:10 +01:00
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
2013-03-26 18:13:35 +01:00
|
|
|
# If you use a partition...
|
2013-05-16 11:18:05 +02:00
|
|
|
#PARTITION_ROOTFS='/dev/mmcblk0p2'
|
|
|
|
#PARTITION_BOOT='/dev/mmcblk0p1'
|
|
|
|
PARTITION_ROOTFS='/dev/sdd2'
|
|
|
|
PARTITION_BOOT='/dev/sdd1'
|
2013-03-26 18:13:35 +01:00
|
|
|
# If you use the img
|
2013-05-15 18:30:02 +02:00
|
|
|
##### Debian
|
2013-03-26 18:13:35 +01:00
|
|
|
IMAGE='2013-02-09-wheezy-raspbian.img'
|
|
|
|
OFFSET_ROOTFS=$((122880 * 512))
|
|
|
|
OFFSET_BOOT=$((8192 * 512))
|
2013-05-15 18:30:02 +02:00
|
|
|
##### Arch
|
|
|
|
#IMAGE='archlinux-hf-2013-02-11.img'
|
|
|
|
#OFFSET_ROOTFS=$((186368 * 512))
|
|
|
|
#OFFSET_BOOT=$((2048 * 512))
|
|
|
|
############
|
2013-03-26 18:13:35 +01:00
|
|
|
|
2013-03-17 02:41:10 +01:00
|
|
|
CHROOT_PATH='/mnt/arm_rPi'
|
|
|
|
|
|
|
|
clean(){
|
|
|
|
mv ${CHROOT_PATH}/etc/ld.so.preload_bkp ${CHROOT_PATH}/etc/ld.so.preload
|
|
|
|
rm ${CHROOT_PATH}/etc/resolv.conf
|
2013-03-26 18:13:35 +01:00
|
|
|
rm ${CHROOT_PATH}/usr/bin/qemu*arm*
|
2013-03-17 02:41:10 +01:00
|
|
|
|
|
|
|
umount ${CHROOT_PATH}/dev/pts
|
2013-05-15 18:30:02 +02:00
|
|
|
#umount ${CHROOT_PATH}/dev/shm
|
2013-03-17 02:41:10 +01:00
|
|
|
umount ${CHROOT_PATH}/dev
|
2013-05-15 18:30:02 +02:00
|
|
|
umount ${CHROOT_PATH}/run
|
2013-03-17 02:41:10 +01:00
|
|
|
umount ${CHROOT_PATH}/proc
|
|
|
|
umount ${CHROOT_PATH}/sys
|
|
|
|
umount ${CHROOT_PATH}/tmp
|
2013-03-26 18:13:35 +01:00
|
|
|
umount ${CHROOT_PATH}/boot
|
2013-03-17 02:41:10 +01:00
|
|
|
umount ${CHROOT_PATH}
|
|
|
|
|
|
|
|
rm -rf ${CHROOT_PATH}
|
|
|
|
}
|
|
|
|
|
|
|
|
trap clean EXIT TERM INT
|
|
|
|
|
2013-05-15 18:30:02 +02:00
|
|
|
export QEMU_CPU=arm1176
|
|
|
|
#export QEMU_STRACE=1
|
|
|
|
|
2013-03-17 02:41:10 +01:00
|
|
|
mkdir -p ${CHROOT_PATH}
|
|
|
|
|
2013-05-16 11:18:05 +02:00
|
|
|
if [ ! -z ${IMAGE} ]; then
|
2013-03-26 18:13:35 +01:00
|
|
|
mount -o loop,offset=${OFFSET_ROOTFS} ${IMAGE} ${CHROOT_PATH}
|
|
|
|
mount -o loop,offset=${OFFSET_BOOT} ${IMAGE} ${CHROOT_PATH}/boot
|
|
|
|
elif [ -a ${PARTITION_ROOTFS} ]; then
|
|
|
|
mount ${PARTITION_ROOTFS} ${CHROOT_PATH}
|
|
|
|
mount ${PARTITION_BOOT} ${CHROOT_PATH}/boot
|
|
|
|
else
|
|
|
|
print 'You need a SD card or an image'
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp /usr/bin/qemu*arm* ${CHROOT_PATH}/usr/bin/
|
2013-03-17 02:41:10 +01:00
|
|
|
|
2013-05-15 18:30:02 +02:00
|
|
|
mount -o bind /run ${CHROOT_PATH}/run
|
2013-03-17 02:41:10 +01:00
|
|
|
mount -o bind /dev ${CHROOT_PATH}/dev
|
2013-05-15 18:30:02 +02:00
|
|
|
mount -t devpts pts ${CHROOT_PATH}/dev/pts
|
|
|
|
#mount -o bind /dev/shm ${CHROOT_PATH}/dev/shm
|
|
|
|
mount -t proc none ${CHROOT_PATH}/proc
|
|
|
|
mount -t sysfs none ${CHROOT_PATH}/sys
|
2013-03-17 02:41:10 +01:00
|
|
|
mount -o bind /tmp ${CHROOT_PATH}/tmp
|
|
|
|
|
|
|
|
cp -pf /etc/resolv.conf ${CHROOT_PATH}/etc
|
2013-03-28 15:28:27 +01:00
|
|
|
|
2013-03-17 02:41:10 +01:00
|
|
|
mv ${CHROOT_PATH}/etc/ld.so.preload ${CHROOT_PATH}/etc/ld.so.preload_bkp
|
|
|
|
|
|
|
|
chroot ${CHROOT_PATH}
|