How to mount new logical volume (adding to fstab and mtab)?

66,921

Solution 1

Yes, you may edit /etc/fstab. /etc/mtab is the same format but a temporary file for what's mounted, leave it alone.

First, make a file system on it. Your system already has ext4 (there are other choices):

mkfs.ext4 /dev/ubuntu-vg/iew-vm-lv

Then find its unique UUID identifier, the line has the name you gave the LV:

blkid

Edit /etc/fstab and add a line similar to this. Your UUID and mount point will be different.

UUID=fcde9bb7-4311-41e2-986a-647a672ebf83       /mnt/example    ext4    defaults        0       2

Make this mount point directory and mount it:

mkdir /mnt/example
mount /mnt/example

Edit: a comment was concerned about LVM snapshots, which make a copy of the block device including its UUID. On the first time taking a snapshot, change its UUID:

tune2fs -U random

If using XFS file system, a -U option provides similar functionality, but with a different keyword:

xfs_admin -U generate

Either way, use the new UUID as the snapshot's mount entry.

UUID=b6c7724e-1c58-4960-8830-bfdeb34a9f4f           /mnt/example-snap    ext4    defaults        0       2

Every time the snapshot is taken, set this snapshot UUID.

tune2fs -U b6c7724e-1c58-4960-8830-bfdeb34a9f4f

You can use several ways to refer to block devices, including for LVM /dev/vg/lv and /dev/mapper/vg-lv. I default to UUID for the same reason the RHEL Storage Administration Guide does. It finds a given file system on any block device it may reside: partitions, LVM volumes, full drives.

Solution 2

Yes, you are supposed to manually edit the fstab file.

  • Create a mount point (directory) for the new file system. Say, /new
  • Format your new file system. For ext4 the command would be

mkfs.ext4 /dev/ubuntu-vg/iew-vm-lv

  • add the following line in /etc/fstab file

/dev/ubuntu-vg/iew-vm-lv /new ext4 defaults 0 0

Now you can mount it.

Share:
66,921

Related videos on Youtube

Nate
Author by

Nate

I'm a senior in college, majoring in EE and minoring in CS, with a passion for electronics and programming. I'm an entrepreneur and started a small hobby electronics company called FoxyTronics a few years ago, and am now working on launching a shopping website called PriceWombat.

Updated on September 18, 2022

Comments

  • Nate
    Nate over 1 year

    I created a new LV for the first time using this command:

    lvcreate -L 20G -n iew-vm-lv /dev/ubuntu-vg #create the new LV
    

    When I try running mount /dev/ubuntu-vg/iew-vm-lv, I get the following error:

    mount: can't find /dev/ubuntu-vg/iew-vm-lv in /etc/fstab or /etc/mtab

    How do I add the new LV to those files? Am I supposed to manually edit them?

    The current contents of the files are:

    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    /dev/mapper/ubuntu--vg-root--lv /               ext4    errors=remount-ro 0       1
    # /boot was on /dev/sda1 during installation
    UUID=93d4132c-7593-4a9d-901e-30d79db3082d /boot           ext2    defaults        0       2
    /dev/mapper/ubuntu--vg-home--lv /home           ext4    defaults        0       2
    /dev/mapper/ubuntu--vg-swap--lv none            swap    sw              0       0
    

    And:

    /dev/mapper/ubuntu--vg-root--lv / ext4 rw,errors=remount-ro 0 0
    proc /proc proc rw,noexec,nosuid,nodev 0 0
    sysfs /sys sysfs rw,noexec,nosuid,nodev 0 0
    none /sys/fs/cgroup tmpfs rw 0 0
    none /sys/fs/fuse/connections fusectl rw 0 0
    none /sys/kernel/debug debugfs rw 0 0
    none /sys/kernel/security securityfs rw 0 0
    udev /dev devtmpfs rw,mode=0755 0 0
    devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
    tmpfs /run tmpfs rw,noexec,nosuid,size=10%,mode=0755 0 0
    none /run/lock tmpfs rw,noexec,nosuid,nodev,size=5242880 0 0
    none /run/shm tmpfs rw,nosuid,nodev 0 0
    none /run/user tmpfs rw,noexec,nosuid,nodev,size=104857600,mode=0755 0 0
    none /sys/fs/pstore pstore rw 0 0
    /dev/sda1 /boot ext2 rw 0 0
    systemd /sys/fs/cgroup/systemd cgroup rw,noexec,nosuid,nodev,none,name=systemd 0 0
    /dev/mapper/ubuntu--vg-home--lv /home ext4 rw 0 0
    
  • vic
    vic over 5 years
    In my case, I just mounted the volume manually and copied the new entry in /etc/mtab to /etc/fstab. Do you see any issues with this approach?
  • John Mahowald
    John Mahowald over 5 years
    On Linux, /etc/mtab aka /proc/self/mounts does have mount lines suitable for /etc/fstab. Yes that will work, but you don't need to know about these files to manage mounts. Personally I add lines directly to fstab, which tests the syntax of fstab immediately.
  • vic
    vic over 5 years
    I'm not sure I follow when you say "fstab tests the syntax immediately". How do you do this? The only option I know of to check fstab is to run mount -a and look for errors.
  • John Mahowald
    John Mahowald over 5 years
    If you copied from mtab incorrectly, any fstab error might be detected later, perhaps after a reboot. I'm going to be editing fstab anyway, might as well do it first. Test by simply mounting the volume, any errors are usually informative.
  • GrGr
    GrGr over 5 years
    It is not recommended to use UUID for LVMs, because snapshots have the same UUID as the original volume. xanmanning.co.uk/2017/05/29/…
  • John Mahowald
    John Mahowald over 5 years
    Definitely possible to use UUID with LVM snapshots, see my edit. Or you can decide to refer to LVM volumes by name, if that is a stable identifier in your environment.