Is it possible to have Vagrant box running on USB? - ssh

I want to creatre portable dev environment inside a Vagrant box. But faced a problem with ssh key access rights. On some target machines I haven't got enough rights to change them. Is it possible to configure Vagrant to have access maybe only with password to make box fully rights-independent?

You can have vagrant box running from USB (I do that a lot and its nice to take hard drive with you and go on another computer and everything is running the same)
If you run VMWare provider, this is all set as all the vagrant file and the VM files are within the .vagrant directory from your project so just run Vagrant init and vagrant up within your USB and all the files are there, you can take the USB drive with you and connect to another computer running vagrant/VMWare and you're good
When you run VirtualBox provider, its a bit different as the vagrant files will be stored within your vagrant directory but your VM files will likely be stored with your My Documents folder.
You can overcome that by forcing VirtualBox to store the files on the USB as well - see this answer https://stackoverflow.com/a/36343325/4296747 to have multiple options how you can do that

Related

Can I run one WSL2 virtual machine instance on two system?

I'm new to the WSL2 and wondering if it's possible to run the same WSL2 ubuntu instance on both my desktop and laptop.
Now I am able to use wsl --export and wsl --import method to save and load the system to/from my portable hard drive. But these methods takes a long time.
I notice that wsl --import load a file named ext4.vhdx. Is there a way to load straightly from this file?
Update v2.0:
I was able to get a workaround and it works great.
Thanks to Booting from vhdx here, I was able to load straightly from my vhdx file on my portable hard disk. Windows track down its subsystem with regedit, So we can write our own(p.s: make sure to get BasePath right, it starts with "\\\\?", or you will not be able to access the subsystem' filesystem on your host system.):
Windows Registry Editor Version 5.00
[HKEY_USERS\【your SID here】\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{【UUID here】}]
"State"=dword:00000001
"DistributionName"="distribution name"
"Version"=dword:00000002
"BasePath"="vhdx folder path" 【 e.g. "\\\\?\\E:\\S061\\WSL\\ubuntu-20"】
"Flags"=dword:0000000f
"DefaultUid"=dword:000003e8
I suppose the best way to do this would be to store ext4.vhd on a network storage device accessible to both devices.
I have previosly mentioned how to move ext4.vhd. You can check that out here
Basically you need to export from one machine and import it while making sure the vhd file is configured for wsl to access from the network storage
Since this should *officially* not supported expect some performance hits
Another way would be to run WSL on one computer and ssh/remote desktop to it from another device on the network
I'm of the strong belief that sharing the same ext4 vhd between two VM's simultaneously would be a bad idea. See this and this Unix & Linux StackExchange, including the part about ...
note that sharing LVs/partitions on a single disk between the servers at the same time is NOT very safe. You should only access whole disks from any of the servers at one time.
However, as dopewind's answer mentioned, you can access the WSL instance on one computer (probably the desktop) from another (e.g. the laptop). There are several techniques you can use:
If you have Windows 10 Professional or Enterprise on one of the computers, you can enable Remote Desktop, which allows you to access pretty much everything on one computer from another. RDP ("Remote Desktop Protocol") even works from other devices such as an iPad or Android tablet (or even a phone, although that's a bit of a small screen for a "desktop"). That said, there are better, more idiomatic solutions for WSL ...
You could enable SSH server on the Windows 10 computer with the WSL instance (instructions). This may sound counterintuitive to some people, since Linux itself running in the WSL instance also includes an SSH server (by default). But by SSH'ing from (for example) your laptop into your desktop's Windows 10, you can then launch any WSL instance you have installed (if you choose to install more than one) via wsl -d <distroName>. You also avoid a lot of the network unpleasantness in the next option ...
You could, as mentioned above, enable SSH on the WSL instance (usually something like sudo service ssh start) and then ssh directly into it. However, note that WSL2 instances are NAT'd, so there's a whole lot more hackery that you have to do to get access to the network interface. There's a whole huge thread on the WSL Github about it. Personally, I'd recommend the "Windows SSH Server" option mentioned about to start out with, then you can worry about direct SSH access later if you need it.
Side note: Even though I have SSH enabled on my WSL instances, I still use Windows SSH to proxy to them, to avoid these networking issues.

How to access the windows subsystem for linux 2 filesystem from another computer?

I know that I can access the wsl2 filesystem by just opening \\wsl$ on the local computer. Can I somehow expose this to another computer in the same network? The goal is to just have a network drive on a remote computer where I drop files to copy them directly to wsl2.
EDIT: While it is not exactly what I wanted, I just noticed I can run a FTP server inside wsl2 and just transfer files in and out that way. I am still leaving the question open though as there might be a simpler solution to this.
You can find your home folder of wsl on c drive (its in AppData) and use ordinary windows folder sharing.
You can mount your network storage directly into WSL like in a particular Linux.
Example for Ubuntu and SMB: https://askubuntu.com/a/1050499

How to load package to openwrt in virtualbox

I have created an image of OpenWRT(x86-64) which I am running on Virtualbox. I have created a custom package and build it for my Virtual Machine. The thing is that I can not figure out how to copy the package file to the virtual machine's disk space.
I tried using using Guest Additions for Virtualbox but I think OpenWRT does not support it because I can not mount the file to install Guest Additions.
Is there any other way or am I doing something wrong?
To answer my own question, you can use Secure Copy (scp) to transfer your files.
Here is the link. SCP Example
SCP uses ssh to transfer files. Make sure that you have root password enabled in your remote host as this is needed to make a connection.
I hope that this may help someone in the future.

How to backup and restore Virtual machine OS?

In VM ware Virtual machine i have installed the Centos in Window 7.Now i want to re install my Window 7 but i do not want to loose my virtual machine Centos. I Google many time for this topic but did not find any helpful information.
Any help?
Thanks
Your virtual machine is saved under the form of multiple files, which you can easily back-up on an external hard-drive, or in the cloud. If you are using VMWare, then your machine will be split into .vmdk, .vmx, .vmxf, .vmsd and .nvram files, depending on your VM configuration.
Just check where you store the VM files, and back them up before re-installing the host system. Afterwards, just import the .vmx file back into VMWare.
In VMWare Player right-click on your VM, go to Settings, then Options, and under Working Directory you should see where your VM files are stored. Just back-up that entire folder before reinstalling.

Ubuntu on VirtualBox and Rails server

I have Windows 7. Installed VirtualBox and Ubuntu 11.04 as guest OS.
Networking is done by NAT.
Everything is fine: I have internet on Ubuntu.
I can access Windows from Ubuntu by its ip.
But i can't access Ubuntu by it's ip which is shown by ifconfig.
I run rails on Ubuntu.
How can I solve this problem: connect to Ubuntu/Rails server on ort 3000 from my Windows?
By default, VirtualBox's NAT allows the virtual machine to access the Internet ; but doesn't allow the physical machine to access the Virtual one.
The simplest solution would be to use another networking setting than NAT, for your Virtual Machine -- for instance, bridge should work fine (your VM would be visible on your network, though).
Another solution would be to use port forwarding ; about that, this article might help : Howto Access via ssh a Virtualbox Guest machine.
I used to struggle with configuring a similar setup until I found Vagrant. Vagrant makes it very simple to setup, connect to and work with a Linux virtual machine. After Vagrant is configured you can just type vagrant ssh to enter the virtual machine and your account has automatic sudo rights and everything works as expected - you don't even have to deal with logging into the vm. The initial setup for ssh does look to be a little more work under Windows though as you need to configure Putty before you can connect.
There is a simple configuration file in Vagrant that you use to specify which ports from the VM you want forwarded to your machine using a syntax like:
config.vm.forward_port("rails", 80, 3000)
config.vm.forward_port("tomcat", 8000, 8080)
and everything is taken care of. Details are here
If, for example, you are using Rails and you start vagrant with the command vagrant up in your Rails project directory than that directory is available on the VM. Since it is the same shared directory between machines, any changes you make in your Rails project directory on your machine using your regular editor is seen on the VM also. This makes testing in other environments very easy.
Instructions for setting Vagrant up with Windows are here and a RailsCast about it is here. Note that Vagrant has nothing to do directly with Rails - you can use it for setup of any virtual machine environment you need.
In short, you can't.
It is a local host not a public domain therefore not publicly accessible outside of your virtualbox environment.
Maybe someone has a clever hack for this but why would you want to do this in the first place?
Your solution is to either use firefox to browse to your localhost within your virtualbox linux session or develop on windows.
Personally I work the other way round I run Ubuntu 11.04 and I have virtualbox installations of xp, 2,000, me, vista and 7 so I can test in different environments. Inevitably I end up sharing my project folder from Ubuntu so that I can run the project in whatever OS I am testing for.