1

I just mounted sda2 to /mnt. How can I force a refresh of fstab so it can pickup the changes and insert a new line for sda2-/mnt?

0

You need to manually edit the file fstab. To find out what to put in there, issue the mount command and look at its output.

  • ok thanks. hard to believe Linux does not do this own its own. Side note - my sda1 in fstab has the UUID listed. If I run blkid I have a UUID for sda2 as well but when I run mount the only output is "/dev/sda2 /mnt ext3 rw 0 0" - will this do it or do I need to use the UUID as well in fstab? – user53029 Aug 30 '14 at 11:25
  • It is always preferable to use the filesystem's UUID in /etc/fstab because device filenames like /dev/sda2 might change if you repartition the disk, add or remove a disk. – uloBasEI Aug 30 '14 at 11:45
4

Linux definitely does provide the tools to do this automatically. Rather than using mount, you should be using findmnt.

man mount 2>/dev/null | 
grep -m1 -B1 findmnt

              For  more robust and customizable output use
              findmnt(8),  especially  in  your   scripts.

printf '%s%s 0 0\n' '/dev/disk/by-uuid/' \
    "$(findmnt -n -o UUID,TARGET,FSTYPE,OPTIONS /mnt)" |
sudo tee -a /etc/fstab

P.S. You'll want to have a look at man fstab for information about the 0 0 bit on the end there. They're related to freq and pass respectively. Whether or not their values above will suit you I cannot say. I can say that those are also output options available with findmnt - but asking it to report on them would make no sense for a disk that isn't already in /etc/fstab. You might also want to reconsider /mnt as the permanent mount point for your new /etc/fstab entry.

  • 1
    Ok I'll run some test on this. Thanks for the tip! – user53029 Aug 30 '14 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.