LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2011, 02:24 PM   #1
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Rep: Reputation: Disabled
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.
 
Old 10-11-2011, 02:48 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ 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
 
Old 10-11-2011, 02:55 PM   #3
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
Okay, thanks. I'll give that a try.
 
Old 10-11-2011, 03:26 PM   #4
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
Something I forgot to ask...

both hard drives on my machine are ext4, should I make one of them ext3 as in your example?
 
Old 10-11-2011, 03:27 PM   #5
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ 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.

Last edited by T3RM1NVT0R; 10-11-2011 at 03:29 PM.
 
Old 10-11-2011, 03:37 PM   #6
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
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?

Last edited by DMTspice; 10-11-2011 at 03:46 PM.
 
Old 10-11-2011, 03:44 PM   #7
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ 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.

Last edited by T3RM1NVT0R; 10-11-2011 at 03:46 PM.
 
Old 10-11-2011, 03:48 PM   #8
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
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?
 
Old 10-11-2011, 03:52 PM   #9
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ 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
 
Old 10-11-2011, 04:00 PM   #10
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-11-2011, 04:05 PM   #11
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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
 
Old 10-11-2011, 04:12 PM   #12
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
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.
 
Old 10-11-2011, 04:14 PM   #13
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ 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.
 
Old 10-11-2011, 04:17 PM   #14
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
Sounds good. Let me try this out and see what happens.
 
Old 10-11-2011, 04:34 PM   #15
DMTspice
Member
 
Registered: Sep 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
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

Last edited by DMTspice; 10-11-2011 at 05:06 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How modify fstab when its 'ro' in "repair filesystem" mode ? emuub Linux - Software 3 03-24-2011 08:46 AM
I need a Linux OS other than Ubuntu which has a repair disk or repair software jhmac77 Linux - Newbie 1 03-17-2008 08:04 AM
How to repair FStab after changin hard drives? Anjin Mandriva 4 03-22-2005 04:04 AM
repair my fstab alaios Linux - General 1 09-14-2003 03:37 PM


All times are GMT -5. The time now is 08:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration