Bug 209791 - To tunefs utilities I added flag for generate new ufsid (unique filesystem id).
Summary: To tunefs utilities I added flag for generate new ufsid (unique filesystem id).
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-05-27 11:43 UTC by Pavel Volkov
Modified: 2017-08-18 15:50 UTC (History)
2 users (show)

See Also:


Attachments
Added G flag. (3.18 KB, patch)
2016-05-27 11:43 UTC, Pavel Volkov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Volkov 2016-05-27 11:43:35 UTC
Created attachment 170723 [details]
Added G flag.

In the superblock of the filesystem present unique id:

/usr/include/ufs/ffs/fs.h

/*
 * Super block for an FFS filesystem.
 */
struct fs {
...
        int32_t  fs_id[2];              /* unique filesystem id */
...

It's may by used to mount filesystem (/dev/ufsid/...).

After duplicating the disc, it is necessary to change it, to restore the uniqueness drives.
Comment 1 Pavel Volkov 2016-06-02 13:10:01 UTC
Hello.
To generate a new ufsid I used an algorithm from a file:

/usr/src/sbin/newfs/mkfs.c

    140                 time(&utime);

    465         sblock.fs_id[0] = (long)utime;
    466         sblock.fs_id[1] = newfs_random();

   1149 /*
   1150  * For the regression test, return predictable random values.
   1151  * Otherwise use a true random number generator.
   1152  */
   1153 static u_int32_t
   1154 newfs_random(void)
   1155 {
   1156         static int nextnum = 1;
   1157
   1158         if (Rflag)
   1159                 return (nextnum++);
   1160         return (arc4random());
   1161 }
Comment 2 Pavel Volkov 2016-06-04 05:30:59 UTC
It's patch applied to FreeBSD 11, Revision: 301300.
Comment 3 Helge Oldach 2017-08-18 15:50:08 UTC
That's indeed the missing bit when you dd an entire partition (copying ufs meta data verbatim) - but then we need to distinguish the copied partition from the original. Thanks, please commit.