Bartek
Posts: 5
Joined: Mon Jul 13, 2020 10:22 pm

Move OS back from USB to SD

Mon Jul 13, 2020 10:33 pm

Hi,

The USB stick that I'm using in my Raspberry 3B+ tends to overheat ans starts to malfunction. I'd like to move OS back to SD and enable ZRAM.

What's the easiest way to move OS from USB to SD?
Or we can approach it from a different angle - what exactly does 'move filesystem to USB' in the latest versions of raspi-config do? I could try to reverse these steps.

Thanks!
B.

fruitoftheloom
Posts: 23548
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Move OS back from USB to SD

Tue Jul 14, 2020 7:11 am

Bartek wrote:
Mon Jul 13, 2020 10:33 pm
Hi,

The USB stick that I'm using in my Raspberry 3B+ tends to overheat ans starts to malfunction. I'd like to move OS back to SD and enable ZRAM.

What's the easiest way to move OS from USB to SD?
Or we can approach it from a different angle - what exactly does 'move filesystem to USB' in the latest versions of raspi-config do? I could try to reverse these steps.

Thanks!
B.

RaspiOS (formerly Raspbian Buster) with Desktop has a program called SD Card Copier, which actually works with USB MSD.
Last edited by fruitoftheloom on Tue Jul 14, 2020 8:43 am, edited 1 time in total.
Rather than negativity think outside the box !
RPi 4B 4GB (SSD Boot) RaspiOS64 ARM64
Asus ChromeBox 3 Celeron is my other computer...

GlowInTheDark
Posts: 741
Joined: Sat Nov 09, 2019 12:14 pm

Re: Move OS back from USB to SD

Tue Jul 14, 2020 7:19 am

RaspiOS (formerly Buster)
Don't you mean: formerly Raspbian?

It's still Buster.

Buster is, effectively, a version #, not a brand name. Raspbian/RaspiOS is the brand name.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Move OS back from USB to SD

Tue Jul 14, 2020 7:21 am

Bartek wrote:
Mon Jul 13, 2020 10:33 pm
what exactly does 'move filesystem to USB' in the latest versions of raspi-config do?

How do you navigate to that option in raspi-config? I'm not seeing it. Version 20200707

But the answer is that raspi-config is a shell script. So it is a text file. So you can examine it to determine what action it takes for any given option.

Bartek
Posts: 5
Joined: Mon Jul 13, 2020 10:22 pm

Re: Move OS back from USB to SD

Tue Jul 14, 2020 11:25 am

RaspiOS (formerly Raspbian Buster) with Desktop has a program called SD Card Copier, which actually works with USB MSD.
I imagine this tool is really useful when copying USB->USB or SD->SD. However, I expect that USB->SD and SD->USB not only requires moving partitions, but also applying some changes to config (mount points?). Can this tool handle that?
How do you navigate to that option in raspi-config? I'm not seeing it. Version 20200707
But the answer is that raspi-config is a shell script. So it is a text file. So you can examine it to determine what action it takes for any given option.
Hehe, I must say I'm a cheater. I have several Raspberry Pis and on the one that I have issues with I run openHabian instead of Raspbian :). OpenHabian is built on top of Raspbian and it the latest version it still does have the 'move to usb' option in openhabian-config. Anyway, thanks for the hint, I'll take a look at contents of openhabian-config.

Thanks!
B.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Move OS back from USB to SD

Tue Jul 14, 2020 12:12 pm

Bartek wrote:
Tue Jul 14, 2020 11:25 am

Hehe, I must say I'm a cheater. I have several Raspberry Pis and on the one that I have issues with I run openHabian instead of Raspbian


I'd call it 'time-waster.' Blocking.

Bartek
Posts: 5
Joined: Mon Jul 13, 2020 10:22 pm

Re: Move OS back from USB to SD

Tue Jul 14, 2020 9:26 pm

