We help IT Professionals succeed at work.

How to edit fstab in ubuntu server after failed boot

DanoliSolutions
DanoliSolutions asked
on
I am new to linux and setup an ubuntu 10.04 server for samba sharing. The initial 80gb disk was too small so I added a pc sata card, install a 1tb drive and powered on. All went well so I modified the fstab file to auto mount the drive (I got it working on the command line first). After the change, I rebooted and now it pauses with an error along the lines

fstab line 14 bad code...

I can't remember the error exactly but the problem is that I cannot boot to get in and edit it?

I tried the slax live cd but can't figure out how to mount the right disk/volume to get to the fstab file to fix it?

I would really appreciate some help, ta
Comment
Watch Question

Commented:
Boot the system from the Parted Magic live CD: http://partedmagic.com (only 86 mb of download)
On the desktop, choose the 'Mount tool' icon, mount your hard drive (or the partition containing /etc); a file manager window will open automatically.

If you are uncertain at any step, Parted Magic also contains screenshot tool and the possibility to easily connect to the internet. Post screenshots here.
Distinguished Expert 2017

Commented:
when booting, use the single user boot or use the ubuntu livecd or any other livecd.  YOu can then mount the disk and navigate to etc/fstab and edit/modify it as you see fit.

http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/
Software Developer
Commented:
You can do this without any extra CDs:

When booting, append this to the boot line from the GRUB boot screen:

init=/bin/bash

