User:Quozl/Remastering: Difference between revisions

From OLPC
Jump to navigation Jump to search
(Created page with '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. <pre> # the build number we are basing on…')
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
Remastering a .zd 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 .zd file, extracts the disk image, mounts the two filesystems, makes changes, then converts the result back to a .zd file.


<pre>
<pre>
#!/bin/bash
# the build number we are basing on
set -evx
BUILD=11

IMAGE=os$BUILD.img
# the build number to use as input
n=12

BUILD=$(printf %02d $n)
BUILD_AS_PATH=$(printf %d $n)

INPUT=210${BUILD}o2.zd
IMAGE=210${BUILD}o2.img
FINAL=fs.zd

if [[ ! -e $INPUT ]]; then
echo no build
exit 1
fi


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


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


# grab the offsets from the partition table
# dump the partition table in case it ever changes
parted $IMAGE "unit B print"
P1=$(parted -m $IMAGE "unit B print"|grep '^1'|cut -f2 -d:|sed 's/B//g')
P2=$(parted -m $IMAGE "unit B print"|grep '^2'|cut -f2 -d:|sed 's/B//g')


# connect the partitions to loopback block devices
# connect the partitions to loopback block devices
losetup -o 4194304 /dev/loop0 $IMAGE
L1=$(losetup --show --find --offset $P1 $IMAGE)
losetup -o 71303168 /dev/loop1 $IMAGE
L2=$(losetup --show --find --offset $P2 $IMAGE)


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

# turn off runin fscheck, it will fail once we change things
touch $ROOT/runin/soiled


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


# force initial runin
# force initial runin
# rm -f $ROOT/runin/runin-fscheck
# touch $ROOT/runin/quick
# touch $ROOT/runin/quick


Line 42: Line 61:
chmod o-rwx,g-rwx $SSH_CONFIG/authorized_keys
chmod o-rwx,g-rwx $SSH_CONFIG/authorized_keys


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


# enable sshd on start
# enable sshd on start
Line 56: Line 75:
touch /etc/rc.local.quozl
touch /etc/rc.local.quozl
fi
fi
(sleep 13 && touch /var/run/powerd-inhibit-suspend/1) < /dev/null > /dev/null &
EOF
EOF
chmod +x $ROOT/etc/rc.local
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


# associate to local wireless
# associate to local wireless
Line 86: Line 97:


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

fill-free-blocks -v /dev/loop1 $IMAGE.fill
# discard the loopback
until losetup -d /dev/loop1; do sleep 0.1; done
until losetup -d $L1; do sleep 0.1; done
until losetup -d $L2; do sleep 0.1; done


# compress back to .zd format
# compress back to .zd format

Latest revision as of 06:20, 2 July 2012

Remastering a .zd 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 .zd 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 to use as input
n=12

BUILD=$(printf %02d $n)
BUILD_AS_PATH=$(printf %d $n)

INPUT=210${BUILD}o2.zd
IMAGE=210${BUILD}o2.img
FINAL=fs.zd

if [[ ! -e $INPUT ]]; then
    echo no build
    exit 1
fi

# convert the .zd file into a disk image
zdextract < $INPUT > $IMAGE

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

# grab the offsets from the partition table
P1=$(parted -m $IMAGE "unit B print"|grep '^1'|cut -f2 -d:|sed 's/B//g')
P2=$(parted -m $IMAGE "unit B print"|grep '^2'|cut -f2 -d:|sed 's/B//g')

# connect the partitions to loopback block devices
L1=$(losetup --show --find --offset $P1 $IMAGE)
L2=$(losetup --show --find --offset $P2 $IMAGE)

# mount the two filesystems
mkdir -p /mnt/root /mnt/boot
mount $L2 /mnt/root
mount $L1 /mnt/boot
ROOT=/mnt/root/versions/run/$BUILD_AS_PATH/
USER=/mnt/root/home/olpc/

# turn off runin fscheck, it will fail once we change things
touch $ROOT/runin/soiled

# 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

# 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 $L1 $IMAGE.fill
fill-free-blocks -v $L2 $IMAGE.fill

# discard the loopback
until losetup -d $L1; do sleep 0.1; done
until losetup -d $L2; do sleep 0.1; done

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