Go to file
Mike Fleetwood a0f5b02f59 Switch to using udevadm info to query drive serial numbers (#263)
A user reported that GParted was displaying binary data for the serial
number of their USB key.  This was because hdparm -I was reporting
binary data for the serial number.  It looked like this (except the
question marks were binary non-printable bytes).
    $ LANG=C sudo hdparm -I /dev/sdh

    /dev/sdh:

    ATA device, with non-removable media
            Model Number:       ?|??t??L??|??
            Serial Number:      ?@>??8
                                      u
            Firmware Revision:  u???
    Standards:
            Likely used: 1
    ...

Back in 2015 when reporting of drive serial numbers was being added
[1][2], using hdparm -I was the best option because it reported the
serial number of all hard drives including those in virtual machines,
worked the same everywhere and was available by default in most
distributions, but didn't work for USB keys.  Where as lsblk -o SERIAL
was a new option not available yet on some distributions and didn't
report the serial number of drives in virtual machines.

Now hdparm -I capabilities are still the same; only working for hard
drives, including SSDs, but not USB keys.  Except for the above case
hdparm has always found to not report serial numbers for USB keys, like
this:
    # hdparm -I /dev/sde

    /dev/sde:
    SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 15 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 70 00 00 00

    ATA device, with non-removable media
    Standards:
            Likely used: 1
    ....

Now the lsblk -o SERIAL option is available on all distributions and
reports the serial numbers of all drives including for virtual machine
disks and USB keys.

From an older but still supported Ubuntu 20.04 LTS virtual machine:
    # lsblk -o KNAME,VENDOR,MODEL,SERIAL,TYPE,TRAN -d
    KNAME VENDOR   MODEL            SERIAL              TYPE TRAN
    sda   ATA      VBOX HARDDISK    VB13d4e080-b35e62d3 disk sata
    sdb   ATA      VBOX HARDDISK    VB221202cf-092e5857 disk sata
    sdc   ATA      VBOX HARDDISK    VB04fefadd-5a185f96 disk sata
    sr0   VBOX     CD-ROM           VB2-01700376        rom  ata

From a physical machine running older but still supported Rocky Linux 8
with 2 SSDs, 2 HDDs, and 6 USB keys:
    # lsblk -o KNAME,VENDOR,MODEL,SERIAL,TYPE,TRAN -d
    KNAME VENDOR   MODEL            SERIAL                   TYPE TRAN
    sda   ATA      Samsung SSD 860  S3Z9NY0M620872V          disk sata
    sdb   ATA      SAMSUNG SSD UM41 DCF4300940SE940B4507     disk sata
    sdc   ATA      WDC WD10JFCX-68N WD-WXE1EB6C3MHY          disk sata
    sdd   ATA      MM0500EBKAE      9XF132MW                 disk sata
    sde   SanDisk  U3 Cruzer Micro  00001853E473AABA         disk usb
    sdf   Kingston DataTraveler 3.0 408D5C1658F7E31079051DB9 disk usb
    sdg   Kingston DataTraveler 2.0 1C6F654FF40FBE50D9341059 disk usb
    sdh            Patriot Memory   07082AA3E0944E31         disk usb
    sdi   Corsair  Slider 3.0       12240400400016361397     disk usb
    sdj   SMI      USB DISK         SMI_USB_DISK-0:0         disk usb
    sr0   ASUS     DRW-24B3LT       B5D0CL213444             rom  sata
    sr1   SanDisk  U3 Cruzer Micro  00001853E473AABA         rom  usb

lsblk gets it's information from udev.  lsblk reports the SERIAL column
from the udev device property ID_SERIAL_SHORT, except when that is blank
it uses the ID_SERIAL property instead [3].  Note that ID_SERIAL is
composed from vendor and model information [4].

USB key with a serial number:
    # udevadm info --query=property --name=/dev/sde | grep SERIAL
    ID_SERIAL=SanDisk_U3_Cruzer_Micro_00001853E473AABA-0:0
    ID_SERIAL_SHORT=00001853E473AABA
    # lsblk -o KNAME,VENDOR,MODEL,SERIAL,TYPE,TRAN -d /dev/sde
    KNAME VENDOR   MODEL            SERIAL           TYPE TRAN
    sde   SanDisk  U3 Cruzer Micro  00001853E473AABA disk usb

USB key without a serial number:
    # udevadm info --query=property --name=/dev/sdj | grep SERIAL
    ID_SERIAL=SMI_USB_DISK-0:0
    # lsblk -o KNAME,VENDOR,MODEL,SERIAL,TYPE,TRAN -d /dev/sdj
    KNAME VENDOR   MODEL            SERIAL           TYPE TRAN
    sdj   SMI      USB DISK         SMI_USB_DISK-0:0 disk usb

To only get the device serial number, or blank when not available, query
the udev ID_SERIAL_SHORT property directly using udevadm info rather
than using lsblk -o SERIAL.  Previously GParted displayed "none" if
hdparm -I successfully found nothing, including for USB keys, and left
the serial number field blank on failure.  Now the field will be blank
in both cases, no serial number and failure to query it.

[1] 4b72ecd44e
    Display device serial numbers (#751251)
[2] Bug 751251 - Show serial number in device information
    https://bugzilla.gnome.org/show_bug.cgi?id=751251
[3] misc-utils/lsblk-properties.c:get_properties_by_udev()
    https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/tree/misc-utils/lsblk-properties.c?h=v2.40.2#n121
[4] what is the difference between ID_SERIAL and ID_SERIAL_SHORT udev
    attributes for a USB descriptor
    https://stackoverflow.com/questions/45940014/what-is-the-difference-between-id-serial-and-id-serial-short-udev-attributes-for
        "The ID_SERIAL_SHORT value comes from the iSerial string (if
        present) in the USB device descriptor.  The ID_SERIAL value is
        constructed in software and made up from various strings (vendor
        or manufacturer, model or product, and serial number if present)
        separated with _.
        "

Closes #263 - Serial number for my USB key showing binary data
2024-08-13 11:43:37 +00:00
data Increase minimum required gtkmm to 2.11.1 (#794253) 2018-03-26 10:16:45 -06:00
doc Update URLs in the remaining files to https://gparted.org (#796411) 2018-06-19 09:47:19 -06:00
help Update Romanian translation 2024-07-26 13:21:05 +00:00
include Prefix ext2 member variables with m_ and initialise all POD members 2024-08-10 10:03:37 +00:00
lib Update to Google Test 1.10.0 (!117) 2023-09-23 15:30:15 +00:00
m4 Update Autoconf macro AX_CXX_COMPILE_STDCXX_11 to latest serial 18 2018-08-01 19:03:01 +01:00
po Add Hindi translation 2024-06-15 14:18:44 +00:00
src Switch to using udevadm info to query drive serial numbers (#263) 2024-08-13 11:43:37 +00:00
tests Replace deprecated Google Test API INSTANTIATE_TEST_CASE_P() (!117) 2023-09-23 15:30:15 +00:00
.gitignore Add missing .gitignore entry for test_EraseFileSystemSignatures 2023-08-15 17:04:30 +00:00
.gitlab-ci.yml Replace CentOS 7 with Rocky Linux 8 in the CI jobs (!124) 2024-08-07 15:20:45 +00:00
AUTHORS Update copyright years 2024-02-26 09:15:09 -07:00
COPYING Revert "Fixed FSF's address. Fixes #721565" 2014-01-31 14:39:20 +01:00
COPYING-DOCS Added COPYING-DOCS and removed help/C/legal.xml file. The GFDL license should be translated only once per language, and not for each and every project that uses the license. See GParted bug #550047 2008-09-01 17:01:14 +00:00
ChangeLog Correctly capitalise GNOME in the Manual and man page (#739805) 2014-12-20 10:02:55 -07:00
HACKING Update HACKING file with coding style hints and tips 2021-03-24 16:22:41 +00:00
Makefile.am Rename Makefile.am variables to APPSTREAM*/appstream* (#241) 2024-02-08 16:19:20 +00:00
NEWS ========== gparted-1.6.0 ========== 2024-02-26 09:18:39 -07:00
README Update README for CentOS EOL and dnf transition 2024-08-07 15:20:45 +00:00
autogen.sh Remove deprecated PKG_NAME from autogen.sh 2019-03-01 16:46:56 +00:00
configure.ac Append -git to version for continuing development 2024-02-26 09:34:30 -07:00
gparted.appdata.xml.in Migrate build from intltool to gettext translation (!107) 2022-11-12 16:44:55 +00:00
gparted.desktop.in.in Migrate build from intltool to gettext translation (!107) 2022-11-12 16:44:55 +00:00
gparted.doap Update bug links from Bugzilla to GitLab issues (!11) 2018-08-24 09:54:12 +01:00
gparted.in Also find system default udev rules in /usr/lib/udev/rules.d (!116) 2023-08-15 17:04:30 +00:00
logo.png Add logo.png for automatic GitLab/GitHub project avatar 2018-05-25 17:18:49 +01:00
org.gnome.gparted.policy.in.in Migrate build from intltool to gettext translation (!107) 2022-11-12 16:44:55 +00:00
testbuild.sh Add testbuild.sh script (#699881) 2013-05-27 11:08:39 -06:00

README

GPARTED
=======
Gparted is the GNOME Partition Editor for creating, reorganizing, and
deleting disk partitions.

A hard disk is usually subdivided into one or more partitions.  These
partitions are normally not re-sizable (making one smaller and the
adjacent one larger.)  Gparted makes it possible for you to take a
hard disk and change the partition organization, while preserving the
partition contents.

More specifically, Gparted enables you to create, destroy, resize,
move, check, label, and copy partitions, and the file systems
contained within.  This is useful for creating space for new operating
systems, reorganizing disk usage, and mirroring one partition with
another (disk imaging).

Gparted can also be used with storage devices other than hard disks,
such as USB flash drives, and memory cards.

Visit https://gparted.org for more information.


LICENSING
---------
GParted is released under the General Public License version 2, or (at
your option) any later version.  (GPLv2+).  All files are released under
the GPLv2+ unless explicitly licensed otherwise.

The GParted Manual is released under the GNU Free Documentation License
version 1.2 or any later version.  (GFDLv1.2+).

Google Test C++ test framework is released under the 3-Clause BSD
License.  (BSD-3-Clause).

See these files for more details:
   COPYING      - GNU General Public License version 2
   COPYING-DOCS - GNU Free Documentation License version 1.2
   lib/gtest/LICENSE
                - 3-Clause BSD License


NEWS
----
Information about changes to this release, and past releases can be
found in the file:
   NEWS


INSTALL
-------
a. Pre-built Binary

   Many GNU/Linux distributions already provide a pre-built binary
   package for GParted.  Instructions on how to install GParted on
   some distributions is given below:

      RHEL
      ----
      su -
      dnf install gparted

      Debian or Ubuntu
      ----------------
      sudo apt install gparted

      Fedora
      ------
      su -
      dnf install gparted

      OpenSUSE
      --------
      sudo zypper install gparted

b. Building from Source

   Briefly, build and install GParted into the default location of
   /usr/local using:
      ./configure
      make
      sudo make install
      sudo install -m 644 org.gnome.gparted.policy \
             /usr/share/polkit-1/actions/org.gnome.gparted.local.policy
   This assumes all the dependencies are already installed, builds the
   default configuration and polkit is being used as the graphical su
   program.

   The following dependencies are required to build GParted from source:
      g++
      make
      parted
      gnome-common
      gtkmm3
      gettext
      polkit
      yelp-tools          - required if help documentation is to be built

   On RHEL, these dependencies may be obtained by running the following
   command as root:
      dnf install gnome-common yelp-tools glib2-devel gcc-c++ \
                  libuuid-devel parted-devel gtkmm30-devel make \
                  polkit-devel gettext-devel

   On Debian or Ubuntu, these dependencies may be obtained by running
   one of the following commands:
     Either;
      sudo apt build-dep gparted
     Or;
      sudo apt install build-essential gnome-common yelp-tools \
                       libglib2.0-dev uuid-dev libparted-dev \
                       libgtkmm-3.0-dev

   Debian 13 and later and Ubuntu 24.04 LTS and later also require this
   dependency installing:
      sudo apt install libpolkit-gobject-1-dev

   On Fedora, these dependencies may be obtained by running the
   following command as root:
      dnf install gnome-common yelp-tools glib2-devel gcc-c++ \
                  libuuid-devel parted-devel gtkmm30-devel make \
                  polkit-devel gettext-devel

   On openSUSE, these dependencies may be obtained by running the
   following commands:
      sudo zypper install gnome-common gcc-c++ libuuid-devel \
                          parted-devel gtkmm3-devel make polkit-devel

   Again, build GParted with the default configuration and install into
   the default location of /usr/local using:
      ./configure
      make
      sudo make install

   If you wish to build this package without the help documentation use
   the --disable-doc flag:
      E.g., ./configure --disable-doc

   If you wish to build this package to use native libparted /dev/mapper
   dmraid support use the --enable-libparted-dmraid flag:
      E.g., ./configure --enable-libparted-dmraid

   If you wish to build this package with online resize support then
   the following is required:
      a)  Linux kernel version 3.6 or higher.
      b)  Libparted with online resize support.  Either:
          i)  Libparted version 3.2 or later which includes online
              resize support as standard.  In this case GParted is
              automatically built with online resize support.
          ii) Online resize support back ported into an earlier version
              of libparted.  This is only known to be included in Debian
              and derived distributions with parted version 2.3-14 and
              higher.  In this case online resize support must be
              specifically enabled with the --enable-online-resize flag:
                E.g., ./configure --enable-online-resize

   If you wish to build GParted to allow it to use xhost to grant root
   access to the X11 server use the --enable-xhost-root flag.  This is
   required to allow GParted to display under Wayland.
      ./configure --enable-xhost-root

   Please note that more than one configure flag can be used:
      E.g., ./configure --disable-doc --enable-libparted-dmraid

   The INSTALL file contains further GNU installation instructions.

c. Installing polkit's Action File

   GParted needs to run as root therefore it needs a graphical switch
   user program to allow normal users to run it.  Most desktops now use
   polkit as their preferred authorisation mechanism.  Therefore
   ./configure looks for polkit's pkexec as the first choice with
   fallbacks in order being: gksudo, gksu, kdesudo and finally xdg-su.
   Also polkit reads action files only from directory
   /usr/share/polkit-1/actions.  Therefore it is likely that a polkit
   action file will need to be installed into this directory.

   To determine if polkit's pkexec program is being used as the
   graphical privilege escalation program examine the output from
   ./configure.  These lines report that pkexec is being used:

      checking for pkexec >= 0.102... 0.112 found

   Where as either of these lines of ./configure output report that
   pkexec is not being used because either it was too old a version or
   it was not found:

      checking for pkexec >= 0.102... 0.96 found

      checking for pkexec >= 0.102... not found

   When GParted is configured with prefix /usr (using command
   ./configure --prefix=/usr) then make install will automatically
   install the polkit action file into the correct directory and no
   further steps need to be taken.  This is typically the case for
   distribution builds of GParted.

   However when GParted is configured with the default prefix of
   /usr/local, or any prefix other than /usr, then the polkit action
   file has to be manually installed into the correct directory.  Also
   it should have a unique file name to avoid overwriting the action
   file from the distribution's package.  Install the polkit action file
   with a unique name including an extra ".local" in the name:

      sudo install -m 644 org.gnome.gparted.policy \
             /usr/share/polkit-1/actions/org.gnome.gparted.local.policy

d. Building using a Specific (lib)parted Version

   1) Download the parted version you wish to use (e.g., 3.2) from:

      http://ftp.gnu.org/gnu/parted/

   2) Build and install parted.

      Extract parted tarball, configure, make, and sudo make install.
      Note that by default this will install into /usr/local.

   3) Set environment variables to inform the GParted build system to
      use libparted from /usr/local:

        export CPPFLAGS=-I/usr/local/include
        export LDFLAGS=-L/usr/local/lib
        export LD_RUN_PATH=/usr/local/lib
        export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

   4) Build gparted using steps listed above in "Building from Source".

      Note that when you run ./configure you should see the specific
      version of parted listed in the check for libparted >= 1.7.1.

      You will also see the libparted version listed when running
      gparted from the command line.


