I am very much new to Linux programming.
My questions are:
I found some commands sudo vol_id --uuid /dev/sda1
, sudo blkid
and ls -l /dev/disk/by-uuid/
. But all of them are commands which need to run in a terminal. But I need to achieve this from a C/C++ program.
Can some one help me with this problem. (FYI: I need to read UUID of the root filesystem ("/") where Linux has been installed.)
Thank you in advance.
Use the blkid command to see the UUID of all partitions. List the contents of the /dev/disk/by-uuid/ directory. Retrieve partition UUIDs with the udevadm command. The hwinfo command can also be used to retrieve the information, assuming that the program has already been installed on your system.
Instead, you're supposed to delete a partition and create a new one with adjusted size. This does not destroy the data (partition layout is stored separately), but will generate a new UUID for the new partition.
The general approach would be:
/etc/mtab
for example
/dev/disks/by-uuid
directory (using opendir/readdir/closedir
) and find which one points to that device.
See the readlink
function for getting the target of a symbolic link. You'll find plenty of code examples for parsing text files on this site or with your favorite search engine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With