Fixing Ubuntu to allow running gparted to format/configure disks
By: +David Herron; Date: January 28, 2018
Ubuntu is supposed to be a well-tested easy-to-use Linux, so when I wanted to run gparted to format a new drive it was frustrating I had to jump so many hoops to launch the program. Fixing the problem of launching gparted on Ubuntu turned out to be easy, but difficult to first determine what went wrong and the fix.
I was setting up a new Ubuntu system, and had two drives to configure. The Ubuntu installer seems to be capable of formatting/partitioning two drives during system setup, but that section of the installer is extremely confusing.
The system is an Intel NUC where I installed a 128GB M.2 SSD and a 2.5" laptop spinning drive (HDD). In the Ubuntu installer I installed Ubuntu to the SSD, and that set up a small partition on the HDD for
/boot/efi. That left a lot of unformatted unallocated space on the HDD, which I wanted to format for the
I could have done this to format that partition:
$ sudo fdisk /dev/sda
But that program is user hostile meaning the user interface is obtruse. I thought surely there must be a simple way to attach a drive, format it, add it to the
fstab and get on with things. I'm coming from almost 20 years using Mac OS X, and the Disk Utility is a wonderful piece of software.
The recommendation on Ubuntu is using gparted. Once I got it launched, I agree it is very good (though isn't so helpful for setting up LVM configurations). The problem was getting it running in the first place.
One must first install gparted because it isn't installed out of the box. That's just a matter of
$ sudo apt-get install gparted
Once installed there's a desktop icon - for the default Ubuntu user experience, click on that button in the lower-left corner with the grid of dots. That button opens the desktop application launcher listing all the applications. You can scroll through that to find gparted, or else enter gparted in the search box. Once you find the icon, you double-click ... and then find that nothing happens.
An error dialog did come up - unable to copy the users Xauthorization file
Running at the command line, I got this:
$ gksudo gparted Error copying '/home/david/.Xauthority' to '/tmp/libgksu-AGXt21': No such file or directory.
That's a little more precise of an error message. The thing is, there was no
.Xauthority file in my home directory. Would it have killed the Ubuntu team to initialize an empty file?
In any case, the application is properly telling me that it cannot copy that file, because the file does not exist. Maybe the application could have been written to initialize an empty file in that case?
$ touch .Xauthority
That's a simple workaround - but shouldn't the system be programmed to automatically do such things?
Once I did that, the output from
gksudo gparted was more promising, except it told me
cannot open display: 0.0.
That message means an X11 program was not able to open X11 display
0.0. There's a number of possible reasons, and a bit of DuckDuckGo searching came up with this note:
https://askubuntu.com/questions/968675/missing-xauthority-file-in-ubuntu-17-10 which referred to this thread: https://bugs.launchpad.net/ubuntu/+source/synaptic/+bug/1551951
The bottom line is this note:
The method pkexec uses to grant root (i.e. the user it runs its argument as) access to the real user's X display doesn't work under Wayland, but still using X (i.e. using Xwayland). Xwayland (at least as started by mutter/gnome-shell) is started without the "-auth" option and hence only grants access to the real user (adopting Wayland's security model). Hence there's no Xauthority file to grant access to other users. The workaround is to explicitly allow root to access the user's X display using
This suggestion did the trick:
$ xhost +si:localuser:root
This configures the
root user on
localhost to be able to open connections to the X11 display. One wonders why Ubuntu did not do this out of the box.
Bottom line is that those two steps - creating an Xauthority file - running
xhost to allow
root@localhost - together make it possible to start
gparted on Ubuntu. I was then able to format my disk. Getting it mounted as
/home was another adventure, however.