~ubuntu-branches/ubuntu/natty/jasper-initramfs/natty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh -e

PREREQ=""

# Output pre-requisites
prereqs()
{
        echo "$PREREQ"
}

case "$1" in
    prereqs)
        prereqs
        exit 0
        ;;
esac

LOGFILE=/dev/.initramfs/jasper.log
# If we are already confiugured we dont want to run again
[ -e /root/etc/flash-kernel.conf ] && exit 0

MYECHO="echo "

if [ -x /bin/plymouth ] && plymouth --ping; then
        MYECHO="plymouth message --text="
fi

# jasper_growroot should have exported this, if not, fall
# back to a hardcoded value
[ -n "${ROOTDEV}" ] || ROOTDEV="mmcblk0p"
ROOTPART="${ROOTDEV}2"

if echo "$root" | grep -q '^UUID='; then
    VOLID=$root
else
    if echo $root| grep -q ^/;then
        ROOTPART=$(basename $root)
    fi
    VOLID=$(blkid |grep ${ROOTPART}|awk '{print $2}'|tr -d [\"])
fi

machine=$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//')

UBOOT_PART="/dev/mmcblk0p1"
TMPDIR="/dev/.initramfs/jasper-tmp"
BOOT_SCRIPT="/boot/boot.script"
BOARD_OPTS="ro elevator=noop quiet splash fixrtc"

# make sure FS is writable
mount -o remount,rw /root

for x in $(cat /proc/cmdline); do
    case ${x} in
        console=tty[A-Z]*)
            $MYECHO"detected serial console= cmdline option, enabling serial console handling"
            cp /root/usr/share/jasper-initramfs/init/serial.conf /root/etc/init/
            BOARD_OPTS="${x} ${BOARD_OPTS}"
            ;;
        root=*)
            BOARD_OPTS="root=${VOLID} ${BOARD_OPTS}"
            ;;
        */*=*)
            # handle preseeding options
            opt=${x%=*}
            val=${x#*=}
            pkg=${opt%/*}
            if [ $pkg = "debian-installer" ]; then
                pkg="oem-config"
            fi
            $MYECHO"preseeding detected, setting ${opt} to ${val} for package ${pkg}"
            echo "set ${opt} ${val}" | chroot /root debconf-communicate ${pkg}
            ;;
        *)
            BOARD_OPTS="${x} ${BOARD_OPTS}"
            ;;
    esac
done

# create fstab in /root, we only support ext3 partitions atm
$MYECHO"Setting up fstab"
if ! cat /root/etc/fstab | grep -v '^#' | awk '{print $3}' | grep -q ^proc; then
  echo "proc /proc proc defaults 0 0" >>/root/etc/fstab
fi
if ! grep -q ${VOLID} /root/etc/fstab; then
  echo "${VOLID} / ext3 defaults,noatime,errors=remount-ro 0 1" >>/root/etc/fstab
fi
$MYECHO"Setting up swap, this will take a moment ..."
if ! grep -q swap /root/etc/fstab; then
    if [ -e /root/SWAP.swap ]; then
    	echo "/SWAP.swap  none  swap  sw  0 0" >>/root/etc/fstab
    fi
fi

$MYECHO"Enabling oem-config"
# switch oem-config on
mkdir -p /root/var/lib/oem-config
touch /root/var/lib/oem-config/run

case "$machine" in
        "OMAP4430 4430SDP board")
            UBOOT_PART="/dev/mmcblk1p1"
        ;;
esac

$MYECHO"Writing flash-kernel.conf"
# create flash-kernel setup
echo "UBOOT_PART=${UBOOT_PART}" >/root/etc/flash-kernel.conf
echo "ROOT=${VOLID}" >>/root/etc/flash-kernel.conf

# create new boot.scr file
$MYECHO"Creating boot.script"
cat >"/root${BOOT_SCRIPT}" <<EOF
        fatload mmc 0:1 0x80000000 uImage
        fatload mmc 0:1 0x81600000 uInitrd
        setenv bootargs ${BOARD_OPTS}
        bootm 0x80000000 0x81600000
EOF
mkdir -p ${TMPDIR}
mount ${UBOOT_PART} ${TMPDIR}
/root/usr/bin/mkimage -A arm -T script -C none -n "Ubuntu boot script" -d /root${BOOT_SCRIPT} ${TMPDIR}/boot.scr >>$LOGFILE 2>&1
umount ${TMPDIR}
rm -rf ${TMPDIR}

$MYECHO"Adding SD card optimizations"
cat >"/root/etc/sysctl.d/30-jasper-root-on-sd.conf" <<EOF
# The values below try to reduce disk writes, they were put in place
# by the jasper-initramfs package during first boot of this computer.
# If you encounter problems due to the settings please file a bug
# against the jasper-initramfs ubuntu package.
vm.swappiness = 0
vm.vfs_cache_pressure=50
vm.dirty_background_ratio = 20
vm.dirty_expire_centisecs = 0
vm.dirty_ratio = 80
vm.dirty_writeback_centisecs = 6000
EOF

$MYECHO"Enabling universe and multiverse"
chroot /root /usr/share/jasper-initramfs/apt/enable_additional_repos.py >>$LOGFILE 2>&1

# move jasper.log to root filesystem
mv $LOGFILE /root/var/log/

# remount readonly
mount -o remount,ro /root

if [ -e /dev/.initramfs/jasper-reboot ];then
    $MYECHO"Rebooting into configuration session ..."
    sleep 3
    reboot
fi