DIRECTORIES
------------
data     - contains desktop icons

doc      - contains manual page documentation

help     - contains GParted Manual and international translations

include  - contains source header files

lib/gtest
         - contains Google Test C++ test framework libraries

m4       - contains macro files

po       - contains international language translations

src      - contains C++ source code


DISTRIBUTION NOTES
------------------
GParted uses GNU libparted to detect and manipulate devices and
partition tables.  The blkid command is also required to detect those
file systems which libparted doesn't detect.  (The blkid command should
be considered a mandatory requirement).

GParted also queries and manipulates the file systems within those
devices and partitions.  When available, it uses each file system's
specific commands.  The following optional file system specific packages
provide this support:

   btrfs-progs / btrfs-tools
   e2fsprogs
   exfatprogs
   f2fs-tools
   dosfstools
   mtools          - required to read and write FAT16/32 volume labels
                     and UUIDs
   hfsutils
   hfsprogs
   jfsutils
   nilfs-utils / nilfs-tools
   ntfs-3g / ntfsprogs
   reiser4progs
   reiserfsprogs / reiserfs-utils / reiserfs
   udftools
   util-linux      - required to create and check MINIX file systems
   xfsprogs, xfsdump


For dmraid support, the following packages are required:

   dmsetup         - removes /dev/mapper entries
   dmraid          - lists dmraid devices and creates /dev/mapper
                     entries

