Happy Friday! Let's work through a hands-on scenario.
Scenario: a new, unformatted 5 GiB disk has been added to your system. Your task is to:
Create a new logical volume named lv_data01 that is 2 GiB in size.
Place it in a new volume group named vg_database.
Format the logical volume with the xfs file system.
Ensure it's automatically mounted on /srv/data at boot.
Without looking at the man pages, what are the main commands (pvcreate, vgcreate, lvcreate, etc.) you would use in order to accomplish this? Let's map out the steps!
My first step would be to use lsblk to identify the device name of the new disk...
# 1. Identify the new disk (e.g., /dev/sdb)
lsblk
# 2. Initialize the disk as a Physical Volume
pvcreate /dev/sdb
# 3. Create a Volume Group named 'vg_database'
vgcreate vg_database /dev/sdb
# 4. Create a 2 GiB Logical Volume named 'lv_data01'
lvcreate -L 2G -n lv_data01 vg_database
# 5. Format the Logical Volume with XFS filesystem
mkfs.xfs /dev/vg_database/lv_data01
# 6. Create the mount point directory
mkdir -p /srv/data
# 7. Get the UUID of the Logical Volume (for fstab)
blkid /dev/vg_database/lv_data01
# 8. Edit /etc/fstab to ensure automatic mounting at boot
vim /etc/fstab
# 9. Reboot the system to validate fstab mount
systemctl reboot
# 10. Verify it's mounted
df -h /srv/data
@shashi01I dont think so we need to reboot the system.
systemctl dameon-reload
mount -av
df -Th /srv/data
Thanks for the suggestion! You're right that mount -a can be used to validate the /etc/fstab entry immediately.
However, the original task requires ensuring that the mount happens automatically at boot , and the most reliable way to confirm that is with a reboot, which simulates the real boot process.
So while mount -a is useful for quick validation, rebooting guarantees that everything works as expected during the actual system startup, which is what the question asked for
The question specifically asks:
"Ensure it's automatically mounted on /srv/data at boot."
That means the system must:
Read the /etc/fstab entry during boot.
Successfully mount the logical volume to /srv/data without manual intervention.
@bnhashmi You are right that for this simple xfs disk/ LVM mounting , we dont need to reboot the system and mount -a will mostly check all the possible errors ( (bad device path, wrong UUID, missing filesystem driver, permission issues etc. )
You can also use nofail in the fstab for non critical entries.
However, please recall that if you have fstab entries for a network device such as NFS, hot plugged devices like USB, multipath, or which needs a custom kernel driver /module which is not available early during boot, then ordering , dependencies or race conditions are there - in this scenario a reboot is indeed the most reliable way to confirm the mount at boot time scenario.
In a systemd-based Linux, the system reads /etc/fstab (via systemd-fstab-generator) early in the boot process to convert fstab entries into .mount units in memory (in /run/systemd/generator/), which is then used by systemd to mount filesystems.
https://www.man7.org/linux/man-pages/man8/systemd-fstab-generator.8.html
I would nominate @Trevor @ARoumiantsev for this challenge!
Chetan,
I accept your nomination!!! Bear with me on the submission of
my solution. For the next 3 days, I'm a little engaged with a
Cybersecurity conference. For sure, after I'm free, I've got to
take a bite of this!!
sure @Trevor take your time !
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.