linka-cloud / d2vm

Build Virtual Machine Image from Dockerfile or Docker image
Apache License 2.0
208 stars 31 forks source link

The file /dev/loop0p1 does not exist and no size was specified #18

Closed bilalshaikh42 closed 1 year ago

bilalshaikh42 commented 1 year ago

Thanks for the great work on this! I am running into the same error reported in #13, but didnt see a solution in there.

This happens regardless of the approach I take, using docker, building from source, binaries, and with and without sudo.

Here is the output I get using the docker instructions in the readme.

 $ docker pull linkacloud/d2vm:latest
latest: Pulling from linkacloud/d2vm
Digest: sha256:52dc3afa3cba9da925e9a8d7d6a487b82e31742d27cfca0490d441fe82d0d446
Status: Image is up to date for linkacloud/d2vm:latest
docker.io/linkacloud/d2vm:latest

$ alias d2vm="docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock --privileged -v $(pwd):/d2vm -w /d2vm linkacloud/d2vm:latest"

 $ d2vm convert ubuntu
Using local image ubuntu:latest
Inspecting image ubuntu
No network manager specified, using distribution defaults: netplan
Docker image based on Ubuntu 22.04.1 LTS (Jammy Jellyfish)
Building kernel enabled image
Creating vm image
Creating raw image
Mounting raw image
Creating raw image file system
Build failed
Unmounting raw image
Failed to unmount
Error: mkfs.ext4 /dev/loop0p1: stdout:  stderr: mke2fs 1.45.5 (07-Jan-2020)
The file /dev/loop0p1 does not exist and no size was specified.
 error: exit status 1

And here is the verbose output

Using local image ubuntu:latest
Inspecting image ubuntu
$ docker image build -t os-release-ubuntu -f /tmp/d2vm/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a/osrelease.Dockerfile /tmp/d2vm/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a
#1 [internal] load build definition from osrelease.Dockerfile
#1 sha256:3964a2a4e71ae4002c89256656aa4c2a2533e5166b5856b1cc41e6a616d14a52
#1 transferring dockerfile: 114B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:d6e455fd32bde387fcf0efa1a558ee6cbeb6d901c8d2fed088e9b5aa569658ee
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:latest
#3 sha256:8c6bdfb121a69744f11ffa1fedfc68ec20085c2dcce567aac97a3ff72e53502d
#3 DONE 0.0s

#4 [1/1] FROM docker.io/library/ubuntu
#4 sha256:0a5f349eacf4edfd2fc1577c637ef52a2ed3280d9d5c0ab7f2e4c4052e7d6c9f
#4 CACHED

#5 exporting to image
#5 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#5 exporting layers done
#5 writing image sha256:b5a1ffdbe367c0c8500ec75486f2b3d084a2fe958c4e5fadc5cb725bb3bae580 done
#5 naming to docker.io/library/os-release-ubuntu done
#5 DONE 0.0s
$ docker image rm os-release-ubuntu
Untagged: os-release-ubuntu:latest
Deleted: sha256:b5a1ffdbe367c0c8500ec75486f2b3d084a2fe958c4e5fadc5cb725bb3bae580
No network manager specified, using distribution defaults: netplan
Docker image based on Ubuntu 22.04.1 LTS (Jammy Jellyfish)
Building kernel enabled image
$ docker image build -t 4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a -f /tmp/d2vm/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a/ubuntu /tmp/d2vm/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a
#1 [internal] load build definition from ubuntu
#1 sha256:bb8119a8d01f073a5b6fa37983ef59c183e9117c9574aeefc26cc0bb7c78b6ec
#1 transferring dockerfile: 644B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:f4c4f2e400d86ec089b85ecc3d7606a65b488053fb3761268fdb0dd88ad3a761
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:latest
#3 sha256:8c6bdfb121a69744f11ffa1fedfc68ec20085c2dcce567aac97a3ff72e53502d
#3 DONE 0.0s

#4 [1/5] FROM docker.io/library/ubuntu
#4 sha256:0a5f349eacf4edfd2fc1577c637ef52a2ed3280d9d5c0ab7f2e4c4052e7d6c9f
#4 DONE 0.0s

#6 [3/5] RUN systemctl preset-all
#6 sha256:d9bd256ae49570708a270aaa0a94221aa8ab503e71644bbdb3b54a48b1afdba6
#6 CACHED

#7 [4/5] RUN apt install -y netplan.io
#7 sha256:971803d10f5ea1ee18cd4750ac3134e5ce89760d833bf5162418b416f554405b
#7 CACHED

#5 [2/5] RUN apt-get update -y &&   DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends   linux-image-virtual   initramfs-tools   systemd-sysv   systemd   dbus   isc-dhcp-client   iproute2   iputils-ping
#5 sha256:0bccb225dc3e39aa44cb1966adf4d6884bf314ec2c068a3246bdd2628bafe256
#5 CACHED

