forked from myugan/firecracker-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_vm_with_filesystem_format.py
More file actions
95 lines (83 loc) · 2.5 KB
/
create_vm_with_filesystem_format.py
File metadata and controls
95 lines (83 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
"""
Example: Creating a MicroVM with Different Filesystem Formats
This example demonstrates how to create microVMs with different rootfs filesystem formats.
The firecracker-python library now supports ext3, ext4, and xfs filesystem formats.
"""
from firecracker import MicroVM
# Example 1: Create a VM with ext4 filesystem (default)
print("Creating VM with ext4 filesystem...")
vm_ext4 = MicroVM(
name="vm-ext4",
image="alpine:latest",
base_rootfs="./rootfs_ext4.img",
rootfs_size="5G",
rootfs_format="ext4", # Explicitly specify ext4 format
kernel_file="/var/lib/firecracker/kernel/vmlinux",
vcpu=2,
memory="2G",
verbose=True,
)
# Build the rootfs with ext4 filesystem
result = vm_ext4.build()
print(f"Result: {result}")
# Example 2: Create a VM with ext3 filesystem
print("\nCreating VM with ext3 filesystem...")
vm_ext3 = MicroVM(
name="vm-ext3",
image="alpine:latest",
base_rootfs="./rootfs_ext3.img",
rootfs_size="5G",
rootfs_format="ext3", # Use ext3 format
kernel_file="/var/lib/firecracker/kernel/vmlinux",
vcpu=2,
memory="2G",
verbose=True,
)
# Build the rootfs with ext3 filesystem
result = vm_ext3.build()
print(f"Result: {result}")
# Example 3: Create a VM with xfs filesystem
print("\nCreating VM with xfs filesystem...")
vm_xfs = MicroVM(
name="vm-xfs",
image="alpine:latest",
base_rootfs="./rootfs_xfs.img",
rootfs_size="5G",
rootfs_format="xfs", # Use xfs format
kernel_file="/var/lib/firecracker/kernel/vmlinux",
vcpu=2,
memory="2G",
verbose=True,
)
# Build the rootfs with xfs filesystem
result = vm_xfs.build()
print(f"Result: {result}")
# Example 4: Create and start a VM with a specific filesystem format
print("\nCreating and starting VM with xfs filesystem...")
vm = MicroVM(
name="running-vm-xfs",
image="ubuntu:24.04",
base_rootfs="./ubuntu_rootfs_xfs.img",
rootfs_size="10G",
rootfs_format="xfs",
kernel_file="/var/lib/firecracker/kernel/vmlinux",
ip_addr="172.16.0.10",
vcpu=2,
memory="4G",
expose_ports=True,
host_port=10222,
dest_port=22,
verbose=True,
)
# Create and start the VM
result = vm.create()
print(f"Result: {result}")
# Clean up (optional)
# vm.delete()
print("\n✓ All examples completed successfully!")
print("\nNotes:")
print("- Supported formats: ext3, ext4, xfs")
print("- Default format: ext4")
print("- The filesystem format is validated during initialization")
print("- Overlayfs also respects the specified format")