This is an old revision of the document!


How to fun_plug

Background info

On startup DSM-G600 will run /etc/rc.sh which will mount the various filesystems and initialize the drive.

...
touch /tmp/boot_finished
/usr/sbin/chk_fun_plug &

/usr/sbin/chk_fun_plug will check for file called fun_plug on the disks root and then execute it.

#!/bin/sh
 
sleep 30
 
Dir_Len=28
Filename_Len=26
CUSTOMIZEHDPATH=/sys/custom/shared_name/HD
 
file=$(find "$CUSTOMIZEHDPATH"/*)
HD_Path=`expr substr "$file" "$Dir_Len" "$Filename_Len"`
HD_Path=$HD_Path"a2"
 
if [ -e /mnt/$HD_Path/fun_plug ]; then
        echo "function plug enable"
        /mnt/$HD_Path/fun_plug
fi

Warning: This was just background information about how DSM-G600 finds and executes fun_plug. All scripts above this warning should not be entered into your fun_plug or any other scripts.

Installing fun_plug

There are 5 ways to setup a working fun_plug file:

  1. To a new hard drive using Linux
  2. To an already partitioned hard drive using Linux
  3. To an already partitioned hard drive using Linux and Samba
  4. To an already partitioned hard drive using Windows and cygwin
  5. To a running DSM using FTP from any Operating System

1. To a new hard drive using Linux

  1. Connect your new hard drive to a Linux (ext3 supported) PC.
  2. Run terminal as root user.
  3. Fire up fdisk using following command fdisk /dev/hdx or fdisk /dev/sdx if you have a SATA or USB hard drive. The x is your hard drive position, for example Primary Master is a, Primary Slave is b, Secondary Master is c and Secondary Slave is d. SATA and USB hard drives are usually a.
  4. Now we are going to make a swap partition.
  5. When you are inside fdisk press n
  6. Then p
  7. And then 1
  8. And then Enter key
  9. And finally +512M
  10. Now we are going to make an ext3 partition for your files. You can also make more than one partition for your files. For example if you do not want to store your files to ext3 partition and you want to use fat32 instead, or if you want to use a chroot environment and want to avoid the chmod bug at bootup.
  11. Press n
  12. Then p
  13. Then 2
  14. Then press the Enter key
  15. And now press the Enter key if you want to make only one ext3 partition. If you are not sure what to do then you should press the Enter key. But if you want to make one or more extra partitions then you must figure out how you are going to allocate your drive space among all those partitions you are going to make. For example if you want to store most of your files to a FAT32 partition then you should enter +100M to make a 100MB ext3 partition.
  16. If you did choose to make more than one partition for your files, then proceed with step 17, otherwise go to step 18.
  17. Now press n then p after that 3 and now Enter key and Enter key once more.
  18. Now we are going to set the partition type to swap.
  19. Press T
  20. Then 1
  21. And then 82
  22. If you chose to make more than one partition for your files then proceed with step 23, otherwise go to step 24.
  23. Now you have to choose a file system for your extra partition. You can leave it as ext3 or change it to FAT32. To change it FAT32, press T then 3 and then c
  24. Now you can review your partition table by pressing p, if it looks good then press w to write changes to hard disk. If you think something went wrong then press q and start again, starting with step 3.
  25. Now we are going to format newly created partitions.
  26. To format the swap partition run mkswap /dev/hdx1
  27. Next we are going to format the ext3 partition with the following command line mke2fs -j /dev/hdx2
  28. And if you chose to make a second partition to your files then we must format this one also. If you chose it to be FAT32 at the 23rd step, then you must run mkdosfs /dev/hdx3
  29. And finally we are going to copy the fun_plug file to your ext3 partition.
  30. We first mount the ext3 partition with this command line mkdir /mnt/dsmg600disk || mount /dev/hdx2 /mnt/dsmg600disk
  31. Now create an empty fun_plug file with this command touch /mnt/dsmg600disk/fun_plug
  32. And now we are going to make it an a executable with this command chmod 777 /mnt/dsmg600disk/fun_plug
  33. Now run ls -la /mnt/dsmg600disk/fun_plug to make sure that we did it correctly. You should see
    -rwxrwxrwx 1 root root 0 some-date-and-time /mnt/dsmg600disk/fun_plug
  34. Optionally you can also install telnet here.
  35. Now we are almost done, we just need to unmount ext3 partition with umount /mnt/dsmg600disk command.
  36. And now you can take out the hard drive from your computer and install it in your DSM-G600.

2. To an already partitioned hard drive using Linux

  1. Take your hard disk out of your DSM-G600.
  2. Connect your already partitioned hard drive to a Linux (ext3 supported) PC.
  3. Run terminal as root user.
  4. We need first mount ext3 partition with this command line mkdir /mnt/dsmg600disk || mount /dev/hdx2 /mnt/dsmg600disk. The x is your hard drive position, for example Primary Master is a, Primary Slave is b, Secondary Master is c and Secondary Slave is d. SATA and USB hard drives are most cases a.
  5. Now create empty fun_plug file with this command touch /mnt/dsmg600disk/fun_plug
  6. And now we are going to make it an a executable with this command chmod 777 /mnt/dsmg600disk/fun_plug
  7. Now run ls -la /mnt/dsmg600disk/fun_plug to make sure that we made it correctly. You should see
    -rwxrwxrwx 1 root root 0 some-date-and-time /mnt/dsmg600disk/fun_plug
  8. Optionally if you like you can also install telnet here.
  9. Now we are almost done, just need to unmount ext3 partition with umount /mnt/dsmg600disk command.
  10. And now you can take out your hard drive from your computer and install it back to your DSM-G600.

3. To an already partitioned hard drive using Linux and Samba

  1. Boot up your DSM-G600.
  2. Mount DSM-G600 share using following command line mount -t smbfs -o username=admin //<insert dsmg IP here>/HDD_a /mnt/somedir
  3. Enter your password you specified for admin user in web interface.
  4. Run touch /mnt/somedir/fun_plug and chmod 777 /mnt/somedir/fun_plug
  5. Optionally if you like you can also install telnet here.
  6. Finally run umount /mnt/somedir and reboot your DSM-G600.

4. To an already partitioned hard drive using Windows and cygwin



5. to a running DSM using FTP from any Operating System

To do this, you have to have at least the 1.01 firmware. Please update if you have an older version.

  1. You will have to enable FTP through the admin pages and set up an ftp user.
  2. Create a test fun_plug on your system.
  3. Connect to your DSM using a command line ftp client (in windows: start / run / ftp)
  4. change to the right directory: cd /HD_a2
  5. upload your fun_plug: put fun_plug
  6. make it executable: chmod 777 fun_plug (in windows ftp: literal site chmod 777 fun_plug)
  7. quit ftp: quit

and you're done. You may edit the fun_plug via samba (windows share) from now on, the permissions will stick.

Using fun_plug

Windows users should note that the fun_plug file must be in unix file format (LF for newline) and not in Windows (CR LF for newline). One suggested editor for Windows is UltraEdit which let you save the file in both formats. To test out if fun_plug works, you can simply add following lines to your fun_plug and reboot.

#!/bin/sh
dmesg > /mnt/HD_a2/dmesg.out

After boot up you should see dmesg.out file at the root of your DSM-G600 hard disk.
If you have not familiar with Unix shell scripting then I suggest you to read some docs about it.


Personal Tools