Revision 5dc61974

b/Makefile.am
8 8

  
9 9
dist_os_SCRIPTS = create import export rename verify
10 10
dist_tools_SCRIPTS = tools/*
11
dist_os_DATA = ganeti_api_version parameters.list
11
dist_os_DATA = ganeti_api_version parameters.list common_linux.sh
12 12
dist_config_DATA = variants.list
13 13
os_DATA = common.sh
14 14

  
b/common.sh.in
109 109
  IMG_PASSWD=$OSP_IMG_PASSWD
110 110
}
111 111

  
112
get_os_type() {
113
    target=$1
114
    if [ -z "${target}" ] ; then
115
        log_error "target is not set in get_os_type"
116
        exit 1
117
    fi
118
    if [ -e ${target}/etc/redhat-release ] ; then
119
        OS_TYPE="redhat"
120
    elif [ -e ${target}/etc/debian_version ] ; then
121
        OS_TYPE="debian"
122
    elif [ -e ${target}/etc/gentoo-release ] ; then
123
        OS_TYPE="gentoo"
124
    elif [ -e ${target}/etc/SuSE-release ] ; then
125
        OS_TYPE="suse"
126
    fi
127
}
128

  
129
get_os() {
130
    target=$1
131
    if [ -z "${target}" ] ; then
132
        log_error "target is not set in get_os"
133
        exit 1
134
    fi
135
    lsb="/usr/bin/lsb_release"
136
    if [ -e ${target}/$lsb ] ; then
137
        OPERATING_SYSTEM="$(chroot ${target} ${lsb} -i -s | tr "[:upper:]" "[:lower:]")"
138
    elif [ -e ${target}/etc/debian_version ] ; then
139
        OPERATING_SYSTEM="debian"
140
    elif [ -e ${target}/etc/gentoo-release ] ; then
141
        OPERATING_SYSTEM="gentoo"
142
    elif [ -e ${target}/etc/fedora-release ] ; then
143
        OPERATING_SYSTEM="fedora"
144
    elif [ -e ${target}/etc/redhat-release ] ; then
145
        if [ -n "$(grep -i centos ${target}/etc/redhat-release)" ] ; then
146
            OPERATING_SYSTEM="centos"
147
        else
148
            OPERATING_SYSTEM="redhat"
149
        fi
150
    fi
151
}
152

  
153
get_os_release() {
154
    target=$1
155
    if [ -z "${target}" ] ; then
156
        log_error "target is not set in get_os_release"
157
        exit 1
158
    fi
159
    lsb="/usr/bin/lsb_release"
160
    if [ -e ${target}/$lsb ] ; then
161
        OS_RELEASE="$(chroot ${target} ${lsb} -r -s | tr "[:upper:]" "[:lower:]")"
162
    elif [ -e ${target}/etc/debian_version ] ; then
163
        OS_RELEASE="$(cat ${target}/etc/debian_version)"
164
    elif [ -e ${target}/etc/fedora-release ] ; then
165
        OS_RELEASE="$(cat ${target}/etc/fedora-release | awk '{print $3}')"
166
    elif [ -e ${$target}/etc/redhat-release ] ; then
167
        OS_RELEASE="$(cat ${target}/etc/redhat-release | awk '{print $3}')"
168
    fi
169
}
170

  
171
format_disk0() {
172
    local sfdisk_cmd="$SFDISK -uM -H 255 -S 63 --quiet --Linux --DOS $1"
173
    if [  "${SWAP}" = "yes" -a -z "${KERNEL_PATH}" ] ; then
174
        # Create three partitions:
175
        # 1 - 100MB /boot, bootable
176
        # 2 - Size of Memory, swap
177
        # 3 - Rest
178
        $sfdisk_cmd > /dev/null <<EOF
179
,100,L,*
180
,${SWAP_SIZE},S
181
,,L
182
EOF
183
    elif [  "${SWAP}" = "no" -a -z "${KERNEL_PATH}" ] ; then
184
        # Create two partitions:
185
        # 1 - 100MB /boot, bootable
186
        # 2 - Rest
187
        $sfdisk_cmd > /dev/null <<EOF
188
,100,L,*
189
,,L
190
EOF
191
    elif [  "${SWAP}" = "yes" -a -n "${KERNEL_PATH}" ] ; then
192
        # Create two partitions:
193
        # 1 - Size of Memory, swap
194
        # 2 - Rest
195
        $sfdisk_cmd > /dev/null <<EOF
196
,$SWAP_SIZE,S
197
,,L
198
EOF
199
    elif [  "${SWAP}" = "no" -a -n "${KERNEL_PATH}" ] ; then
200
        # Create two partitions:
201
        # 1 - Whole
202
        $sfdisk_cmd > /dev/null <<EOF
203
,,L
204
EOF
205
    fi
206
}
207

  
208
mkfs_disk0() {
209
    local mkfs="mkfs.${FILESYSTEM}"
210
    # Format /
211
    $mkfs -Fq -L / $root_dev > /dev/null
212
    # Format /boot
213
    if [ -n "${boot_dev}" ] ; then
214
        $mkfs -Fq -L /boot $boot_dev > /dev/null
215
    fi
216
    # Format swap
217
    if [ -n "${swap_dev}" ] ; then
218
        # Format swap
219
        mkswap -f $swap_dev > /dev/null
220
    fi
221
    # During reinstalls, ext4 needs a little time after a mkfs so add it here
222
    # and also run a sync to be sure.
223
    sync
224
    sleep 2
225
}
226

  
227 112
mount_disk0() {
228 113
    local target=$1
229 114
    mount $root_dev $target
......
279 164
  $KPARTX -d -p- $1
280 165
}
281 166

  
282
setup_fstab() {
283
    local target=$1 fs=${FILESYSTEM}
284
    get_os_type $target
285
    cat > $target/etc/fstab <<EOF
286
# /etc/fstab: static file system information.
287
#
288
# <file system>   <mount point>   <type>  <options>       <dump>  <pass>
289
UUID=$root_uuid   /               $fs     defaults        0       1
290
proc              /proc           proc    defaults        0       0
291
EOF
292

  
293
if [ -n "$boot_dev" -a -n "$boot_uuid" ] ; then
294
    cat >> $target/etc/fstab <<EOF
295
UUID=$boot_uuid   /boot           $fs     defaults        1       2
296
EOF
297
fi
298

  
299
if [ -n "$swap_dev" -a -n "$swap_uuid" ] ; then
300
    cat >> $target/etc/fstab <<EOF
301
UUID=$swap_uuid   swap            swap    defaults        0       0
302
EOF
303
fi
304

  
305
# OS Specific fstabs
306
if [ "$OS_TYPE" = "redhat" ] ; then
307
    cat >> $target/etc/fstab <<EOF
308
tmpfs             /dev/shm        tmpfs   defaults        0       0
309
devpts            /dev/pts        devpts  gid=5,mode=620  0       0
310
sysfs             /sys            sysfs   defaults        0       0
311
EOF
312
fi
313

  
314
if [ "$OS_TYPE" = "gentoo" ] ; then
315
    cat >> $target/etc/fstab <<EOF
316
shm               /dev/shm        tmpfs   nodev,nosuid,noexec 0   0
317
EOF
318
fi
319
}
320

  
321
setup_console() {
322
    local target=$1
323
    if [ -z "$target" ] ; then
324
        log_error "target not set for setup_console"
325
        exit 1
326
    fi
327
    # Upstart is on this system, so do this instead
328
    if [ -e ${target}/etc/event.d/tty1 ] ; then
329
        cat ${target}/etc/event.d/tty1 | sed -re 's/tty1/ttyS0/' \
330
            > ${target}/etc/event.d/ttyS0
331
        return
332
    fi
333
    # upstart in karmic and newer
334
    if [ -e ${target}/etc/init/tty1.conf ] ; then
335
        cat ${target}/etc/init/tty1.conf | \
336
        sed -re 's/^exec.*/exec \/sbin\/getty -L 115200 ttyS0 vt102/' \
337
            > ${target}/etc/init/ttyS0.conf
