現在需要從宿主機(Ubuntu)傳一些文件到VirtualBox的客戶機中,客戶機的磁盤文件是arch.vdi,下面是掛載vdi到Linux的方法。
apt install qemu-utils
modprobe nbd
vdi="vdi文件路徑"
qemu-nbd -c /dev/nbd0 "$vdi"
# 使用相關命令查看分區結構
fdisk -l /dev/nbd0
# 下面是實例輸出
"""
Disk /dev/nbd0: 25.3 GiB, 27162755072 bytes, 53052256 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4209d41f
Device Boot Start End Sectors Size Id Type
/dev/nbd0p1 2048 20973567 20971520 10G 83 Linux
/dev/nbd0p2 20973568 53052255 32078688 15.3G 83 Linux
"""
# 掛載分區
mount /dev/nbd0p1 /mnt
如果卸載的話
umount /dev/nbd0p1
qemu-nbd --disconnect /dev/nbd0