0
declare -i s=${foo}; n=${bar}; mp=${baz}; cn=${qux}; mac_adr=${quux} 
sudo hdiutil create -size ${s}b -fs JHFS+X -volname "${n}" -type SPARSEBUNDLE \
"/Volumes/${mp}/${cn}_${mac_addr}.sparsebundle" && echo "Done"

does not work, but

declare -i s=${foo}; n=${bar}; mp=${baz}; cn=${qux}; mac_adr=${quux} 
sudo hdiutil create -size ${s}b -fs JHFS+X -volname "${n}" -type SPARSEBUNDLE \
"/Volumes/${cn}_${mac_addr}.sparsebundle" &&
sudo mv -vn "/Volumes/${cn}_${mac_addr}.sparsebundle" "/Volumes/${mp}" && echo "Done"

Works correctly

What am I doing wrong?

0

The only difference I can see is that you are trying to create sparse bundle on different volumes. /Volume/test.sparsebundle will be located on your startup disk. /Volume/Data/test.sparsebundle will be located (probably) on another disk. Please try to check what kind of filesystem is on your second drive.

You can try your issue both commands with -debug option and compare result.

  • /Volume/Data/test.sparsebundle Is sparsebundle on Time Capsule – cave-canem Oct 17 '16 at 11:43
  • Have you tried the same with -debug option? – mbamac Oct 19 '16 at 5:47
0

I used the following command in 10.9.5:

read -p "Size in GB? = " s; ((s= 10**9*s/512)); read -p "Name of image volume? = " n; read -p "External Volume name (Escape spaces with a backslash - the volume has to exist)? = " m; cn=`scutil --get ComputerName`; mac_addr=`ifconfig en0 | grep "ether"`; mac_addr=${mac_addr#*ether}; mac_addr=${mac_addr// /} ; mac_addr=${mac_addr//:/}; sudo hdiutil create -size ${s}b -fs JHFS+X -volname "${n}" -type SPARSEBUNDLE "/Volumes/${m}/${cn}_${mac_addr}.sparsebundle" && echo "Done"

and it works (with a workaround for spaces in volume names like "Macintosh HD") for internal volumes:

Size in GB? = 2
Name of image volume? = aaa
Existing External Volume Name (Escape spaces with a backslash)? = test\ 2
created: /Volumes/test 2/host_001122334455.sparsebundle
Done
host:~ user$ 

This doesn't work if you create a sparsebundle on a network share. Here you mustn't use the sudo command. Instead use (I also simplified $mac_addr):

read -p "Size in GB? = " s; ((s= 10**9*s/512)); read -p "Name of image volume? = " n; read -p "External Volume name (Escape spaces with a backslash - the volume has to exist)? = " m; cn=`scutil --get ComputerName`; mac_addr=`ifconfig en0 | grep ether | awk '{print $2}' | sed 's/://g'`; hdiutil create -size ${s}b -fs JHFS+X -volname "${n}" -type SPARSEBUNDLE "/Volumes/${m}/${cn}_${mac_addr}.sparsebundle" && echo "Done"
  • Please see the answer below: – cave-canem Oct 17 '16 at 10:05
  • @cave-canem Updated answer – klanomath Oct 17 '16 at 15:00
  • There is no need to use the "awk" From minimalist prntsipe if "bash" built-in tools can be used. "Sudo" should not be used with a network share, see "hdiutil -verbose" – cave-canem Oct 21 '16 at 14:00
-1

So (without sudo before hdiutil) it works:

clear; read -p "Желаемый размер раздела в GB? = " s; ((s= 10**9*s/512)); read -p "Введите название раздела? = " n; cn=`scutil --get ComputerName`; mac_addr=`ifconfig en0 | grep "ether"`; mac_addr=${mac_addr#*ether}; mac_addr=${mac_addr// /}; mac_addr=${mac_addr//:/}; read -p "Точка Монтирования = " mp; hdiutil create -size ${s}b -fs JHFS+X -volname "${n}" -type SPARSEBUNDLE "/Volumes/${mp}/${cn}_${mac_addr}.sparsebundle" && echo "Done"

Желаемый размер раздела в GB? = 10
Введите название раздела? = rrr
Точка Монтирования = Data
created: /Volumes/Data/Air_60c54700b918.sparsebundle
Done

The matter of rights on the network drive:

hdiutil - verbose
DIDiskImageCreateWithCFURL: creator returned 0  
::getBandEntry: chown() - 501  
Сompletion...  

DIHLDiskImageCreate() returned 1    
hdiutil: create: returning 1  
hdiutil: create failed - operation is not permitted
this file is created, but then the operation fails, before he makes the format:  
DIDiskImageCreateWithCFURL: creator returned 0  
DI_kextWaitQuiet: about to call IOServiceWaitQuiet...  
DI_kextWaitQuiet: IOServiceWaitQuiet took 0.000011 seconds  
Formatting ...
Completing ...
created: /Volumes/Data/Air_60c22700b922.sparsebundle

Do not use "sudo" to the shared network resources!

  • Don't steel my answer! You should accept my answer instead of repeating my answer. – klanomath Oct 20 '16 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .