~kirkland/ubuntu/quantal/cloud-initramfs-tools/overlayroot-chroot

« back to all changes in this revision

Viewing changes to overlayroot/scripts/init-bottom/overlayroot

  • Committer: Scott Moser
  • Date: 2012-07-20 15:22:03 UTC
  • Revision ID: smoser@ubuntu.com-20120720152203-ac333ak4rf3id6er
initial crack at dir= support

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
}
115
115
crypto_setup() {
116
116
        local fstype="ext3" pass="" mapname="secure" mkfs="1" dev=""
117
 
        local timeout=0
 
117
        local timeout=0 dir="/"
118
118
        # this does necessary crypto setup and sets _RET
119
119
        # to the appropriate block device (ie /dev/mapper/secure)
120
120
 
134
134
        mkfs=${_RET_mkfs:-${mkfs}}
135
135
        dev=${_RET_dev:-${dev}}
136
136
        timeout=${_RET_timeout:-${timeout}}
 
137
        dir=${_RET_dir:-${dir}}
 
138
 
 
139
        dev="/dev/${dev#/dev/}"
137
140
 
138
141
        debug "fstype=${fstype} pass=${pass} mapname=${mapname}"
139
 
        debug "mkfs=${mkfs} dev=${dev} timeout=${timeout}"
 
142
        debug "mkfs=${mkfs} dev=${dev} timeout=${timeout} dir=${dir}"
140
143
 
141
 
        dev="/dev/${dev#/dev/}"
142
144
        [ -n "$dev" ] ||
143
145
                { log_fail "dev is required input for crypt setup"; return 1; }
144
146
 
181
183
                return 1;
182
184
        }
183
185
 
184
 
        _RET="/dev/mapper/$mapname"
 
186
        _RET_DEVICE="/dev/mapper/$mapname"
 
187
        _RET_DIR="$dir"
185
188
        return 0
186
189
}
187
190
 
188
191
dev_setup() {
189
 
        local options="$1" dev="" timeout=0
 
192
        local options="$1" dev="" timeout=0 path="/"
190
193
        # options supported:
191
 
        #    dev=device,timeout=X
 
194
        #    dev=device,timeout=X,path=/
192
195
        parse_string "${options}" ||
193
196
                { log_fail "failed parsing '${options}'"; return 1; }
194
197
 
195
198
        dev=${_RET_dev:-${dev}}
196
199
        timeout=${_RET_timeout:-${timeout}}
 
200
        dir=${_RET_dir:-${dir}}
197
201
 
198
202
        dev="/dev/${dev#/dev/}"
 
203
 
 
204
        debug "dev=${dev} timeout=${timeout} dir=${dir}"
 
205
 
199
206
        wait_for_dev "$dev" "$timeout"
200
 
        _RET="$dev"
 
207
        _RET_DEVICE="$dev"
 
208
        _RET_DIR="$dir"
201
209
}
202
210
 
203
211
 
238
246
                dev_setup "device=${overlayroot#device:}" ||
239
247
                        fail "failed setup overlay for ${overlayroot}"
240
248
                mode="device"
241
 
                device="$_RET"
 
249
                device="$_RET_DEVICE"
 
250
                dir_prefix="$_RET_DIR"
242
251
                ;;
243
252
        crypt|crypt:*)
244
253
                mode="crypt"
245
254
                t=${overlayroot#crypt}
246
255
                crypto_setup "${t#:}" ||
247
256
                        fail "failed setup crypt for ${overlayroot}"
248
 
                device="$_RET"
 
257
                device="$_RET_DEVICE"
 
258
                dir_prefix="$_RET_DIR"
249
259
                ;;
250
260
        disabled)
251
261
                debug "overlayroot disabled${used_desc:+ per ${used_desc}}"
265
275
case "${overlayroot_driver}" in
266
276
        overlayfs)
267
277
                mount_type="overlayfs"
268
 
                mount_opts="-o lowerdir=${root_ro},upperdir=${root_rw}"
 
278
                mount_opts="-o lowerdir=${root_ro},upperdir=${root_rw}/${dir_prefix}"
269
279
                mount_opts="${mount_opts} overlayfs-root ${ROOTMNT}"
270
280
                ;;
271
281
        aufs)
272
282
                mount_type="aufs"
273
 
                mount_opts="-o dirs=${root_rw}:${root_ro}=ro aufs-root ${ROOTMNT}"
 
283
                mount_opts="-o dirs=${root_rw}/${dir_prefix}:${root_ro}=ro aufs-root ${ROOTMNT}"
274
284
                ;;
275
285
        *)
276
286
                log_fail "invalid overlayroot driver: ${overlayroot_driver}"
299
309
        # dev or crypto
300
310
        mount "$device" "${root_rw}" ||
301
311
                fail "failed mount backing device $device"
 
312
        mkdir -p "${root_rw}/${dir_prefix}" ||
 
313
                fail "failed to create ${dir_prefix} on ${device}"
302
314
fi
303
315
 
304
316
# root is mounted on ${ROOTMNT}, move it to ${ROOT_RO}.