LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-24-2013, 04:00 PM   #1
zedmelon
Member
 
Registered: Jun 2004
Location: colorado, USA
Distribution: slack, oBSD
Posts: 119

Rep: Reputation: 24
rebuild overwritten fstab?


I'm in a time crunch. I did something stupid. I overwrote my /etc/fstab. Is there a way to rebuild fstab from files in /proc or /sys or /dev? Until I reboot, I'm fine, of course.

I generally use Slackware, but this is specifically Linux Mint, which in my experience uses UUID instead of /dev/sdX notation.

Any ideas?
 
Old 05-24-2013, 04:08 PM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
UUID notation is optional, however you can get currently mounted volumes by use of the 'mount' command (mount with NO arguments)
then you can re-build the fstab by hand, not sure how to obtain the uuid from a device node, you can, but device node (/dev/HDX or /dev/SDX etc... will still work)
 
Old 05-24-2013, 04:20 PM   #3
zedmelon
Member
 
Registered: Jun 2004
Location: colorado, USA
Distribution: slack, oBSD
Posts: 119

Original Poster
Rep: Reputation: 24
Today I'm a poster child for "Dumb Mistakes 101." For want of a single character--and adequate time to perform the task at hand--I have done something which has cost me time instead.
Quote:
Originally Posted by zedmelon View Post
I'm in a time crunch. I did something stupid. I overwrote my /etc/fstab.
Again, for the newbies reading this and the experienced guys ready to tell me I've made a foolish oversight, yes:
I should have made a backup.
I should have double-checked the command I executed as root.
I blithely and complacently edited a critical system file.
Ugh.

