Gatley
Posts: 38
Joined: Thu Jan 16, 2020 11:38 am

Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Thu Jan 23, 2020 12:49 pm

I have read how to put the file system on an external USB3 SSD, but cannot see if I can transfer a working OS from micro SD card in my Pi4B to a blank external USB3 drive. Can this be done please? My Pi 4B 4 gig is running a GPS tracking server (Traccar) on MYsql which was a bit of a bear to set up but is now running well, but I feel the constant data transfer to an SD card is not ideal for longevity.

Finally, a command of lsusb fails to show the same level of detail for the adapter in my Orico USB to SSD drive case as some people show, how do I asceratin this built into the case adapter is suitable for the Pi4 before I commence? Thanks.

User avatar
hansotten
Posts: 357
Joined: Fri Jul 13, 2012 6:01 am
Contact: Website

Re: Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Thu Jan 23, 2020 1:21 pm

Copying a running OS, it may work, but with an open database?

Remove your current SD, Boot from fresh SD with OS, add an external SD card reader, insert your SD with MysSQL system in that reader, copy to hard disk drive.
http://duinorasp.hansotten.com for Raspberry Pi and Arduino and ESP8266
http://retro.hansotten.nl for retrocomputing with the 6502 cpu

swampdog
Posts: 413
Joined: Fri Dec 04, 2015 11:22 am

Re: Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Thu Jan 23, 2020 3:07 pm

It's possible to do it with a running OS but you need to be familiar with linux, mountpoints and rsync and be able to make decisions on the fly (like shutting down services).

Things get a bit easier if you can shut it down. Just clone the sdcard to the USB then change the /boot/cmdline.txt accordingly.

However, if all you want to do is keep that mysql data secure you have another three options.

a) Move the mysql data folder to the ssd then use a symlink.
b) Use (eg: mysqldump) to make a backup once in a while.
c) timeshift (eg: stop mysql, manual timeshift, start mysql).
^^^point timeshift at the ssd.

Although (c) does screw up restoring (no grub) the rest of the system does get restored. I used it once on an rpi4. Hopefully others will be able to say how reliable timeshift is under raspbian.

(b) is what you want to achieve and if (c) is confirmed to be reliable then you get the bonus of being able to restore everything when the sdcard dies.

User avatar
thagrol
Posts: 3731
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Fri Jan 24, 2020 12:53 am

swampdog wrote:
Thu Jan 23, 2020 3:07 pm
Things get a bit easier if you can shut it down. Just clone the sdcard to the USB then change the /boot/cmdline.txt accordingly.
It ain't that simple.

Do you mean the /boot.cmdline.txt on the SD card or the one on the HDD?

With or without the SD card present? Hint: probably with as the 4B doesn't currently support booting from USB (unless that was announced today and I've missed it).

Having both the SD card present and an HDD cloned from it means two sets of partitons with identical UUID/PARTUUID. It's my understanding that the SD card ones will win so while you might think you're booting and running from the HDD you won't be.

Forum user ronr has released a tool for this and while I don't have the link a forum search for "USB boot made easy" and/or for his posts should find it. While I've not used his tool, I suspect it will be the easiest solution.
Arguing with strangers on the internet since 1993.

User avatar
thagrol
Posts: 3731
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Fri Jan 24, 2020 12:55 am

hansotten wrote:
Thu Jan 23, 2020 1:21 pm
Copying a running OS, it may work, but with an open database?

Remove your current SD, Boot from fresh SD with OS, add an external SD card reader, insert your SD with MysSQL system in that reader, copy to hard disk drive.
Yep. But that won't give you a system that boots on a 4B. See my previous post.
Arguing with strangers on the internet since 1993.

User avatar
HawaiianPi
Posts: 5994
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Fri Jan 24, 2020 2:58 am

While I agree RonR's script might be the simplest solution, it's actually not too difficult to DIY.

See here for RonR's script. Running Raspbian from USB Devices : Made Easy

For a DIY solution, try this.
  • Stop your data recording and database services, so that nothing is lost or left open during the OS transfer.
  • Use the Raspbian SD Card Copier to clone the working card to the USB drive, and be sure to check the New Partition UUIDs box.
  • Remove and reconnect the USB drive so the OS will recognize it.
  • Plug in a card reader with an empty FAT32 formatted micro SD card.
  • Copy the files from the USB "boot" partition to the empty FAT32 card. *
  • Edit /etc/fstab on the USB drive to mount the SD card as /boot. *

* Notes and instructions

I've made a few assumptions here, that you are using Raspbian with the desktop GUI and the default pi user. For the instructions below we're also assuming the empty FAT32 micro SD card is named "SDcard" so adjust as needed.

Code: Select all

cd /media/pi/boot
sudo cp -rv * /media/pi/SDcard
sudo nano /media/pi/rootfs/etc/fstab
Change the /boot mount from whatever PARTUUID it is, to /dev/mmcblk0p1 (replace PARTUUID=xxxxxxxx-01 with /dev/mmcblk0p1).
Save the file and exit (^x y enter).

That it!

Shut down the system, replace the micro SD card in the system with the one from the card reader, make sure the USB drive is connected and fire it up. It should load the kernel and overlays from the SD card, then run the main OS from the USB drive.

Restart your data services and you're good to go!
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

swampdog
Posts: 413
Joined: Fri Dec 04, 2015 11:22 am

Re: Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Fri Jan 24, 2020 6:13 am

thagrol wrote:
Fri Jan 24, 2020 12:53 am
swampdog wrote:
Thu Jan 23, 2020 3:07 pm
Things get a bit easier if you can shut it down. Just clone the sdcard to the USB then change the /boot/cmdline.txt accordingly.
It ain't that simple.

Do you mean the /boot.cmdline.txt on the SD card or the one on the HDD?

With or without the SD card present? Hint: probably with as the 4B doesn't currently support booting from USB (unless that was announced today and I've missed it).

Having both the SD card present and an HDD cloned from it means two sets of partitons with identical UUID/PARTUUID. It's my understanding that the SD card ones will win so while you might think you're booting and running from the HDD you won't be.

Forum user ronr has released a tool for this and while I don't have the link a forum search for "USB boot made easy" and/or for his posts should find it. While I've not used his tool, I suspect it will be the easiest solution.
Yeah, brain-fade on my part there. I was thinking about (c) and I'm starting to use LVM(*) so the whole UUID/PARTUUID and editing the target "fstab" disappeared into a void. Oops! ;-)

(*) I might write that up if anyone is interested.

Gatley
Posts: 38
Joined: Thu Jan 16, 2020 11:38 am

Re: Transfer an operating set up on microSD to external USB3 SSD drive (RP 4)

Fri Jan 24, 2020 1:59 pm

I used usb-boot and copied the files from the sd card to the ssd drive and after a lot of head scratching a new version of usb-boot was made and posted which solved my odd issues. It's working fine now, but many thanks for the posts which I have bookmarked.

Return to “Beginners”