File: md

package info (click to toggle)
partman-md 115
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,792 kB
  • sloc: sh: 777; makefile: 2
file content (121 lines) | stat: -rwxr-xr-x 2,702 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh

. /usr/lib/partman/lib/base.sh

# Check if we have RAID
if [ ! -f /proc/mdstat ]; then
	exit 0
fi

# Obtain the size of an MD device
get_size () {
	while [ -z "$(echo "$line" | grep "^md$NUMBER :")" ]; do
		read line
		[ $? -eq 1 ] && break  # EOF
	done
	read line
	size=$(echo "$line" | sed -e 's/ blocks.*//')
	# If the sed failed, the line didn't contain the size; just
	# return 0 in that case.
	if [ "$size" = "$line" ]; then
		size=0
	fi
}

# Mark all RAID partitions as being MD
for dev in $DEVICES/*; do
	[ -d "$dev" ] || continue
	cd $dev

	# Get all partitions, and check if they have the md flag set.
	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

	# Check if device/partitions are used for software RAID
	for id in $partitions; do
		md=no
		open_dialog GET_FLAGS $id
		while { read_line flag; [ "$flag" ]; }; do
			if [ "$flag" = raid ]; then
				md=yes
			fi
		done
		close_dialog
		if [ "$md" = yes ]; then
			mkdir -p $id
			echo raid > $id/method
		fi
	done

	# Check if the device is a new software RAID device
	if [ -f device ] && [ -z "$partitions" ]; then
		NUMBER=$(sed -e 's,/dev/md/\?,,' device)
		if ! grep -q "^md$NUMBER :" /proc/mdstat; then
			continue
		fi

		# Set an appropriate value for device model
		db_metaget partman-md/text/device description
		echo "${RET}" > model

		# fix size
		get_size < /proc/mdstat
		sector_size=$(grep " sectors" /proc/mdstat | sed -e 's/[^0-9]\+//g')
		if [ -z "$sector_size" ]; then
			sector_size=1024
		fi
		size=$(($size * $sector_size))
		echo "$size" > size

		# create a label
		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
			case $fs in
			    free|unknown)
				free_space=$id
				free_size=$size
				free_fs=$fs
				;;
			esac
		done
		close_dialog
		# create partition in the free space
		if [ "$free_space" ]; then
			id=
			if [ "$free_fs" = unknown ]; then
				# parted >= 3.2 gives us a partition
				# automatically.
				id=$free_space
			else
				# With parted < 3.2 we must create a
				# partition manually.
				open_dialog NEW_PARTITION primary ext2 $free_space full $free_size
				read_line num id size type fs path name
				close_dialog
			fi
			if [ "$id" ]; then
				open_dialog GET_FILE_SYSTEM $id
				read_line filesystem
				close_dialog
				if [ "$filesystem" != none ]; then
					open_dialog CHANGE_FILE_SYSTEM $id $filesystem
					close_dialog
				fi
			fi
		fi
		open_dialog DISK_UNCHANGED
		close_dialog
	fi
done

exit 0