LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need to Repair Fstab (https://www.linuxquestions.org/questions/linux-newbie-8/need-to-repair-fstab-907623/)

DMTspice 10-11-2011 01:24 PM

Need to Repair Fstab
 
Hi- is there a command that I can run that will detect devices on my machine and then automatically repair my fstab file?

For some reason hard drive device names on my machine keep switching and it's screwing up my fstab. /dev/sda which was my primary drive is now /dev/sdb and /dev/sdb which was my secondary drive is now /dev/sda.

Thanks in advance.

T3RM1NVT0R 10-11-2011 01:48 PM

@ Reply
 
Well I am not aware of any tool that can automatically fix your /etc/fstab file. However, I would suggest you to mount the device using UUID instead.

You can find the UUID of a particular partition using the following command:

Code:

blkid /dev/sdaX
where X will be the partition number.

You can put this UUID in /etc/fstab as follows:

Code:

UUID="b6759bda-d6d7-4e1c-b184-d3b9ed29a641"      /            ext3      defaults        1 1

DMTspice 10-11-2011 01:55 PM

Okay, thanks. I'll give that a try.

DMTspice 10-11-2011 02:26 PM

Something I forgot to ask...

both hard drives on my machine are ext4, should I make one of them ext3 as in your example?

T3RM1NVT0R 10-11-2011 02:27 PM

@ Reply
 
Nope, that was just an example use ext4 instead.

It is just an example how you have to put entry in fstab. Instead of using /dev/sdax you have to use the UUID of the partition thats it. Rest all will remain the same.

DMTspice 10-11-2011 02:37 PM

Okay, here's the original file:

Quote:

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' 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>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=a97e6722-7e13-4f56-a96f-e46a841a29c6 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=3ee6628e-c69e-4925-8adf-3c4804acd33b none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
This is the new file:

Quote:

UUID="a97e6722-7e13-4f56-a96f-e46a841a29c6 / default ext4 0 1

UUID=3ee6628e-c69e-4925-8adf-3c4804acd33b none swap sw 0 0

/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0

proc /proc proc nodev,noexec,nosuid 0 0
Not sure what the last line "proc" is but I left it in there. Does this look okay to you?

T3RM1NVT0R 10-11-2011 02:44 PM

@ Reply
 
Wait. I can see that your orginal file uses UUID format then what was the issue?

In your new file I do not see quotes at both end. Either do not use them or use them at both ends:

New file:

Quote:

UUID="a97e6722-7e13-4f56-a96f-e46a841a29c6 / default ext4 0 1

UUID="54915623-8ff7-4b43-8c41-94485063590f none default ext4 0 0

/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0

proc /proc proc nodev,noexec,nosuid 0 0
Do you see that " is missing at the end of UUID. Where is the entry for swap? I can see it was there in your old file.

/proc is virtual file system that linux uses to manage file system and various processes. Leave it as it is.

Please do not reboot your system unless you are sure that /etc/fstab is 100% correct as it might result in system not booting up at all.

Make sure that you backup your existing /etc/fstab file.

DMTspice 10-11-2011 02:48 PM

I can remove the quotes- that's no problem. And I can add the following swap:
Quote:

UUID=3ee6628e-c69e-4925-8adf-3c4804acd33b none swap sw 0 0
The only line I'm not seeing in the original file is my second hard drive and its swap. Why is it not showing up?

T3RM1NVT0R 10-11-2011 02:52 PM

@ Reply
 
Do you mount the partitions on your second hard drive manually? If not, then it should be there in /etc/fstab.

Please paste the output of the following commands:

1.
Code:

df -h
2.
Code:

fdisk -l
3.
Code:

ls -l /dev/ | grep sd

DMTspice 10-11-2011 03:00 PM

I can manually mount the 2nd hard drive, but I can't get it to boot up.

1.
Code:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              71G  20G  48G  29% /
none                  998M  264K  998M  1% /dev
none                1004M  200K 1004M  1% /dev/shm
none                1004M  216K 1004M  1% /var/run
none                1004M    0 1004M  0% /var/lock


2.
Code:

Disk /dev/sdb: 120.1 GB, 120060444672 bytes
255 heads, 63 sectors/track, 14596 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00005599

  Device Boot      Start        End      Blocks  Id  System
/dev/sdb1  *          1      13120  105386368+  83  Linux
/dev/sdb2          13121      14597    11860128  82  Linux swap / Solaris

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000af1e6

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1        9328    74920960  83  Linux
/dev/sda2            9328        9730    3227649    5  Extended
/dev/sda5            9328        9730    3227648  82  Linux swap / Solaris

3.
Code:

lrwxrwxrwx  1 root root          4 2011-10-11 14:10 root -> sda1
brw-rw----  1 root disk      8,  0 2011-10-11 14:10 sda
brw-rw----  1 root disk      8,  1 2011-10-11 14:10 sda1
brw-rw----  1 root disk      8,  2 2011-10-11 14:10 sda2
brw-rw----  1 root disk      8,  5 2011-10-11 14:10 sda5
brw-rw----  1 root disk      8,  16 2011-10-11 14:10 sdb
brw-rw----  1 root disk      8,  17 2011-10-11 14:10 sdb1
brw-rw----  1 root disk      8,  18 2011-10-11 14:10 sdb2


PTrenholme 10-11-2011 03:05 PM

I've never tried using quoted strings in fstab, but I suppose it would work that way.

Here's an example of what you can do with fstab. It's my personal "standard" to create my system device mount points under the root directory with a name that starts with an upper-case letter (so the names won't collide with any of the usual Linux names) by use of a sudo mkdir /Name command.
Code:

#
# /etc/fstab
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=31ae217a-e756-4465-9e52-7f4040dcd2b8 /    ext4        defaults        1 1
UUID=65c92b08-9f35-4ba3-8c3e-e3c3f0efaf01 /boot ext4        defaults        1 2
tmpfs                  /dev/shm                tmpfs      defaults        0 0
devpts                  /dev/pts                devpts      gid=5,mode=620  0 0
sysfs                  /sys                    sysfs      defaults        0 0
proc                    /proc                  proc        defaults        0 0
UUID=8ECEC31BCEC2FA8B        /Win7                        ntfs-3g    defaults,rw        0 0
# Mirror
UUID=f52a4cdd-befe-4197-82dc-18a34eacf783 /Mirror btrfs    defaults        0 0
# USB 120 Gb drive
UUID=004a12e0-a205-4b45-8ca1-2a7ba8e6a73f /Fedora      ext4 defaults,noauto 0 0
UUID=5793cd07-fe28-4fae-9069-2ddca8a05420 /Fedora/boot ext3 defaults,noauto 0 0
# USB 500Gb drive
UUID=53eb35a6-dc07-4956-9376-a8ef7d10a9fb /Backup      ext4 defaults,noauto 0 0
UUID=ea123517-ebae-495c-afdd-08b3712638ef /Ubuntu      ext4 defaults,noauto 0 0
# SMB files (Note: This will cause a boot abort if the network is down.)
//Office/Books    /Smb/Books    cifs credentials=/.Smb_credentials,rw 0 0
//Office/Documents /Smb/Documents cifs credentials=/.Smb_credentials,rw 0 0
//Office/FEBE      /Smb/FEBE      cifs credentials=/.Smb_credentials,rw 0 0
//Office/Public    /Smb/Public    cifs credentials=/.Smb_credentials,rw 0 0
//Office/Sys      /Smb/Noaccess  cifs uid=0,gid=0,credentials=/.Smb_credentials,rw 0 0
//Office/Users    /Smb/Users    cifs credentials=/.Smb_credentials,rw 0 0


DMTspice 10-11-2011 03:12 PM

Maybe I should explain what I'm trying to do here so you guys can better help me.

I have two hard drives. My primary is Ubuntu. My secondary drive is slackware.

When I boot up, I get a grub splash screen. Slackware is one of the options, but if I select it, it won't boot up. I get error messages.

That's the short and sweet of it.

T3RM1NVT0R 10-11-2011 03:14 PM

@ Reply
 
Alright. As I can see from the output of fdisk -l and ls -l /dev/ | grep sd you have got 2 partitions on your second hard drive. Out of which 1 is swap and other is normal linux paritition. We will talk about swap partition your second drive later which is /dev/sdb2. First we will work on your /dev/sdb1 partition which is linux partition.

This is what you have to do:

1. Find out the UUID of /dev/sdb1 using blkid. Here is the syntax
Code:

blkid /dev/sdb1
2. Choose the directory where you want to mount this partition. Remember, either choose a blank directory or the directory on which you use to mount this partition before otherwise your existing data will become inaccessible.
3. Add the following line to your /etc/fstab:

Code:

UUID=      /mount_point        file_system        defaults    0 0
Where,

UUID= Will be the output of blkid command mentioned in the first step.
/mount_point= Will be the directory location where you want to mount the partition.
file_system= Will be the file system type like ext3 or ext4.
defaults= We will use the defaults option to mount the file system

Paste the output of 1st step and your /etc/fstab file after editing.

Make sure that you take backup of /etc/fstab file before making any changes.

I hope this helps.

DMTspice 10-11-2011 03:17 PM

Sounds good. Let me try this out and see what happens.

DMTspice 10-11-2011 03:34 PM

Didn't work. This time I got a different error message. When I select slackware from the grub splash screen it says media not yet present, or something like that. Luckily I was still able to get into ubuntu.

This is my fstab now:

Quote:

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' 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>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=a97e6722-7e13-4f56-a96f-e46a841a29c6 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=3ee6628e-c69e-4925-8adf-3c4804acd33b none swap sw 0 0
# linuxSlack on /dev/sdb1
UUID="54915623-8ff7-4b43-8c41-94485063590f /media/LinuxSlack ext4 defaults 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0


All times are GMT -5. The time now is 05:11 PM.