I am tyring to understand linux file system layout. Why does the command work inside virtual box but not on linux shell on windows?
I tried to use the command sudo fdisk -l dev/sda on both my virtual box(Ubuntu) and Ubuntu on windows(from microsoft store). It didn't work on any of them but when I changed the command to sudo fdisk -l, it worked inside virtual box but not on linux bash shell on windows.
Inside linux shell on windows:
:~$ sudo fdisk -l /dev/sda
.
fdisk: cannot open /dev/sda: No such file or directory
:~$ sudo fdisk -l
fdisk: cannot open /proc/partitions: No such file or directory
:~$ man fdisk
:~$ whereis fdisk
fdisk: /sbin/fdisk /usr/share/man/man8/fdisk.8.gz
The fundamental of Windows Subsystem for Linux (WSL) - Ubuntu is a POSIX emulator which is like Cygwin kind of environment helps to port some Linux based commands/applications running on windows platform as windows process.
It contains an abstraction layer of a virtual filesystem (vfs) which has read-only app image & RAM based writable tmpfs and neither it doesn't have access control to read the raw devices on host system nor it emulates the raw devices for the subsystem.
from man(fdisk) :
Description
This command is used to create and modify the partition table, and to install the master boot (IA only) record that
is put in the first sector of the fixed disk. This table is used by
the first-stage bootstrap (or firmware) to identify parts of the disk
reserved for different operating systems, and to identify the
partition containing the second-stage bootstrap (the active Solaris
partition). The rdevice argument must be used to specify the raw
device associated with the fixed disk, for example,
/dev/rdsk/c0t0d0p0.
So WSL-Ubuntu can't execute the fdisk command successfully since it doesn't have its own kernel to manage host resources.
On the other hand, Oracle's VirtualBox is a virtualized system which imitates a fully functional OS running on bare metal. It simulates its own system-space & user-space with the help of virtualization hypervisor and manages the virtual resources via the Guest OS kernel. This is why fdisk command execution was successful on VirtualBox
Reference :
https://www.microsoft.com/en-us/research/wp-content/uploads/2013/01/posix-emulation-submitted.pdf
Credits: https://www.quora.com/How-is-Windows-Subsystem-for-Linux-different-from-running-Linux-on-Windows-in-a-VM
Related
I am currently running a Vagrant box with archlinux for development purposes. I wanted to go beyond the 2GB so I installed the vagrant-disksize plugin and after ssh'ing into the box and changing the partition size, I ran resize2fs as suggested here.
However, when I do that, I get the following error:
resize2fs: Device or resource busy while trying to open /dev/sdax
Couldn't find valid filesystem superblock.
Here's what the man page says about resize2fs:
If the filesystem is mounted, it can be used to expand the size of the
mounted filesystem, assuming the kernel and the file system supports
on-line resizing.
How can I use resize2fs with my archlinux box?
tldr: resize2fs doesn't work on btrfs
Resolution:
After investigating the issue, I found out that the archlinux Vagrant box was set up with btrfs instead ext4. If you want to expand your disk size on Vagrant/VirtualBox and Arch Linux you will have to.
Steps to follow
Increase the physical disk size by either 1. using the Vagrant disk-resize plugin, 2. manually dismounting and cloning the drive with VBoxManage, or 3. activating the Vagrant experimental feature flag (oct. 2020).
Resize the partition inside the OS with {,c}fdisk or parted.
Check the file system on your partition with lsblk --fs. If you happen to run on btrfs, you won't be able to use resize2fs. You'll have to go through
btrfs filesystem resize max / (the mount point)
A few links that could be of use:
https://www.suse.com/support/kb/doc/?id=000018798
https://gist.github.com/christopher-hopper/9755310
https://askubuntu.com/questions/317338/how-can-i-increase-disk-size-on-a-vagrant-vm
I can't set up another virtual box session because when i run the session the computer freeze. I'm using ubuntu 16.04
You can mount the disk on your Ubuntu Host system
VBoxManage clonehd --format RAW windows.vdi windows.img
Then
mount -t ntfs -o loop,ro ./windows.img /mnt/windows
You need to know the file system format you used when installing the VM. Since you are using Windows inside your VM, the file system is most likely ntfs.
Source
Some tutorials recommend making modifications to files such as wpa_supplicant.conf within the Android Things image file, as per this answer https://stackoverflow.com/a/41732035/766115. I'm trying with the Android Things developer preview 4.1 image file.
However, I've had no luck mounting this file for editing purposes on OS X. Various attempts to use os x Disk Utility or the mount command from the terminal all result in some type of error message telling me the file format is not compatible. I can see in Disk Util, or through terminal mount, that the ISO image has 15 sectors (or partitions), but I can't access them.
I've even tried spinning up an Ubuntu in AWS, uploading and mounting from there. No dice.
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
Any advice? What am I missing.
On macOS I have done this way:
Connect the sdcard on your Mac
Run on terminal diskutil list and see the name of your sdcard (in my case /dev/disk2s1)
Create a directory where the sdcard will be mounted: sudo mkdir -p /Volumes/pisdcard
Mount the sdcard: sudo mount -t msdos /dev/disk2s1 /Volumes/pisdcard
Edit what you want and unmount the sdcard with: sudo umount /dev/disk2s1
It worked for me, I used to change config.txt and cmdline.txt to change UART mode and use a GPS module on Android Things.
hdiutil attach [file] is the macOS command to treat an image file as a disk device. If the image file contains a filesystem macOS can read, it should also mount any volumes contained in the file. If your image contains a volume not supported by macOS (e.g., ext4), you also need to install an appropriate driver before you can mount the volume.
One of my commands in my bash script will depend on the virtualization of the server (XEN or OpenVZ or KVM ). How can I check which of these is in use in bash?
There's a very useful script called imvirt that handles Xen, OpenVZ, VMware, VirtualBox, KVM, and lots of others. It's available as a package in Debian, or from the imvirt web site.
$ imvirt
Xen PV 4.1
I found a small shell script that is able to detect virtualization and it handles Xen,OpenVZ,KVM,Parallels, Vmware and many more
virt-what
Installation with yum is pretty straight forward
Here is the output on my system
$ virt-what
kvm
If you want to detect host (dom0) for xen, check
[ "$(cat /proc/xen/capabilities)" == "control_d" ]
If you want to detect in VM,
You need to execute cpuid instruction in VM, with original_eax=1.
If the resultant ecx has MSB set ((ecx & 0x80000000) != 0), then you are under VM.
This is assuming that your hypervisor supports viridian interface. Xen does.
cpuid package is easily available for many linux distros. I'm sure windows port would be available too. Else, the code is pretty simple for you to write...
Is there an easy way to integrate with VirtualBox such that I could develop under the host, Windows, and deploy and run scripts via a mounted folder in a guest linux system?
I'm looking to develop for Linux under Windows, kind of.
You can use VirtualBox's Shared Folders feature to enable your Ubuntu virtual machine to mount a directory of your Windows host. However, you're likey to be deal with some impedance mismatches like different line endings. I hope that is the least of your worries.
You might want to check out vagrant http://vagrantup.com/
It provides a nice and easy system to create a VM from a template in Virtual Box, and will automatically mount the project folder in the guest VM. The config can also easily be included in your project so others can use it.
I develop in PHP. And I use Debian as guest OS, and Win7 as host OS.
You can done automaticly mount share folder by:
new a file in /etc/init.d/ named mnt_win_sf, than you edit it:
It must has the same info head with /etc/init.d/apache2. And you need just one line of command:
mount -t vboxsf share_folder_name mount_point
We also need to excute this script before apache2, so we edit /etc/init.d/apache2. In the Require Start line, add mnt_win_sf
update them by:
sudo update-rc.d mnt_win_sf defaults
sudo update-rc.d apache2 defaults