Добавление в Linux второго диска Virtual Box
И так, представим картину, у нас есть сервер на unix системе в VirtualBox и мы например не хотим забивать корень системы каким нибудь ПО или базой, что делать? Будем добавлять второй диск в систему.
И так, что мы сейчас имеем? вводим команду и смотрим её результат
мы имеем диск sda объемом 8Гб разделенный на 2 части.
sda1 — тут находится все необходимое для загрузки ОС
sda2 — а тут лежат уже все остальные файлы, корень, домашние директории и т.д
И так, добавляем диск. Для этого выключаем нашу виртуальную машину и заходим в её настройки VirtualBox
Выбираем нужный размер диска и создаем
В итоге у нас получится как то так.
После того как добавили диск запускаем виртуальную машину и смотрим появился ли он на уровне ОС.
Появился диск sdb объемом 8Gb , теперь давайте его введем в эксплуатацию, для этого нам поможет утилита pvcreate
Готово, диск создан, осталось еще чуть чуть.
Проверяем, вводим команду, которая покажет сколько диском она видит.
В данном случае sda2 , на котором сама ОС и sdb , который только что добавлен нами.
Теперь нужно создать для этого диска группу, для этого используем команду vgcreate
Команда vgs показывает какие volume группы в нашей ОС есть.
После создания группы нужно создать Logic Volume и уже ему назначить весь объем диска, для этого нужна команда lvcreate -n -l+100%FREE
Команда lvs покажит какие Logic Volume в нашей ОС уже есть и покажет их объем.
После этих манипуляций осталось только создать файловую систему и примонтировать диск к какой нибудь папке.
Для создания файловой системы я буду использовать команду mkfs.xfs
команда blkid покажет наши UUID’s и в какой файловой системе они у нас сейчас.
Видим что наш новый диск находится в группе vg00 , а в эту группу входит Logic Volume lv00 и имеет файловую систему xfs
Осталось только добавить UUID в файл fstab и замапить диск к папке.
На cкрине выше берем UUID /dev/mapper/vg00-lv00 и через echo добавляем его в файл fstab ( ОСТОРОЖНО, У ВАС БУДЕТ ДРУГОЙ UUID )
echo UUID=ваш_uuid /новая/папка xfs defaults 0 0 >> /etc/fstab
Overview
vmdk ’s, the underlying filesystem commonly used in vmware , can be mounted on a Linux server using the qemu utilities. In this example, I downloaded an ova , unarchived it, and retrieved the vmdk files. Once exposed, I am able to mount the filesystems embedded within the vmdk .
In this example, the ova is a virtual “appliance” which prohibits access a low level root shell. By mounting the vmdk file system directly, we can take a peek at the hidden secrets the vendor keeps under lock and key.
Details
sudo apt install qemu-utils
Load the network block device module:
jemurray@home-server:~/ib$ sudo modprobe nbd
Create the network block devices from the vmdk image:
jemurray@home-server:~/ib$ sudo qemu-nbd -r -c /dev/nbd1 ./vnios-disk.vmdk
Examine the images qemu created:
jemurray@home-server:~/ib$ ls -al /dev/nbd1p* brw-rw---- 1 root disk 43, 33 Jan 9 14:28 /dev/nbd1p1 brw-rw---- 1 root disk 43, 34 Jan 9 14:28 /dev/nbd1p2 brw-rw---- 1 root disk 43, 35 Jan 9 14:28 /dev/nbd1p3 brw-rw---- 1 root disk 43, 36 Jan 9 14:28 /dev/nbd1p4 brw-rw---- 1 root disk 43, 37 Jan 9 14:28 /dev/nbd1p5 brw-rw---- 1 root disk 43, 38 Jan 9 14:28 /dev/nbd1p6 brw-rw---- 1 root disk 43, 39 Jan 9 14:28 /dev/nbd1p7
Create mount points for the new filesystems:
jemurray@home-server:~/ib$ mkdir p1 jemurray@home-server:~/ib$ mkdir p2 jemurray@home-server:~/ib$ mkdir p3 jemurray@home-server:~/ib$ mkdir p4 jemurray@home-server:~/ib$ mkdir p5 jemurray@home-server:~/ib$ mkdir p6 jemurray@home-server:~/ib$ mkdir p7
Attempt to mount each individual directory:
jemurray@home-server:~/ib$ sudo mount /dev/nbd1p1 ./p1 mount: /home/jemurray/ib/p1: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p2 ./p2 mount: /home/jemurray/ib/p2: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p3 ./p3 NTFS signature is missing. Failed to mount '/dev/nbd1p3': Invalid argument The device '/dev/nbd1p3' doesn't seem to have a valid NTFS. Maybe the wrong device is used? Or the whole disk instead of a partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around? jemurray@home-server:~/ib$ sudo mount /dev/nbd1p4 ./p4 mount: /home/jemurray/ib/p4: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p5 ./p5 mount: /home/jemurray/ib/p5: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p6 ./p6 mount: /home/jemurray/ib/p6: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p7 ./p7 mount: /home/jemurray/ib/p7: unknown filesystem type 'swap'.
jemurray@home-server:~/ib/p1$ ls -al total 104 drwxr-xr-x 23 root root 4096 Oct 8 12:42 . drwxrwxr-x 9 jemurray jemurray 4096 Jan 9 14:31 .. drwxr-xr-x 2 root root 4096 Oct 8 12:41 bin drwxr-xr-x 4 root root 4096 Oct 8 12:42 boot drwxr-xr-x 4 root root 4096 Oct 8 12:41 dev drwxr-xr-x 29 root root 4096 Oct 8 12:42 etc drwxr-xr-x 2 root root 4096 Oct 8 12:41 home drwxr-xr-x 7 root root 4096 Oct 8 12:42 lib drwx------ 2 root root 16384 Oct 8 12:58 lost+found drwxr-xr-x 5 root root 4096 Oct 8 12:41 media drwxr-xr-x 2 root root 4096 Oct 8 12:41 mnt
How to mount a virtual hard disk?
Have you searched Google? It abounds with guides on mounting VMDK, VDI, VHD, and raw disk image files on Ubuntu.
4 Answers 4
Linux and other Unix-like hosts can mount images created with the raw format type using a loopback device. From a root login (or using sudo), mount a loopback with an offset of 32,256.
mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
For other types of qemu images, you can use qemu-nbd
modprobe nbd max_part=16 qemu-nbd -c /dev/nbd0 image.qcow2 partprobe /dev/nbd0 mount /dev/nbd0p1 /mnt/image
Plus, usually, you can convert image from one format to another.
raw - (default) the raw format is a plain binary image of the disc image, and is very portable. On filesystems that support sparse files, images in this format only use the space actually used by the data recorded in them. cloop - Compressed Loop format, mainly used for reading Knoppix and similar live CD image formats cow - copy-on-write format, supported for historical reasons only and not available to QEMU on Windows qcow - the old QEMU copy-on-write format, supported for historical reasons and superseded by qcow2 qcow2 - QEMU copy-on-write format with a range of special features, including the ability to take multiple snapshots, smaller images on filesystems that don't support sparse files, optional AES encryption, and optional zlib compression vmdk - VMware 3 & 4, or 6 image format, for exchanging images with that product vdi - VirtualBox 1.1 compatible image format, for exchanging images with VirtualBox.
I found this solution for (VirtualBox) .VDI when I searched, on this website:
modprobe nbd max_part=16 qemu-nbd -c /dev/nbd0 /path/to/some.vdi mount -o loop /dev/nbd0p1 /mnt # do stuff umount /mnt qemu-nbd -d /dev/nbd0 rmmod nbd
The same as «Qemu’s way» commands. No borders!
How can I attach a VHDx or VHD file in Linux? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
- This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
- This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
How can I attach a VHDX or VHD file in Linux?
I mean attach the virtual hard disk as a block device, and use external tools to read these devices.
The filesystem inside is not mountable. I do not need to mount the filesystem, but deal with it as if it was on a real hard disk.
I read the manual page of guestfish , but could not find how to do it.
1 Answer 1
You can use libguestfs-tools to achieve this.
- First, you need to install it, on Ubuntu/Debian-like Linux that would be:
sudo apt-get install libguestfs-tools
guestmount --add yourVirtualDisk.vhdx --inspector --ro /mnt/anydirectory
Using virt-inspector(1) code, inspect the disks looking for an operating system and mount filesystems as they would be mounted on the real virtual machine.
Add devices and mount everything read-only. Also disallow writes and make the disk appear read-only to FUSE.
When the vhd file is too big (say 1TB with millions of files), guestmount could successfully mount it but fail in reading files (you can’t even ls -1f to see the files). This must be an unsolved bug. Anyone who encounters this problem can try qemu.
And guestmount (with no args at all) just segfaults on me (after newly installed here on a Raspbian Jessie).
Thanks for bringing up guestmount which I hoped would allow me to mount my .vhd containing a single partition with a exFAT-volume inside. Sadly, guestmount (v1.38.4) did not accept my specification of the volume within the .vhd and asking me Did you mean to mount one of these filesystems? . /dev/sda1 (exfat) . What I had specified was -m «/dev/sda1» as this was what virt-filesystems had returned. When the volume is NTFS, mounting works. And yes, I’ve got exfat-utils.x86_64 (v1.2.8, a fuse-fs-driver) installed.