1virt-edit(1)                Virtualization Support                virt-edit(1)
2
3
4

NAME

6       virt-edit - Edit a file in a virtual machine
7

SYNOPSIS

9        virt-edit [--options] -d domname file [file ...]
10
11        virt-edit [--options] -a disk.img [-a disk.img ...] file [file ...]
12
13        virt-edit [-d domname|-a disk.img] file -e 'expr'
14
15       Old-style:
16
17        virt-edit domname file
18
19        virt-edit disk.img [disk.img ...] file
20

WARNING

22       Using "virt-edit" on live virtual machines, or concurrently with other
23       disk editing tools, can be dangerous, potentially causing disk
24       corruption.  The virtual machine must be shut down before you use this
25       command, and disk images must not be edited concurrently.
26

DESCRIPTION

28       "virt-edit" is a command line tool to edit "file" where each "file"
29       exists in the named virtual machine (or disk image).
30
31       Multiple filenames can be given, in which case they are each edited in
32       turn.  Each filename must be a full path, starting at the root
33       directory (starting with '/').
34
35       If you want to just view a file, use virt-cat(1).
36
37       For more complex cases you should look at the guestfish(1) tool (see
38       "USING GUESTFISH" below).
39
40       "virt-edit" cannot be used to create a new file.  guestfish(1) can do
41       that and much more.
42

EXAMPLES

44       Edit the named files interactively:
45
46        virt-edit -d mydomain /boot/grub/grub.conf
47
48        virt-edit -d mydomain /etc/passwd
49
50       For Windows guests, some Windows paths are understood:
51
52        virt-edit -d mywindomain 'c:\autoexec.bat'
53
54       If Perl is installed, you can also edit files non-interactively (see
55       "NON-INTERACTIVE EDITING" below).  To change the init default level to
56       5:
57
58        virt-edit -d mydomain /etc/inittab -e 's/^id:.*/id:5:initdefault:/'
59

OPTIONS

