0

I am using a lent 3B+ and now I will buy my own 4B. I have PMS, Pi-Hole, and Samba Server. I don't want to reinstall and re-configure everything again, is there an easy alternative?

1

One easy way to do this is with the image-utils tool. It copies everything on your SD card, and writes it to a file. You can use your desktop machine (or your RPi) with balena etcher or rufus to write this image file to another SD card.

Note: This procedure assumes that the RPi 3B you've been using is running the Buster version of RPi OS. Buster was released in mid-2019, so it has been around for about 18 months now. The RPi 4B will not run an older version of the OS. Therefore: If the RPi 3B has Stretch, or an even older OS, you'll need to do a fresh install of Buster on the RPi from scratch using these instructions - or similar.

If you're not sure what version of the OS you are running on the RPi 3B, you can check that from the CLI:

$ cat /etc/os-release

You may see this output:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
...

If it doesn't say buster, you can quit reading this, and start a fresh install on your 4B.

If your RPi 3B is running Buster, following is a step-by-step process for duplicating the entire OS, including all files, preferences, settings, configurations, etc. This procedure uses the CLI/terminal:

1. Install git on your Raspberry Pi if you don't already have it:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git

2. Clone the image-utils repo to create a local copy on your Raspberry Pi

$ cd
$ git clone https://github.com/seamusdemora/RonR-RPi-image-utils

This will create a new folder in your home directory: RonR-RPi-image-utils

3. Mark all of the scripts executable:

$ chmod 755 ~/RonR-RPi-image-utils/image-*

4. Verify that everything is in place:

$ ls -l ~/RonR-RPi-image-utils
-rwxr-xr-x 1 pi pi 12773 Aug 14 21:54 image-backup
-rwxr-xr-x 1 pi pi  1534 Apr 23  2020 image-check
-rwxr-xr-x 1 pi pi  2772 Apr 23  2020 image-compare
-rwxr-xr-x 1 pi pi  2685 Apr 28  2020 image-info
-rwxr-xr-x 1 pi pi  1667 Apr 23  2020 image-mount
-rwxr-xr-x 1 pi pi  5640 May  4  2020 image-set-partuuid
-rwxr-xr-x 1 pi pi  4148 Aug 11 20:11 image-shrink

You will also see README file... Check that all 7 files listed above are present, and have the permissions you see above (-rwxr-xr-x).

5. Select an external ext4 drive as the image file destination

Since the image file may be large, it must be written to an external drive; specifically an external drive under /mnt or /media. Verify that you have a suitable drive mounted in one of those locations - if not, you must mount it. In this case, the drive at /mnt/Passport2TB will be used

$ ls -l /mnt
total ...
drwxr-xr-x 6 pi   pi   4096 Jul 11 11:17 Passport2TB  
$ lsblk --fs
NAME        FSTYPE LABEL       UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda
└─sda1      ext4   PASSPORT2TB 86645948-d127-4991-888c-a466b7722f05    1.5T    10% /mnt/Passport2TB
mmcblk0
├─mmcblk0p1 vfat               6969-16D1                             200.3M    22% /boot
└─mmcblk0p2 ext4               f6ea6ef9-68be-479d-b447-5f76391cc02f     26G     6% /

6. Create your "backup" image file:

NOTES:

  1. In the following "dialog", the user (your) inputs are enclosed in braces {}
  2. In response to the prompt, "Image file to create?", use the full path
  3. In response to the prompt, "Image file to create?", use an .img file extension
$ $ sudo RonR-RPi-image-utils/image-backup

Image file to create? {/mnt/Passport2TB/RPi4Bimage_20201202.img}

Initial image file ROOT filesystem size (MB) [2216]?  {↵}

Added space for incremental updates after shrinking (MB) [0]?  {222↵}

Create /mnt/Passport2TB/RPi4Bimage_20201202 (y/n)? {y}

Starting full backup (for incremental backups, run: RonR-RPi-image-utils/image-backup /mnt/Passport2TB/RPi4Bimage_20201202)

## It will take some time to create the image file... but eventually (a few minutes)

...

