1 # Example showing how to inspect a virtual machine disk.
6 puts "usage: inspect_vm disk.img"
11 g = Guestfs::Guestfs.new()
13 # Attach the disk image read-only to libguestfs.
14 g.add_drive_opts(disk, :readonly => 1)
16 # Run the libguestfs back-end.
19 # Ask libguestfs to inspect for operating systems.
20 roots = g.inspect_os()
22 puts "inspect_vm: no operating systems found"
27 printf("Root device: %s\n", root)
29 # Print basic information about the operating system.
30 printf(" Product name: %s\n", g.inspect_get_product_name(root))
31 printf(" Version: %d.%d\n",
32 g.inspect_get_major_version(root),
33 g.inspect_get_minor_version(root))
34 printf(" Type: %s\n", g.inspect_get_type(root))
35 printf(" Distro: %s\n", g.inspect_get_distro(root))
37 # Mount up the disks, like guestfish -i.
39 # Sort keys by length, shortest first, so that we end up
40 # mounting the filesystems in the correct order.
41 mps = g.inspect_get_mountpoints(root)
42 mps = mps.sort {|a,b| a[0].length <=> b[0].length}
45 g.mount_ro(mp[1], mp[0])
46 rescue Guestfs::Error => msg
47 printf("%s (ignored)\n", msg)
51 # If /etc/issue.net file exists, print up to 3 lines.
52 filename = "/etc/issue.net"
53 if g.is_file filename then
54 printf("--- %s ---\n", filename)
55 lines = g.head_n(3, filename)