raspersey
Posts: 2
Joined: Wed Jan 29, 2014 6:39 am

lvm on raid not activate during startup

Wed Jan 29, 2014 6:59 am

Hello everyone,

I have two USB disks connected to my PI:
sda
\- sda1
\- lvm: vg_disk1
\- sda2
\- raid: md0
\- vg_raid1
sdb
\- sdb1
\- lvm: vg_disk2
\- sdb2
\- raid: md0
\- vg_raid1

md0 is a raid 1 array.

Parted information:

Model: WD My Passport 0820 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 1049kB 500GB 500GB primary lvm
2 500GB 1000GB 500GB primary raid

Model: WD My Passport 0820 (scsi)
Disk /dev/sdb: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 1049kB 500GB 500GB primary lvm
2 500GB 1000GB 500GB primary raid

However, when I boot up, vg_raid1 is not activated. vg_disk1 and vg_disk2 are activated fine.

Checking what's going on, I see that mdamd_raid is starting but not assembling /dev/md0. This is the line added to /etc/mdadm/mdadm.conf:
ARRAY /dev/md0 metadata=1.2 name=raspberrypi:0 UUID=83316dd2:b2d49e3f:b6bf46c5:f5447b91

After mdadm_raid, lvm2 is started but only activating vg_disk1 and vg_disk2.

After boot, it's not problem to activate the raid and the vg on it.

What did I miss ?
PI board B rev 2

raspersey
Posts: 2
Joined: Wed Jan 29, 2014 6:39 am

Re: lvm on raid not activate during startup

Sun Feb 02, 2014 8:41 pm

After some trial-and-error, it seems that it is related to a timing issue. When mdadm-raid is started, the disks are not fully visible (the device is visible but the partitions are not yet).

I have added following start/stop script to implement a wait and the problem seems to be gone:

Code: Select all

#! /bin/sh
### BEGIN INIT INFO
# Provides:          wait-for-disks
# Required-Start:    mountkernfs hostname
# X-Start-Before:    mdadm-raid
# Required-Stop:     mountkernfs
# Should-Stop:       udev
# X-Stop-After:      mdadm-raid
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: Wait for the external disks (if available) to be fully initialised
# Description:       Wait for at most 5 seconds to see the partitions of external disks
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Waiting for disks to initialize"

. /lib/init/vars.sh

. /lib/lsb/init-functions

do_start()
{
	max_secs=5
	secs=0
	log_action_begin_msg "Waiting max $max_secs seconds for disks to initialize"
	while [ $secs -lt $max_secs ]
	do
		non_init_disks=''
		# check again in loop to make sure no new disks popped up
		disks=$(awk '$4 ~ "^sd[a-z]+$" {print $4}' /proc/partitions)
		for disk in $disks
		do
			if ! awk 'BEGIN {code = 1} $4 ~ "^'$disk'[0-9]+$" {code = 0} END {exit code}' /proc/partitions
			then
				non_init_disks="$non_init_disks $disk"
			fi
		done
		if [ -n "$non_init_disks" ]
		then
			sleep 1
			secs=$((secs + 1))
		else
			log_action_end_msg 0
			return 0
		fi
	done
	log_action_end_msg 1
	return 1
}

do_stop()
{
	return 0
}

do_reload() {
	return 0
}

case "$1" in
  start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	do_start
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  status)
	status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
	;;
  restart|force-reload)
	log_daemon_msg "Restarting $DESC" "$NAME"
	do_stop
	case "$?" in
	  0|1)
		do_start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
		log_end_msg 1
		;;
	esac
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
	exit 3
	;;
esac

:
On execution of update-rc.d the problems seems to be gone now. I have rebooted several times successfully now.
PI board B rev 2

Return to “Raspberry Pi OS”