source: src-sh/pc-sysinstall/backend/functions-newfs.sh @ d464bcc

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since d464bcc was d464bcc, checked in by Kris Moore <kris@…>, 13 months ago

Remove gnop trickery, conflicts with GRUB. We will need to look
into another method to set ashift=12

  • Property mode set to 100755
File size: 7.2 KB
Line 
1#!/bin/sh
2#-
3# Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-newfs.sh 247735 2013-03-03 23:07:27Z jpaetzel $
27
28# Functions related to disk operations using newfs
29
30
31# Function which performs the ZFS magic
32setup_zfs_filesystem()
33{
34  PART="$1"
35  PARTFS="$2"
36  PARTMNT="$3"
37  EXT="$4"
38  PARTGEOM="$5"
39  ZPOOLOPTS="$6"
40  ROOTSLICE="`echo ${PART} | rev | cut -b 2- | rev`"
41  ZPOOLNAME=$(get_zpool_name "${PART}")
42
43  # Sleep a few moments, let the disk catch its breath
44  sleep 5
45  sync
46
47  # Check if we have multiple zfs mounts specified
48  for i in `echo ${PARTMNT} | sed 's|,| |g'`
49  do
50    # Check if we ended up with needing a zfs bootable partition
51    if [ "${i}" = "/" -o "${i}" = "/boot" ]
52    then
53      if [ "$HAVEBOOT" = "YES" ] ; then continue ; fi
54      if [ "${PARTGEOM}" = "MBR" ] ; then
55        # Lets stamp the proper ZFS boot loader
56        echo_log "Setting up ZFS boot loader support" 
57        rc_halt "dd if=/boot/zfsboot of=${ROOTSLICE} count=1"
58        rc_halt "dd if=/boot/zfsboot of=${PART}${EXT} skip=1 seek=1024"
59      fi
60    fi
61  done 
62
63  # Check if we have some custom zpool arguments and use them if so
64  if [ ! -z "${ZPOOLOPTS}" ] ; then
65    echo_log "Creating zpool ${ZPOOLNAME} with $ZPOOLOPTS"
66    rc_halt "zpool create -m none -f ${ZPOOLNAME} ${ZPOOLOPTS}"
67  else
68    # No zpool options, create pool on single device
69    echo_log "Creating zpool ${ZPOOLNAME} on ${PART}${EXT}"
70    rc_halt "zpool create -m none -f ${ZPOOLNAME} ${PART}${EXT}"
71  fi
72
73  # Disable atime for this zfs partition, speed increase
74  rc_nohalt "zfs set atime=off ${ZPOOLNAME}"
75
76};
77
78# Runs newfs on all the partiions which we've setup with bsdlabel
79setup_filesystems()
80{
81
82  # Create the keydir
83  rm -rf ${GELIKEYDIR} >/dev/null 2>/dev/null
84  mkdir ${GELIKEYDIR}
85
86  # Lets go ahead and read through the saved partitions we created, and determine if we need to run
87  # newfs on any of them
88  for PART in `ls ${PARTDIR}`
89  do
90    PARTDEV="`echo $PART | sed 's|-|/|g'`"
91    PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
92    PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
93    PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
94    PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`"
95    PARTGEOM="`cat ${PARTDIR}/${PART} | cut -d '#' -f 5`"
96    PARTXTRAOPTS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 6`"
97    PARTIMAGE="`cat ${PARTDIR}/${PART} | cut -d '#' -f 7`"
98
99    if [ ! -e "${PARTDEV}" ] ; then
100      exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
101    fi 
102
103    # Make sure journaling isn't enabled on this device
104    if [ -e "${PARTDEV}.journal" ]
105    then
106      rc_nohalt "gjournal stop -f ${PARTDEV}.journal"
107      rc_nohalt "gjournal clear ${PARTDEV}"
108    fi
109
110    # Setup encryption if necessary
111    if [ "${PARTENC}" = "ON" -a "${PARTFS}" != "SWAP" ]
112    then
113      echo_log "Creating geli provider for ${PARTDEV}"
114
115      if [ -e "${PARTDIR}-enc/${PART}-encpass" ] ; then
116        # Using a passphrase
117        rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1"
118        rc_halt "geli init -J ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}"
119        rc_halt "geli attach -j ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}"
120      else
121        # No Encryption password, use key file
122        rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1"
123        rc_halt "geli init -b -s 4096 -P -K ${GELIKEYDIR}/${PART}.key ${PARTDEV}"
124        rc_halt "geli attach -p -k ${GELIKEYDIR}/${PART}.key ${PARTDEV}"
125
126      fi
127
128      EXT=".eli"
129    else
130      # No Encryption
131      EXT=""
132    fi
133
134    case ${PARTFS} in
135      UFS)
136        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
137        sleep 2
138        rc_halt "newfs -t ${PARTXTRAOPTS} ${PARTDEV}${EXT}"
139        sleep 2
140        rc_halt "sync"
141        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
142        rc_halt "sync"
143
144        # Set flag that we've found a boot partition
145        if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
146                  HAVEBOOT="YES"
147        fi
148        sleep 2
149        ;;
150
151      UFS+S)
152        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
153        sleep 2
154        rc_halt "newfs -t ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}"
155        sleep 2
156        rc_halt "sync"
157        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
158        rc_halt "sync"
159            # Set flag that we've found a boot partition
160            if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
161          HAVEBOOT="YES"
162        fi
163        sleep 2
164        ;;
165
166      UFS+SUJ)
167        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
168        sleep 2
169        rc_halt "newfs -t ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}"
170        sleep 2
171        rc_halt "sync"
172        rc_halt "tunefs -j enable ${PARTDEV}${EXT}"
173        sleep 2
174        rc_halt "sync"
175        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
176        rc_halt "sync"
177            # Set flag that we've found a boot partition
178            if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
179          HAVEBOOT="YES"
180        fi
181        sleep 2
182        ;;
183
184
185      UFS+J)
186        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
187        sleep 2
188        rc_halt "newfs ${PARTDEV}${EXT}"
189        sleep 2
190        rc_halt "gjournal label -f ${PARTDEV}${EXT}"
191        sleep 2
192        rc_halt "newfs ${PARTXTRAOPTS} -O 2 -J ${PARTDEV}${EXT}.journal"
193        sleep 2
194        rc_halt "sync"
195        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal"
196        rc_halt "sync"
197            # Set flag that we've found a boot partition
198            if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
199          HAVEBOOT="YES"
200            fi
201        sleep 2
202        ;;
203
204      ZFS)
205        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" 
206        setup_zfs_filesystem "${PARTDEV}" "${PARTFS}" "${PARTMNT}" "${EXT}" "${PARTGEOM}" "${PARTXTRAOPTS}"
207        ;;
208
209      SWAP)
210        rc_halt "sync"
211        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" 
212        rc_halt "sync"
213        sleep 2
214        ;;
215
216      IMAGE)
217        write_image "${PARTIMAGE}" "${PARTDEV}"
218        sleep 2
219        ;;
220
221      *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
222    esac
223
224  done
225};
Note: See TracBrowser for help on using the repository browser.