f013 [Solved] mdconfig at system boot - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Base System > Storage

Storage Place to ask questions about partitioning, labelling, filesystems, encryption or anything else related to storage area.

Reply
 
Thread Tools Display Modes
  #1  
Old April 23rd, 2012, 20:13
Leander Leander is offline
Junior Member
 
Join Date: Apr 2010
Location: Stuttgart
Posts: 58
Thanks: 4
Thanked 0 Times in 0 Posts
Default mdconfig at system boot

Hi fellows,

Code:
truncate -s 1G /mnt/VirtualDisk
chmod 0600 /mnt/VirtualDisk
mdconfig -a -t vnode -f /mnt/VirtualDisk
works perfectly, but problem is that I still need the same md setup after a reboot as well. Unfortunately the system doesn't remember the mdconfig setup. So I found /etc/rc.d/mdconfig and /etc/rc.d/mdconfig2 and I started to add the following into my rc.conf:
Code:
rc_debug="YES"
rc_info="YES"
mdconfig_md2="-t vnode -f /mnt/VirtualDisk"
After adding this, I tried /etc/rc.d/mdconfig start and /etc/rc.d/mdconfig2 start but nothing helped, md2 wasn't listed by mdconfig -lv After scanning a bit through the rc.d/mdconfig scripts, I figured it may want to have the actual md_n_ device to start so I tried /etc/rc.d/mdconfig start md2 and voila:
Code:
FreeBSD [~]# mdconfig -lv
md0	swap	  512M
md1	vnode	 4096M	/var/swap

FreeBSD [~]# /etc/rc.d/mdconfig start md2
/etc/rc.d/mdconfig: DEBUG: run_rc_command: start_precmd: [ -n "${_mdconfig_list}" ] 
/etc/rc.d/mdconfig: DEBUG: load_kld: geom_md kernel module already loaded.
/etc/rc.d/mdconfig: DEBUG: run_rc_command: doit: mdconfig_start 
/etc/rc.d/mdconfig: DEBUG: md2 config: -t vnode -f /mnt/VirtualDisk
/etc/rc.d/mdconfig: DEBUG: md2 type: vnode
/etc/rc.d/mdconfig: DEBUG: md2 dev: /dev/md2
/etc/rc.d/mdconfig: DEBUG: md2 file: /mnt/VirtualDisk
/etc/rc.d/mdconfig: DEBUG: md2 fs: /
/etc/rc.d/mdconfig: DEBUG: md2 newfs flags: 
Creating md2 device (vnode).
/etc/rc.d/mdconfig: DEBUG: checkyesno: background_fsck is set to YES.
fsck: Could not determine filesystem type
Fsck failed on /dev/md2, not mounting the filesystem.

FreeBSD [~]# mdconfig -lv
md0	swap	  512M
md1	vnode	 4096M	/var/swap
md2	vnode	 1024M	/mnt/VirtualDisk

FreeBSD [~]# mdconfig -du 2
But I'm unhappy about the script complaining about fsck and about the mount issue. Fact is, that I do not want to fsck neither mount it since it will be an iSCSI share. Still I could ignore this error since md2 is now listed by mdconfig -lv But then I tried rc.d/mdconfig2 and it doesn't seem to complain about fsck:
Code:
FreeBSD [~]# /etc/rc.d/mdconfig2 start md2
/etc/rc.d/mdconfig2: DEBUG: run_rc_command: start_precmd: [ -n "${_mdconfig2_list}" ] 
/etc/rc.d/mdconfig2: DEBUG: load_kld: geom_md kernel module already loaded.
/etc/rc.d/mdconfig2: DEBUG: run_rc_command: doit: mdconfig2_start 
/etc/rc.d/mdconfig2: DEBUG: md2 config: -t vnode -f /mnt/VirtualDisk
/etc/rc.d/mdconfig2: DEBUG: md2 type: vnode
/etc/rc.d/mdconfig2: DEBUG: md2 dev: /dev/md2
/etc/rc.d/mdconfig2: DEBUG: md2 file: /mnt/VirtualDisk
/etc/rc.d/mdconfig2: DEBUG: md2 fs: /
/etc/rc.d/mdconfig2: DEBUG: md2 owner: 
/etc/rc.d/mdconfig2: DEBUG: md2 perms: 
/etc/rc.d/mdconfig2: DEBUG: md2 files: 
/etc/rc.d/mdconfig2: DEBUG: md2 populate cmd: 
/etc/rc.d/mdconfig2: DEBUG: checkyesno: _mounted is set to no.
But mdconfig -lv doesn't list it - so it's not configured?

So what am I doing wrong? My aim is to initialize a simple md device right at system boot in order to let eg. iSCSI (istg) benefit of the md device.

Any hints or ideas?

Last edited by DutchDaemon; April 23rd, 2012 at 23:51. Reason: Proper formatting: http://forums.freebsd.org/showthread.php?t=8816
Reply With Quote
  #2  
Old April 26th, 2012, 21:16
usdmatt usdmatt is offline
Member
 
Join Date: Mar 2009
Posts: 249
Thanks: 1
Thanked 67 Times in 56 Posts
Default

Have you tried changing the variable in rc.conf to mdconfig_md0 instead of mdconfig_md2?

I've no experience with the mdconfig startup script but I wouldn't be surprised if it runs in a loop, looking for 0 first, processing that, then 1, etc. The ifconfig scripts work like this for aliases. You'll probably find it's looking for mdconfig_md0, not finding it and giving up (unless you specify the md number as you say).