The system will boot to a shell prompt. Nothing will be mounted except the root device, which will be mounted read-only. You will need to type the full path name of many commands (but not if they're in /bin or /usr/bin if I remember right).

The first thing you need to do is make the root disk writable:

/sbin/mount -orw,remount /

Now you can fix your fstab:

cd /etc
vi fstab

Now you can put things back the way they were and continue the boot process:

cd /
/sbin/mount -oro,remount /
exec /sbin/init

For clarity, I've reproduced the actual commands below.
init=/bin/bash     # Append this to the boot line in GRUB or LILO boot menu
/sbin/mount -orw,remount /
cd /etc
vi fstab
cd /
/sbin/mount -oro,remount /
exec /sbin/init

Open in new window

Author

Commented:
How do I do he first bit, i.e. append the code the to boot line in grub / lilo.  How do I get into this boot screen?  
Hi!

Do this:
1. Boot your computer and hold SHIFT to enter the GRUB-menu
2. Select a Linux entry and press 'e' to edit it

Regards, Tobias

Author

Commented:
For info, when I boot to the live cd, I can see the primary hard drive which is 80gb but it says 80gb hard disk: 255Mb file system.  The only thing on there is a lost and found directory and a grub directory.  

I am guessing there is another partition but it is not showing? I cannot remember the setup but it would have been default settings.

Author

Commented:
I tried that (edit grub) and it looks to be that there may be some sort of disk fault?
Ther following are some of the errors on screen:

warning: bad format on line 14 fstab
/dev/sdc1 was not cleanly unmounted, check forced
mountall: mount /storage/disk1 [624] terminated with status 32
/dev/sdc1 211/124496 files 3.3% non contiguous
mountall fsck /boot [319] terminated with status 1
Sounds like the file system has crashed...

This is a tool that can find lost Ext2/Ext3/Ext4 partitions:
http://www.unformat-unerase.com/Intelligent_Scan.shtml

I haven't tested it though. But a guy called 'codaaladdin' has:
"I ended up purchasing the using R-Studio.  The ext4 recovery seems to work well.
I recovered 500GB out of 1500GB.  :(  Thanks for all of the help guys."

Regards, Tobias
Duncan RoeSoftware Developer

Commented:
Did you get the shell prompt first up? It sounds like either you didn't, or you didn't fix fstab - could you see anything wrong with line 14? I don't use GRUB so can't help you much with that, except when you append "init=/bin/bash" you must append a space first

Author

Commented:
duncan
I did append the line at the end of the other code but when it booted it gave the errors in my post (3 up from here).  I did this on a new line and did not put a new line at the end? I did not get to a shell as I was unable to type anything after receiving the errors.

Author

Commented:
Just had a thought, the /etc/fstab must be somewhere if it is saying line 14 is bad, so maybe not a failed disk?  Any thoughts?
It's in '/etc/fstab'
Duncan RoeSoftware Developer

Commented:
Yes you must have a good root partition somewhere, to have that message about /etc/fstab. So all may not be lost.
As for not getting the shell prompt, you can't be editing the boot line right  - init=/bin/bash *always* works with LILO. Rather than "e", try "a" (append): remember to type a space i.e. type " init=/bin/bash"

Author

Commented:
It looks like after I edit the boot line it does not save, when I esc out and e to go bak in it reverts to the unsaved. There is no option to save it?
No, I don't think so, but I might be wrong. I think you have to boot into Linux to be able to change the boot-files in Grub2 permanently.

Does it work to boot if you edit the Grub-menu?

Author

Commented:
If I edit the grub menu I can't get to a shell prompt?

Author

Commented:
If I add init=/bin/bash to the end of the grub boot menu it gives the same error as if I didn't edit it.
Distinguished Expert 2017

Commented:
do you have a ubuntu liveCD?
Boot the system using the liveCD, then you would need to mount the file system that has /etc/fstab i.e. /dev/sda1 it all depends on how your disk was setup.
mount -t ext3 /dev/sda1 /mnt
cd /mnt/etc/
vi fstab
.
Have you also tried the single user boot option instead of modifying grub to call vi /etc/fstab?

Commented:
If you used the Parted Magic live CD as I suggested in my first post, you would not only get an 'objective' external assessment of the state of your system, you would also have the best Linux diagnostic, repair and recovery tools right at your fingertip.

If your partitions mount, you'd be able to edit /etc/fstab. If they don't, you still could:
-inspect your detected partitions with GParted and fdisk
-run a filesystem check
-make a physical clone of your faulty HDD with ddrescue
-try to repair your filesystem (load backup superblocks) with TestDisk (will not work for Ext4, however)
-etc.

Attach output/screenshots here to get an analysis.

Author

Commented:
There is an LVM partition (sda5) on the sda disk with a red triangle in GParted?
Did you run GParted from the Ubuntu 10.04 LiveCD? (is it the newest version of GParted?)

Author

Commented:
Yes, this was what showed the sda5 lvm partition but did not say what was wrong with it or offer any way to fix it.
>I tried the slax live cd but can't figure out how to mount the right disk/volume to get to the fstab file to fix it?

Boot an Ubuntu LiveCD and start a terminal window. Check which partition you want to mount:

sudo fdisk -l

Mount the partition and set it as root (I use sda1 in the example below):

sudo mount /dev/sda1 /mntsudo mount --bind /dev /mnt/devsudo chroot /mnt

Edit your fstab.

Regards, Tobias

Author

Commented:
Unfortunately that didn't work, I have decided to wipe the server and reinstall.  I appreciate all the help offered.
Duncan RoeSoftware Developer

Commented:
Too bad. Last try in case you haven't wiped it yet - boot slax disk again then cat /proc/partitions. That will show you everything you could possibly mount. If you want, try Ubuntu live CD and see if there's any difference
Distinguished Expert 2017

Commented:
I think the complexity lies that it might be LVM volumes and the person may not recall how the partitions were setup nor interested in mounting one at a time and searching them.
IMHO, that a single user boot, should be enough to then modify the fstab.
But perhaps it did not work.
Duncan RoeSoftware Developer

Commented:
The trouble with a single-use boot is, it still tries to mount everything in fstab. The boot loader mounts the root though. That's why it works to boot a system then bypass init as I posted earlier. I thought I saw an explanation in a Q once about how to do that properly in GRUB, but I can't find it now.