I'd call it 'time-waster.' Blocking.
I wouldn't go that far. Openhabian is built on top of Raspbian. I guess all core stuff is taken from Raspbian without modifications. My question was related to such core stuff that Openhabian inherited from Raspbian, so to me this is the right forum to ask such a question. :roll:

Anyway, thanks for the hint to look at scripts. Under /opt/[NAME MASKED NOT TO PISS ANYONE OFF]/functions there's ext-storage.bash. Contents seem to be taken from Raspbian without any modifications, so this might be useful for users of (older versions of?) Raspbian.

It seems that most steps are responsible for creating partitions and copying stuff. The only extra changes seem to be the ones related with fstab and cmdline.txt.
echo
echo "adjusting fstab on new root"
# adjust system root in fstab
sed -i "s#$rootpart#$NEWROOTPART#" /mnt/etc/fstab

echo "adjusting system root in kernel bootline"
# make a copy of the original cmdline
cp /boot/cmdline.txt /boot/cmdline.txt.sdcard
# adjust system root in kernel bootline
sed -i "s#root=$rootpart#root=$NEWROOTPART#" /boot/cmdline.txt

Bartek
Posts: 5
Joined: Mon Jul 13, 2020 10:22 pm

Re: Move OS back from USB to SD

Sun Aug 02, 2020 9:17 pm

Hi,

I've finally found some time to look into this issue and managed to move the filesystem back to the second partition on my SD card. Below is a short description of what I've done. I'm definitely not an expert, so some of the steps below might not be required
.
BTW, these steps aren''t specific to Openhabian. These should work with Raspbian (at least some versions of Raspbian) without any modifications.

DISCLAIMER:
- Use at your own risk!
- These were tested against a fairly new Openhabian distribution (based on Raspbian Buster). Not sure how partitions are organized in the latest versions of Raspberry Pi OS. For sure in older version of Raspbian (those published before mid 2017) they were organized differently than in Buster. You should examine the contents of /opt/<my distribution name>/functions/ext-storage.bash before you start.
- These steps only show the happy path - when second partition on SD card is still there and partion uuid is properly set in /boot/cmdline.txt.sdcard.

1) Check if second partiton on your SD card is still there and remove its contents.

Code: Select all

sudo mount /dev/mmcblk0p2 /whatever
cd /whatever
rm -rf *
sudo umount /whatever
2) Make sure partition UUIDs match

a)

Code: Select all

sudo blkid -p /dev/mmcblk0p2
should print something like this:

Code: Select all

/dev/mmcblk0p2: LABEL="rootfs" UUID="8d008fde-f12a-47f7-8519-197ea707d3d4" VERSION="1.0" TYPE="ext4" USAGE="filesystem" PART_ENTRY_SCHEME="dos" PART_ENTRY_UUID="04c099f8-02" PART_ENTRY_TYPE="0x83" PART_ENTRY_NUMBER="2" PART_ENTRY_OFFSET="540672" PART_ENTRY_SIZE="30575616" PART_ENTRY_DISK="179:0"
b)

Code: Select all

cat /boot/cmdline.txt.sdcard 
should print a command with some PARTUUID, e.g. "PARTUUID=04c099f8-02"

Make sure PARTUUID from the latter matches PART_ENTRY_UUID from the former.

3) May the God of your choice bless you ...
This one is Openhabian-specific:

Code: Select all

sudo systemctl stop openhab2
These should be ok to be run against both Raspbian & Openhabian:

Code: Select all

sudo mount /dev/mmcblk0p2 /mnt
sudo rsync -aAXH --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/boot/*"} / /mnt
sudo cp /boot/cmdline.txt.sdcard /boot/cmdline.txt

sudo reboot
... and pray ...

Bartek
Posts: 5
Joined: Mon Jul 13, 2020 10:22 pm

Re: Move OS back from USB to SD

Sun Aug 02, 2020 9:17 pm

Forgot to say:

Have fun!

Return to “General discussion”