What did I break? No ethernet on pi after shutdown

I just bought a new case for my rasbperrypi4. I ran the command “sudo shutdown” on my console and waited for putty to close the connection, after a few seconds and went over to my pi and unplugged it, put it into the new case and replugged everything. Unfortunately my pi4 now does not work correctly anymore. It does not connect to the network (via ethernet) anymore. I can see that my router sees the device on port4, but it does not get an ip from my router. Unfortunately I have no minihdmi to connect a monitor here, so without a network I seem a bit lost. But maybe some has a few ideas.

My setup is Rasbian Buster, my SD loads everything from an SSD that is connected via USB 3.0. I was thinking maybe I pulled the plug too early and “destroyed” my SD/SSD, but wouldn’t my pi then still obtain an ip?

No that is done at the OS level.

Port link is good, means hardware should technically be fine, but you’ll need to go get a minihdmi cable to find out what the problem is.

So I checked the SSD and apparantly I messed up the fs. I reflashed the SSD and set everything up again, but now I cannot SSH into my os…

I’ve done this before so I don’t know why it’s not working this time. I SSH into my pi (booting from SD), change the boot to my SSD, reboot - I can see that it’s working because I can ping my pi - but then when I try to SSH into my pi (SSD) I get a “connection refused”. I double checked: the SSH file is on the /boot/ from my SSD.

console=serial0,115200 console=tty1 root=PARTUUID= d34db33f-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh

Is what I used for booting from SSD, and I made sure d34db33f-02 is the ID of /dev/sda2

you’d have to make sure the /etc/fstab is set correctly

that makes no difference :-/

the os removes the ssh file as soon as it has booted for the first time, or? because when I checked the SSD the ssh file was still in /boot/… I guess as long as I don’t have my hdmi cable here I won’t be able to know what is going on… Although none of this makes sense to me. I’m going to run off my sd as long as I have no idea what is going on.

If your fstab isn’t setup correctly you get the problem you’re experiencing.

The system should boot from SSD even without editing the fstab. So the problem must be somewhere else.

try a fsck of the filesystem if you can

Also SSHd is disabled by default on a Pi now, so if you connect a keyboard and login blind, you should be able to issue the command: sudo systemctl start sshd it should work as long as you keep track of your keystrokes :wink:

The thing is that I have the ssh file on the SSD… so… I still don’t know why it isnt working… tomorrow my cable will arrive. Either it’s just a stupid little thing that I missed or it won’t help at all :smiley:

I still don’t know what I did wrong, but I used a script from this site to boot from my SSD which worked perfectly:

#!/bin/bash

trap '{ stty sane; echo ""; errexit "Aborted"; }' SIGINT SIGTERM

BOOTBEG=8192
BOOTEND=532480
ROOTBEG=540672

MNTPATH="/tmp/usb-boot-mnt"

mntusb()
{
  MNTED=TRUE
  if [ ! -d "${MNTPATH}/" ]; then
    mkdir "${MNTPATH}/"
    if [ $? -ne 0 ]; then
      errexit "Unable to make ROOT partition mount point"
    fi
  fi
  mount "${USB_ROOT}" "${MNTPATH}/"
  if [ $? -ne 0 ]; then
    errexit "Unable to mount ROOT partition"
  fi
  if [ ! -d "${MNTPATH}/boot/" ]; then
    mkdir -p "${MNTPATH}/boot/"
    if [ $? -ne 0 ]; then
      errexit "Unable to make BOOT partition mount point"
    fi
  fi
  mount "${USB_BOOT}" "${MNTPATH}/boot/"
  if [ $? -ne 0 ]; then
    errexit "Unable to mount BOOT partition"
  fi
}

umntusb()
{
  umount "${MNTPATH}/boot/"
  if [ $? -ne 0 ]; then
    errexit "Unable to unmount BOOT partition"
  fi
  umount "${MNTPATH}/"
  if [ $? -ne 0 ]; then
    errexit "Unable to unmount ROOT partition"
  fi
  rm -r "${MNTPATH}/"
  MNTED=FALSE
}

errexit()
{
  echo ""
  echo "$1"
  echo ""
  if [ "${MNTED}" = "TRUE" ]; then
    umount "${MNTPATH}/boot/" &> /dev/null
    umount "${MNTPATH}/" &> /dev/null
    rm -rf "${MNTPATH}/" &> /dev/null
  fi
  exit 1
}

MNTED=FALSE

if [ $(id -u) -ne 0 ]; then
  errexit "Must be run as root user: sudo $0"
fi

