RHEL 5.11 full-virt now boots to login prompt.
[virt-v2v-test-cases-nonfree.git] / rhel5xen-rhel / create-rhel.sh
1 #!/bin/bash -
2
3 # The script used to install guests on RHEL 5 Xen.
4
5 # NB: You have to run this script on the RHEL 5 Xen host itself.
6 if ! uname -a | grep -sq 'el5xen'; then
7     echo "$0: You must run this on RHEL 5 Xen host"
8     exit 1
9 fi
10
11 if [ $# -ne 4 ]; then
12     echo "$0 major minor arch pv|fv"
13     exit 1
14 fi
15
16 # Ancient RHEL versions didn't work very well headless.  I cannot
17 # get RHEL 4 to install at all.
18 if [ "$DISPLAY" = "" ]; then
19     echo "$0: DISPLAY variable is not set"
20     exit 1
21 fi
22
23 major=$1
24 minor=$2
25 arch=$3
26 pvfv=$4
27 name=rhel_${major}${minor}_${arch}_${pvfv}
28
29 case $major in
30     3)
31         tree=http://tock/download/released/RHEL-$major/U$minor/AS/$arch/tree
32         ;;
33     4)
34         tree=http://tock/download/released/RHEL-$major/U$minor/AS/$arch/tree
35         ;;
36     5)
37         tree=http://tock/download/released/RHEL-$major-Server/U$minor/$arch/os
38         ;;
39     6)
40         # https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/chap-RHEL6_On_RHEL5.html
41         # In theory the paravirt-opts RHEL 6 kernel should be
42         # installable as a PV guest on RHEL 5 Xen, but I could not
43         # make it work.
44         tree=http://tock/download/released/RHEL-$major/$major.$minor/Server/$arch/os
45         ;;
46     *)
47         echo "$0: $major.$minor not supported yet"
48         exit 1
49 esac
50
51 echo tree=$tree
52
53 case $pvfv in
54     pv)
55         pvfv_option=--paravirt
56         ;;
57     fv)
58         pvfv_option=--hvm
59         ;;
60     *)
61         echo "$0: the fourth parameter must be [pv|fv]"
62         exit 1
63 esac
64
65 # Create the kickstart.
66 #
67 # RHEL 5 didn't have virt-install --initrd-inject, so the following
68 # only works because I have a webserver and an NFS server which map
69 # the same directory.
70 webserver=http://192.168.0.249/scratch
71 nfsserver=/mnt/scratch
72 ks=$(mktemp -p $nfsserver)
73 cat > $ks <<EOF
74 install
75 url --url $tree
76 text
77 lang en_US.UTF-8
78 keyboard us
79 network --bootproto dhcp
80 rootpw 123456
81 firewall --enabled --ssh
82 timezone --utc America/New_York
83 EOF
84
85 if [ $major -ge 4 ]; then
86     echo "selinux --enforcing" >> $ks
87     echo "poweroff" >> $ks
88 fi
89
90 # This doesn't work on RHEL 5.  Didn't check RHEL 6 yet.
91 #if [ $major -ge 5 ]; then
92 #    echo "hostname $name" >> $ks
93 #fi
94
95 cat >> $ks <<EOF
96
97 zerombr
98 clearpart --all --initlabel
99 autopart
100
101 xconfig --defaultdesktop=GNOME
102
103 %packages
104 @core
105 @gnome-desktop
106 @admin-tools
107 @system-tools
108 EOF
109 chmod 0644 $ks
110
111 ks_url="$webserver/`basename $ks`"
112 echo ks=$ks_url
113
114 # Output disk.
115 echo Creating the output disk ...
116 output=/mnt/fastscratch/$name.img
117 rm -f $output
118 dd if=/dev/zero of=$output bs=1 count=0 seek=6G
119
120 virsh destroy $name ||:
121 virsh undefine $name ||:
122
123 set -e
124
125 echo Running virt-install ...
126 virt-install \
127     $pvfv_option \
128     --name=$name \
129     --ram=1024 \
130     --vcpus=1 \
131     --os-type=linux --os-variant=rhel$major \
132     --file=$output \
133     --location=$tree \
134     --extra-args="ks=$ks_url"
135
136 virsh dumpxml $name > /mnt/fastscratch/$name.xml
137
138 echo Output written to /mnt/fastscratch:
139 ls -l /mnt/fastscratch/$name*