You are not logged in.

#1 2017-06-15 08:38:52

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Script: Create that >2TiB .vdi for virtualbox! The easy way

For those whom use VirtualBox.
You might have noticed that the GUI doesn't allow you to create vdi's bigger than 2TiB. Of course, this is possible to do with the VBoxManager command in the terminal.

However, it is quite annoying to calculate your prefered size (since VBoxManage expects you too input the size in MiB) when not using sizes like 6000000 MiB, which btw, is not 6TiB.

Therefore, I've created a script which creates a vdi, according to your preferred size in TiB, and places it in your preferred destination.

I hope this helps.

https://pastebin.com/88qfd09v

Offline

#2 2017-06-15 09:19:07

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: Script: Create that >2TiB .vdi for virtualbox! The easy way

You might as well copy those few lines here, rather than link to an ad-infested paste site...


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#3 2017-06-15 10:42:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Script: Create that >2TiB .vdi for virtualbox! The easy way

There's far more cruft there than there is code.  There is no need for bc and then string manipulation to clean up the output of bc.  Bash can do (simple) arithmetic.  Also putting random sleep commands in scripts is silly.  I once heard someone say it was to make it seem like the computer was "thinking".  I'd prefer to have it seem like script authors were thinking.

All that can be a oneliner:

function makeTBvdi() { VBoxManage createhd --filename "$1" --size "$(($2 * 1048576))" --variant Standard; }

EDIT: oops, no, bash can only do simpler arithmetic, sorry.  But still that script is ridiculously complex for a very simple function.  But this will do it:

function makeTBvdi() {
        size=$(( ${2%.*} * 1048576 + ${2#*.} * 1024))
        VBoxManage createhd --filename "$1" --size "$size" --variant Standard;
}

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2017-06-15 10:51:11

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Script: Create that >2TiB .vdi for virtualbox! The easy way

Trilby, for basic arithmetic, sh and bash are unable to handle floating point numbers¹.

I'd go with a POSIX-compliant (but bc-depending)

makeTBvdi() { VBoxManage createhd --filename "$1" --size "$(dc -e "$2 1048576*1/p")" --variant Standard; }

The division by 1 in there is so that `dc` truncates the digits after the floating point (it's a hack, yes).

--edit: oops, too late ^^

____
¹ zsh is fine, though.

Last edited by ayekat (2017-06-15 10:54:10)


pkgshackscfgblag

Offline

#5 2017-06-15 10:54:13

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Re: Script: Create that >2TiB .vdi for virtualbox! The easy way

Trilby wrote:

There's far more cruft there than there is code.  There is no need for bc and then string manipulation to clean up the output of bc.  Bash can do (simple) arithmetic.  Also putting random sleep commands in scripts is silly.  I once heard someone say it was to make it seem like the computer was "thinking".  I'd prefer to have it seem like script authors were thinking.

All that can be a oneliner:

function makeTBvdi() { VBoxManage createhd --filename "$1" --size "$(($2 * 1048576))" --variant Standard; }

EDIT: oops, no, bash can only do simpler arithmetic, sorry.  But still that script is ridiculously complex for a very simple function.  But this will do it:

function makeTBvdi() {
        size=$(( ${2%.*} * 1048576 + ${2#*.} * 1024))
        VBoxManage createhd --filename "$1" --size "$size" --variant Standard;
}

I get your points. However, the sleep command isn't used  for  "thinking time" but more for giving (and a bit of enforcing) users to read the echo output.
The last echo, was more of an mistake though, I will remove that one.

I will try using your code and see if I can understand how it works (since I'm nothing more than a beginner in scripting).

Thanks for the feedback!

Offline

#6 2017-06-15 11:00:51

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Script: Create that >2TiB .vdi for virtualbox! The easy way

DJNightchild wrote:

I get your points. However, the sleep command isn't used  for  "thinking time" but more for giving (and a bit of enforcing) users to read the echo output.

Forcing the user to read a "copyright notice" is very annoying, so I would remove that note altogether. It only applies to people who edit the file, so a comment in the file is sufficient (also, 3 seconds are not enough to read that note anyway).
For other cases, I would rather put something that waits for the user to hit a key before continuing or something.

Also, Alad has already pointed it out, but let me also quote our robotic overlord:

phrik wrote:

Pastebin.com is swamped with advertisements and random captchas. Malware found on pastebin.com has resulted in it being blocked for some users. It injects CRLF line-endings. Please, use something else. Use something sane like https://ptpb.pw https://gist.github.com https://bpaste.net https://ix.io

--edit: Just to be clear about the copyright notice, it's fine to just display it. But putting an artificial delay just for that is not very user-friendly.

Last edited by ayekat (2017-06-15 11:07:57)


pkgshackscfgblag

Offline

#7 2017-06-19 11:13:01

DJNightchild
Member
Registered: 2013-08-02
Posts: 16

Re: Script: Create that >2TiB .vdi for virtualbox! The easy way

ayekat wrote:
DJNightchild wrote:

I get your points. However, the sleep command isn't used  for  "thinking time" but more for giving (and a bit of enforcing) users to read the echo output.

Forcing the user to read a "copyright notice" is very annoying, so I would remove that note altogether. It only applies to people who edit the file, so a comment in the file is sufficient (also, 3 seconds are not enough to read that note anyway).
For other cases, I would rather put something that waits for the user to hit a key before continuing or something.

Also, Alad has already pointed it out, but let me also quote our robotic overlord:

phrik wrote:

Pastebin.com is swamped with advertisements and random captchas. Malware found on pastebin.com has resulted in it being blocked for some users. It injects CRLF line-endings. Please, use something else. Use something sane like https://ptpb.pw https://gist.github.com https://bpaste.net https://ix.io

--edit: Just to be clear about the copyright notice, it's fine to just display it. But putting an artificial delay just for that is not very user-friendly.

Will remove the sleep command wink and I'll remember to not use pastebin for posts in this forum.

Offline

Board footer

Powered by FluxBB