How to exchange the UUID of a partition via C code?

Asked

Viewed 261 times

2

I am making a program in C, and through Linux, I have been able to "get" UUID easily, with the command blkid.

This program needs to know if the disk on which it was installed is still the same and allow you to exchange the UUID on your own.

Is it possible to programmatically swap the UUID of a partition? I found nothing conclusive by searching the internet.

  • 3

    Roberval, I believe that this question will end up being closed due to the scope of the site (as well as the lack of relevant information in the question). That said, assuming you have a partition ext4 on Ubuntu take a look in that reply of Ask Ubuntu, the command tune2fs /dev/{device} -U {uuid} should do what you want.

  • thanks for the tip! I’m still learning... sorry p bad jeitro!

  • I happen to be making a program, in c, that must read the UUID of the disk, to know if it is still installed on the same computer / disk.. That clarifies? It was this explanation that was missing?

  • 1

    I suggest rethinking your program, tampering with the user’s disk UUID can break other existing applications. There may even be some legitimate reason for this, but almost always it is not. If you need to identify the user’s disk, it is more elegant to store existing UUID and store somewhere for future comparison, without tampering.

  • 1

    For my part, it was just a recommendation. If I had the answer, I would have, because I don’t think it’s up to us to assess how you’re going to use knowledge or not. I just thought it was important to let you know, because it’s something to consider, in case you’re really going to opt for this solution in your application.

  • Hello @Roberval, imagine, the issue here is not personal, we all had to learn the format of the site one day. As you are modifying the question to clarify the points I would suggest that you include an example of code and more details about your environment: "What is your distribution? What file systems are you managing? Why are you doing this?" For more information at a glance in How to ask a good question? and How to create a Minimum, Complete and Verifiable example.

  • I understand @Anthony Accioly, but .. in another post, I put an example of Prog in C++ and tags C and C++.. our.. broke up with me, always in a very polite way.... but I felt very bad, mainly because I did not know how to ask the question. good efins he negatived me... good.. now I am REAL afraid of you.... but as I have to learn... let’s go there..

  • I still don’t understand... why this is not a matter of programming...

  • the current solution I’m using is a system("tune2fs /dev/sde5 -U f0acce91-a416-474c-8a8c-43f3ed3768f9"); IE.. I’m programming in C.. but I had to use system commands... too bad... it took a lot of work... It’s too bad to be a beginner.. and be snubbed by the veterans... I will continue with the research.... maybe sometime I’ll find the correct C commands to change the UUID... and partition label. My current project, I’ll have to do.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.