You can write a single line file easily in guestfish by doing:
><fs> write /file "hello world"
However this doesn’t work for multi-line files, ie. this does not work:
><fs> write /file "hello\nworld\n"
(Because our parsing code sucks) There’s another way to do it using the upload command and the heredoc-like syntax:
><fs> upload -<<END /file hello world END
If you want to upload a binary file, use base64 encoding:
><fs> base64-in -<<EOF /binfile f0VMRgEBAQAAAAAAAAAAAAIAAwABAAAAgIIECDQAAAAcBwAAAAAAADQAIAAHACgAGgAZAAYAAAA0 AAAANIAECDSABAjgAAAA4AAAAAUAAAAEAAAAAwAAABQBAAAUgQQIFIEECBMAAAATAAAABAAAAAEA AAABAAAAAAAAAACABAgAgAQIRAQAAEQEAAAFAAAAABAAAAEAAABEBAAARJQECESUBAj4AAAAAAEA [.....] AAAAPAUAABQBAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAMAAAAAAAAAAAAAAFAGAADLAAAAAAAAAAAA AAABAAAAAAAAAA== EOF ><fs> file /binfile ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
At some point when doing this you hit limitations in guestfish. If you want to create and manipulate lots of configuration files, it’s probably better to use guestfish with augeas (for Linux guests) or hivex (Windows guests). If you find yourself using a lot of shell script and guestfish, at some point you should consider using the libguestfs API directly from a scripting language. This gives you far more control and predictability.