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

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

Re-enable the GNOP fix to set ZFS 4k sector sizes, includes a fix to make
raidz play nicely with GRUB now

  • Property mode set to 100755
File size: 8.0 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    # Sort through devices and run gnop on them
66    local gnopDev=""
67    local newOpts=""
68    local hGnop=0
69    for i in $ZPOOLOPTS
70    do
71       echo "$i" | grep -q '/dev/'
72       if [ $? -eq 0 -a $hGnop -eq 0 ] ; then
73          rc_halt "gnop create -S 4096 ${i}"
74          gnopDev="$gnopDev $i"
75          newOpts="$newOpts ${i}.nop"
76          hGnop=1
77       else
78          newOpts="$newOpts $i"
79       fi
80    done
81   
82    echo_log "Creating zpool ${ZPOOLNAME} with $newOpts"
83    rc_halt "zpool create -m none -f ${ZPOOLNAME} ${newOpts}"
84
85    # Export the pool
86    rc_halt "zpool export ${ZPOOLNAME}"
87
88    # Destroy the gnop devices
89    for i in $gnopDev
90    do
91       rc_halt "gnop destroy ${i}.nop"
92    done
93
94    # And lastly re-import the pool
95    rc_halt "zpool import ${ZPOOLNAME}"
96  else
97    # Lets do our pseudo-4k drive
98    rc_halt "gnop create -S 4096 ${PART}${EXT}"
99
100    # No zpool options, create pool on single device
101    echo_log "Creating zpool ${ZPOOLNAME} on ${PART}${EXT}"
102    rc_halt "zpool create -m none -f ${ZPOOLNAME} ${PART}${EXT}.nop"
103
104    # Finish up the gnop 4k trickery
105    rc_halt "zpool export ${ZPOOLNAME}"
106    rc_halt "gnop destroy ${PART}${EXT}.nop"
107    rc_halt "zpool import ${ZPOOLNAME}"
108  fi
109
110};
111
112# Runs newfs on all the partiions which we've setup with bsdlabel
113setup_filesystems()
114{
115
116  # Create the keydir
117  rm -rf ${GELIKEYDIR} >/dev/null 2>/dev/null
118  mkdir ${GELIKEYDIR}
119
120  # Lets go ahead and read through the saved partitions we created, and determine if we need to run
121  # newfs on any of them
122  for PART in `ls ${PARTDIR}`
123  do
124    PARTDEV="`echo $PART | sed 's|-|/|g'`"
125    PARTFS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 1`"
126    PARTMNT="`cat ${PARTDIR}/${PART} | cut -d '#' -f 2`"
127    PARTENC="`cat ${PARTDIR}/${PART} | cut -d '#' -f 3`"
128    PARTLABEL="`cat ${PARTDIR}/${PART} | cut -d '#' -f 4`"
129    PARTGEOM="`cat ${PARTDIR}/${PART} | cut -d '#' -f 5`"
130    PARTXTRAOPTS="`cat ${PARTDIR}/${PART} | cut -d '#' -f 6`"
131    PARTIMAGE="`cat ${PARTDIR}/${PART} | cut -d '#' -f 7`"
132
133    if [ ! -e "${PARTDEV}" ] ; then
134      exit_err "ERROR: The partition ${PARTDEV} does not exist. Failure in bsdlabel?"
135    fi 
136
137    # Make sure journaling isn't enabled on this device
138    if [ -e "${PARTDEV}.journal" ]
139    then
140      rc_nohalt "gjournal stop -f ${PARTDEV}.journal"
141      rc_nohalt "gjournal clear ${PARTDEV}"
142    fi
143
144    # Setup encryption if necessary
145    if [ "${PARTENC}" = "ON" -a "${PARTFS}" != "SWAP" ]
146    then
147      echo_log "Creating geli provider for ${PARTDEV}"
148
149      if [ -e "${PARTDIR}-enc/${PART}-encpass" ] ; then
150        # Using a passphrase
151        rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1"
152        rc_halt "geli init -J ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}"
153        rc_halt "geli attach -j ${PARTDIR}-enc/${PART}-encpass ${PARTDEV}"
154      else
155        # No Encryption password, use key file
156        rc_halt "dd if=/dev/random of=${GELIKEYDIR}/${PART}.key bs=64 count=1"
157        rc_halt "geli init -b -s 4096 -P -K ${GELIKEYDIR}/${PART}.key ${PARTDEV}"
158        rc_halt "geli attach -p -k ${GELIKEYDIR}/${PART}.key ${PARTDEV}"
159
160      fi
161
162      EXT=".eli"
163    else
164      # No Encryption
165      EXT=""
166    fi
167
168    case ${PARTFS} in
169      UFS)
170        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
171        sleep 2
172        rc_halt "newfs -t ${PARTXTRAOPTS} ${PARTDEV}${EXT}"
173        sleep 2
174        rc_halt "sync"
175        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
176        rc_halt "sync"
177
178        # Set flag that we've found a boot partition
179        if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
180                  HAVEBOOT="YES"
181        fi
182        sleep 2
183        ;;
184
185      UFS+S)
186        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
187        sleep 2
188        rc_halt "newfs -t ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}"
189        sleep 2
190        rc_halt "sync"
191        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
192        rc_halt "sync"
193            # Set flag that we've found a boot partition
194            if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
195          HAVEBOOT="YES"
196        fi
197        sleep 2
198        ;;
199
200      UFS+SUJ)
201        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
202        sleep 2
203        rc_halt "newfs -t ${PARTXTRAOPTS} -U ${PARTDEV}${EXT}"
204        sleep 2
205        rc_halt "sync"
206        rc_halt "tunefs -j enable ${PARTDEV}${EXT}"
207        sleep 2
208        rc_halt "sync"
209        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}"
210        rc_halt "sync"
211            # Set flag that we've found a boot partition
212            if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
213          HAVEBOOT="YES"
214        fi
215        sleep 2
216        ;;
217
218
219      UFS+J)
220        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}"
221        sleep 2
222        rc_halt "newfs ${PARTDEV}${EXT}"
223        sleep 2
224        rc_halt "gjournal label -f ${PARTDEV}${EXT}"
225        sleep 2
226        rc_halt "newfs ${PARTXTRAOPTS} -O 2 -J ${PARTDEV}${EXT}.journal"
227        sleep 2
228        rc_halt "sync"
229        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}.journal"
230        rc_halt "sync"
231            # Set flag that we've found a boot partition
232            if [ "$PARTMNT" = "/boot" -o "${PARTMNT}" = "/" ] ; then
233          HAVEBOOT="YES"
234            fi
235        sleep 2
236        ;;
237
238      ZFS)
239        echo_log "NEWFS: ${PARTDEV} - ${PARTFS}" 
240        setup_zfs_filesystem "${PARTDEV}" "${PARTFS}" "${PARTMNT}" "${EXT}" "${PARTGEOM}" "${PARTXTRAOPTS}"
241        ;;
242
243      SWAP)
244        rc_halt "sync"
245        rc_halt "glabel label ${PARTLABEL} ${PARTDEV}${EXT}" 
246        rc_halt "sync"
247        sleep 2
248        ;;
249
250      IMAGE)
251        write_image "${PARTIMAGE}" "${PARTDEV}"
252        sleep 2
253        ;;
254
255      *) exit_err "ERROR: Got unknown file-system type $PARTFS" ;;
256    esac
257
258  done
259};
Note: See TracBrowser for help on using the repository browser.