----------------------------------------
In case anyone's curious, I wrote a shell script to mass-duplicate 1500 USB thumb sticks from a single master (naturally this needs to be done last week, even though I only got the sticks yesterday). Initial testing has gone well, and I'm now writing a wrapper script to automatically copy to each new stick as it's connected. I'm using a predefined array of directories for mounting and executed this command to add them to my fstab, omitting one single character (line breaks are mine, to prevent line-wrappage on this forum page:
Code:
# [14.40.37] ROOT@mintlap [~] 5   for i in b c d e f g h i j k l m n o p q r s t u v w x y z;
do echo "/dev/sdZ1 /files/stickcp/Z auto noauto,user,rw 0 0" | sed "s/Z/$i/g" > /etc/fstab;
done
...needless to say, it *nearly* gave me what I wanted. My fstab should look like this:
Code:
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda8 during installation
UUID=17f434e1-eead-4684-b291-17931f5dbfc5 /               ext4    errors=remount-ro 0       1
# /files was on /dev/sda13 during installation
UUID=0fdc1742-1e36-4207-b13f-80ce10ca33d5 /files          ext4    defaults        0       2
# /home was on /dev/sda12 during installation
UUID=8f34b43d-5910-4d4f-96e9-aca2a2a2b816 /home           ext4    defaults        0       2
# /usr was on /dev/sda9 during installation
UUID=2fe320c9-7d03-4f3f-8d25-c13d2fd5767a /usr            ext4    defaults        0       2
# /usr/local was on /dev/sda10 during installation
UUID=eea3302f-7f7a-420f-b77b-e67a90ad5333 /usr/local      ext4    defaults        0       2
# /var was on /dev/sda11 during installation
UUID=c055187e-6f46-4a4e-9cce-9c28ff57faec /var            ext4    defaults        0       2
# swap was on /dev/sda14 during installation
UUID=8cc15220-5c35-4190-8988-f1a71cd49149 none            swap    sw              0       0
# from the slackware side:
# /dev/sda8        /os/mint         ext4        defaults         1   2
# /dev/sda2        /os/winxp        ntfs-3g     fmask=133,dmask=022 1   0
# /dev/cdrom      /mnt/cdrom       auto        noauto,owner,ro,comment=x-gvfs-show 0   0
# /dev/fd0         /mnt/floppy      auto        noauto,owner     0   0
#
# my phone:
UUID=1ADD-921F   /files/android   vfat noauto,user,exec,noatime,rw 0 0
/dev/sdc1 /files/stickcp/c auto noauto,user,rw 0 0
/dev/sdd1 /files/stickcp/d auto noauto,user,rw 0 0
...
/dev/sdz1 /files/stickcp/z auto noauto,user,rw 0 0
...but instead this is now my entire fstab:
Code:
/dev/sdz1 /files/stickcp/z auto noauto,user,rw 0 0
Ugh.

If anyone has a quick-n-dirty rebuild method, I'd love to hear it. I'll buy you a Sam Adams or a Guinness.

Last edited by zedmelon; 05-24-2013 at 04:22 PM. Reason: typo
 
Old 05-24-2013, 04:27 PM   #4
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
add your system volumes by hand to fstab than do something like this
Code:
#!/bin/bash
for letter in {c..z}
do 
echo /dev/sd"$letter"1 /files/stickcp/$letter auto noauto,user rw 0 0 >> /etc/fstab
done
 
Old 05-24-2013, 04:58 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Let the machine do it
Code:
mount | awk '/^\/dev\/sda/ {print $1,"\t",$3,"\t",$5,"\tdefaults\t0","\t0"}'
Note my sigline.

Last edited by syg00; 05-24-2013 at 05:00 PM. Reason: added defaults
 
Old 05-24-2013, 05:06 PM   #6
zedmelon
Member
 
Registered: Jun 2004
Location: colorado, USA
Distribution: slack, oBSD
Posts: 119

Original Poster
Rep: Reputation: 24
THanks. I guess I was just worried I wasn't going to get enough options to properly rebuild the file. But I suppose the lines output by 'mount' only bother showing options if they're not simply the default.

Quote:
Originally Posted by frieza View Post
not sure how to obtain the uuid from a device node
FWIW, blkid will show the rest.

Code:
# [15.20.43] ROOT@mintlap [~] 15   blkid
/dev/sda1: UUID="aa275bbc-d3e4-4df2-a4ad-24c4b5ef2f60" TYPE="ext4" 
/dev/sda2: UUID="F6E4C282E4C24519" TYPE="ntfs" 
/dev/sda3: UUID="a2f4b30d-580f-4c9a-a44b-01f5e5621c21" TYPE="ext4" 
/dev/sda5: UUID="87c14de1-7e1d-43b8-b52f-cfc191e756ca" TYPE="ext4" 
/dev/sda6: UUID="84b20f8a-4c92-4ee6-8e8b-8c6a93f7ae12" TYPE="ext4" 
/dev/sda7: UUID="9a69bf16-0ea9-455f-8f80-e7b1e1894acc" TYPE="ext4" 
/dev/sda8: UUID="17f434e1-eead-4684-b291-17931f5dbfc5" TYPE="ext4" 
/dev/sda9: UUID="2fe320c9-7d03-4f3f-8d25-c13d2fd5767a" TYPE="ext4" 
/dev/sda10: UUID="eea3302f-7f7a-420f-b77b-e67a90ad5333" TYPE="ext4" 
/dev/sda11: UUID="c055187e-6f46-4a4e-9cce-9c28ff57faec" TYPE="ext4" 
/dev/sda12: UUID="8f34b43d-5910-4d4f-96e9-aca2a2a2b816" TYPE="ext4" 
/dev/sda13: UUID="0fdc1742-1e36-4207-b13f-80ce10ca33d5" TYPE="ext4" 
/dev/sda14: UUID="8cc15220-5c35-4190-8988-f1a71cd49149" TYPE="swap"
/dev/sdb1: UUID="144C-AF42" TYPE="vfat"
Thanks again! Cheers
 
1 members found this post helpful.
Old 05-24-2013, 05:10 PM   #7
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
thanks, hehe, i've been using linux since before UUID even was a thing, hehe.
 
Old 05-24-2013, 05:12 PM   #8
zedmelon
Member
 
Registered: Jun 2004
Location: colorado, USA
Distribution: slack, oBSD
Posts: 119

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by frieza View Post
add your system volumes by hand to fstab than do something like this
Yeah, I'm not really sure why I used sed. Like I said, it's a crazy day. And I missed a greater-than symbol and wasted half an hour between at least three people.

Thank you both for your help.
 
Old 05-24-2013, 05:16 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
I forgot to do the swap - "swapon" will give you what you need to add.
As mentioned, UUID is optional - and doesn't always help. There are other options see under "/dev/disk".
 
Old 05-24-2013, 05:17 PM   #10
zedmelon
Member
 
Registered: Jun 2004
Location: colorado, USA
Distribution: slack, oBSD
Posts: 119

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by syg00 View Post
Code:
mount | awk '/^\/dev\/sda/ {print $1,"\t",$3,"\t",$5,"\tdefaults\t0","\t0"}'
beautiful, thanks
Code:
/dev/sda1 	 / 	 ext4 	defaults	0 	0
/dev/sda7 	 /tmp 	 ext4 	defaults	0 	0
/dev/sda8 	 /home 	 ext4 	defaults	0 	0
/dev/sda2 	 /usr 	 ext4 	defaults	0 	0
/dev/sda9 	 /files 	 ext4 	defaults	0 	0
/dev/sda3 	 /usr/local 	 ext4 	defaults	0 	0
/dev/sda5 	 /var 	 ext4 	defaults	0 	0
/dev/sda6 	 /var/log 	 ext4 	defaults	0 	0
..and why didn't you call me an hour ago and tell me to read your sig?
:-)
 
Old 05-24-2013, 05:26 PM   #11
zedmelon
Member
 
Registered: Jun 2004
Location: colorado, USA
Distribution: slack, oBSD
Posts: 119

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by frieza View Post
been using linux since before UUID even was a thing
Yeah, me too. Love the sig, BTW. There are days it feels my guitar is tuned by Bill Gates. Evidently today, my brain is as well. Append file, overwrite file, it's all the same...
 
Old 05-24-2013, 06:01 PM   #12
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by zedmelon View Post
Yeah, me too. Love the sig, BTW. There are days it feels my guitar is tuned by Bill Gates. Evidently today, my brain is as well. Append file, overwrite file, it's all the same...
why thanks ^^ hehe
i'll tell ya, when i first started learning how to use linux.. well, let's just say i was an absolute EXPERT on reinstalling linux.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I rebuild my /etc/fstab file? levicc00123 Debian 4 10-10-2004 09:58 AM
Stopping fstab being overwritten on boot martinjh99 Fedora 14 10-04-2004 08:47 PM
fstab file being overwritten MacLin Fedora 3 07-26-2004 01:25 PM
fstab overwritten? (RedHat 8) hoborocks Linux - Software 2 01-08-2003 11:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:03 PM.

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
Open Source Consulting | Domain Registration