61       --help
62           Display brief help.
63
64       -a file
65       --add file
66           Add file which should be a disk image from a virtual machine.  If
67           the virtual machine has multiple block devices, you must supply all
68           of them with separate -a options.
69
70           The format of the disk image is auto-detected.  To override this
71           and force a particular format use the --format=.. option.
72
73       -a URI
74       --add URI
75           Add a remote disk.  See "ADDING REMOTE STORAGE" in guestfish(1).
76
77       -b EXTENSION
78       --backup EXTENSION
79           Create a backup of the original file in the guest disk image.  The
80           backup has the original filename with "extension" added.
81
82           Usually the first character of "extension" would be a dot "."  so
83           you would write:
84
85            virt-edit -b .orig [etc]
86
87           By default, no backup file is made.
88
89       --blocksize=512
90       --blocksize=4096
91       --blocksize
92           This parameter sets the sector size of the disk image.  It affects
93           all explicitly added subsequent disks after this parameter.  Using
94           --blocksize with no argument switches the disk sector size to the
95           default value which is usually 512 bytes.  See also
96           "guestfs_add_drive_opts" in guestfs(3).
97
98       -c URI
99       --connect URI
100           If using libvirt, connect to the given URI.  If omitted, then we
101           connect to the default libvirt hypervisor.
102
103           If you specify guest block devices directly, then libvirt is not
104           used at all.
105
106       -d GUEST
107       --domain GUEST
108           Add all the disks from the named libvirt guest.  Domain UUIDs can
109           be used instead of names.
110
111       --echo-keys
112           When prompting for keys and passphrases, virt-edit normally turns
113           echoing off so you cannot see what you are typing.  If you are not
114           worried about Tempest attacks and there is no one else in the room
115           you can specify this flag to see what you are typing.
116
117       -e EXPR
118       --edit EXPR
119       --expr EXPR
120           Instead of launching the external editor, non-interactively apply
121           the Perl expression "EXPR" to each line in the file.  See "NON-
122           INTERACTIVE EDITING" below.
123
124           Be careful to properly quote the expression to prevent it from
125           being altered by the shell.
126
127           Note that this option is only available when Perl 5 is installed.
128
129       --format=raw|qcow2|..
130       --format
131           The default for the -a option is to auto-detect the format of the
132           disk image.  Using this forces the disk format for -a options which
133           follow on the command line.  Using --format with no argument
134           switches back to auto-detection for subsequent -a options.
135
136           For example:
137
138            virt-edit --format=raw -a disk.img file
139
140           forces raw format (no auto-detection) for disk.img.
141
142            virt-edit --format=raw -a disk.img --format -a another.img file
143
144           forces raw format (no auto-detection) for disk.img and reverts to
145           auto-detection for another.img.
146
147           If you have untrusted raw-format guest disk images, you should use
148           this option to specify the disk format.  This avoids a possible
149           security problem with malicious guests (CVE-2010-3851).
150
151       --key SELECTOR
152           Specify a key for LUKS, to automatically open a LUKS device when
153           using the inspection.
154
155           --key NAME:key:KEY_STRING
156           --key UUID:key:KEY_STRING
157           --key all:key:KEY_STRING
158               "NAME" is the libguestfs device name (eg. "/dev/sda1").  "UUID"
159               is the device UUID.  "all" means try the key against any
160               encrypted device.
161
162               Use the specified "KEY_STRING" as passphrase.
163
164           --key NAME:file:FILENAME
165           --key UUID:file:FILENAME
166           --key all:file:FILENAME
167               Read the passphrase from FILENAME.
168
169           --key NAME:clevis
170           --key UUID:clevis
171           --key all:clevis
172               Attempt passphrase-less unlocking for the device with Clevis,
173               over the network.  Please refer to "ENCRYPTED DISKS" in
174               guestfs(3) for more information on network-bound disk
175               encryption (NBDE).
176
177               Note that if any such option is present on the command line,
178               QEMU user networking will be automatically enabled for the
179               libguestfs appliance.
180
181       --keys-from-stdin
182           Read key or passphrase parameters from stdin.  The default is to
183           try to read passphrases from the user by opening /dev/tty.
184
185           If there are multiple encrypted devices then you may need to supply
186           multiple keys on stdin, one per line.
187
188       -m dev[:mountpoint[:options[:fstype]]]
189       --mount dev[:mountpoint[:options[:fstype]]]
190           Mount the named partition or logical volume on the given
191           mountpoint.
192
193           If the mountpoint is omitted, it defaults to /.
194
195           Specifying any mountpoint disables the inspection of the guest and
196           the mount of its root and all of its mountpoints, so make sure to
197           mount all the mountpoints needed to work with the filenames given
198           as arguments.
199
200           If you don’t know what filesystems a disk image contains, you can
201           either run guestfish without this option, then list the partitions,
202           filesystems and LVs available (see "list-partitions", "list-
203           filesystems" and "lvs" commands), or you can use the
204           virt-filesystems(1) program.
205
206           The third (and rarely used) part of the mount parameter is the list
207           of mount options used to mount the underlying filesystem.  If this
208           is not given, then the mount options are either the empty string or
209           "ro" (the latter if the --ro flag is used).  By specifying the
210           mount options, you override this default choice.  Probably the only
211           time you would use this is to enable ACLs and/or extended
212           attributes if the filesystem can support them:
213
214            -m /dev/sda1:/:acl,user_xattr
215
216           Using this flag is equivalent to using the "mount-options" command.
217
218           The fourth part of the parameter is the filesystem driver to use,
219           such as "ext3" or "ntfs". This is rarely needed, but can be useful
220           if multiple drivers are valid for a filesystem (eg: "ext2" and
221           "ext3"), or if libguestfs misidentifies a filesystem.
222
223       -v
224       --verbose
225           Enable verbose messages for debugging.
226
227       -V
228       --version
229           Display version number and exit.
230
231       -x  Enable tracing of libguestfs API calls.
232

OLD-STYLE COMMAND LINE ARGUMENTS

234       Previous versions of virt-edit allowed you to write either:
235
236        virt-edit disk.img [disk.img ...] file
237
238       or
239
240        virt-edit guestname file
241
242       whereas in this version you should use -a or -d respectively to avoid
243       the confusing case where a disk image might have the same name as a
244       guest.
245
246       For compatibility the old style is still supported.
247

NON-INTERACTIVE EDITING

249       "virt-edit" normally calls out to $EDITOR (or vi) so the system
250       administrator can interactively edit the file.
251
252       There are two ways also to use "virt-edit" from scripts in order to
253       make automated edits to files.  (Note that although you can use
254       "virt-edit" like this, it’s less error-prone to write scripts directly
255       using the libguestfs API and Augeas for configuration file editing.)
256
257       The first method is to temporarily set $EDITOR to any script or program
258       you want to run.  The script is invoked as "$EDITOR tmpfile" and it
259       should update "tmpfile" in place however it likes.
260
261       The second method is to use the -e parameter of "virt-edit" to run a
262       short Perl snippet in the style of sed(1).  For example to replace all
263       instances of "foo" with "bar" in a file:
264
265        virt-edit -d domname filename -e 's/foo/bar/'
266
267       The full power of Perl regular expressions can be used (see perlre(1)).
268       For example to delete root’s password you could do:
269
270        virt-edit -d domname /etc/passwd -e 's/^root:.*?:/root::/'
271
272       What really happens is that the snippet is evaluated as a Perl
273       expression for each line of the file.  The line, including the final
274       "\n", is passed in $_ and the expression should update $_ or leave it
275       unchanged.
276
277       To delete a line, set $_ to the empty string.  For example, to delete
278       the "apache" user account from the password file you can do:
279
280        virt-edit -d mydomain /etc/passwd -e '$_ = "" if /^apache:/'
281
282       To insert a line, prepend or append it to $_.  However appending lines
283       to the end of the file is rather difficult this way since there is no
284       concept of "last line of the file" - your expression just doesn't get
285       called again.  You might want to use the first method (setting $EDITOR)
286       if you want to do this.
287
288       The variable $lineno contains the current line number.  As is
289       traditional, the first line in the file is number 1.
290
291       The return value from the expression is ignored, but the expression may
292       call "die" in order to abort the whole program, leaving the original
293       file untouched.
294
295       Remember when matching the end of a line that $_ may contain the final
296       "\n", or (for DOS files) "\r\n", or if the file does not end with a
297       newline then neither of these.  Thus to match or substitute some text
298       at the end of a line, use this regular expression:
299
300        /some text(\r?\n)?$/
301
302       Alternately, use the perl "chomp" function, being careful not to chomp
303       $_ itself (since that would remove all newlines from the file):
304
305        my $m = $_; chomp $m; $m =~ /some text$/
306

WINDOWS PATHS

308       "virt-edit" has a limited ability to understand Windows drive letters
309       and paths (eg. E:\foo\bar.txt).
310
311       If and only if the guest is running Windows then:
312
313       •   Drive letter prefixes like "C:" are resolved against the Windows
314           Registry to the correct filesystem.
315
316       •   Any backslash ("\") characters in the path are replaced with
317           forward slashes so that libguestfs can process it.
318
319       •   The path is resolved case insensitively to locate the file that
320           should be edited.
321
322       There are some known shortcomings:
323
324       •   Some NTFS symbolic links may not be followed correctly.
325
326       •   NTFS junction points that cross filesystems are not followed.
327

USING GUESTFISH

329       guestfish(1) is a more powerful, lower level tool which you can use
330       when "virt-edit" doesn't work.
331
332       Using "virt-edit" is approximately equivalent to doing:
333
334        guestfish --rw -i -d domname edit /file
335
336       where "domname" is the name of the libvirt guest, and /file is the full
337       path to the file.
338
339       The command above uses libguestfs’s guest inspection feature and so
340       does not work on guests that libguestfs cannot inspect, or on things
341       like arbitrary disk images that don't contain guests.  To edit a file
342       on a disk image directly, use:
343
344        guestfish --rw -a disk.img -m /dev/sda1 edit /file
345
346       where disk.img is the disk image, /dev/sda1 is the filesystem within
347       the disk image to edit, and /file is the full path to the file.
348
349       "virt-edit" cannot create new files.  Use the guestfish commands
350       "touch", "write" or "upload" instead:
351
352        guestfish --rw -i -d domname touch /newfile
353
354        guestfish --rw -i -d domname write /newfile "new content"
355
356        guestfish --rw -i -d domname upload localfile /newfile
357

ENVIRONMENT VARIABLES

359       "EDITOR"
360           If set, this string is used as the editor.  It may contain
361           arguments, eg. "emacs -nw"
362
363           If not set, "vi" is used.
364

EXIT STATUS

366       This program returns 0 if successful, or non-zero if there was an
367       error.
368

SEE ALSO

370       guestfs(3), guestfish(1), virt-cat(1), virt-copy-in(1), virt-tar-in(1),
371       http://libguestfs.org/, perl(1), perlre(1).
372

AUTHOR

374       Richard W.M. Jones http://people.redhat.com/~rjones/
375
377       Copyright (C) 2009-2023 Red Hat Inc.
378

LICENSE

380       This program is free software; you can redistribute it and/or modify it
381       under the terms of the GNU General Public License as published by the
382       Free Software Foundation; either version 2 of the License, or (at your
383       option) any later version.
384
385       This program is distributed in the hope that it will be useful, but
386       WITHOUT ANY WARRANTY; without even the implied warranty of
387       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
388       General Public License for more details.
389
390       You should have received a copy of the GNU General Public License along
391       with this program; if not, write to the Free Software Foundation, Inc.,
392       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
393

BUGS

395       To get a list of bugs against libguestfs, use this link:
396       https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools
397
398       To report a new bug against libguestfs, use this link:
399       https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools
400
401       When reporting a bug, please supply:
402
403       •   The version of libguestfs.
404
405       •   Where you got libguestfs (eg. which Linux distro, compiled from
406           source, etc)
407
408       •   Describe the bug accurately and give a way to reproduce it.
409
410       •   Run libguestfs-test-tool(1) and paste the complete, unedited output
411           into the bug report.
412
413
414
415guestfs-tools-1.51.6              2023-12-09                      virt-edit(1)
Impressum