Finally after so many tries the best and only working solution I found to automount logical volume is to use SystemD.
Create your <path-to-mount-folder>.mount
and <path-to-mount-folder>.automount
file under /etc/systemd/system/
media-username-wd.mount
[Unit]
Description=Western Digital external drive mount in media
[Mount]
What=/dev/wdhdd0/wd0
Where=/media/username/wd
Type=ext4
Options=defaults
[Install]
WantedBy=multi-user.target
media-username-wd.automount
[Unit]
Description=Western Digital external drive automount in media
[Automount]
Where=/media/username/wd
[Install]
WantedBy=multi-user.target
Install these new services
systemctl daemon-reload
systemctl disable media-mil-wd.mount
systemctl enable media-mil-wd.automount
The service .mount
is disabled and only the .automount
is enabled on purpose.
The former is used in the spirit of fstab to mount partition at startup and the
latter to automount partition when detected (external drive is plugged).
Although the existence of a .mount
file is required for every .automount
file created, it is not mandatory to enable the service.
Check status
systemctl start media-mil-wd.automount
systemctl status media-mil-wd.automount
I would like to thanks Tomáš Tomeček for its inestimable post Automount with SystemD that could have saved me hours of udev manual reading if only I discovered it sooner.
Finally this solution is now good enough for me it solve my main issue [Problem1] and also [Problem2] which is nice. However it does not resolve [Problem3] but I can live with that for now.
I am still open to any suggestions especially if they are either simpler or allow to solve the [Problem3] that is perfect integration in Nautilus.
Best Answer
An example LVM diagram:
The idea of LVM is it abstracts the logical volume away from the physical volume, such that multiple physical volumes will appear to the user a single continuous logical volume.
The root file system is in
/dev/file-server-vg/root
and the swap is in/dev/file-server-vg/swap
. The idea is we can actually have multiple real hard disks in the PV layer, and they can be all added into a Volume Group, which will allow them to all appear as a single continuous file system to the system at/dev/file-server-vg/root
.In this problem I have been using
/dev/file-server-vg/root
as a file server and it is running out of space. Luckily this system is on a virtual machine, and I was able to expand the physical volume/dev/sda
using the virtual machine manager. However, the increase in size doesn’t get automatically passed to the/dev/file-server-vg/root
file system. We need to do a few simple command to get this to work.Before we start, use
pvdisplay
to see which physical volumes are present. This will list all the physical volumes and the volume group that it belongs to. In this case we only have one physical volume that is/dev/sda3
.The current partition table can be listed by using
sudo parted
and thenprint
.In this example we want to expand the capacity from 155.56GiB to 255.56GiB. Using the virtual machine manager we can usually extend the disk space, and in this case we will expand it by 100GiB.
After expansion is successful, the resulting partition table (use
print free
) will look like the following. Please note the “Free space” shows 108GB (~100GiB).There are two way to expand the logical volume: Create a new partition and add this to the Volume Group, or Increase the same partition.
In my opinion, where possible, the second method is neater. Of course if
/dev/sda3
is a physical hard disk, and you bought another hard disk to expand the space, then it will be logical to use the first method.In parted type
resize 3 794MB 275GB
will resize partition 3 to take up all the free space, well almost:This is good enough, just 1MB not being used.
Next we will reboot the machine. This is needed to refresh the partition table.
What you will see now is that the physical volume has increased in size with
pvdisplay
This increase in size will be automatically passed to the volume group, using
vgdisplay
you get the following. Please notevgextend
doesn’t actually do what you might think it does. It doesn’t take up the free space, instead it is used for adding new physical volumes to a particular volume group.The logical volume doesn’t increase in size automatically. This is actually makes sense because the computer has no idea which logical volume you want to increase in size, or perhaps you want to create a new logical volume with the extra space in the volume group. So with
lvdisplay
you will see the following table, showing the/dev/file-server-vg/root
only has 153.26GiB, but don’t worry we are very close.The way to increase the logical volume is to use
lvextend -L +100GB /dev/file-server-vg/root
After that expand the file system with
resize2fs /dev/file-server-vg/root
And you are done. You can do
lvdisplay
to check that the/dev/file-server-vg/root
volume has extended to 253.26GiB