File: zfs

package info (click to toggle)
partman-zfs 24
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,404 kB
  • sloc: sh: 1,446; makefile: 2
file content (97 lines) | stat: -rwxr-xr-x 2,422 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh

# This script sets method "zfs" for all partitions that have the zfs
# flag set.  It also discovers the logical volumes and creates in them
# a loop partition table and partition.

. /lib/partman/lib/base.sh
. /lib/partman/lib/zfs-base.sh

log-output -t partman zpool import -a -f -o altroot=/target

# Some ZFS versions don't create cachefile when "-o altroot" is used.
# Request it explicitly.
for vg in $(zpool list -H -o name) ; do
	log-output -t partman-zfs zpool set cachefile=/boot/zfs/zpool.cache "$vg" || return 1
done

if [ -x /sbin/zpool ]; then
	vgroups=$(/sbin/zpool list -H 2>/dev/null | \
		sed -e 's/\t.*//' | sort)
else
	vgroups=''
fi

for dev in /var/lib/partman/devices/*; do
	[ -d "$dev" ] || continue
	cd $dev
	partitions=
	open_dialog PARTITIONS
	while { read_line num id size type fs path name; [ "$id" ]; }; do
		if [ "$fs" != free ]; then
			partitions="$partitions $id"
		fi
	done
	close_dialog

	for id in $partitions; do
		zfs=no

		# If the device is in fact being used for zfs, mark it as such.
		# This is a hack and it only works for full block devices, not
		# partitions. It makes raid devices used for zfs show up as such.
		if zpool status 2>/dev/null | grep -q "\s$(basename $(cat $dev/device))\s" ; then
			zfs=yes
		fi

		open_dialog GET_FILE_SYSTEM $id
		read_line fs
		close_dialog
		if [ "$fs" = zfs ]; then
			zfs=yes
		fi
		if [ "$zfs" = yes ]; then
			mkdir -p $id
			echo zfs >$id/method
		fi
	done

	if [ -f device ]; then
		# Obtain the VG from the device name
		device=`cat device`
		case "$device" in
		    /dev/zvol/*)
			vglv=${device#/dev/zvol/}
			vglv=$(echo "$vglv" | sed -e 's/\([^-]\)-\([^-]\)/\1 \2/' |
			       sed -e 's/--/-/g')
			vg=$(echo "$vglv" | cut -d" " -f1)
			;;
		esac
		is_vg=no
		for vgs in $vgroups; do
			[ "$vgs" = "$vg" ] && is_vg=yes
		done
		if [ "$is_vg" = yes ] ; then
			# this is an activated logical volume
			# let's create label on it
			open_dialog NEW_LABEL loop
			close_dialog
			# find the free space
			open_dialog PARTITIONS
			free_space=''
			while { read_line num id size type fs path name; [ "$id" ]; }; do
				if [ "$fs" = free ]; then
					free_space=$id
					free_size=$size
				fi
			done
			close_dialog
			# create partition in the free space
			if [ "$free_space" ]; then
				create_new_partition primary $free_space full $free_size "zfs"
			fi
			open_dialog DISK_UNCHANGED
			close_dialog
		fi
	fi
done