e2fsck 1.44.5 (15-Dec-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0p2: 55598/157760 files (0.6% non-contiguous), 495225/623872 blocks
$ 

Recap

You should now have a file that contains an image of the "root and boot" partitions of your RPi OS from the SD card on your RPi 3B. You may now transfer this file to your Windows/Mac/Linux desktop, where you can use rufus or etcher (for example) to write (not copy) this image file to an SD card. Insert this SD card into your RPi 4B, and it should boot with no problems.

That should do it. Let us know if you have questions.

13
  • Old boot partitions were of ~50MB and thus firmware for the 4B is not installed during upgrades (no space left). This was an issue when I tried to move from 3B+ to 4B in my case. Does the util allow writing to a different partition setup so that one may increase boot and install 4B firmware?
    – FelixJN
    Dec 3 '20 at 11:15
  • I have seen that stock 3b+ boot being less for 4b firmware. what's the solution for that? because everything else seems to be in place. Dec 3 '20 at 13:48
  • lsblk --fs NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT sda └─sda1 ntfs TOSHIBA EXT 843671A53671993E 731.9G 61% /mnt/disk1 mmcblk0 ├─mmcblk0p1 vfat boot A764-6923 198.2M 21% /boot └─mmcblk0p2 ext4 rootfs 2f4adfbf-32e5-44ec-9323-1d08cbe8c29e 5.4G 77% / as you can see my boot is 200M that may be because I am using a 32 gb or that I am update with debian 10 - buster Dec 3 '20 at 13:57
  • sorry for the bad formatting I am very new to asking questions cos I was able to make it so far by just googling and finding that someone has already asked that question before. Dec 3 '20 at 14:01
  • @AbbasMerchant: I'm not completely clear on the meaning of your comments, but you should know this: The 3B+ and the 4B are very different with respect to the "firmware". The 4B has additional hardware in the form of an EEPROM for storing firmware. The 4B ships from the factory with some version of the firmware installed in the EEPROM - it could not boot without it. The 3B+ "firmware" may be included in the image file (created as above), but it will not affect your 4B. You do not need to worry this point.
    – Seamus
    Dec 3 '20 at 22:21
0

Just copy the SD card. Everything is stored on the card.

1
  • One thing to be careful of is if you have set a static IP address up for Pi-Hole on your router and not your Pi as the change over will give a new MAC address and therefore a new IP address unless you have set either the MAC or IP up on that card.
    – user115418
    Dec 2 '20 at 20:00
0

Provided the Pi has an up-to-date Raspberry Pi OS it will work on ALL Pi models.

It is POSSIBLE to configure Raspberry Pi OS in such a way that it operates differently on different models, but not by default. If you examine /boot/config.txt you would see these.

Setting a static IP Address is one of potential problems.

1
  • 1
    I am using LAN cable and I haven't set any static IP anywhere to the best of my knowledge. Dec 3 '20 at 14:02
0

Since I had to do the same, here is how I managed.

First off: While Raspberry Pi OS is now compatible with all versions, it looks like the older installs created the boot partition too small, thus relevant firmware files for the Pi 4(B) cannot be put where they need to be. Thus increasing the boot partition is a must. If you are lucky enough to already have had a boot partition of at least 100MB, you may just upgrade and use the SD as is. However most likely you went with the old standard and should have some 50MB for boot.

Prerequirements: A linux/UNIX OS on a PC (may be a live version, too), SD-card adapter to said PC and either enough space for the image (dangerous) or preferably a second SD-card.

Since you run SAMBA and seem to have quite a bit of modifications, I assume you are advanced regarding CLI, the dangers of dd(!!!), and e.g. device files.

1. Update OS

Ensure that you are running the latest version of Raspberry Pi OS, on the Pi run:

apt update && apt upgrade

Now cat /etc/issue should get you Rasbpian 10 (= buster).

2. Create image of existing root partition

Take out the SD-Card and connect it to your PC. I'll assume the device is /dev/sdX

2a. Preparations for speeding up dd

Mount the root partion (/dev/sdX2) of your RPi OS and create a dummy file anywhere. Write zeros to it.

dd if=/dev/zero of=<path/to/dummy/file/on/SD/card/zerofiller.dummy>

The reasoning behind this is that dd copies empty areas of a partition, too, however NUL-bytes can be skipped while creating the image. Of course this means one writing for the whole SD Card, thus don't do that too often (may reduce lifetime). The boot-partition is rather small, zero-filling can be skipped there.

2b. Creating an image

In this case I'll create an image of the boot and root partitions and save it on the PC's hard drive. If you happen to have two SD-Card adapters and the new SD card is larger, you may directly copy the image to the new SD-Card and save some time. (see point 4)

dd if=/dev/sdX1 of=/home/joe/RPi_boot.image bs=4M 
dd if=/dev/sdX2 of=/home/joe/RPi_root.image bs=4M conv=sparse

Now conv=sparse is for skipping the NUL bytes from 2a. The image is now of the original size of the partition. In order to shrink it to the size of the actual data only, use this:

#this check is a prerequirement before running the resizing
e2fsck -f RPi_root.image
resize2fs -M RPi_root.image

The skrinking is necessary if you want to either reuse the old SD or have a new one of the same size as the old one. Why? The new boot partition is sligtly larger, this the old root won't fit in the leftover space. For a new, larger SD, this is not needed. dd performance should not vary, as the empty space was filled with zeros. By the way: the new boot partition size goes from ~50MB to ~250MB, thus roughly 200MB of free space in the original root are assumed.

3. Preparing the new SD

Now here is the problem: if you are lucky to have a new SD, use this, if you must reuse the old one, this is where the danger comes in, as you need to format it - so make sure the images from 2b are good!

I'll assume the new SC-Card is on /dev/sdY

3a. Download RPi OS image

The light version will do. Unzip the image and copy it to the (new) SD Card.

dd if=/home/joe/2020-08-20-raspios-buster-armhf-lite.img of=/dev/sdY bs=4M

(At this point you may check if the Pi properly boots with this. Then back to the PC with the SD-Card).

3b. Copy old image to new root

Now is the time to put the old image on the new SD. Note that it is not necessary to copy the boot partition unless you made deeper changes there, the root will suffice. The above image of boot image is just for backup and restoration reasons.

dd if=/home/joe/RPi_root.image of=/dev/sdY2 bs=4M conv=sparse

Since the image is of the exact size of the data, the partition will now only be of smaller size, so we need to increase it to fill all of the free space on the SD. Similarly to 2b, but resize2fs without options will just increase to the maximum:

e2fsck -f /dev/sdY2
resize2fs /dev/sdY2

3c. Finalizing

Last but not least your partition IDs will most likely have changed, thus /etc/fstab needs an update. To get the relevant IDs use blkid. Example output for my RPi OS SD-partitions:

blkid
/dev/sda1: LABEL_FATBOOT="boot" LABEL="boot" UUID="3725-1C05" TYPE="vfat" PARTUUID="38de8cd2-01"
/dev/sda2: LABEL="rootfs" UUID="fd695ef5-f047-44bd-b159-2a78c53af20a" TYPE="ext4" PARTUUID="38de8cd2-02"

Mount the root partition, open /etc/fstab, and update the PARTUUIDs. Example file:

proc            /proc           proc    defaults          0       0
PARTUUID=38de8cd2-01  /boot           vfat    defaults          0       2
PARTUUID=38de8cd2-02  /               ext4    defaults,noatime  0       1

Just to be sure run sync to finalize the writes, unmount and you should be ready to boot the RPi 4B with all the old stuff in place and the whole system as you had it before.

4. Alternative: direct copy to a new, larger SD Card

In case your new SD is larger than the old one and you may connect both at the same time, you can skip writing an image to the PC's hard drive.

  • With the old SD, do steps 1 and 2a.

  • Prepare the new SD with a fresh image as in 3a

  • Alter step 3b to directly copy the root partition from old to new:

    dd if=/dev/sdX1 of=/dev/sdY1 conv=sparce bs=4M

  • Proceed with resizing, finalizing and updating fstab as above.

3
  • Thus increasing the boot partition is a must. . I don't think this is correct - have you actually tried this? Firmware for the 4B is stored in EEPROM - not in /boot. And when it is downloaded during an apt update it is stored in /lib/firmware/raspberrypi/bootloader/. It is not stored in the boot partition on a 4B. Please read The Organization's documentation of the process; you may wish to revise your answer accordingly.
    – Seamus
    Dec 3 '20 at 22:38
  • @Seamus Yes, I did and it fixed my problem regarding moving my system from a 3B+ to a 4B - the whole config could be restored as is on the new hardware. The official documentation claims elf-files to be firmware (incl. specific Pi4 elf's), the boot section of the official, fresh image is already larger (even with light version). I can only imagine removing some kernel?.img to save space as alternative, but have not tried and it would create the same space-limitation problems during the next upgrade, so no good fix.
    – FelixJN
    Dec 4 '20 at 8:37
  • To clarify the above: contents of /boot in the current officiall image (2020-08-20) are larger than 50MB
    – FelixJN
    Dec 4 '20 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.