For GNU/Linux distribution dmraid support, the following are required:
   - kernel built with Device Mapping and Mirroring built.  From
     menuconfig, it is under Device Drivers -> <something> (RAID & LVM).
   - dmraid drive arrays activated on boot (e.g., dmraid -ay).


For LVM2 Physical Volume support the following command is required:
   lvm             - LVM2 administration tool
And device-mapper support in the kernel.


For accurate detection and reporting of Linux Software RAID Arrays the
following command is required:

   mdadm           - SWRaid administration tool


For LUKS support the following commands are required:
   cryptsetup      - LUKS volume administration tool
   dmsetup         - Device-mapper administration tool


Several more commands are optionally used by GParted if found on the
system.  These commands include:

   blkid           - [mandatory requirement] used to detect file systems
                     libparted doesn't, read UUIDs and volume labels
   hdparm          - used to query disk device serial numbers
   udisks          - used to prevent automounting of file systems
   hal-lock        - used to prevent automounting of file systems
   pkexec          - used to acquire root privileges in gparted shell
                     script wrapper, but only if available when gparted
                     source is configured
   gksudo          - alternatively used to acquire root privileges in
                     gparted shell script wrapper, second choice if
                     available when gparted source is configured
   gksu            - alternatively used to acquire root privileges in
                     gparted shell script wrapper, third choice if
                     available when gparted source is configured
   kdesudo         - alternatively used to acquire root privileges in
                     gparted shell script wrapper, fourth choice if
                     available when gparted source is configured
   xdg-su          - alternatively used to acquire root privileges in
                     gparted shell script wrapper, last choice if
                     available when gparted source is configured
   udevadm         - used in dmraid to query udev name
   yelp            - used to display help manual
                     (requires gvfs to be able to launch yelp)
   xhost           - used to grant root access to the X11 server, only
                     when configured to do so