That may make /etc/rc.d/mdconfig start work but looking at the script I can't see any obvious way of stopping it trying to format and mount the device. You may end up having to make a custom rc script to run the commands on boot.

Last edited by DutchDaemon; April 27th, 2012 at 01:50. Reason: Proper formatting: http://forums.freebsd.org/showthread.php?t=8816
Reply With Quote
  #3  
Old April 27th, 2012, 11:02
usdmatt usdmatt is offline
Member
 
Join Date: Mar 2009
Posts: 249
Thanks: 1
Thanked 67 Times in 56 Posts
Default

The following rc script should create the required md device on boot and remove it on shutdown (tested on 8.3-RELEASE). I'm not sure whether istg will be starting/stopping on boot/shutdown but if so the REQUIRE/KEYWORD stuff at the top may require tweaking to make sure istg starts after this and stops first.

(Note the device is hardcoded to /dev/md100)

Code:
#!/bin/sh

# PROVIDE: iscsimd
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="iscsimd"
rcvar="iscsimd_enable"
start_cmd="iscsimd_start"
stop_cmd="iscsimd_stop"

disk="/mnt/VirtualDisk"
size="1G"

iscsimd_start()
{
        /usr/bin/truncate -s ${size} ${disk}
	/bin/chmod 0600 ${disk}
	/sbin/mdconfig -a -t vnode -f ${disk} -u 100
}

iscsimd_stop()
{
        /sbin/mdconfig -d -u 100
	/bin/unlink ${disk}
}

load_rc_config $name
run_rc_command "$1"
Save it as /usr/local/etc/rc.d/iscsimd, permissions 0500 and then add
Code:
iscsimd_enable="YES"
to /etc/rc.conf.
It will then run on boot/shutdown and can be run manually as follows:

Code:
# service iscsimd start
# service iscsimd stop

Last edited by DutchDaemon; April 27th, 2012 at 22:54.
Reply With Quote
  #4  
Old April 28th, 2012, 09:38
Leander Leander is offline
Junior Member
 
Join Date: Apr 2010
Location: Stuttgart
Posts: 58
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Nice work, hey!
Thanks a lot
Reply With Quote
  #5  
Old April 29th, 2012, 20:52
Leander Leander is offline
Junior Member
 
Join Date: Apr 2010
Location: Stuttgart
Posts: 58
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Here is a tuned version of previous rc script. The method of evaluating md[n] is limited to 100 only! Please let me know if someone knows a better way of getting the "n" of md_file_md[n]. I tried my luck in this thread: http://forums.freebsd.org/showthread.php?t=31707

rc.conf entries can look like:
Code:
### Memory Disks
md_enable="YES"
md_file_md0="/mnt/VirtualDisk"
md_file_md1="/mnt/FileX"
md_file_md12="/mnt/SomeOtherFile"
The rc script for this would be:
Code:
#!/bin/sh

# PROVIDE: md
# REQUIRE: localswap root
# BEFORE: SERVERS

. /etc/rc.subr

name="md"
rcvar="md_enable"
start_cmd="${name}_start"
stop_cmd="md_stop"
required_modules="geom_md:g_md"


md_start() {
    for i in $(seq 0 100); do

        unset MD_FILE
        eval MD_FILE=\$md_file_md${i}

        if [ ! -z $MD_FILE ]; then
            if [ -f $MD_FILE ]; then

                if [ ! -z "$(/sbin/mdconfig -lv | /usr/bin/grep "${MD_FILE}")" ]; then
                    USED_MD="$(/sbin/mdconfig -lv | /usr/bin/grep "${MD_FILE}" | awk '{print $1}')"
                    echo "mdconfig: Skipped md${i}. File $MD_FILE is configured as $USED_MD already."
                    unset USED_MD
                else
                    /sbin/mdconfig -a -t vnode -f $MD_FILE -u ${i} && \
                    MSG="mdconfig: Created /dev/md${i}" && \
                    SIZE=$(diskinfo -v /dev/md${i} | grep "mediasize in bytes" | grep -E -o "\(.*\)") && \
                    printf "%s %s %-10s %s\n" $MSG $SIZE
                fi

            else
                echo "mdconfig: Error: Skipped md${i}. File $MD_FILE not found."
            fi
        fi

    done
}

md_stop() {
    echo "Sorry - this script does not support \"stop\". Use i.e."
    echo "'mdconfig -du 3' in order to unconfigure /dev/md3"
}


load_rc_config $name
run_rc_command "$1"
Don't forget to chmod 0555 /usr/local/etc/rc.d/md the rc script. There is no stop since stop could cause collateral damage to data on md. There is also no file creation if a file doesn't exist. It is necessary to invoke i.e.
Code:
truncate -s 1G /mnt/VirtualDisk
chmod 0600 /mnt/VirtualDisk
once before
Code:
service md start
as mentioned earlier already.

Last edited by DutchDaemon; April 30th, 2012 at 02:15. Reason: Formatting & Style: http://forums.freebsd.org/showthread.php?t=8816 / http://forums.freebsd.org/showthread.php?t=18043
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
System boot error after System upgrade hp21 Installing & Upgrading 0 November 19th, 2010 12:00
[Solved] mdconfig and device numbers tobe Userland Programming & Scripting 6 June 12th, 2009 13:30
mdconfig: Writeable Vnode, is it possible? vaclinux General 4 March 17th, 2009 07:18
low perfomance throuch mdconfig layer Ole General 0 February 3rd, 2009 12:46
Can't boot system randux Installing & Upgrading 3 February 2nd, 2009 17:31


All times are GMT +1. The time now is 20:51.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0