OLD | NEW |
---|---|
1 #!/bin/sh -u | 1 #!/bin/sh -u |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 # | 5 # |
6 # A script to install from removable media to hard disk. | 6 # A script to install from removable media to hard disk. |
7 | 7 |
8 # Load functions and constants for chromeos-install. | 8 # Load functions and constants for chromeos-install. |
9 . "$(dirname "$0")/chromeos-common.sh" || exit 1 | 9 . "$(dirname "$0")/chromeos-common.sh" || exit 1 |
10 . /usr/lib/shflags || exit 1 | 10 . /usr/lib/shflags || exit 1 |
11 | 11 |
12 DEFINE_string dst "/dev/sda" "Destination device" | 12 if [ $(uname -m) = "armv7l" ]; then |
13 DEFAULT_DST=/dev/mmcblk0 | |
14 else | |
15 DEFAULT_DST=/dev/sda | |
16 fi | |
17 | |
18 DEFINE_string dst "${DEFAULT_DST}" "Destination device" | |
13 DEFINE_boolean skip_src_removable ${FLAGS_FALSE} \ | 19 DEFINE_boolean skip_src_removable ${FLAGS_FALSE} \ |
14 "Skip check to ensure source is removable" | 20 "Skip check to ensure source is removable" |
15 DEFINE_boolean skip_rootfs ${FLAGS_FALSE} \ | 21 DEFINE_boolean skip_rootfs ${FLAGS_FALSE} \ |
16 "Skip installing the rootfs; Only set up partition table" | 22 "Skip installing the rootfs; Only set up partition table" |
17 DEFINE_boolean run_as_root ${FLAGS_FALSE} \ | 23 DEFINE_boolean run_as_root ${FLAGS_FALSE} \ |
18 "Allow root to run this script (Careful, it won't prompt for a password!)" | 24 "Allow root to run this script (Careful, it won't prompt for a password!)" |
19 DEFINE_boolean yes ${FLAGS_FALSE} \ | 25 DEFINE_boolean yes ${FLAGS_FALSE} \ |
20 "Answer yes to everything" | 26 "Answer yes to everything" |
21 | 27 |
22 # Parse command line | 28 # Parse command line |
23 FLAGS "$@" || exit 1 | 29 FLAGS "$@" || exit 1 |
24 eval set -- "${FLAGS_ARGV}" | 30 eval set -- "${FLAGS_ARGV}" |
25 | 31 |
26 set -e | 32 set -e |
27 | 33 |
28 # Unless you pass --run_as_root, you can't be root when you start this, | 34 # Unless you pass --run_as_root, you can't be root when you start this, |
29 # because we want to force you to give the root password as confirmation | 35 # because we want to force you to give the root password as confirmation |
30 # that you're allowed to do it. We don't care what other account you're using; | 36 # that you're allowed to do it. We don't care what other account you're using; |
31 # you'll still need to sudo before this works. | 37 # you'll still need to sudo before this works. |
32 if [ $(id -u) -eq "0" -a "${FLAGS_run_as_root}" -eq "${FLAGS_FALSE}" ] | 38 if [ $(id -u) -eq "0" -a "${FLAGS_run_as_root}" -eq "${FLAGS_FALSE}" ] |
33 then | 39 then |
34 echo "Note: You must be the 'chronos' user to run this script. Unless" | 40 echo "Note: You must be the 'chronos' user to run this script. Unless" |
35 echo "you pass --run_as_root and run as root." | 41 echo "you pass --run_as_root and run as root." |
36 exit 1 | 42 exit 1 |
37 fi | 43 fi |
38 | 44 |
39 # First find the root partition that we are installing from and verify it. | 45 # First find the root partition that we are installing from and verify it. |
40 ROOTDEV=$(rootdev) | 46 ROOTDEV=$(rootdev) |
41 # Remove numbers at end of rootfs device. | 47 # From root partition to root block device. |
42 SRC=${ROOTDEV%%[0-9]*} | 48 SRC=$(get_block_dev_from_partition_dev ${ROOTDEV}) |
43 REMOVABLE=$(cat /sys/block/${SRC#/dev/}/removable) | 49 REMOVABLE=$(cat /sys/block/${SRC#/dev/}/removable) |
44 if [ "$FLAGS_skip_src_removable" -eq "${FLAGS_FALSE}" -a "$REMOVABLE" != "1" ] | 50 if [ "$FLAGS_skip_src_removable" -eq "${FLAGS_FALSE}" -a "$REMOVABLE" != "1" ] |
45 then | 51 then |
46 echo "Error: Source does not look like a removable device: $SRC" | 52 echo "Error: Source does not look like a removable device: $SRC" |
47 exit 1 | 53 exit 1 |
48 fi | 54 fi |
49 | 55 |
50 # Check out the dst device. | 56 # Check out the dst device. |
51 if [ ! -b "$FLAGS_dst" ] | 57 if [ ! -b "$FLAGS_dst" ] |
52 then | 58 then |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 # Copy the rest of the source to the dest. | 179 # Copy the rest of the source to the dest. |
174 sudo dd if=${src_partition} of=${dst_dev} conv=notrunc \ | 180 sudo dd if=${src_partition} of=${dst_dev} conv=notrunc \ |
175 bs=512 skip=4 seek=$((${start_offset} + 4)) | 181 bs=512 skip=4 seek=$((${start_offset} + 4)) |
176 | 182 |
177 sync | 183 sync |
178 } | 184 } |
179 | 185 |
180 ############################################################################## | 186 ############################################################################## |
181 | 187 |
182 # What do we expect & require to have on the source device? | 188 # What do we expect & require to have on the source device? |
183 STATEFUL_IMG=${SRC}1 | 189 STATEFUL_IMG=$(make_partition_dev ${SRC} 1) |
184 KERNEL_IMG=${SRC}2 | 190 KERNEL_IMG=$(make_partition_dev ${SRC} 2) |
185 ROOTFS_IMG=${SRC}3 | 191 ROOTFS_IMG=$(make_partition_dev ${SRC} 3) |
186 ESP_IMG=${SRC}4 | 192 ESP_IMG=$(make_partition_dev ${SRC} 4) |
187 | 193 |
188 # Steal the PMBR code from the source MBR to put on the dest MBR, for booting | 194 if [ $(uname -m) = "armv7l" ]; then |
189 # on legacy-BIOS devices. | 195 PMBRCODE=/dev/zero |
190 sudo dd if=$SRC of=$PMBRCODE bs=512 count=1 | 196 else |
197 # Steal the PMBR code from the source MBR to put on the dest MBR, for booting | |
198 # on legacy-BIOS devices. | |
199 sudo dd if=$SRC of=$PMBRCODE bs=512 count=1 | |
200 fi | |
191 | 201 |
192 # Create the GPT. | 202 # Create the GPT. |
193 install_gpt $FLAGS_dst $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG | 203 install_gpt $FLAGS_dst $ROOTFS_IMG $KERNEL_IMG $STATEFUL_IMG $PMBRCODE $ESP_IMG |
194 | 204 |
205 if [ $(uname -m) = "armv7l" ]; then | |
206 DEVICE=$(echo $FLAGS_dst | sed -e 's/^.*\([0-9]\)$/\1/') | |
207 MBR_SCRIPT_UIMG=$(make_arm_mbr ${START_KERN_A} ${NUM_KERN_SECTORS} ${DEVICE}) | |
208 sudo dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ | |
209 if="$MBR_SCRIPT_UIMG" of=${FLAGS_dst} conv=notrunc | |
210 fi | |
211 | |
195 if [ "$FLAGS_skip_rootfs" -eq "$FLAGS_TRUE" ]; then | 212 if [ "$FLAGS_skip_rootfs" -eq "$FLAGS_TRUE" ]; then |
196 echo Done installing partitons. | 213 echo Done installing partitons. |
197 exit 0 | 214 exit 0 |
198 fi | 215 fi |
199 | 216 |
200 # Install the content. | 217 # Install the content. |
201 echo "Copying kernel..." | 218 echo "Copying kernel..." |
202 sudo dd if=${KERNEL_IMG} of=${FLAGS_dst} conv=notrunc bs=512 \ | 219 sudo dd if=${KERNEL_IMG} of=${FLAGS_dst} conv=notrunc bs=512 \ |
203 seek=${START_KERN_A} | 220 seek=${START_KERN_A} |
204 sudo dd if=${KERNEL_IMG} of=${FLAGS_dst} conv=notrunc bs=512 \ | 221 sudo dd if=${KERNEL_IMG} of=${FLAGS_dst} conv=notrunc bs=512 \ |
205 seek=${START_KERN_B} | 222 seek=${START_KERN_B} |
206 | 223 |
207 echo "Copying rootfs..." | 224 echo "Copying rootfs..." |
208 install_rootfs ${ROOTFS_IMG} ${FLAGS_dst} ${START_ROOTFS_A} "H-ROOT-A" | 225 install_rootfs ${ROOTFS_IMG} ${FLAGS_dst} ${START_ROOTFS_A} "H-ROOT-A" |
209 install_rootfs ${ROOTFS_IMG} ${FLAGS_dst} ${START_ROOTFS_B} "H-ROOT-B" | 226 install_rootfs ${ROOTFS_IMG} ${FLAGS_dst} ${START_ROOTFS_B} "H-ROOT-B" |
210 | 227 |
211 echo "Copying ESP..." | 228 echo "Copying ESP..." |
212 sudo dd if=${ESP_IMG} of=${FLAGS_dst} conv=notrunc bs=512 seek=${START_ESP} | 229 sudo dd if=${ESP_IMG} of=${FLAGS_dst} conv=notrunc bs=512 seek=${START_ESP} |
213 | 230 |
214 # We can't guarantee that the kernel will see the new partition table, so we | 231 if [ $(uname -m) != "armv7l" ]; then |
215 # can't use it directly. We could force the kernel to reload it with an ioctl, | |
216 # but then we might have the UI mounting and displaying any old filesystems | |
217 # left over from the last install, and we don't want that either. So any access | |
218 # that we need to do to the destination partitions will have to go through loop | |
219 # devices. | |
220 | 232 |
221 # Now run the postinstall script in each new rootfs. Note that even though | 233 # We can't guarantee that the kernel will see the new partition table, so we |
222 # we're passing the new destination partition number as an arg, the postinst | 234 # can't use it directly. We could force the kernel to reload it with an ioctl, |
223 # script had better not try to access it, for the reasons we just gave. | 235 # but then we might have the UI mounting and displaying any old filesystems |
224 loop_offset_setup ${FLAGS_dst} ${START_ROOTFS_A} | 236 # left over from the last install, and we don't want that either. So any acces s |
piman
2010/04/12 21:59:02
80 chars
| |
225 trap loop_offset_cleanup EXIT | 237 # that we need to do to the destination partitions will have to go through loo p |
piman
2010/04/12 21:59:02
80 chars
| |
226 mount_on_loop_dev | 238 # devices. |
227 trap my_cleanup EXIT | |
228 sudo ${TMPMNT}/postinst ${FLAGS_dst}3 | |
229 umount_from_loop_dev | |
230 trap loop_offset_cleanup EXIT | |
231 loop_offset_cleanup | |
232 trap - EXIT | |
233 | 239 |
234 loop_offset_setup ${FLAGS_dst} ${START_ROOTFS_B} | 240 # Now run the postinstall script in each new rootfs. Note that even though |
235 trap loop_offset_cleanup EXIT | 241 # we're passing the new destination partition number as an arg, the postinst |
236 mount_on_loop_dev | 242 # script had better not try to access it, for the reasons we just gave. |
237 trap my_cleanup EXIT | 243 loop_offset_setup ${FLAGS_dst} ${START_ROOTFS_A} |
238 sudo ${TMPMNT}/postinst ${FLAGS_dst}5 | 244 trap loop_offset_cleanup EXIT |
239 umount_from_loop_dev | 245 mount_on_loop_dev |
240 trap loop_offset_cleanup EXIT | 246 trap my_cleanup EXIT |
241 loop_offset_cleanup | 247 sudo ${TMPMNT}/postinst $(make_partition_dev ${FLAGS_dst} 3) |
242 trap - EXIT | 248 umount_from_loop_dev |
249 trap loop_offset_cleanup EXIT | |
250 loop_offset_cleanup | |
251 trap - EXIT | |
252 | |
253 loop_offset_setup ${FLAGS_dst} ${START_ROOTFS_B} | |
254 trap loop_offset_cleanup EXIT | |
255 mount_on_loop_dev | |
256 trap my_cleanup EXIT | |
257 sudo ${TMPMNT}/postinst $(make_partition_dev ${FLAGS_dst} 5) | |
258 umount_from_loop_dev | |
259 trap loop_offset_cleanup EXIT | |
260 loop_offset_cleanup | |
261 trap - EXIT | |
262 | |
263 fi | |
243 | 264 |
244 echo "Installing the stateful partition..." | 265 echo "Installing the stateful partition..." |
245 loop_offset_setup $FLAGS_dst $START_STATEFUL | 266 loop_offset_setup $FLAGS_dst $START_STATEFUL |
246 trap loop_offset_cleanup EXIT | 267 trap loop_offset_cleanup EXIT |
247 sudo mkfs.ext3 -F -b 4096 -L "H-STATE" ${LOOP_DEV} \ | 268 sudo mkfs.ext3 -F -b 4096 -L "H-STATE" ${LOOP_DEV} \ |
248 $(($NUM_STATEFUL_SECTORS / 8)) | 269 $(($NUM_STATEFUL_SECTORS / 8)) |
249 | 270 |
250 # Install the stateful partition content | 271 # Install the stateful partition content |
251 if [ -f /root/.dev_mode ] ; then | 272 if [ -f /root/.dev_mode ] ; then |
252 mount_on_loop_dev | 273 mount_on_loop_dev |
253 trap my_cleanup EXIT | 274 trap my_cleanup EXIT |
254 sudo cp -fpru /mnt/stateful_partition/var "$TMPMNT/var" | 275 sudo cp -fpru /mnt/stateful_partition/var "$TMPMNT/var" |
255 if [ -d /mnt/stateful_partition/dev_image ] ; then | 276 if [ -d /mnt/stateful_partition/dev_image ] ; then |
256 sudo cp -fpru /mnt/stateful_partition/dev_image "$TMPMNT/dev_image" | 277 sudo cp -fpru /mnt/stateful_partition/dev_image "$TMPMNT/dev_image" |
257 fi | 278 fi |
258 umount_from_loop_dev | 279 umount_from_loop_dev |
259 trap loop_offset_cleanup EXIT | 280 trap loop_offset_cleanup EXIT |
260 fi | 281 fi |
261 loop_offset_cleanup | 282 loop_offset_cleanup |
262 trap - EXIT | 283 trap - EXIT |
263 | 284 |
285 if grep "vogue" /etc/lsb-release > /dev/null; then | |
286 sudo uboot-env.py -f /dev/mtdblock0 -o 0x7c000 -s 0x4000 \ | |
287 --set bootcmd="mmc read 0 C0008000 0 1; autoscr C0008000" | |
288 fi | |
289 | |
264 # Force data to disk before we declare done. | 290 # Force data to disk before we declare done. |
265 sync | 291 sync |
266 | 292 |
267 echo "------------------------------------------------------------" | 293 echo "------------------------------------------------------------" |
268 echo "" | 294 echo "" |
269 echo "Installation to '$FLAGS_dst' complete." | 295 echo "Installation to '$FLAGS_dst' complete." |
270 echo "Please shutdown, remove the USB device, cross your fingers, and reboot." | 296 echo "Please shutdown, remove the USB device, cross your fingers, and reboot." |
OLD | NEW |