WARNING: You can destroy you primary hard drive and loose all data if you are not careful. Please do not attempt unless you completely understand the instructions and what fdisk
is.
Summary: I want to use a file to mimic a USB flash drive instead of using a physical usb drive. I needed a usb drive to allow Debugging the Home Assistant Operating System | Home Assistant Developer Docs to let me setup VLAN access. This is how I created the virtual usb drive / file instead of using a physical flash drive. Note: the file has a partition within it just like a hard drive. You can not directly mount and edit the file contents.
-
Back up all your data and use a different virtual machine to run this commands. Donβt use your main / host machine.
-
Create the virtual flash drive. I like using the location
/var/lib/libvirt/images
for my saved usb drive. -
cd /var/lib/libvirt/images/
-
fallocate -l 10M ha-usb.img
-
fdisk ha-usb.img
You need to follow the instructions here How to create FAT32 USB drive on Linux β Redips spideR Net to create the partition. -
kpartx -asv ha-usb.img ; ls -l /dev/mapper/loop*
You will need to know what the correct value is to change<<loop0p1>>
below -
mkfs -t vfat /dev/mapper/<<loop0p1>>
-
dosfslabel /dev/mapper/<<loop0p1>> CONFIG
-
kpartx -dsv ha-usb.img
-
Now can see what is inside the virtual flash drive
-
mkdir /tmp/t
-
kpartx -asv ha-usb.img ; ls -l /dev/mapper/loop*
You will need to know what the correct value is to change<<loop0p1>>
below -
mount -t auto -o loop /dev/mapper/<<loop0p1>> /tmp/t/
-
ls -l /tmp/t
-
edit the files per https://github.com/home-assistant/operating-system/blob/eba7099adcf20ebafd84015c90c615191a7bfc71/Documentation/configuration.md
You can use an USB drive with HassOS to configure network options, SSH access to the host and to install updates. Format a USB stick with FAT32/EXT4/NTFS and name it CONFIG (in all capitals). Alternative you can create a CONFIG folder inside the boot partition. Use the following directory structure within the USB drive:
-
umount /tmp/t
-
kpartx -dsv ha-usb.img
-
-
Follow the instructions here to install KVM / QE Install Home Assistant OS with KVM on Ubuntu headless (CLI only).
-
start Home Assistant virtually and verify it is running
-
Using
virt-manager
stop and edit the home assistant settings. You need to add a the created virtual usb drive- click on the show virtual hardware details icon. In the tool bar it looks like a light bulb.
- click
Add Hardware
, bottom left, button - click
Storage
- click
Select or create custom storage
- click
Manage
- click on the new file
ha-usb.img
and pressChoose Volume
- leave
Device type
asDisk device
-
Bus Type:
must beUSB
- Optionally click
Advanced Options
- check
Read Only
- check
Shareable
- check
-
To check the ssh access is working
ssh root@homeassistant -I <<your_file_location/id_rsa>> -p 22222