Blame view
install.sh
16.2 KB
4cb9c27fc Added files from ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
#! /bin/bash # Copyright (c) 2007 XenSource, Inc. # # This script installs or updates the XE support packages installed in a guest. os_distro="" os_majorver="" install_kernel=1 interactive=1 if [ -z "${DATADIR}" ] ; then DATADIR=$(dirname $0) fi usage() { echo "usage: install.sh [-d <DISTRO> -m <MAJOR>] [-k]" echo "" echo " -d <DISTRO> Specifies the distro name." echo " -m <MAJOR> Specifies the major version of the distro release." echo " -k Do not update the kernel." echo " -n Non interactive mode." echo "" echo "The -d and -m options must be used together. If neither is given then" echo "auto-detection will be attempted." exit 1 } while getopts d:hkm:n OPT ; do case $OPT in d) os_distro="$OPTARG" ;; k) install_kernel=0 ;; m) os_majorver="$OPTARG" ;; n) interactive=0 ;; h|\?) usage ;; esac done if [ -z "${os_distro}" -a -n "${os_majorver}" ] || \ [ -n "${os_distro}" -a -z "${os_majorver}" ] ; then echo "Distribution name (-d) and major version (-m) must be specified" echo "together on the command line." exit 1 fi if [ -z "${os_distro}" ] ; then if [ -z "${XE_LINUX_DISTRIBUTION}" ] ; then XE_LINUX_DISTRIBUTION=${DATADIR}/xe-linux-distribution fi if [ ! -f "${XE_LINUX_DISTRIBUTION}" ] ; then echo "Fatal Error: xe-linux-distribution script not found in ${DATADIR}." exit 1 fi if [ ! -f "${DATADIR}/versions.deb" -o ! -f "${DATADIR}/versions.rpm" ] ; then echo "Fatal Error: versions.deb or versions.rpm not found in ${DATADIR}." exit 1 fi eval $(${XE_LINUX_DISTRIBUTION}) if [ $? -ne 0 -o -z "${os_distro}" -o -z "${os_majorver}" ] ; then echo "Fatal Error: Failed to determine Linux distribution and version." exit 1 fi echo "Detected \`${os_name}' (${os_distro} version ${os_majorver})." echo else echo "Distribution \`${os_distro}' version \`${os_majorver}' given on command line." echo fi ARCH=$(uname -m | sed -e 's/i.86/i386/g') case "${ARCH}" in i386|x86_64) ;; *) echo "Architecture ${ARCH} is not supported" exit 1 ;; esac failure() { echo "Unable to install guest packages for distribution" if [ -n "${os_name}" ] ; then echo "${os_name} (${os_distro})." else echo "${os_distro}." fi echo if [ $# -gt 0 ] ; then echo $@ echo fi echo "You should manually install a version of" echo "xe-guest-utilities which is suitable for your" echo "distribution." exit 1 } select_rpm_utilities() { if [ -f "${DATADIR}/versions.rpm" ] ; then source ${DATADIR}/versions.rpm XGU= for p in $(eval echo \${XE_GUEST_UTILITIES_PKG_FILE_${ARCH}}) ; do XGU="$XGU ${DATADIR}/${p}" done else echo "Warning: Guest utilities not found in ${DATADIR}." fi } select_pkgs_rhel() { GUEST_PKG_TYPE=rpm case "${os_distro}${os_majorver}" in rhel4|centos4) # RHEL 4.9 already contains a Xen aware kernel if [ "${ARCH}" == "i386" -a "${install_kernel}" -gt 0 ] ; then REQUIRE_XENBLK_KO=yes REQUIRE_XENNET_KO=yes fi ;; rhel5|centos5|oracle5|scientific5) # No additional kernel package ;; rhel6|centos6|oracle6|scientific6) # No additional kernel package ;; rhel7|centos7|oracle7|scientific7) # No additional kernel package ;; rhel3|fedora*) # Not officially supported therefore no additional packages required. ;; *) failure "Unknown RedHat Linux variant \`${os_distro} ${os_majorver}'." ;; esac select_rpm_utilities } select_pkgs_sles() { GUEST_PKG_TYPE=rpm case "${os_distro}${os_majorver}" in sles9|"suse linux9") # SLES9.4+ already contains a Xen aware kernel ;; sles10|"suse linux10") # SLES10 already contains a Xen aware kernel ;; sles11|"suse linux11") # SLES11 already contains a Xen aware kernel ;; sles12|"suse linux12") # SLES12 already contains a Xen aware kernel ;; *) failure "Unknown SuSE Linux variant \`${os_distro} ${os_majorver}'." ;; esac select_rpm_utilities } select_pkgs_coreos() { GUEST_PKG_TYPE=coreos XGU="xe-linux-distribution" } select_pkgs_debian() { GUEST_PKG_TYPE=deb case ${os_distro}:${os_majorver}:${os_minorver} in debian:[0-5]:*) failure "This version of Debian is no longer supported by these utilities." ;; debian:[6-9]:*) ;; debian:[1-9][0-9]:*) ;; debian:testing:*|debian:unstable:*) ;; ubuntu:[1-9]:*) failure "This version of Ubuntu is no longer supported by these utilities." ;; ubuntu:[1-9][0-9]:*) ;; *) failure "Unknown Debian variant ${os_distro}:${os_majorver}:${os_minorver}" ;; esac case ${ARCH} in i386) DARCH=i386 ;; x86_64) DARCH=amd64 ;; esac if [ -f "${DATADIR}/versions.deb" ] ; then source ${DATADIR}/versions.deb XGU=${DATADIR}/$(eval echo \${XE_GUEST_UTILITIES_PKG_FILE_${DARCH}}) else echo "Warning: Guest utilities not found in ${DATADIR}." fi } select_pkgs_xe() { GUEST_PKG_TYPE=rpm select_rpm_utilities } update_lvm_configuration_required() { if test "${os_distro}" != rhel then return 1 fi if test ${os_majorver} != 4 then return 1 fi if test \! -f /etc/lvm/lvm.conf then return 1 fi lvm_types="`grep -e '^[ \t]*types' /etc/lvm/lvm.conf`" if [[ -z "$lvm_types" || "$lvm_types" != *\"xvd\"* ]] then return 0 fi return 1 } update_lvm_configuration() { if test -z "`grep -e '^[ \t]*types' /etc/lvm/lvm.conf`" then sed -i '/^[ \t]*devices[ \t]*{[ \t]*/a \ types = ["xvd", 16]' /etc/lvm/lvm.conf else sed -i 's/^[ \t]*types.*/ types = ["xvd", 16]/g' /etc/lvm/lvm.conf fi } update_inittab_configuration_required() { case "${os_distro}${os_majorver}" in sles10|"suse linux10"|sles11|"suse linux11") # SLES10 starts up two gettys, and we want to disable one of them if grep -Eq '^cons:12345:respawn:/sbin/smart_agetty -L 42 console' /etc/inittab; then if grep -Eq '^x0:12345:respawn:/sbin/agetty -L 9600 xvc0 xterm' /etc/inittab; then return 0 fi fi ;; *) ;; esac return 1 } update_inittab_configuration() { case "${os_distro}${os_majorver}" in sles10|"suse linux10"|sles11|"suse linux11") # Disable duplicate getty sed -i 's/^x0:12345:respawn:/# x0:12345:respawn:/g' /etc/inittab ;; *) ;; esac /sbin/telinit q } update_arp_notify_required() { # PV ops kernels do not emit gratuitous ARPs on migrate unless this is set file=/proc/sys/net/ipv4/conf/all/arp_notify if [ -f ${file} ] ; then val=$(cat ${file}) if [ "${val}" = 0 ] ; then return 0; fi fi return 1 } update_arp_notify_configuration() { file=/etc/sysctl.conf if [ -e "${file}" ] ; then sed -i -e 's/\(^\s*net\.ipv4\.conf\.[^.]\+\.arp_notify\s*=\s*0\)/#Auto-disabled by xs-tools:install.sh #\1/' ${file} else folder=/etc/sysctl.d/ if [ ! -d "${folder}" ] ; then echo "Cannot update arp_notify configuration as neither ${file} nor ${folder} present" >&2 return 1 fi file=${folder}/10-enable-arp-notify.conf fi echo -e "# Auto-enabled by xs-tools:install.sh net.ipv4.conf.all.arp_notify = 1" >> ${file} return 0 } update_modules_configuration_required() { if [ -f "/etc/modprobe.conf" ] ; then conf="/etc/modprobe.conf" elif [ -f "/etc/modules.conf" ] ; then conf="/etc/modules.conf" else return 1 fi if [ -z "${KERNEL}" ] ; then return 1 fi if [ X"${REQUIRE_XENNET_KO}" = "Xyes" ] ; then if ! grep -Eq '^alias eth0 xennet$' "${conf}" ; then # Required module alias not present! return 0 fi else if grep -Eq '^[^#]*eth0' "${conf}" ; then # Module alias shouldn't be present as driver is kernel resident! return 0 fi fi if [ X"${REQUIRE_XENBLK_KO}" = "Xyes" ] ; then if ! grep -Eq '^alias scsi_hostadapter xenblk$' "${conf}" ; then # Required module alias not present! return 0 fi else if grep -Eq '^[^#]*scsi_hostadapter' "${conf}" ; then # Module alias shouldn't be present as driver is kernel resident! return 0 fi fi # no need to update modules configuration return 1 } update_modules_configuration() { if [ -f "/etc/modprobe.conf" ] ; then conf="/etc/modprobe.conf" elif [ -f "/etc/modules.conf" ] ; then conf="/etc/modules.conf" else return 1 fi echo "Updating ${conf}, original saved in ${conf}.bak" cp "${conf}" "${conf}.bak" # Flush lines concerning PV modules grep -Ev '\beth0\b|\bscsi_hostadapter\b' "${conf}.bak" >"${conf}" || true # Add lines to alias any PV modules needed if [ X"${REQUIRE_XENNET_KO}" = "Xyes" ] ; then echo 'alias eth0 xennet' >>"${conf}" fi if [ X"${REQUIRE_XENBLK_KO}" = "Xyes" ] ; then echo 'alias scsi_hostadapter xenblk' >>"${conf}" fi return 0 } update_grub_configuration() { if [ -f "/boot/grub/menu.lst" ] ; then conf=$(readlink -f "/boot/grub/menu.lst") elif [ -f "/boot/grub/grub.conf" ] && [ ! -L "/boot/grub/grub.conf" ] ; then conf=$(readlink -f "/boot/grub/grub.conf") else echo "No grub configuration found. Not updating" return 1 fi cmdline=$(cat /proc/cmdline) if [ -z "${cmdline}" ] ; then echo "No kernel command line found. Not updating grub configuration." return 1 fi echo "Updating ${conf}, original saved in ${conf}.bak" cp "${conf}" "${conf}.bak" # Correct kernel command line. echo " * set kernel command line to \`${cmdline}'." # Ensure kernel initrd and module lines include /boot/ if it is # not a separate filesystem. root_stat=$(stat --format='%d' --terse "/") boot_stat=$(stat --format='%d' --terse "/boot") if [ "${root_stat}" == "${boot_stat}" ] ; then echo " * prepend /boot/ to kernel path." rewrite_path="s;^\(\([^\#]*\|\)\(kernel\|initrd\|module\)\) \(/boot\)\?/\?;\1 /boot/;g" fi sed -e "s;^\(\([^\#]*\|\)kernel [^ ]*\) .*;\1 ${cmdline};g ; ${rewrite_path}" \ <"${conf}.bak" >"${conf}" # Make sure there is an entry for the kernel pointed to by /boot/xenkernel if [ -L "/boot/xenkernel" ] && [ -x "/sbin/grubby" ] ; then kernel=$(readlink -f "/boot/xenkernel") initrd=$(readlink -f "/boot/xeninitrd") k="$(basename ${kernel} | sed -e 's/vmlinu.-//g')" echo " * add entry for ${k} (/boot/xenkernel)." [ -n "${initrd}" ] && INITRD="--initrd ${initrd}" /sbin/grubby --add-kernel=${kernel} $INITRD \ --copy-default --make-default --title="${k}" fi echo return 0 } update_vmlinuz_symlink() { local symlink=$(readlink -f "/boot/vmlinuz") case ${symlink} in /boot/xenu-linux-*) ;; *) echo "\`/boot/vmlinuz' does not point to a Xen kernel. Leaving." return 1 ;; esac local version=${symlink/\/boot\/xenu-linux-} mv -v "/boot/vmlinuz" "/boot/vmlinuz-xenu-${version}" if [ -L "/boot/initrd.img" ] && \ [ "$(readlink -f /boot/initrd.img)" = "/boot/initrd.img-${version}" ] ; then mv -v "/boot/initrd.img" "/boot/initrd.img-xenu-${version}" fi } install_rpms() { if [ -n "${XGU}" ] ; then rpm -Uvh ${XGU} fi if [ -n "${MKINITRD}" ] ; then rpm -Fvh --replacefiles --replacepkgs "${MKINITRD}" fi if [ -n "${ECRYPTFS_UTILS}" ] ; then rpm -Fvh --replacefiles --replacepkgs "${ECRYPTFS_UTILS}" fi # Install not upgrade so that old kernel is retained. if [ -n "${KERNEL}" ] ; then rpm -ivh "${KERNEL}" version=$(rpm -qp --qf "%{V}-%{R} " "${KERNEL}") if [ -f "/boot/vmlinuz-${version}xenU" ] && [ -x "/sbin/grubby" ] ; then echo "Making kernel ${version}xenU" echo "the default in grub configuration." /sbin/grubby --set-default="/boot/vmlinuz-${version}xenU" echo "" fi fi echo "" } install_debs() { dpkg -i ${KERNEL} ${MKINITRD} ${XGU} echo "" } install_coreos() { echo "Installing the agent..." mkdir -p /usr/share/oem/xs/ cp -f ${DATADIR}/xe-daemon \ ${DATADIR}/xe-linux-distribution \ ${DATADIR}/xe-update-guest-attrs /usr/share/oem/xs/ cp -f ${DATADIR}/xen-vcpu-hotplug.rules /etc/udev/rules.d/ cp -f ${DATADIR}/xe-linux-distribution.service /etc/systemd/system/ systemctl enable /etc/systemd/system/xe-linux-distribution.service echo "Installation complete." systemctl start xe-linux-distribution.service } case "${os_distro}" in rhel|centos|oracle|fedora) select_pkgs_rhel ;; scientific) select_pkgs_rhel ;; sles|"suse linux") select_pkgs_sles ;; debian|ubuntu) select_pkgs_debian ;; xe-ddk|xe-sdk) select_pkgs_xe ;; CoreOS) select_pkgs_coreos ;; *) failure "Unknown Linux distribution \`${os_distro}'." ;; esac if [ -n "${KERNEL}" ] ; then for K in ${KERNEL} ; do if [ ! -f "${K}" ] ; then echo "Warning: kernel ${K} not found." echo "" KERNEL="" fi done fi if [ -n "${MKINITRD}" -a ! -f "${MKINITRD}" ] ; then echo "Warning: mkinitrd ${MKINITRD} not found." echo "" MKINITRD="" fi if [ -n "${ECRYPTFS_UTILS}" ] ; then for E in ${ECRYPTFS_UTILS} ; do if [ ! -f "${E}" ] ; then echo "Warning: ecryptfs-utils ${E} not found." echo "" ECRYPTFS_UTILS="" fi done fi if [ -n "${XGU}" ] ; then for P in ${XGU} ; do if [ ! -f "${P}" ] ; then echo "Warning: xe-guest-utilities ${P} not found." XGU="" fi done fi if [ -z "${XGU}" ] ; then echo "" echo "Certain guest features will not be active until a version of " echo "xe-guest-utilities is installed." echo "" fi if [ -z "${KERNEL}" -a -z "${MKINITRD}" -a -z "${XGU}" -a -z "${ECRYPTFS_UTILS}" ] ; then echo "No updates required to this Virtual Machine." exit 0 fi echo "The following changes will be made to this Virtual Machine:" if [ -n "${KERNEL}" -a -L "/boot/xenkernel" ] || [ -n "${KERNEL}" -a -L "/boot/vmlinuz" ] ; then echo " * grub configuration update." echo " * remove legacy kernel and initrd symbolic links." update_grub=1 else update_grub=0 fi if update_modules_configuration_required ; then echo " * modules configuration update." update_modules=1 else update_modules=0 fi if update_lvm_configuration_required ; then echo " * lvm configuration update." update_lvm=1 else update_lvm=0 fi if update_inittab_configuration_required ; then echo " * update gettys in inittab." update_inittab=1 else update_inittab=0 fi if update_arp_notify_required ; then echo " * update arp_notify sysctl." update_arp_notify=1 else update_arp_notify=0 fi echo " * packages to be installed/upgraded:" for K in ${KERNEL}; do echo -e " - $(basename ${K})" done [ -n "${MKINITRD}" ] && echo -e " - $(basename ${MKINITRD})" for E in ${ECRYPTFS_UTILS}; do echo -e " - $(basename ${E})" done for P in ${XGU}; do echo -e " - $(basename ${P})" done echo "" if [ ${interactive} -gt 0 ] ; then while read -p "Continue? [y/n] " -n 1 ans ; do echo case "$ans" in Y|y) break ;; N|n) echo "Aborting." exit 0 ;; *) echo "Invalid response \`$ans'" ;; esac done echo fi set -e # Any failures from here onwards should be fatal if [ "${update_grub}" -gt 0 ] ; then update_grub_configuration # Remove /boot/xenkernel if [ -L "/boot/xenkernel" ] || [ -L "/boot/xeninitrd" ] || [ -L "/boot/vmlinuz" ] ; then echo "Removing legacy boot kernel and initrd symbolic links." [ -L "/boot/xenkernel" ] && mv -v "/boot/xenkernel" "/boot/xenkernel.bak" [ -L "/boot/xeninitrd" ] && mv -v "/boot/xeninitrd" "/boot/xeninitrd.bak" [ -L "/boot/vmlinuz" ] && update_vmlinuz_symlink echo fi fi if [ "${update_modules}" -gt 0 ] ; then update_modules_configuration fi if [ "${update_lvm}" -gt 0 ] ; then update_lvm_configuration fi if [ "${update_inittab}" -gt 0 ] ; then update_inittab_configuration fi if [ "${update_arp_notify}" -gt 0 ] ; then update_arp_notify_configuration fi case ${GUEST_PKG_TYPE} in rpm) install_rpms ;; deb) install_debs ;; coreos) install_coreos ;; esac if [ -n "${KERNEL}" -o -n "${XGU}" ] ; then echo "You should now reboot this Virtual Machine." fi exit 0 |