PGMNAME="$(basename $0)"
for PID in $(pidof -x -o %PPID "${PGMNAME}"); do
  if [ ${PID} -ne $$ ]; then
    errexit "${PGMNAME} is already running"
  fi
done

rsync --version &> /dev/null
if [ $? -ne 0 ]; then
  errexit "rsync not installed (run: apt-get install rsync)"
fi

BOOT_PART="$(mount | sed -n 's|^\(/dev/.*\) on /boot .*|\1|p')"
ROOT_PART="$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')"
ROOT_TYPE="$(blkid "/dev/${ROOT_PART}" | sed -n 's|^.*TYPE="\(\S\+\)".*|\1|p')"
ROOT_DEV="${ROOT_PART:0:(${#ROOT_PART} - 1)}"
if [ "${ROOT_DEV}" = "mmcblk0p" ]; then
  ROOT_DEV="${ROOT_DEV:0:(${#ROOT_DEV} - 1)}"
fi

USBDEVS=($(ls -l /dev/sd? 2> /dev/null | sed -n 's|^.*\(/dev/.*\)|\1|p'))
if [ ${#USBDEVS[@]} -eq 0 ]; then
  errexit "No available USB mass storage devices found"
fi
for i in ${!USBDEVS[@]}; do
  USBDEVS[i]="${USBDEVS[i]} ${USBDEVS[i]} OFF"
done

if [ -b /dev/mmcblk0 ]; then
  USESDC=TRUE
else
  USESDC=FLASE
fi
if [[ "${USESDC}" = "TRUE" && "$(vcgencmd otp_dump | grep 17:)" = "17:3020000a" ]]; then
  whiptail --backtitle "USB Boot" --title "USB Boot Method"  --yesno "\nUse SD card to boot the USB device (recommended)?" 12 64
  YESNO=$?
  if [ ${YESNO} -eq 255 ]; then
    errexit "Aborted"
  elif [ ${YESNO} -ne 0 ]; then
    USESDC=FALSE
  fi
elif [[ "${USESDC}" = "FALSE" && "$(vcgencmd otp_dump | grep 17:)" != "17:3020000a" ]]; then
  errexit "Not a Raspberry Pi 3B+ or a Raspberry Pi 3B with OTP set and no SD card present"
fi

USB_DEST="$(whiptail --backtitle "USB Boot" --title "USB Mass Storage Devices" --notags --radiolist \
"\nSelect the USB mass storage device to boot" 13 47 ${#USBDEVS[@]} ${USBDEVS[@]} 3>&1 1>&2 2>&3)"
if [[ $? -ne 0 || "${USB_DEST}" = "" ]]; then
  errexit "Aborted"
fi

USB_BOOT="${USB_DEST}1"
USB_ROOT="${USB_DEST}2"

if [ "/dev/${ROOT_DEV}" != "${USB_DEST}" ];then
  whiptail --backtitle "USB Boot" --title "Replicate BOOT/ROOT Contents"  --yesno "\nReplicate BOOT/ROOT contents from /dev/${ROOT_DEV} to ${USB_DEST}?" 12 64
  YESNO=$?
  if [ ${YESNO} -eq 255 ]; then
    errexit "Aborted"
  elif [ ${YESNO} -eq 0 ]; then
    if [ $(mount | grep -c "^${USB_DEST}") -ne 0 ]; then
      errexit "USB mass storage device in use (mounted)"
    fi
    whiptail --backtitle "USB Boot" --title "WARNING"  --yesno "\nWARNING\n\nAll existing data on USB device ${USB_DEST} will be destroyed!\n\nDo you wish to continue?" 14 64
    YESNO=$?
    if [ ${YESNO} -ne 0 ]; then
      errexit "Aborted"
    fi
    echo ""
    echo "Replicating BOOT/ROOT contents from /dev/${ROOT_DEV} to ${USB_DEST} (this will take a while)"
    fdisk "${USB_DEST}" <<EOF &> /dev/null
p
o
n
p
1
${BOOTBEG}
${BOOTEND}
t
c
p
n
p
2
${ROOTBEG}

p
w
EOF
    partprobe
    mkfs.vfat "${USB_BOOT}" > /dev/null
    if [ $? -ne 0 ]; then
      errexit "Unable to create BOOT filesystem"
    fi
    dosfsck "${USB_BOOT}" > /dev/null
    if [ $? -ne 0 ]; then
      errexit "BOOT filesystem appears corrupted"
    fi
    if [ "${ROOT_TYPE}" = "f2fs" ]; then
      mkfs.f2fs -f "${USB_ROOT}" > /dev/null
    else
      mkfs.ext4 -F -q -b 4096 "${USB_ROOT}" > /dev/null
    fi
    if [ $? -ne 0 ]; then
      errexit "Unable to create ROOT filesystem"
    fi
    mntusb
    mkdir "${MNTPATH}/dev/" "${MNTPATH}/media/" "${MNTPATH}/mnt/" "${MNTPATH}/proc/" "${MNTPATH}/run/" "${MNTPATH}/sys/" "${MNTPATH}/tmp/"
    if [ $? -ne 0 ]; then
      errexit "Unable to create directories"
    fi
    chmod a+rwxt "${MNTPATH}/tmp/"
    rsync -aDH --partial --numeric-ids --delete --force --exclude "${MNTPATH}" --exclude '/dev' --exclude '/media' --exclude '/mnt' --exclude '/proc' \
--exclude '/run' --exclude '/sys' --exclude '/tmp' --exclude '/lost+found' --exclude '/etc/udev/rules.d/70-persistent-net.rules' \
--exclude '/var/lib/asterisk/astdb.sqlite3-journal' / "${MNTPATH}/"
    if [[ $? -ne 0 && $? -ne 24 ]]; then
      errexit "Unable to replicate BOOT/ROOT contents from /dev/${ROOT_DEV} to ${USB_DEST}"
    fi
    umntusb
    echo ""
    echo "BOOT/ROOT contents replicated from /dev/${ROOT_DEV} to ${USB_DEST}"
  fi
fi

PTUUID="$(blkid "${USB_DEST}" | sed -n 's|^.*PTUUID="\(\S\+\)".*|\1|p')"

if [ "${USESDC}" = "TRUE" ]; then
  if [ -b /dev/mmcblk0 ]; then
    while [ "$(blkid /dev/mmcblk0 | sed -n 's|^.*PTUUID="\(\S\+\)".*|\1|p')" = "${PTUUID}" ]
    do
      echo ""
      echo "WARNING : SD card (/dev/mmcblk0) and USB device (${USB_DEST}) have the same PTUUID (${PTUUID}) : SD card will boot instead of USB device"
      XXUUID="$(hexdump -n 4 -e '"%08X"' /dev/random | tr [A-Z] [a-z])"
      echo ""
      echo -n "Ok to change PTUUID on USB device (${USB_DEST}) to ${XXUUID} (y/n)? "
      while read -r -n 1 -s answer; do
        if [[ "${answer}" = [yYnN] ]]; then
          echo "${answer}"
          if [[ "${answer}" = [yY] ]]; then
            break
          else
            break 2
          fi
        fi
      done
      echo ""
      echo "Changing PTUUID on USB device (${USB_DEST}) to ${XXUUID}"
      fdisk "${USB_DEST}" <<EOF &> /dev/null
p
x
i
0x${XXUUID}
r
p
w
EOF
      PTUUID="${XXUUID}"
    done
    if [ ! -d "${MNTPATH}/" ]; then
      mkdir "${MNTPATH}/"
      if [ $? -ne 0 ]; then
        errexit "Unable to make BOOT partition mount point"
      fi
    fi
    mount "${BOOT_PART}" "${MNTPATH}/"
    if [ $? -ne 0 ]; then
      errexit "Unable to mount BOOT partition"
    fi
    sed -i "/^[[:space:]]*#/!s|^\(.*root=\)\S\+\(\s\+.*\)$|\1PARTUUID=${PTUUID}-02\2|" "${MNTPATH}/cmdline.txt"
    umount "${MNTPATH}/"
    rm -r "${MNTPATH}/"
  else
    errexit "No SD card present"
  fi
fi

mntusb
sed -i "/^[[:space:]]*#/!s|^\(.*root=\)\S\+\(\s\+.*\)$|\1PARTUUID=${PTUUID}-02\2|" "${MNTPATH}/boot/cmdline.txt"
sed -i "/^[[:space:]]*#/!s|^\S\+\(\s\+/\s\+.*\)$|PARTUUID=${PTUUID}-02\1|" "${MNTPATH}/etc/fstab"
if [ "${USESDC}" = "TRUE" ]; then
  sed -i "/^[[:space:]]*#/!s|^\S\+\(\s\+/boot\s\+.*\)$|${BOOT_PART}\1|" "${MNTPATH}/etc/fstab"
  sed -i "/dtoverlay=sdtweak,poll_once/d" "${MNTPATH}/boot/config.txt"
  sed -i '1{/^$/d}' "${MNTPATH}/boot/config.txt"
  if [ -f "${MNTPATH}/boot/wpa_supplicant.conf" ];then
    mv "${MNTPATH}/boot/wpa_supplicant.conf" "${MNTPATH}/etc/wpa_supplicant/wpa_supplicant.conf"
  fi
  cat <<EOF > "${MNTPATH}/etc/sdc-boot"
#!/bin/bash

EOF
  if [ "$(find ${MNTPATH}/boot/ -type f -iregex "${MNTPATH}/boot/ssh\(\.txt\)?" -print -delete)" != "" ]; then
    cat <<EOF >> "${MNTPATH}/etc/sdc-boot"
update-rc.d ssh enable && invoke-rc.d ssh start
EOF
  fi
  cat <<\EOF >> "${MNTPATH}/etc/sdc-boot"
ROOT_PART="$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')"
ROOT_DEV="${ROOT_PART:0:(${#ROOT_PART} - 1)}"
cp /usr/bin/raspi-config /tmp/raspi-config-usb-tmp
sed -i -E "s/mmcblk0p?/${ROOT_DEV}/" /tmp/raspi-config-usb-tmp
sed -i 's|    resize2fs /dev/$ROOT_PART &&|    ROOT_DEV=\\$(findmnt / -o source -n) \&\&\n    resize2fs \\$ROOT_DEV \&\&|' /tmp/raspi-config-usb-tmp
/tmp/raspi-config-usb-tmp --expand-rootfs &> /dev/null
rm /tmp/raspi-config-usb-tmp
sed -i '/sdc-boot/d' /etc/rc.local
rm /etc/sdc-boot
shutdown --no-wall -r now
exit 0
EOF
  chmod +x "${MNTPATH}/etc/sdc-boot"
  sed -i 's|^exit 0$|/etc/sdc-boot\nexit 0|' "${MNTPATH}/etc/rc.local"
else
  sed -i "/^[[:space:]]*#/!s|^\S\+\(\s\+/boot\s\+.*\)$|PARTUUID=${PTUUID}-01\1|" "${MNTPATH}/etc/fstab"
  if [ $(grep -c dtoverlay=sdtweak,poll_once "${MNTPATH}/boot/config.txt") -eq 0 ]; then
    sed -i '1s/^/dtoverlay=sdtweak,poll_once\n\n/' "${MNTPATH}/boot/config.txt"
  fi
fi
umntusb

DEV_LIST=()
if [ -b /dev/mmcblk0 ]; then
  DEV_LIST+=/dev/mmcblk0
fi
DEV_LIST+=($(ls -l /dev/sd? 2> /dev/null | sed -n 's|^.*\(/dev/.*\)|\1|p'))
if [ ${#DEV_LIST[@]} -gt 1 ]; then
  for i in ${!DEV_LIST[@]}; do
    if [ ${i} -lt $((${#DEV_LIST[@]} - 1)) ]; then
      j=$((i + 1))
      while [ ${j} -lt ${#DEV_LIST[@]} ]; do
        if [ "$(blkid "${DEV_LIST[i]}" | sed -n 's|^.*PTUUID="\(\S\+\)".*|\1|p')" = "$(blkid "${DEV_LIST[j]}" | sed -n 's|^.*PTUUID="\(\S\+\)".*|\1|p')" ];then
          if [[ "${DEV_LIST[i]}" != "/dev/mmcblk0" || "${DEV_LIST[j]}" != "${USB_DEST}" ]]; then
            echo ""
            echo "WARNING : ${DEV_LIST[i]} and ${DEV_LIST[j]} have the same PTUUID : $(blkid "${DEV_LIST[i]}" | sed -n 's|^.*PTUUID="\(\S\+\)".*|\1|p')"
          fi
        fi
      ((j += 1))
      done
    fi
  done
fi
echo ""
if [ "${USESDC}" = "TRUE" ]; then
  echo "SD card must remain in place to boot the USB device"
else
  if [ -b /dev/mmcblk0 ]; then
    echo "SD card must be removed to boot the USB device"
  fi
fi
echo ""

Jeeze thats a lot. I just wrote a new fresh image to the SD card, and deleted the other non boot partitions, copied my SSD boot folder over the one on the SDcard (I had made changes from stock) and then just modified the device it was booting from to ‘sda’ instead of ‘mmcblk0’ and it worked fine.

That’s what I did the last time (and this time - which for what ever reason did not work) and this is also what this script does. It also offers some extras though, like cloning the sd card to the ssd if you want.