root / import @ 916b6dd1
History | View | Annotate | Download (2.4 kB)
1 | 79224631 | Lance Albertson | #!/bin/bash |
---|---|---|---|
2 | 79224631 | Lance Albertson | |
3 | 79224631 | Lance Albertson | # Copyright (C) 2007, 2008, 2009 Google Inc. |
4 | 79224631 | Lance Albertson | # |
5 | 79224631 | Lance Albertson | # This program is free software; you can redistribute it and/or modify |
6 | 79224631 | Lance Albertson | # it under the terms of the GNU General Public License as published by |
7 | 79224631 | Lance Albertson | # the Free Software Foundation; either version 2 of the License, or |
8 | 79224631 | Lance Albertson | # (at your option) any later version. |
9 | 79224631 | Lance Albertson | # |
10 | 79224631 | Lance Albertson | # This program is distributed in the hope that it will be useful, but |
11 | 79224631 | Lance Albertson | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 79224631 | Lance Albertson | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | 79224631 | Lance Albertson | # General Public License for more details. |
14 | 79224631 | Lance Albertson | # |
15 | 79224631 | Lance Albertson | # You should have received a copy of the GNU General Public License |
16 | 79224631 | Lance Albertson | # along with this program; if not, write to the Free Software |
17 | 79224631 | Lance Albertson | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 79224631 | Lance Albertson | # 02110-1301, USA. |
19 | 79224631 | Lance Albertson | |
20 | 79224631 | Lance Albertson | set -e |
21 | 79224631 | Lance Albertson | |
22 | 79224631 | Lance Albertson | . common.sh |
23 | 79224631 | Lance Albertson | |
24 | 79224631 | Lance Albertson | # If the target device is not a real block device we'll first losetup it. |
25 | 79224631 | Lance Albertson | # This is needed for file disks. |
26 | 79224631 | Lance Albertson | if [ ! -b $blockdev ]; then |
27 | 79224631 | Lance Albertson | ORIGINAL_BLOCKDEV=$blockdev |
28 | 8d0132dc | Lance Albertson | blockdev=$($LOSETUP -sf $blockdev) |
29 | 8d0132dc | Lance Albertson | CLEANUP+=("$LOSETUP -d $blockdev") |
30 | 79224631 | Lance Albertson | fi |
31 | 79224631 | Lance Albertson | |
32 | 79224631 | Lance Albertson | if [ "$PARTITION_STYLE" = "none" ]; then |
33 | 79224631 | Lance Albertson | filesystem_dev=$blockdev |
34 | 79224631 | Lance Albertson | elif [ "$PARTITION_STYLE" = "msdos" ]; then |
35 | 79224631 | Lance Albertson | # Create one big partition, and make it bootable |
36 | 79224631 | Lance Albertson | format_disk0 $blockdev |
37 | 79224631 | Lance Albertson | filesystem_dev=$(map_disk0 $blockdev) |
38 | 79224631 | Lance Albertson | CLEANUP+=("unmap_disk0 $blockdev") |
39 | 79224631 | Lance Albertson | else |
40 | 79224631 | Lance Albertson | echo "Unknown partition style $PARTITION_STYLE" |
41 | 79224631 | Lance Albertson | exit 1 |
42 | 79224631 | Lance Albertson | fi |
43 | 79224631 | Lance Albertson | |
44 | 79224631 | Lance Albertson | mke2fs -Fjq $filesystem_dev |
45 | 79224631 | Lance Albertson | root_uuid=$($VOL_ID $filesystem_dev ) |
46 | 79224631 | Lance Albertson | |
47 | 79224631 | Lance Albertson | if [ -n "$swapdev" ]; then |
48 | 79224631 | Lance Albertson | mkswap $swapdev |
49 | 79224631 | Lance Albertson | swap_uuid=$($VOL_ID $swapdev || true ) |
50 | 79224631 | Lance Albertson | fi |
51 | 79224631 | Lance Albertson | |
52 | 79224631 | Lance Albertson | TMPDIR=`mktemp -d` || exit 1 |
53 | 79224631 | Lance Albertson | CLEANUP+=("rmdir $TMPDIR") |
54 | 79224631 | Lance Albertson | |
55 | 79224631 | Lance Albertson | mount $filesystem_dev $TMPDIR |
56 | 79224631 | Lance Albertson | CLEANUP+=("umount $TMPDIR") |
57 | 79224631 | Lance Albertson | |
58 | 79224631 | Lance Albertson | ( cd $TMPDIR; restore -r -y -f - ) |
59 | 79224631 | Lance Albertson | rm -f $TMPDIR/etc/udev/rules.d/z*_persistent-net.rules |
60 | 79224631 | Lance Albertson | |
61 | 79224631 | Lance Albertson | # Fix /etc/fstab with the new volumes' UUIDs |
62 | 79224631 | Lance Albertson | if [ -e $TMPDIR/etc/fstab ]; then |
63 | 79224631 | Lance Albertson | ROOT_LINE="UUID=$root_uuid / ext3 defaults 0 1" |
64 | 79224631 | Lance Albertson | if [ -n "$swapdev" -a -n "$swap_uuid" ]; then |
65 | 79224631 | Lance Albertson | SWAP_LINE="UUID=$swap_uuid swap swap defaults 0 0" |
66 | 79224631 | Lance Albertson | cat $TMPDIR/etc/fstab | \ |
67 | 79224631 | Lance Albertson | sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \ |
68 | 79224631 | Lance Albertson | -e "s#^(/dev/sdb|UUID=[a-f0-9-]+)\s+swap\s+.*\$#$SWAP_LINE#" \ |
69 | 79224631 | Lance Albertson | > $TMPDIR/etc/fstab.new |
70 | 79224631 | Lance Albertson | else |
71 | 79224631 | Lance Albertson | cat $TMPDIR/etc/fstab | \ |
72 | 79224631 | Lance Albertson | sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \ |
73 | 79224631 | Lance Albertson | > $TMPDIR/etc/fstab.new |
74 | 79224631 | Lance Albertson | fi |
75 | 79224631 | Lance Albertson | mv $TMPDIR/etc/fstab.new $TMPDIR/etc/fstab |
76 | 79224631 | Lance Albertson | fi |
77 | 79224631 | Lance Albertson | |
78 | 79224631 | Lance Albertson | # execute cleanups |
79 | 79224631 | Lance Albertson | cleanup |
80 | 79224631 | Lance Albertson | trap - EXIT |
81 | 79224631 | Lance Albertson | |
82 | 79224631 | Lance Albertson | exit 0 |