[Libguestfs] Does anybody know how to use the getxattr/setxattr commmands in guestfish?

Richard W.M. Jones rjones at redhat.com
Thu Apr 8 09:07:11 UTC 2010


On Thu, Apr 08, 2010 at 09:01:31AM +0100, Richard W.M. Jones wrote:
> On Thu, Apr 08, 2010 at 09:49:26AM +0800, Pengzhen Cao wrote:
> > Hi All,
> >
> > Does anybody know how to use the getxattr/setxattr commands in guestfish?
> > It seems not working for ext2/3 filesystem. I did not find the  
> > corresponding commands in bash either.
> > So is it  for xfs only?
> 
> Not just for xfs, this should work for ext2/3 as well.
> 
> The problem is you cannot just create any xattr.  The kernel will only
> recognize certain xattrs on files, so it's probably best to read the
> attr(5) manual page first.

In particular in order to set user.* attributes, you have to mount the
filesystem with the user_xattr option.  The example guestfish script
below shows how to do it.

$ /tmp/test.fish 
Extended attributes before setting
Extended attributes after setting
[0] = {
  attrname: user.test
  attrval: hello
}

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
-------------- next part --------------
#!/usr/bin/guestfish -f

sparse /tmp/test.img 10M
run
part-disk /dev/sda mbr
mkfs ext3 /dev/sda1
mount-options user_xattr /dev/sda1 /

touch /test

echo "Extended attributes before setting"
getxattrs /test

setxattr user.test hello 5 /test

echo "Extended attributes after setting"
getxattrs /test


More information about the Libguestfs mailing list