6

My Pi was working until I followed this tutorial on how to auto-mount a specific drive on RPi boot. I added the following to the fstab file:

UUID="123091823" /media/pi/"Orange Passport" auto defaults,user,nofail 0 2    

I believe I messed up because I put quotes around the UUID (the above is a random string, I forget exactly what the UUID is), when there shouldn't be any. Now I can't even boot to the command line. I constantly get this error:

enter image description here

And in the bottom middle-left of the screen, I see emergency.service I hit ENTER and after a minute or two, the same issue pops up, only now it says plymouth-start.service in the middle-left corner.

I've edited the cmdline.txt to have init=/bin/sh at the end, and tried to boot, following the instructions here. I've also tried removing that and adding systemd.unit=rescue.target, and that doesn't get me to a command prompt either.

How can I get back in to my Pi to fix this?

(Edit: I've unplugged the USB External drive too, just to be sure).

BruceWayne
  • 197
  • 1
  • 1
  • 9
  • 1
    To get a linux life system on your computer and fix it from there might be the easiest way. – jake Mar 28 '19 at 03:52
  • @jake - Yeah, I am struggling now to get windows to use Ext2Fsd, as I keep seeing that recommended. I'm on Windows 10 and can't get the service to start ("Ext2Fsd could NOT be started."), so now I'm troubleshooting that but getting nowhere fast. I did get a read-only viewer (Disk Internals Linux Reader), and can indeed see the `fstab` file and the line I added, but can't write/fix it... – BruceWayne Mar 28 '19 at 03:58
  • I can't help you with Windows, because I don't use it. What about flashing Ubuntu to an usb stick? From there you can edit everything. – jake Mar 28 '19 at 04:07
  • @jake ah, good idea. Did that, removed the quotes from the file ...still get errors. I will remove that line completely from fstab and see if it fixes things. (There's also an `fstab~` file ...should that be there?) – BruceWayne Mar 28 '19 at 05:30
  • @jake I did `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!) – BruceWayne Mar 28 '19 at 05:34

4 Answers4

5

If you want to edit files on the root partition, an easy way is to download some Linux distribution (Ubuntu for example) flash it to an USB stick and boot from it. Here is a tutorial how to do it.

When you successfully booted Ubuntu you can edit your fstab with sudoedit /media/ubuntu/rootfs/etc/fstab

If you want to edit it from "Files" hit Ctrl + l and type admin:///media/ubuntu/rootfs/etc and open the file.

jake
  • 1,129
  • 7
  • 21
  • That's such an awesome tutorial for someone totally new to this (note for others, I had to press "e" and add `nouveau.modeset=0` to the end of the Linux line for it to work from my Dell). Any difference in `sudoedit` and `sudo nano`? – BruceWayne Mar 28 '19 at 05:45
  • [It's not an good idea to open your editor as root](https://superuser.com/a/1062377) – jake Mar 28 '19 at 05:48
  • thanks! It's a little over my head but I get the explanation for why to use `sudoedit`. I'll definitely read more in to that, cheers :D – BruceWayne Mar 28 '19 at 05:50
  • @BruceWayne I'm glad I could help you! – jake Mar 28 '19 at 05:51
4

You can repair most such problems on the Pi by rebooting to a root shell.

  1. Append init=/bin/sh at the end of cmdline.txt and reboot.
  2. After booting you will be at the prompt in a root shell.
  3. Your root file system is mounted as readonly now, so remount it as read/write
    mount -n -o remount,rw /

You can then edit files.

If you don't get a prompt then presumably the filesystem is not mounted, and you won't be able to run any commands.

You can fix on any Linux system - this can be one on the Pi itself by booting from a new SD Card, and mounting the old card in a SD Card reader.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • I can't do that. I tried adding `init=/bin/sh` to the end, and kept getting the same error on startup. I also tried `init=/bin/bash` (saw that somewhere). I didn't get to the prompt in root shell. – BruceWayne Mar 28 '19 at 04:14
  • If it `Can't find PARTUUID=ab12345c-02` (the "0**2**" is important), then you can `mount -n -o remount,rw /dev/mmcblk0p2` (see the "**2**" at the end). – Milan Jaros Jan 11 '20 at 01:23
  • @MilanJaros I ran the above command, but I get the message: /dev/mmcblk0p2: mount point not mounted or bad option. Any idea? – ilCosmico Sep 11 '21 at 10:44
2

For anyone that hits this problem that only has a mac, you can install this software and use the free 10-day trial to mount the sd card on your mac and just edit the /etc/fstab file directly on your mac.

https://www.paragon-drivers.com/en/extfsmac/

It's not free software though so just don't mess up your fstab again ;)

matt burns
  • 131
  • 3
1

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.

solution
  • 11
  • 1