3 # ovirt-early Start early ovirt services
8 # Provides: ovirt-early
9 # Default-Start: 2 3 4 5
10 # Dewscription: Managed node early configuration service
13 # Source functions library
14 .
/etc
/init.d
/functions
15 .
/usr
/libexec
/ovirt-functions
16 .
/usr
/libexec
/ovirt-boot-functions
19 VAR_SUBSYS_OVIRT_EARLY
=/var
/lock
/subsys
/$prog
21 BONDING_MODCONF_FILE
=/etc
/modprobe.d
/bonding
22 AUGTOOL_CONFIG
=/var
/tmp
/augtool-config
23 EARLY_DIR
=/etc
/ovirt-early.d
29 devices
=$
(ls -b /sys
/class
/net
/)
30 for device
in $devices; do
31 if [ "$device" != "$DEVICE" ]; then
32 mac
=$
(cat /sys
/class
/net
/$device/address
2>/dev
/null
)
33 if [ -n "$mac" -a "$mac" != "00:00:00:00:00:00" ]; then
34 macs
="${macs}${mac}=${device},"
40 configure_ovirt_management_nic
() {
43 if [ -n "$DEVICE" ]; then
44 log
"Configuring network"
45 if ! network_up
; then
46 log
"Using interface $DEVICE"
47 # setup temporary interface to retrieve configuration
48 /sbin
/dhclient
-1 $1 \
49 && [ -f /var
/run
/dhclient.pid
] \
50 && kill $
(cat /var
/run
/dhclient.pid
)
53 # from network-scripts/ifup-post
54 IPADDR
=$
(LC_ALL
=C ip
-o -4 addr
ls dev
${DEVICE} |
awk '{ print $4 ; exit }')
55 log
"Interface brought up with $IPADDR"
56 eval $
(ipcalc
--silent --hostname ${IPADDR} ; echo "status=$?")
57 if [ "$status" = "0" ]; then
59 log
"Hostname resolved to $HOSTNAME"
60 # retrieve remote config
62 if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then
63 log
"oVirt Server found at: $SRV_HOST:$SRV_PORT"
65 get_mac_addresses
$DEVICE
66 log
"MACs to use: $macs"
67 wget
-O $cfgdb --no-check-certificate \
68 "http://$SRV_HOST:$SRV_PORT/ovirt/managed_node/config?host=$(hostname)&macs=$macs"
70 log
"Remote configuration bundle retrieved to $cfgdb"
71 /usr
/libexec
/ovirt-process-config
$cfgdb $BONDING_MODCONF_FILE $AUGTOOL_CONFIG
73 log
"Remote configuration retrieved and applied"
76 log
"Failure to retrieve or apply remote configuration"
79 log
"Failed to retrieve configuration bundle"
85 # for non-PXE boot when BOOTIF parameter is not specified
86 # otherwise default network config is invalid
89 # default oVirt network configuration:
90 # bridge each ethernet device in the system
92 local ifcfg
=/etc
/sysconfig
/network-scripts
/ifcfg-
$BRIDGE
94 # only write a default file if one does not exist
95 if [ ! -f $ifcfg ]; then
96 log
"Applying default configuration to $DEVICE and $BRIDGE"
97 printf '%s\n' "DEVICE=$DEVICE" ONBOOT
=yes "BRIDGE=$BRIDGE" \
98 > /etc
/sysconfig
/network-scripts
/ifcfg-
$DEVICE
99 printf '%s\n' "DEVICE=$BRIDGE" "BOOTPROTO=dhcp" \
100 ONBOOT
=yes TYPE
=Bridge PEERNTP
=yes DELAY
=0 \
101 > /etc
/sysconfig
/network-scripts
/ifcfg-
$BRIDGE
102 log
"Default config applied"
105 service network restart
109 configure_management_interface
() {
110 log
"Configuring the manangement interface."
111 case $OVIRT_RUNTIME_MODE in
113 configure_ovirt_management_nic
$bootif
114 if [ -n "$init" ]; then
115 /usr
/libexec
/ovirt-config-storage AUTO
116 # initial configuration storage, after /config creation
118 /etc
/sysconfig
/network-scripts
/ifcfg-
* \
119 $BONDING_MODCONF_FILE
120 if [ $upgrade = 1 ]; then
121 # local disk installation for managed mode
123 /usr
/libexec
/ovirt-config-boot
/live
"$bootparams"
128 if [ -x $MANAGEMENT_SCRIPTS_DIR/configure-management-interface
]; then
129 log
"Executing $MANAGEMENT_SCRIPTS_DIR/configure-management-interface"
130 $MANAGEMENT_SCRIPTS_DIR/configure-management-interface
132 echo "No script to configure management interface found."
136 log
"Unmanaged node: no management interface to configure."
140 start_ovirt_early
() {
141 touch $VAR_SUBSYS_OVIRT_EARLY
142 # oVirt boot parameters
143 # BOOTIF=link|eth*|<MAC> (appended by pxelinux)
144 # storage_init=[usb|scsi[:serial#]|/dev/...]
145 # storage_vol=BOOT_MB:SWAP_MB:ROOT_MB:CONFIG_MB:LOGGING_MB:DATA_MB
146 # mem_overcommit=<overcommit_ratio>
152 # pxelinux format: ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
153 # anaconda format: ip=<client-ip> netmask=<netmask> gateway=<gw-ip>
156 # dns=server[,server]
157 # ntp=server[,server]
160 # syslog=server[:port]
161 # collectd=server[:port]
163 # TBD logrotate maxsize
164 # rhn_type=[classic|sam]
165 # rhn_url=SATELLITE_URL
166 # rhn_CA_CERT=CA_CERT_URL
167 # rhn_username=RHN-USERNAME
168 # rhn_password=RHN-PASSWORD
169 # rhn_profile=RHNPROFILE
170 # rhn_activationkey=ACTIVATIONKEY
171 # RHN registration, activation key takes precedence
172 # rhn_proxy=PROXY-HOST:PORT
173 # rhn_proxyuser=PROXY-USERNAME
174 # rhn_proxypassword=PROXY-PASSWORD
175 # snmp_password=<authpassphrase>
177 # BOOTIF=link|eth*|<MAC> (appended by pxelinux)
178 # network boot interface is assumed to be on management network where
179 # management server is reachable
180 # BOOTIF=<MAC> e.g. BOOTIF=01-00-16-3e-12-34-57
181 # PXELINUX option IPAPPEND 2 in pxelinux.cfg appends MAC address
182 # of the booting node
183 # BOOTIF=link - take first eth for which ethtool reports link
184 # BOOTIF=eth* e.g. BOOTIF=eth0 - use given interface
187 # ovirt_init=HOSTVGDISK1[,HOSTVGDISK2...][;APPVGDISK1[,APPVGDISK2...]]
188 # where DISK=[ata|cciss|scsi|usb[:serial#]|/dev/...]
189 # local installation target disks
190 # Allow specification of multiple disks per VG
191 # usb|scsi - select disk type, as reported by udev ID_BUS
192 # serial# - select exact disk using serial number, as reported by
194 # e.g. ovirt_init=usb:Generic_STORAGE_DEVICE_0000145418-0:0
195 # /dev/... - use specified disk device
196 # (for cases when HAL doesn't handle it)
197 # w/o value - grab the first disk (/dev/?da)
201 # storage_vol=:SWAP_MB::CONFIG_MB:LOGGING_MB:DATA_MB:SWAP2_MB:DATA2_MB
203 # storage_vol=size[,{Swap|Data|Config|Logging|Data2|Swap2}][:size...]
204 # local partition sizes in MB
205 # LVs ending in 2 go to AppVG, all the others fall into HostVG
211 # data size can be set to 0 to disable data partition, -1 to use
212 # remaining free space after the other above partitions are defined
213 # or a specific positive number in MB
216 # swap2 and data2 will be placed into AppVG, 0 disables, data2
217 # can be -1 or a positive number in MB for each
221 # swap_encrypt={Swap|Swap2},cypher1[:cypher2...][;{Swap|Swap2}...]
222 # request swap encryption
223 # the default cypher is set to aes-cbc-essiv:sha256
228 # install/update oVirt Node image on the local installation target disk
231 # mem_overcommit=<overcommit_ratio>
232 # set the swap size coefficient
236 # force oVirt Node standalone mode
240 # force firstboot configuration even if it has already been run
241 # in auto-install mode, overwrite the disk chosen by storage_init parameter
245 # overrides the runtime mode defined in /etc/sysconfig/node-config
249 # enter emergency shell for fixing configuration issues
252 # rootpw=<encrypted_password>
253 # sets a temporary root password, change is forced on first login
254 # password is crypted, same as Kickstart option rootpw --iscrypted
255 # WARNING: use for debugging only, this is not secure!
258 # adminpw=<encrypted_password>
259 # sets a temporary password for admin, change is forced on first login
260 # password is crypted, same as Kickstart option rootpw --iscrypted
261 # WARNING: use for debugging only, this is not secure!
264 # snmp_password=<authpassphrase>
265 # enable snmpd and set password for "root" SNMPv3 USM user
268 # pxelinux format: ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
269 # anaconda format: ip=<client-ip> netmask=<netmask> gateway=<gw-ip>
272 # dns=server[,server]
273 # ntp=server[,server]
276 # static network configuration
293 # syslog=server[:port]
294 # default syslog server
298 # collectd=server[:port]
299 # default collectd server
303 # rhn_type=[classic|sam]
305 # rhn_url=SATELLITE_URL
306 # rhn_CA_CERT=CA_CERT_URL
307 # rhn_username=RHN-USERNAME
308 # rhn_password=RHN-PASSWORD
309 # rhn_profile=RHNPROFILE
310 # rhn_activationkey=ACTIVATIONKEY
311 # RHN registration, activation key takes precedence
312 # rhn_proxy=PROXY-HOST:PORT
313 # rhn_proxyuser=PROXY-USERNAME
314 # rhn_proxypassword=PROXY-PASSWORD
326 # save boot parameters like console= for local disk boot menu
328 cat /etc
/system-release
>> $OVIRT_LOGFILE
330 for i
in $
(cat /proc
/cmdline
); do
342 for eth
in $
(cd /sys
/class
/net
; echo eth
*); do
343 if ethtool
$eth 2>/dev
/null|
grep -q "Link detected: yes"
350 ??
-??
-??
-??
-??
-??
-??
)
352 bootif
=$
(grep -il $
(echo $i|
sed 's/-/:/g') /sys
/class
/net
/eth
*/address|
rev|cut
-d/ -f2|
rev)
356 storage_init
* | ovirt_init
*)
360 # 'storage_init' without value: grab first disk
361 init
=$
(ls -1 /dev
/?da
/dev
/cciss
/c?d?
2>/dev
/null |
head -n1)
364 eval $
(printf $i|
awk -F\
; '{ print "hostvgdisks="$1; print "appvgdisks="$2; }')
365 # Look into HostVG disks
366 if [ -n "$hostvgdisks" ]; then
370 for d
in $hostvgdisks; do
371 did
="$(IFS="$oldIFS" parse_disk_id "$d")"
372 if [ -z "$did" ]; then
375 if [ -n "$init" ]; then
376 init
="$init${SEP}$did"
383 # Look into AppVG disks
384 if [ -n "$appvgdisks" ]; then
388 for d
in $appvgdisks; do
389 did
="$(IFS="$oldIFS" parse_disk_id "$d")"
390 if [ -z "$did" ]; then
393 if [ -n "$init_app" ]; then
394 init_app
="$init_app${SEP}$did"
402 if [ -z "$init" ]; then
403 log
"Selected disk $i is not valid."
406 storage_vol
* | ovirt_vol
=*)
409 eval $
(printf $i|
awk -F: '{ print "lv1="$1; print "lv2="$2; print "lv3="$3; print "lv4="$4; print "lv5="$5; print "lv6="$6; print "lv7="$7; print "lv8="$8; }')
410 # Reads each provided LV size and assign them
411 # NOTE: Boot and Root size are ignored by o-c-storage
412 for p
in $
(seq 1 8); do
416 if [ -n "${!var}" ]; then
417 eval $
(printf '${!var}'|
awk -F, '{ print "size="$1; print "lv="$2; }')
418 if [ -n "${size}" ]; then
430 vol_config_size
=$size
433 vol_logging_size
=$size
445 ## This is here to preserve old styled syntax (in order)
446 ## BOOT_MB:SWAP_MB:ROOT_MB:CONFIG_MB:LOGGING_MB:DATA_MB:SWAP2_MB:DATA2_MB
458 vol_config_size
=$size
461 vol_logging_size
=$size
479 upgrade
* | ovirt_upgrade
* | local_boot | local_boot
=* | ovirt_local_boot
*)
481 if ! grep -q admin
/etc
/passwd
; then
482 unmount_config
/etc
/passwd
/etc
/shadow
483 useradd
-g admin
-s /usr
/libexec
/ovirt-admin-shell admin
484 [ ! grep -q ^
%wheel
/etc
/sudoers
] && echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc
/sudoers
485 /usr
/sbin
/usermod
-p $
(grep ^root
/etc
/shadow |
sed 's/:/ /g' |
awk '{print $2}') admin
486 persist
/etc
/shadow
/etc
/passwd
489 standalone
=no | standalone
=0 | ovirt_standalone
=no | ovirt_standalone
=0)
491 bootparams
="$bootparams $i"
493 standalone
* | ovirt_standalone
*)
495 bootparams
="$bootparams $i"
497 firstboot
=no | firstboot
=0 | ovirt_firstboot
=no | ovirt_firstboot
=0 | reinstall
=0 | reinstall
=no
)
500 firstboot
* | ovirt_firstboot
* | reinstall
)
507 runtime_mode
=${i#runtime_mode=}
513 adminpw
=${i#adminpw=}
517 if [ -z "$adminpw" ]; then
522 snmp_password
=${i#snmp_password=}
525 mem_overcommit
* | ovirt_overcommit
*)
526 i
=${i#mem_overcommit=}
527 i
=${i#ovirt_overcommit=}
528 eval $
(printf $i|
awk -F: '{print "overcommit="$1;}')
533 if [ "$i" = "dhcp" ]; then
536 eval $
(printf $i|
awk -F: '{print "ip_address="$1; print "ip_gateway="$3; print "ip_netmask="$4}')
540 netmask
=${i#netmask=}
543 gateway
=${i#gateway=}
555 hostname
=${i#hostname=}
560 ssh_pwauth
=1 | ssh_pwauth
=true
)
563 ssh_pwauth
=0 | ssh_pwauth
=false
)
568 eval $
(printf $i|
awk -F: '{print "syslog_server="$1; print "syslog_port="$2;}')
572 eval $
(printf $i|
awk -F: '{print "netconsole_server="$1; print "netconsole_port="$2;}')
576 eval $
(printf $i|
awk -F: '{print "collectd_server="$1; print "collectd_port="$2;}')
579 rhn_type
=${i#rhn_type=}
582 rhn_url
=${i#rhn_url=}
585 rhn_ca_cert
=${i#rhn_ca_cert=}
588 rhn_username
=${i#rhn_username=}
591 rhn_password
=${i#rhn_password=}
594 rhn_profile
=${i#rhn_profile=}
597 rhn_activationkey
=${i#rhn_activationkey=}
600 rhn_proxy
=${i#rhn_proxy=}
603 rhn_proxyuser
=${i#rhn_proxyuser=}
606 rhn_proxypassword
=${i#rhn_proxypassword=}
609 bootparams
="$bootparams $i"
611 ovirt_early
=$
(echo $i|
tr ",:;" " ")
613 # Don't store these parameters in /etc/default/ovirt
614 BOOT_IMAGE
=* | initrd
=* | check | linux | liveimg | \
615 root
=* | rootfstype
=* | rootflags
=* | ro | single |
install)
618 bootparams
="$bootparams $i"
621 kdump_nfs
=${i#kdump_nfs=}
624 iscsi_name
=${i#iscsi_name=}
626 swap_encrypt
=* | ovirt_swap_encrypt
=* )
627 i
=${i#ovirt_swap_encrypt=}
629 eval $
(printf $i|
awk -F\
; '{ print "swap1="$1; print "swap2="$2; }')
634 local default_cypher
="aes-cbc-essiv:sha256"
635 if [ -n "${!var}" ]; then
636 eval $
(printf ${!var} |
awk -F, '{ print "swapdev="$1; print "swapcyph="$2; }')
637 if [ "${swapdev}" = "Swap" ]; then
638 if [ -n "${swapcyph}" ]; then
639 crypt_swap
=${swapcyph}
641 crypt_swap
=${default_cypher}
643 elif [ "${swapdev}" = "Swap2" ]; then
644 if [ -n "${swapcyph}" ]; then
645 crypt_swap2
=${swapcyph}
647 crypt_swap2
=${default_cypher}
654 # check the params to be ignored before adding to bootparams
656 if ! grep -qw $varname /etc
/ovirt-commandline.d
/* 2>/dev
/null
; then
657 bootparams
="$bootparams $i"
663 for hook
in $ovirt_early; do
664 pre
="$EARLY_DIR/pre-$hook"
665 if [ -e "$pre" ]; then
670 if [ -z "$ip_netmask" ]; then
673 if [ -z "$ip_gateway" ]; then
676 # Handle uninstall arg
677 # need to wipe mbr if passed
678 if [ "$uninstall" = "yes" ]; then
680 log
"Found uninstall arg, wiping mbr from init disks"
682 for init_disk
in $init $init_app $
(get_boot_device
); do
683 echo "Wiping $init_disk"
684 wipe_mbr
"$init_disk"
687 log
"Uninstall complete, rebooting"
692 # save boot parameters as defaults for ovirt-config-*
694 params
="bootif init init_app vol_boot_size vol_swap_size vol_root_size vol_config_size vol_logging_size vol_data_size vol_swap2_size vol_data2_size crypt_swap crypt_swap2 upgrade standalone overcommit ip_address ip_netmask ip_gateway ipv6 dns ntp vlan ssh_pwauth syslog_server syslog_port collectd_server collectd_port bootparams hostname firstboot rhn_type rhn_url rhn_ca_cert rhn_username rhn_password rhn_profile rhn_activationkey rhn_proxy rhn_proxyuser rhn_proxypassword runtime_mode kdump_nfs iscsi_name snmp_password install netconsole_server netconsole_port"
695 # mount /config unless firstboot is forced
696 if [ "$firstboot" != "1" ]; then
699 log
"Updating $OVIRT_DEFAULTS"
704 if [ -n "$value" -o $p = 'init' -o $p = 'bootif' -o $p = 'upgrade' -o $p = 'install' ]; then
705 log
"Updating OVIRT_$PARAM to '$value'"
706 echo "set /files$OVIRT_DEFAULTS/OVIRT_$PARAM '\"$value\"'" \
712 if [ "$firstboot" != "1" -a -f /etc
/ovirt-crypttab
]; then
715 if [ -f /etc
/sysconfig
/network
]; then
716 .
/etc
/sysconfig
/network
717 if [ -n "$HOSTNAME" ]; then
722 if [ -n "$adminpw" ]; then
723 log
"Setting temporary admin password: $adminpw"
724 unmount_config
/etc
/passwd
/etc
/shadow
725 /usr
/sbin
/usermod
-p "$adminpw" admin
728 if [ -n "$rootpw" ]; then
729 log
"Setting temporary root password: $rootpw"
730 unmount_config
/etc
/passwd
/etc
/shadow
731 /usr
/sbin
/usermod
-p "$rootpw" root
734 # check if root or admin password is expired, this might be upon reboot
735 # in case of automated installed with rootpw or adminpw parameter!
736 if LC_ALL
=C chage
-l root |
grep -q "password must be changed" \
737 || LC_ALL
=c chage
-l admin |
grep -q "password must be changed"; then
738 unmount_config
/etc
/passwd
/etc
/shadow
739 # PAM will force password change at first login
740 # so make sure we persist it after a successful login
741 cat >> /etc
/profile
<< EOF
742 # added by ovirt-early
743 sudo persist /etc/passwd /etc/shadow
744 if LC_ALL=C sudo chage -l root | grep -q "password must be changed" \
745 || LC_ALL=C sudo chage -l admin | grep -q "password must be changed"; then
746 sudo /usr/libexec/ovirt-functions unmount_config /etc/passwd /etc/shadow
751 if [ "$rescue" = 1 ]; then
752 log
"Rescue mode requested, starting emergency shell"
754 plymouth
--hide-splash
755 bash
< /dev
/console
> /dev
/console
2> /dev
/console
756 plymouth
--show-splash
760 # link to the kernel image for kdump
761 chcon
-t boot_t
/boot-kdump
762 if is_booted_from_local_disk
; then
764 if [ -f /dev
/.initramfs
/live
/backup-vmlinuz
]; then
766 cp -p /dev
/.initramfs
/live
/backup-vmlinuz0
/boot-kdump
/vmlinuz-$
(uname
-r)
768 cp -p /dev
/.initramfs
/live
/vmlinuz0
/boot-kdump
/vmlinuz-$
(uname
-r)
773 if [ -e /live
/*linux
/vmlinuz0
]; then
774 cp -p /live
/*linux
/vmlinuz0
/boot-kdump
/vmlinuz-$
(uname
-r)
778 if [ "$standalone" = 1 ]; then
779 log
"Skip runtime mode configuration."
781 configure_management_interface
784 rm -f $VAR_SUBSYS_OVIRT_EARLY
786 for hook
in $ovirt_early; do
787 post
="$EARLY_DIR/post-$hook"
788 if [ -e "$post" ]; then
796 stop_ovirt_early
() {
797 echo -n "Stopping ovirt-early: "
801 reload_ovirt_early
() {
808 [ -f "$VAR_SUBSYS_NODE_CONFIG" ] && exit 0
809 echo -n "Starting ovirt-early: "
811 log
"Starting ovirt-early"
813 # TEMP fix broken libvirtd.conf
814 sed -c -i '/^log_filters=/d' /etc
/libvirt
/libvirtd.conf
815 log
"Completed ovirt-early"
817 } >> $OVIRT_LOGFILE 2>&1
818 test $RETVAL == 0 && success || failure
830 echo "Usage: ovirt-early {start}"