338
        sed -ie 's/tty1/ttyS0/g' ${target}/etc/init/ttyS0.conf
339
        return
340
    fi
341
    get_os $target
342
    case $OPERATING_SYSTEM in
343
        gentoo)
344
            sed -i -e 's/.*ttyS0.*/s0:12345:respawn:\/sbin\/agetty 115200 ttyS0 vt100/' \
345
                ${target}/etc/inittab
346
            ;;
347
        centos)
348
            echo "s0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100" >> \
349
                ${target}/etc/inittab
350
            ;;
351
        debian|ubuntu)
352
            sed -i -e 's/.*T0.*/T0:23:respawn:\/sbin\/getty -L ttyS0 115200 vt100/' \
353
                ${target}/etc/inittab
354
            ;;
355
        *)
356
            echo "No support for your OS in instance-image, skipping..."
357
            ;;
358
    esac
359
}
360

  
361
filesystem_check() {
362
    local target=$1
363
    if [ -z "$target" ] ; then
364
        log_error "target not set for filesystem_check"
365
        exit 1
366
    fi
367

  
368
    get_os $target
369

  
370
    if [ "${OPERATING_SYSTEM}" = "fedora" ]; then
371
        # we have to force a filesystem relabeling for SELinux after messing
372
        # around with the filesystem in fedora
373
        echo "Enforce an automatic relabeling in the initial boot process..."
374
        touch $target/.autorelabel
375
    fi
376
}
377

  
378 167
cleanup() {
379 168
  if [ ${#CLEANUP[*]} -gt 0 ]; then
380 169
    LAST_ELEMENT=$((${#CLEANUP[*]}-1))
b/common_linux.sh
1

  
2
get_os_type() {
3
    target=$1
4
    if [ -z "${target}" ] ; then
5
        log_error "target is not set in get_os_type"
6
        exit 1
7
    fi
8
    if [ -e ${target}/etc/redhat-release ] ; then
9
        OS_TYPE="redhat"
10
    elif [ -e ${target}/etc/debian_version ] ; then
11
        OS_TYPE="debian"
12
    elif [ -e ${target}/etc/gentoo-release ] ; then
13
        OS_TYPE="gentoo"
14
    elif [ -e ${target}/etc/SuSE-release ] ; then
15
        OS_TYPE="suse"
16
    fi
17
}
18

  
19
get_os() {
20
    target=$1
21
    if [ -z "${target}" ] ; then
22
        log_error "target is not set in get_os"
23
        exit 1
24
    fi
25
    lsb="/usr/bin/lsb_release"
26
    if [ -e ${target}/$lsb ] ; then
27
        OPERATING_SYSTEM="$(chroot ${target} ${lsb} -i -s | tr "[:upper:]" "[:lower:]")"
28
    elif [ -e ${target}/etc/debian_version ] ; then
29
        OPERATING_SYSTEM="debian"
30
    elif [ -e ${target}/etc/gentoo-release ] ; then
31
        OPERATING_SYSTEM="gentoo"
32
    elif [ -e ${target}/etc/fedora-release ] ; then
33
        OPERATING_SYSTEM="fedora"
34
    elif [ -e ${target}/etc/redhat-release ] ; then
35
        if [ -n "$(grep -i centos ${target}/etc/redhat-release)" ] ; then
36
            OPERATING_SYSTEM="centos"
37
        else
38
            OPERATING_SYSTEM="redhat"
39
        fi
40
    fi
41
}
42

  
43
get_os_release() {
44
    target=$1
45
    if [ -z "${target}" ] ; then
46
        log_error "target is not set in get_os_release"
47
        exit 1
48
    fi
49
    lsb="/usr/bin/lsb_release"
50
    if [ -e ${target}/$lsb ] ; then
51
        OS_RELEASE="$(chroot ${target} ${lsb} -r -s | tr "[:upper:]" "[:lower:]")"
52
    elif [ -e ${target}/etc/debian_version ] ; then
53
        OS_RELEASE="$(cat ${target}/etc/debian_version)"
54
    elif [ -e ${target}/etc/fedora-release ] ; then
55
        OS_RELEASE="$(cat ${target}/etc/fedora-release | awk '{print $3}')"
56
    elif [ -e ${$target}/etc/redhat-release ] ; then
57
        OS_RELEASE="$(cat ${target}/etc/redhat-release | awk '{print $3}')"
58
    fi
59
}
60

  
61
format_disk0() {
62
    local sfdisk_cmd="$SFDISK -uM -H 255 -S 63 --quiet --Linux --DOS $1"
63
    if [  "${SWAP}" = "yes" -a -z "${KERNEL_PATH}" ] ; then
64
        # Create three partitions:
65
        # 1 - 100MB /boot, bootable
66
        # 2 - Size of Memory, swap
67
        # 3 - Rest
68
        $sfdisk_cmd > /dev/null <<EOF
69
,100,L,*
70
,${SWAP_SIZE},S
71
,,L
72
EOF
73
    elif [  "${SWAP}" = "no" -a -z "${KERNEL_PATH}" ] ; then
74
        # Create two partitions:
75
        # 1 - 100MB /boot, bootable
76
        # 2 - Rest
77
        $sfdisk_cmd > /dev/null <<EOF
78
,100,L,*
79
,,L
80
EOF
81
    elif [  "${SWAP}" = "yes" -a -n "${KERNEL_PATH}" ] ; then
82
        # Create two partitions:
83
        # 1 - Size of Memory, swap
84
        # 2 - Rest
85
        $sfdisk_cmd > /dev/null <<EOF
86
,$SWAP_SIZE,S
87
,,L
88
EOF
89
    elif [  "${SWAP}" = "no" -a -n "${KERNEL_PATH}" ] ; then
90
        # Create two partitions:
91
        # 1 - Whole
92
        $sfdisk_cmd > /dev/null <<EOF
93
,,L
94
EOF
95
    fi
96
}
97

  
98
mkfs_disk0() {
99
    local mkfs="mkfs.${FILESYSTEM}"
100
    # Format /
101
    $mkfs -Fq -L / $root_dev > /dev/null
102
    # Format /boot
103
    if [ -n "${boot_dev}" ] ; then
104
        $mkfs -Fq -L /boot $boot_dev > /dev/null
105
    fi
106
    # Format swap
107
    if [ -n "${swap_dev}" ] ; then
108
        # Format swap
109
        mkswap -f $swap_dev > /dev/null
110
    fi
111
    # During reinstalls, ext4 needs a little time after a mkfs so add it here
112
    # and also run a sync to be sure.
113
    sync
114
    sleep 2
115
}
116

  
117
setup_fstab() {
118
    local target=$1 fs=${FILESYSTEM}
119
    get_os_type $target
120
    cat > $target/etc/fstab <<EOF
121
# /etc/fstab: static file system information.
122
#
123
# <file system>   <mount point>   <type>  <options>       <dump>  <pass>
124
UUID=$root_uuid   /               $fs     defaults        0       1
125
proc              /proc           proc    defaults        0       0
126
EOF
127

  
128
if [ -n "$boot_dev" -a -n "$boot_uuid" ] ; then
129
    cat >> $target/etc/fstab <<EOF
130
UUID=$boot_uuid   /boot           $fs     defaults        1       2
131
EOF
132
fi
133

  
134
if [ -n "$swap_dev" -a -n "$swap_uuid" ] ; then
135
    cat >> $target/etc/fstab <<EOF
136
UUID=$swap_uuid   swap            swap    defaults        0       0
137
EOF
138
fi
139

  
140
# OS Specific fstabs
141
if [ "$OS_TYPE" = "redhat" ] ; then
142
    cat >> $target/etc/fstab <<EOF
143
tmpfs             /dev/shm        tmpfs   defaults        0       0
144
devpts            /dev/pts        devpts  gid=5,mode=620  0       0
145
sysfs             /sys            sysfs   defaults        0       0
146
EOF
147
fi
148

  
149
if [ "$OS_TYPE" = "gentoo" ] ; then
150
    cat >> $target/etc/fstab <<EOF
151
shm               /dev/shm        tmpfs   nodev,nosuid,noexec 0   0
152
EOF
153
fi
154
}
155

  
156
setup_console() {
157
    local target=$1
158
    if [ -z "$target" ] ; then
159
        log_error "target not set for setup_console"
160
        exit 1
161
    fi
162
    # Upstart is on this system, so do this instead
163
    if [ -e ${target}/etc/event.d/tty1 ] ; then
164
        cat ${target}/etc/event.d/tty1 | sed -re 's/tty1/ttyS0/' \
165
            > ${target}/etc/event.d/ttyS0
166
        return
167
    fi
168
    # upstart in karmic and newer
169
    if [ -e ${target}/etc/init/tty1.conf ] ; then
170
        cat ${target}/etc/init/tty1.conf | \
171
        sed -re 's/^exec.*/exec \/sbin\/getty -L 115200 ttyS0 vt102/' \
172
            > ${target}/etc/init/ttyS0.conf
173
        sed -ie 's/tty1/ttyS0/g' ${target}/etc/init/ttyS0.conf
174
        return
175
    fi
176
    get_os $target
177
    case $OPERATING_SYSTEM in
178
        gentoo)
179
            sed -i -e 's/.*ttyS0.*/s0:12345:respawn:\/sbin\/agetty 115200 ttyS0 vt100/' \
180
                ${target}/etc/inittab
181
            ;;
182
        centos)
183
            echo "s0:12345:respawn:/sbin/agetty 115200 ttyS0 vt100" >> \
184
                ${target}/etc/inittab
185
            ;;
186
        debian|ubuntu)
187
            sed -i -e 's/.*T0.*/T0:23:respawn:\/sbin\/getty -L ttyS0 115200 vt100/' \
188
                ${target}/etc/inittab
189
            ;;
190
        *)
191
            echo "No support for your OS in instance-image, skipping..."
192
            ;;
193
    esac
194
}
195

  
196
filesystem_check() {
197
    local target=$1
198
    if [ -z "$target" ] ; then
199
        log_error "target not set for filesystem_check"
200
        exit 1
201
    fi
202

  
203
    get_os $target
204

  
205
    if [ "${OPERATING_SYSTEM}" = "fedora" ]; then
206
        # we have to force a filesystem relabeling for SELinux after messing
207
        # around with the filesystem in fedora
208
        echo "Enforce an automatic relabeling in the initial boot process..."
209
        touch $target/.autorelabel
210
    fi
211
}
212

  
b/create
23 23

  
24 24
debug set -x
25 25

  
26
OS_FAMILY="linux"
27

  
26 28
if [ "$IMAGE_TYPE" = "tarball" ] ; then
27 29
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.tar.gz"
28 30
elif [ "$IMAGE_TYPE" = "qemu" ] ; then
......
31 33
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}-root.dump"
32 34
fi
33 35

  
36
. common_linux.sh
37

  
34 38
if [ "$CDINSTALL" = "no" ] ; then
35 39
    # If the target device is not a real block device we'll first losetup it.
36 40
    # This is needed for file disks.

Also available in: Unified diff