VirtualBox » History » Version 2
Charles Atkinson, 21/08/2020 11:18
Added h1. Storage
1 | 1 | Charles Atkinson | h1. VirtualBox |
---|---|---|---|
2 | 1 | Charles Atkinson | |
3 | 1 | Charles Atkinson | {{toc}} |
4 | 1 | Charles Atkinson | |
5 | 2 | Charles Atkinson | h1. Introduction |
6 | 2 | Charles Atkinson | |
7 | 2 | Charles Atkinson | Here are miscellaneous techniques used on Debian VirtualBox hosts |
8 | 2 | Charles Atkinson | |
9 | 2 | Charles Atkinson | h1. Storage |
10 | 2 | Charles Atkinson | |
11 | 2 | Charles Atkinson | h2. Fix Linux guest file system full |
12 | 2 | Charles Atkinson | |
13 | 2 | Charles Atkinson | Increasing the size of the .vdi is routine. The challenge is re-partitioning to use the extra space. Most solutions found on the Internet have the guest booting a gparted .iso. A more convenient solution uses qemu's nbd. |
14 | 2 | Charles Atkinson | |
15 | 2 | Charles Atkinson | * Ensure the qemu-utils package is installed |
16 | 2 | Charles Atkinson | * <pre> |
17 | 2 | Charles Atkinson | modprobe nbd |
18 | 2 | Charles Atkinson | </pre> |
19 | 2 | Charles Atkinson | * Ensure the .vdi is not in use |
20 | 2 | Charles Atkinson | * Create the network block device (NBD) |
21 | 2 | Charles Atkinson | <pre> |
22 | 2 | Charles Atkinson | qemu-nbd -c /dev/nbd0 <path of .vdi file> |
23 | 2 | Charles Atkinson | </pre> |
24 | 2 | Charles Atkinson | * Adjust the partition table. Example |
25 | 2 | Charles Atkinson | <pre> |
26 | 2 | Charles Atkinson | parted /dev/nbd0 |
27 | 2 | Charles Atkinson | ... |
28 | 2 | Charles Atkinson | (parted) print free |
29 | 2 | Charles Atkinson | ... |
30 | 2 | Charles Atkinson | (parted) resizepart 4 100% |
31 | 2 | Charles Atkinson | ... |
32 | 2 | Charles Atkinson | </pre> |
33 | 2 | Charles Atkinson | * If growing the file system on the host instead of the guest, example for partition 4 |
34 | 2 | Charles Atkinson | <pre> |
35 | 2 | Charles Atkinson | e2fsck -f /dev/nbd0p4 |
36 | 2 | Charles Atkinson | ... |
37 | 2 | Charles Atkinson | resize2fs /dev/nbd0p4 |
38 | 2 | Charles Atkinson | ... |
39 | 2 | Charles Atkinson | </pre> |
40 | 2 | Charles Atkinson | * Disconnect the NBD |
41 | 2 | Charles Atkinson | <pre> |
42 | 2 | Charles Atkinson | qemu-nbd -d /dev/nbd0 |
43 | 2 | Charles Atkinson | </pre> |
44 | 2 | Charles Atkinson | |
45 | 2 | Charles Atkinson | h2. Migrating Xen DomU (un-partitioned LV for /) to VirtualBox |
46 | 2 | Charles Atkinson | |
47 | 2 | Charles Atkinson | Scenario: a Xen DomU using an un-partitioned LV for its / file system and booting via pygrub was to be migrated to VirtualBox. |
48 | 2 | Charles Atkinson | |
49 | 2 | Charles Atkinson | Converting to .vdi was easy using @VBoxManage convertfromraw <path of LV image> <path of output .vdi> --format VDI@ but no way was found to make VirtualBox boot the .vdi |
50 | 2 | Charles Atkinson | |
51 | 2 | Charles Atkinson | The workaround was: |
52 | 2 | Charles Atkinson | * Add a new .vdi to the VM definition |
53 | 2 | Charles Atkinson | * Fresh OS installation to the new .vdi thus creating a conventional bootable partitioned layout |
54 | 2 | Charles Atkinson | * Boot the VM from standalone media |
55 | 2 | Charles Atkinson | * Sync files from the conversion output .vdi to the new .vdi |
56 | 2 | Charles Atkinson | |
57 | 2 | Charles Atkinson | h1. systemd: start VMs at host boot and shut down during host shutdown |
58 | 1 | Charles Atkinson | |
59 | 1 | Charles Atkinson | h2. Script |
60 | 1 | Charles Atkinson | |
61 | 1 | Charles Atkinson | "/usr/local/bin/shut_down_vbox_vm.sh":https://redmine.auroville.org.in/attachments/download/7747/shut_down_vbox_vm.sh |
62 | 1 | Charles Atkinson | |
63 | 1 | Charles Atkinson | h2. /etc/systemd/system/vboxvmservice@.service |
64 | 1 | Charles Atkinson | |
65 | 1 | Charles Atkinson | This is specific to the User= user |
66 | 1 | Charles Atkinson | <pre> |
67 | 1 | Charles Atkinson | [Unit] |
68 | 1 | Charles Atkinson | Description=VBox Virtual Machine %i Service |
69 | 1 | Charles Atkinson | Requires=systemd-modules-load.service |
70 | 1 | Charles Atkinson | After=systemd-modules-load.service |
71 | 1 | Charles Atkinson | |
72 | 1 | Charles Atkinson | [Service] |
73 | 1 | Charles Atkinson | User=c |
74 | 1 | Charles Atkinson | Group=vboxusers |
75 | 1 | Charles Atkinson | ExecStart=/usr/bin/VBoxManage startvm %i --type headless |
76 | 1 | Charles Atkinson | ExecStop=/usr/local/bin/shut_down_vbox_vm.sh %i |
77 | 1 | Charles Atkinson | RemainAfterExit=yes |
78 | 1 | Charles Atkinson | |
79 | 1 | Charles Atkinson | [Install] |
80 | 1 | Charles Atkinson | WantedBy=multi-user.target |
81 | 1 | Charles Atkinson | </pre> |
82 | 1 | Charles Atkinson | |
83 | 1 | Charles Atkinson | h2. Instantiation |
84 | 1 | Charles Atkinson | |
85 | 1 | Charles Atkinson | Example, for user c's VM aems3.iciti.av |
86 | 1 | Charles Atkinson | <pre> |
87 | 1 | Charles Atkinson | # systemctl enable vboxvmservice@aems3.iciti.av |
88 | 1 | Charles Atkinson | </pre> |