Ran into the same problem.
Here is my solution, hope somebody will find it useful.
Issue:
- messed up /etc/fstab
- bootfail
- my PI is , as many, not hooked up to a screen or keyboard, running somewhere doing its job.
Solution:
- made a img backup of the broken pi image on a networkdrive
- reinstalled a older backup on the pi
- mounted the broken image on the networkdrive from the pi
- fixed fstab on the broken image
- reinstalled the image.
I needed the following:
- win32diskimager for imaging (i use a windows laptop i can carry around)
- a good way to mount the network drive AND the brokenimage.
- you could use a usb HD instead of the network hd, solution is the same.
Mouting networkdrive:
mount -t cifs "//networkshare/folder" "/localpath" -o username=user,vers=2.0
Here, -t cifs specifies samba as filesystem. (if not already, apt get install samba)
Here, -o username needed, password will be prompted.
Here, vers=2.0 for telling the right samba version , won't find out on its own. (can be 1.0 also)
Use dmesg | tail to get a log if mounting fails.
Mounting the image with resides in the networkmount:
How can I mount a Raspberry Pi Linux distro image?
Use the second block.
The broken fstab can be found in /etc/fstab
Edit, save, reinstall the image.
-------- if the link above fails, here what's in there:
You can't mount the image as a whole because it actually contains two partitions and a boot sector. However, you can mount the individual partitions in the image if you know their offset inside the file.
To find them, examine the image as a block device with fdisk -l whatever.img. The output should include a table like this:
Device Boot Start End Blocks Id System
whatever.img1 8192 122879 57344 c W95 FAT32 (LBA)
whatever.img2 122880 5785599 2831360 83 Linux
These are the two partitions. The first one is labelled "FAT32", and the other one "Linux". Above this table, there's some other information about the device as a whole, including:
Units: sectors of 1 * 512 = 512 bytes
We can find the offset in bytes by multiplying this unit size by the Start block of the partition:
1st partition 512 * 8192 = 4194304
2nd partition 512 * 122880 = 62914560
These can be used with the offset option of the mount command. We also have a clue about the type of each partition from fdisk. So, presuming we have directories /mnt/img/one and /mnt/img/two available as mount points:
mount -v -o offset=4194304 -t vfat whatever.img /mnt/img/one
mount -v -o offset=62914560 -t ext4 whatever.img /mnt/img/two
If you get an "overlapping loop" error here, your version of mount requires you to specify the size as well as the offset of the first partition. Unmount that, and use the number of blocks (57344) * 512 (= 29360128):
mount -v -o offset=4194304,sizelimit=29360128
-t vfat whatever.img /mnt/img/one
The second partition doesn't need a sizelimit since there's nothing after it in the image.
fstab
file and the line I added, but can't write/fix it...fstab~
file ...should that be there?)sudo nano /media/ubuntu/rootfs/fstab
, removed the line completely and put the SD card back in my Pi and it works! ...now it's not detecting my USB drive but I suppose that's a different issue. Care to make this into an answer?? Thanks so much! (Plus I learned how to boot to Ubuntu from usb!)