Support changing the UUID of a btrfs file system (#751337)

Btrfs-progs 4.1, released June 2015, includes support for changing the
UUID of a btrfs file system using the btrfstune command.  Check for
availability by looking for the -u option in the btrfstune help output.
Use btrfstune like this:

    # umount /dev/sdb1
    # btrfstune -f -u /dev/sdb1
    Current fsid: e7ad5dba-d721-4f99-990b-1ba2901c8ad2
    New fsid: 231563d9-e173-410d-b1da-d34c4319a423
    Set superblock flag CHANGING_FSID
    Change fsid in extents
    Change fsid on devices
    Clear superblock flag CHANGING_FSID
    Fsid change finished
    # echo $?
    0

Bug 751337 - btrfstune in btrfs-progs 4.1 supports changing the file
             system UUID
This commit is contained in:
Mike Fleetwood 2015-06-19 13:02:32 +01:00 committed by Curtis Gedak
parent d405bb2264
commit 8308ee6051
2 changed files with 13 additions and 0 deletions

View File

@ -39,6 +39,7 @@ public:
void read_label( Partition & partition ) ; void read_label( Partition & partition ) ;
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ; bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
void read_uuid( Partition & partition ) ; void read_uuid( Partition & partition ) ;
bool write_uuid( const Partition & partition, OperationDetail & operationdetail );
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ; bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ; bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ; bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;

View File

@ -107,6 +107,13 @@ FS btrfs::get_filesystem_support()
} }
} }
if ( ! Glib::find_program_in_path( "btrfstune" ).empty() )
{
Utils::execute_command( "btrfstune --help", output, error, true );
if ( Utils::regexp_label( error, "^[[:blank:]]*(-u)[[:blank:]]" ) == "-u" )
fs.write_uuid = FS::EXTERNAL;
}
if ( fs .check ) if ( fs .check )
{ {
fs .copy = GParted::FS::GPARTED ; fs .copy = GParted::FS::GPARTED ;
@ -422,6 +429,11 @@ void btrfs::read_uuid( Partition & partition )
} }
} }
bool btrfs::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{
return ! execute_command( "btrfstune -f -u " + partition.get_path(), operationdetail );
}
void btrfs::clear_cache() void btrfs::clear_cache()
{ {
btrfs_device_cache .clear() ; btrfs_device_cache .clear() ;