#8 [5/5] RUN mkdir -p /etc/netplan && printf 'network:\n  version: 2\n  renderer: networkd\n  ethernets:\n    eth0:\n      dhcp4: true\n      dhcp-identifier: mac\n      nameservers:\n        addresses:\n        - 8.8.8.8\n        - 8.8.4.4\n' > /etc/netplan/00-netcfg.yaml
#8 sha256:9376b75d64382b03230d99424609058e67c77754ecee3fcd964bdc02ef8e57f4
#8 CACHED

#9 exporting to image
#9 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#9 exporting layers done
#9 writing image sha256:c38c8a335bffad48ee0f07a5856e27f71ac4db07d267edca84475a288cc838be done
#9 naming to docker.io/library/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a done
#9 DONE 0.0s
Creating vm image
Creating raw image
$ parted -s /tmp/d2vm/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a/disk0.d2vm.raw mklabel msdos mkpart primary 1Mib 100% set 1 boot on
Mounting raw image
$ partprobe /dev/loop0
Creating raw image file system
$ mkfs.ext4 /dev/loop0p1
mke2fs 1.45.5 (07-Jan-2020)
The file /dev/loop0p1 does not exist and no size was specified.
Build failed
Unmounting raw image
$ umount /tmp/d2vm/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a/mnt
umount: /tmp/d2vm/4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a/mnt: not mounted.
$ losetup -d /dev/loop0
Failed to unmount
$ docker image rm 4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a
Untagged: 4fb21713-22a0-47aa-abbf-6d0fa7fbbc8a:latest
Deleted: sha256:c38c8a335bffad48ee0f07a5856e27f71ac4db07d267edca84475a288cc838be
Error: exit status 1
bilalshaikh42 commented 1 year ago

Here is the results of the debugging steps you asked for in #13. The only difference here is that I am using the latest tag for the image rather than the previous version.

bilal@bilal-framework ~ $ docker run --rm -i -t --privileged --entrypoint bash linkacloud/d2vm:latest
root@87661a652d6b:/# fallocate -l 5G /tmp/disk
root@87661a652d6b:/# parted -s /tmp/disk mklabel msdos mkpart primary 1Mib 100% set 1 boot on
root@87661a652d6b:/# fdisk -l /tmp/disk 
Disk /tmp/disk: 5 GiB, 5368709120 bytes, 10485760 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: 0x0a7ae771

Device     Boot Start      End  Sectors Size Id Type
/tmp/disk1 *     2048 10485759 10483712   5G 83 Linux
root@87661a652d6b:/# losetup
root@87661a652d6b:/# LOOPDEV=$(losetup --show -f /tmp/disk)
root@87661a652d6b:/# echo $LOOPDEV
/dev/loop0
root@87661a652d6b:/# partprobe $LOOPDEV
root@87661a652d6b:/# ls /dev/loop*
/dev/loop-control  /dev/loop0
root@87661a652d6b:/# mkfs.ext4 ${LOOPDEV}p1
mke2fs 1.45.5 (07-Jan-2020)
The file /dev/loop0p1 does not exist and no size was specified.
root@87661a652d6b:/# mkfs.ext4 ${LOOPDEV}p0
mke2fs 1.45.5 (07-Jan-2020)
The file /dev/loop0p0 does not exist and no size was specified.
root@87661a652d6b:/# losetup -d $LOOPDEV
root@87661a652d6b:/# 
Adphi commented 1 year ago

Lately I have been experiencing the same problem after every restart of Docker. But usually it works without problems after that first failure.

On other projects I had a lot of problems with the behaviour of partprobe in containers. I have to change the implementation to use kpartx which seems to work much better.

If you are on linux, can you try to also mount /dev/ inside the container (-v /dev:/dev) ?

bilalshaikh42 commented 1 year ago

Mounting dev seems to have helped!

bilal@bilal-framework ~$ docker run --rm -i -t --privileged -v /dev:/dev --entrypoint bash linkacloud/d2vm:latest
root@dc1a38e3afa7:/# fallocate -l 5G /tmp/disk
root@dc1a38e3afa7:/# 
root@dc1a38e3afa7:/# parted -s /tmp/disk mklabel msdos mkpart primary 1Mib 100% set 1 boot on
root@dc1a38e3afa7:/#  fdisk -l /tmp/disk 
Disk /tmp/disk: 5 GiB, 5368709120 bytes, 10485760 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: 0x9a7ae2fc

Device     Boot Start      End  Sectors Size Id Type
/tmp/disk1 *     2048 10485759 10483712   5G 83 Linux
root@dc1a38e3afa7:/# losetup
root@dc1a38e3afa7:/# LOOPDEV=$(losetup --show -f /tmp/disk)
root@dc1a38e3afa7:/# echo $LOOPDEV
/dev/loop0
root@dc1a38e3afa7:/# partprobe $LOOPDEV
root@dc1a38e3afa7:/# mkfs.ext4 ${LOOPDEV}p1
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done                            
Creating filesystem with 1310464 4k blocks and 327680 inodes
Filesystem UUID: c04a3613-344c-440b-bd45-dfae2761201f
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

root@dc1a38e3afa7:/# partprobe $LOOPDEV
root@dc1a38e3afa7:/# losetup -d $LOOPDEV
root@dc1a38e3afa7:/#