blob: d7bba30ae8d0a96c1d60112f0a6fd710cbc06ee1 (
plain)
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
|
#!/sbin/runscript
# Copyright 1999-2012 Gentoo Foundation
# Released under the 2-clause BSD license.
# $Header: /var/cvsroot/gentoo-x86/sys-fs/zfs/files/zfs-shutdown,v 1.2 2012/11/29 05:19:12 ryao Exp $
description="Export ZFS Root Filesystem"
copy_binaries() {
local destdir=$1
shift
lddtree "$@" \
| tr ')(' '\n' \
| awk '/=>/{ if($3 ~ /^\//){print $3}}' \
| sort \
| uniq \
| cpio -p --make-directories --dereference --quiet $destdir
}
depend()
{
need mount-ro
keyword -prefix -openvz -vserver -lxc
}
start()
{
ROOTFSTYPE=$(df -TP / | awk 'NR>1{print $2}')
TMPDIR='/dev/pivot_root'
MOVEFS=$(df -TP -x zfs | awk 'NR>2{print $7}')
# Make sure that we are dealing with zfs
if test "${ROOTFSTYPE}" = "zfs"
then
eerror "rootfs is not zfs"
return 1
fi
# Construct new rootfs
mkdir -p "${TMPDIR}"
mount -t tmpfs none ${TMPDIR}
mkdir "${TMPDIR}/oldroot" "${TMPDIR}/dev"
mknod -m 660 "${TMPDIR}/dev/null" c 1 3
mknod -m 660 "${TMPDIR}/dev/zfs" c 10 59
# Make tmpfs root filesystem
copy_binaries ${TMPDIR} $(which chroot sh cat mount mkdir zfs zpool)
# Make directories for temporary mounts
for i in $(seq $(echo "$MOVEFS" | wc -w)); do mkdir "${TMPDIR}/${i}"; done;
# Pass temporary mount information to chroot
echo "$MOVEFS" > "${TMPDIR}/movefs"
# Copy shutdown script
cp /usr/share/zfs/linuxrc "${TMPDIR}/linuxrc"
# Pivot into new root
cd "${TMPDIR}"
pivot_root . oldroot
exec chroot . /linuxrc
}
|