User:Quozl/Remastering

From OLPC
< User:Quozl
Revision as of 23:38, 22 November 2011 by Quozl (talk | contribs)
Jump to: navigation, search

Remastering a .zd4 file without having to make a build. Useful for XO-1.75 when no ARM build machinery is on your side of a slow pipe.

The script takes as input a .zd4 file, extracts the disk image, mounts the two filesystems, makes changes, then converts the result back to a .zd file.

#!/bin/bash
set -evx

# the build number we are basing on
BUILD=12
IMAGE=os$BUILD.img

# convert the .zd file into a disk image
zdextract < os$BUILD.zd4 > $IMAGE

# build a random fill pattern for later use
dd if=/dev/urandom of=$IMAGE.fill bs=4096 count=1 2>/dev/null

# dump the partition table in case it ever changes
parted $IMAGE "unit B print"

# connect the partitions to loopback block devices
losetup -o 4194304 /dev/loop0 $IMAGE
losetup -o 71303168 /dev/loop1 $IMAGE

# mount the two filesystems
mkdir -p /mnt/root /mnt/boot
mount /dev/loop1 /mnt/root
mount /dev/loop0 /mnt/boot
ROOT=/mnt/root/versions/run/$BUILD/
USER=/mnt/root/home/olpc/

# turn off runin fscheck, it will fail once we change things
rm -f $ROOT/runin/runin-fscheck

# provide local kernel
rsync -av /tmp/xo/bootpart/boot/* /mnt/boot/boot/
rsync -av /tmp/xo/lib/modules ${ROOT}/lib/

# force initial runin
# touch $ROOT/runin/quick

# open to your key
SSH_CONFIG=/mnt/root/home/root/.ssh
mkdir --mode=g-rwx,o-rwx $SSH_CONFIG
cat << EOF > $SSH_CONFIG/authorized_keys
(put your key here)
EOF
chmod o-rwx,g-rwx $SSH_CONFIG/authorized_keys

# save some space and therefore compression and fs-update time
# rm -rf $USER/Activities/Wikipedia*
# rm -rf $USER/Activities/Scratch*
# rm -rf $USER/Library/*

# enable sshd on start
cat <<EOF > $ROOT/etc/rc.local
#!/bin/sh
touch /var/lock/subsys/local
if [[ ! -f /etc/rc.local.quozl ]]; then
    service sshd start
    chkconfig sshd on
    touch /etc/rc.local.quozl
fi
EOF
chmod +x $ROOT/etc/rc.local

# reduce powerd enthusiasm
cat <<EOF >> $ROOT/etc/powerd/powerd.conf
config_PLUGGED_TIME_DIM="15"
config_PLUGGED_TIME_BLANK="30"
config_PLUGGED_TIME_SLEEP="3600"
EOF

# disable idle suspend
# touch $ROOT/etc/powerd/flags/inhibit-suspend

# associate to local wireless
mkdir -p $USER/.sugar/default/nm/
chown -R 500:500 $USER/.sugar
cat <<EOF > $USER/.sugar/default/nm/connections.cfg
[Auto qz]
type = 802-11-wireless
ssid = qz
uuid = 757dc7687efb4e7250f4eb6697568482ae948526
autoconnect = True
timestamp = 1321510400

EOF

# dismount the filesystem
umount /mnt/boot
umount /mnt/root
rmdir /mnt/root /mnt/boot

# fill the free blocks, to ensure sparse output
fill-free-blocks -v /dev/loop0 $IMAGE.fill
until losetup -d /dev/loop0; do sleep 0.1; done
fill-free-blocks -v /dev/loop1 $IMAGE.fill
until losetup -d /dev/loop1; do sleep 0.1; done

# compress back to .zd format
zhashfs 0x20000 sha256 $IMAGE fs.zsp fs.zd