gptboot revision 213137
1213137Spjd#!/bin/sh 2213137Spjd# 3213137Spjd# Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4213137Spjd# All rights reserved. 5213137Spjd# 6213137Spjd# Redistribution and use in source and binary forms, with or without 7213137Spjd# modification, are permitted provided that the following conditions 8213137Spjd# are met: 9213137Spjd# 1. Redistributions of source code must retain the above copyright 10213137Spjd# notice, this list of conditions and the following disclaimer. 11213137Spjd# 2. Redistributions in binary form must reproduce the above copyright 12213137Spjd# notice, this list of conditions and the following disclaimer in the 13213137Spjd# documentation and/or other materials provided with the distribution. 14213137Spjd# 15213137Spjd# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 16213137Spjd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17213137Spjd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18213137Spjd# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 19213137Spjd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20213137Spjd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21213137Spjd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22213137Spjd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23213137Spjd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24213137Spjd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25213137Spjd# SUCH DAMAGE. 26213137Spjd# 27213137Spjd# $FreeBSD: head/etc/rc.d/gptboot 213137 2010-09-24 19:53:55Z pjd $ 28213137Spjd# 29213137Spjd 30213137Spjd# PROVIDE: gptboot 31213137Spjd# REQUIRE: mountcritremote 32213137Spjd# KEYWORD: nojail 33213137Spjd 34213137Spjd. /etc/rc.subr 35213137Spjd 36213137Spjdname="gptboot" 37213137Spjdstart_cmd="gptboot_report" 38213137Spjd 39213137Spjdgptboot_report() 40213137Spjd{ 41213137Spjd gpart show | \ 42213137Spjd egrep '(^=>| freebsd-ufs .*(\[|,)(bootfailed|bootonce)(,|\]))' | \ 43213137Spjd sed 's/^=>//' | \ 44213137Spjd egrep -v '(\[|,)bootme(,|\])' | \ 45213137Spjd while read start size pos type attrs rest; do 46213137Spjd case "${pos}" in 47213137Spjd [0-9]*) 48213137Spjd if [ -n "${disk}" ]; then 49213137Spjd part="${disk}p${pos}" 50213137Spjd echo "${attrs}" | egrep -q '(\[|,)bootfailed(,|\])' 51213137Spjd bootfailed=$? 52213137Spjd echo "${attrs}" | egrep -q '(\[|,)bootonce(,|\])' 53213137Spjd bootonce=$? 54213137Spjd if [ ${bootfailed} -eq 0 ]; then 55213137Spjd logger -t gptboot -p local0.notice "Boot from ${part} failed." 56213137Spjd gpart unset -a bootfailed -i ${pos} ${disk} >/dev/null 57213137Spjd elif [ ${bootonce} -eq 0 ]; then 58213137Spjd # We want to log success after all failures. 59213137Spjd echo -n "Boot from ${part} succeeded." 60213137Spjd gpart unset -a bootonce -i ${pos} ${disk} >/dev/null 61213137Spjd fi 62213137Spjd fi 63213137Spjd ;; 64213137Spjd *) 65213137Spjd if [ "${type}" = "GPT" ]; then 66213137Spjd disk="${pos}" 67213137Spjd else 68213137Spjd disk="" 69213137Spjd fi 70213137Spjd ;; 71213137Spjd esac 72213137Spjd done | logger -t gptboot -p local0.notice 73213137Spjd} 74213137Spjd 75213137Spjdload_rc_config $name 76213137Spjdrun_rc_command "$1" 77