WD MyCloud - Delete Public Share

This is a step by step guide for removing the public share from a WD MyCloud NAS device. My devices are on the latest firmware so you may find some slight differences if you are on an older firmware or have different devices then I have. Hopefully the info here will allow you to jump over that hurdle. I have tried to explain where things may be different and how to handle them but I don’t have every MyCloud device. Please understand that you are invalidating your warranty and could possibly mess up or brick your hardware (If your here probably not). You will need to login to your MyCloud via SSH to make these changes.

I have taken the time to make a fairly detailed guide but feel free to skip ahead and go for the Quick and Easy way it you understand what you are doing. Skip the Instructions and Get to the Scripts

Table of Contents

1. Backup the System Files that we will Modify

 /bin/cp /etc/wdcomp.d/boot/bootscript_005_wd-nas /root/bootscript_005_wd-nas.bkup 
/bin/cp /usr/local/sbin/createDataVolume.sh /root/createDataVolume.sh.bkup
/bin/cp /etc/samba/overall_share /root/overall_share.bkup

2. Prevent WD MyCloud from Re-Creating the Public Share

This script runs at boottime and creates a new Public share if one is not found.

Comment out the following lines from – /etc/wdcomp.d/boot//bootscript_005_wd-nas

>209    uniqShareName=$(createUniqueShare "Public" "Public" "any")"  
>210 result=$?
>211 if [$result -eq 0]; then
>212 logger -s -p local2.debug "
$0: DEBUG: createUniqueShare ${uniqShareName} returned$
>213 else
>214 logger -s -p local2.err "$0: ERROR: createUniqueShare ${uniqShareName} returned $$
>215 fi

Comment out lines 209-215: sed -i '209,215 s/^/#/' /etc/wdcomp.d/boot/bootscript_005_wd-nas

3. Prevent Directory Structure Creation

The next script creates the folder structure for the Public share. Now that the public share is not going to exist we need to prevent the script from running into errors.

Comment out the folowing lines from – */usr/local/sbin/createDataVolume.sh*

>  mkdir -p "/DataVolume/shares/Public/Shared Music"
> mkdir -p "/DataVolume/shares/Public/Shared Videos"
> mkdir -p "/DataVolume/shares/Public/Shared Pictures"
> chown -R root:share /DataVolume/shares/Public

4. Delete the Public share

Everything in the Public folder will be deleted for good. Make sure you have moved your data.

We are using WD MyClouds deleteShare script to remove the share since it does alot of the cleanup for us. Depending on what version firmware you have you might need to comment out a few lines in this file as well. But it won’t do any harm to try running it first.

/usr/local/sbin/deleteShare.sh "Public"

If you get an error: Cannot delete Public share then you need to comment out the following lines.

> lowerCaseShare=echo $shareName | tr '[:upper:]' '[:lower:]'
> if [$lowerCaseShare == "public"]; then
> echo "Cannot delete Public share"
> exit 1
> fi

Comments out the code causing the “Cannot delete Public share” error
sed -i '/echo \$shareName/ {N;N; /delete Public/ s/^/#!!#/}' /usr/local/sbin/deleteShare.sh
sed -i '/#!!#if/,+4 s/^/#/; s/#!!#//' /usr/local/sbin/deleteShare.sh

5. Remove Public Folder from SMB Config

Comment out the following lines from–*/etc/samba/overall_share*
If your listing is slightly different that is okay. We just want to comment out the Public Share Settings

> 1   [Public]
> 2 comment = Public
> 3 path = /shares/Public
> 4 browseable = yes
> 5 public = yes
> 6 available = yes
> 7 oplocks = yes
> 8 map archive = no
> 9 guest ok = yes
> 10 writable = yes

Comment out lines 1-10: sed -i '1,10 s/^/#/' overall_share

6. Restart the Samba Service

service samba restart

Thats all there is to it. Check to ensure that you don’t see the Pubic Share in the WebUI or Network shares to confirm that it worked.

7. The Quick Way - Scripts

I've provided a remove and restore script that I've tested on my devices.

curl -L https://gist.githubusercontent.com/codedecay/7d30df8d12b506407d26/raw | sh

#Backup Files
cp /etc/wdcomp.d/boot/bootscript_005_wd-nas /root/bootscript_005_wd-nas.bkup
cp /usr/local/sbin/createDataVolume.sh /root/createDataVolume.bkup
cp /etc/samba/overall_share /root/overall_share.bkup

#Comment out relevant lines in the boot and create script.
sed -i '209,215 s/^/#/' /etc/wdcomp.d/boot/bootscript_005_wd-nas
sed -i '23,25 s/^/#/' /usr/local/sbin/createDataVolume.sh
sed -i '29,29 s/^/#/' /usr/local/sbin/createDataVolume.sh

#Comment out validation in deleteShare.sh if it is present.
sed -i '/echo \$shareName/ {N;N; /delete Public/ s/^/#!!#/}' /usr/local/sbin/deleteShare.sh
sed -i '/#!!#if/,+4 s/^/#/; s/#!!#//' /usr/local/sbin/deleteShare.sh`

#Delete the public share
/usr/local/sbin/deleteShare.sh "Public"

#Comment out the public share definition from the Samba config.
sed -i '1,10 s/^/#/' /etc/samba/overall_share

#Restart the samba service.
service samba restart

8. Restore the Public Folder

curl -L https://gist.github.com/codedecay/02e5dc3d487a38d0a89f/raw | sh

#Either Restore from your backup files..
/bin/cp /root/bootscript_005_wd-nas.bkup /etc/wdcomp.d/boot/bootscript_005_wd-nas
/bin/cp /root/createDataVolume.bkup /usr/local/sbin/createDataVolume.sh
/bin/cp /root/deleteShare.bkup /usr/local/sbin/deleteShare.sh
/bin/cp /root/overall_share.bkup /etc/samba/overall_share

#Or undo the comments in the existing files.
sed -i '209,215 s/^#//' /etc/wdcomp.d/boot/bootscript_005_wd-nas
sed -i '23,25 s/^#//' /usr/local/sbin/createDataVolume.sh
sed -i '29,29 s/^#//' /usr/local/sbin/createDataVolume.sh
sed -i '1,10 s/^#//' /etc/samba/overall_share
sed -i '/#if.*shareName/,+4 s/#//' /usr/local/sbin/deleteShare.sh

#Recreate the Public Share and Directory Structure
mkdir -p "/DataVolume/shares/Public"
mkdir -p "/DataVolume/shares/Public/Shared Music"
mkdir -p "/DataVolume/shares/Public/Shared Videos"
mkdir -p "/DataVolume/shares/Public/Shared Pictures"
chmod -R 775 /DataVolume/shares
chown -R root:share /DataVolume/shares/Public

#Restart the samba service
service samba restart