Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] VirtualBox v6 support #27

Merged
merged 1 commit into from
Mar 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lib/VBoxProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ const isPortAvailable = require('is-port-available');

class VBoxProvider {

// Returns the major version of the VirtualBox instance
async majorVersion() {
let version = await execute("--version", "", false);

return Number(version.split('.')[0]);
}

// Returns the correct serial port settings based on version.
async serialOut(name) {
let version = await this.majorVersion();

if (version < 6) { return 'disconnected'; }

let logPath = path.join(os.homedir(),'.baker',`${name}.log`);

return `file ${logPath}`;
}

/**
* Get default run command.
*
Expand All @@ -44,7 +62,8 @@ class VBoxProvider {
await execute("storagectl", `"${name}" --name IDE --add ide`, verbose);
await execute("storageattach", `${name} --storagectl IDE --port 0 --device 0 --type dvddrive --medium "${iso}"`, verbose);

await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 disconnected`, verbose);
let serial = await this.serialOut(name);
await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 ${serial}`, verbose);

// NIC1 =======
await execute("modifyvm", `${name} --nic1 nat`, verbose);
Expand Down Expand Up @@ -93,15 +112,16 @@ class VBoxProvider {
let sshConfig = {port: ssh_port, user: 'root', private_key: sshKeyPath};
//let cmd = 'echo -e "o\nn\np\n1\n\n\nw" | fdisk /dev/sda && /sbin/mkfs.ext4 /dev/sda1';
let cmd = `/sbin/mkfs.ext4 /dev/sda; mount -t ext4 /dev/sda /mnt/disk`;
console.log('Formating virtual drive');
console.log('Formatting virtual drive');

await util.sshExec(cmd, sshConfig, 60000, verbose).catch( e => {console.log(e)});;
}
}

async customize(name, ip, ssh_port, forward_ports=[], syncs, verbose) {
// modifyvm ${VM} --uart1 0x3f8 4 --uartmode1 disconnected
await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 disconnected`, verbose);
let serial = await this.serialOut(name);
await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 ${serial}`, verbose);

// syncs
if( syncs.length > 0 )
Expand Down