UFS [SOLVED] How can I clone the FreeBSD microSD of my Raspberry Pi in a bigger microSD card

Hello,
I have FreeBSD 13.1 running on my 128Gb microsd card perfectly well, but now I need/want more space in /usr/local/www.

If I buy a bigger card, a 256Gb for example, is it possible to expand the system if I clone the 128Gb card into the new 256Gb card? How could I expand it?

Thanks in advance.

Joan
 
Have a good look at the man page for growfs. It'll tell you what you need to know. The Raspberry Pi uses that to expand into the size of the card upon first boot as well, so you may find the initial bootup script for that useful.
 
Adding growfs_enable=YES in /etc/rc.conf should do the trick.
It will expand partition and filesystem.
 
Thanks everybody for your tips and comments.
I'll buy a new 256GB card and I'll try tomorrow. Thank you.
 
Though you could do a dd, repair the gpt and more easily expand the last partition or use other tools to move partitions for resizing others that currently had no free space after them, for a new disk you may consider partition, format, and transfer just the data (ufs=dump & restore, zfs=zfs send & recv) which will minimize writes to the new drive and may accelerate the transfer as a result. If sticking with dd, you can consider if you want to use features like 'conv=sparse' to skip writing blocks containing only zeroes which can help for speed and amount of written data.
 
Making it smaller would be interesting too. Like, download the 5GB aarch64 image, remove /usr/lib/debug and resize it to 1200MB
 
I have not advanced :(

I cloned my 64GB microSD into a new 128GB microSD and it worked perfectly.
But it says the filesystem / is 64GB.

I added growfs_enable=YES in /etc/rc.conf as oOiOo said, but nothing changed... it doesn't expand the partition.

1.png


2.png


Could somebody send me an article or a how to?
I read and read, but the information about how to expand a microSD card is not clear.

Thanks in advance.
 
There's en example in here. This is growfs' own documentation which should get you going. If you have any specific questions, drop a note.

It's likely that the growfs flag in rc.conf only fires once after the first boot of the system. I don't have a Pi ready to test this with, but I wouldn't be surprised by it. In that case you're going to have to manually do what the growfs script does for you automatically. It may help to check out the growfs script on your Pi in /usr/local/etc/rc.d to see what it does exactly.
 
/usr/local is for 3rd party packaged content and growfs rc.d script comes with base so is in /etc/rc.d . The growfs command resizes a filesystem to the larger partition but requires the partition be larger than the filesystem. The manpage bvdw78 posted shows an example of doing so assuming the partition to grow is the last partition on the disk and has an index # of 1 which is probably not matching your case. Output of
gpart show gives the id# in the 3rd column and helps see there is nothing after the partition except free space to resize it into.
 
I have not advanced :(

I cloned my 64GB microSD into a new 128GB microSD and it worked perfectly.
But it says the filesystem / is 64GB.

I added growfs_enable=YES in /etc/rc.conf as oOiOo said, but nothing changed... it doesn't expand the partition.
You need to add firstboot flag to activate growfs service at startup
sh:
touch /firstboot
However, this only works if you have a root partition that is at the end of the disk.
Sorry for the incomplete information.
 
Ok. I did a backup of the production MicroSD Card and I show you the partitions (gpart show):


Code:
 # gpart show
=>       63  499744705  mmcsd0  MBR  (238G)
         63       1985          - free -  (993K)
       2048     102400       1  fat32lba  [active]  (50M)
     104448  499640320       2  freebsd  (238G)

=>        0  499640320  mmcsd0s2  BSD  (238G)
          0        128            - free -  (64K)
        128  112150400         1  freebsd-ufs  (53G)
  112150528   12476416         2  freebsd-swap  (5.9G)
  124626944  375013376            - free -  (179G)

I deleted the swap partition:

Code:
# gpart delete -i 2 mmcsd0s2
mmcsd0s2b deleted

Now, if I do "gpart show" there is no swap partition anymore:

Code:
# gpart show
=>       63  499744705  mmcsd0  MBR  (238G)
         63       1985          - free -  (993K)
       2048     102400       1  fat32lba  [active]  (50M)
     104448  499640320       2  freebsd  (238G)

=>        0  499640320  mmcsd0s2  BSD  (238G)
          0        128            - free -  (64K)
        128  112150400         1  freebsd-ufs  (53G)
  112150528  387489792            - free -  (185G)

Now I did this change on the kernel:

Code:
# sysctl kern.geom.debugflags=16
kern.geom.debugflags: 0 -> 16
root@mercuri:/home/joan #

I resized the root partition where I have the "/" of my system:
Code:
 # gpart resize -i 1 -s 233G -a 4k mmcsd0s2
mmcsd0s2a resized

Ok. Now I have a look on the partitions:

Code:
# gpart show
=>       63  499744705  mmcsd0  MBR  (238G)
         63       1985          - free -  (993K)
       2048     102400       1  fat32lba  [active]  (50M)
     104448  499640320       2  freebsd  (238G)

=>        0  499640320  mmcsd0s2  BSD  (238G)
          0        128            - free -  (64K)
        128  488636416         1  freebsd-ufs  (233G)
  488636544   11003776            - free -  (5.2G)

Finally I create the swap partion and I have some strange message:

Code:
# gpart add -t freebsd-swap -a 4k mmcsd0s2
mmcsd0s2b added, but partition is not aligned on 4194304 bytes

If I do "gpart show" I see the root partition with 233G and the swap partition:
Code:
# gpart show
=>       63  499744705  mmcsd0  MBR  (238G)
         63       1985          - free -  (993K)
       2048     102400       1  fat32lba  [active]  (50M)
     104448  499640320       2  freebsd  (238G)

=>        0  499640320  mmcsd0s2  BSD  (238G)
          0        128            - free -  (64K)
        128  488636416         1  freebsd-ufs  (233G)
  488636544   11003776         2  freebsd-swap  (5.2G)

So, apparently I have 233G for the / partition, and 5.2G for the swap partition.
Everything seems to be right, isn't it?

I reboot with "shutdown -r now" but the system doesn't boot properly and I see the message of the attached image.

Can somebody tell me where is the problem? Do I need to do some more commands of gpart before reboot the system?

Joan
 

Attachments

  • IMG_20240822_223644.jpg
    IMG_20240822_223644.jpg
    274.6 KB · Views: 35
Did you label the root partition on your new card? It is supposed to have the label "rootfs" based on your picture.
None of your commands show labeling the root partition.
 
You did a partition resize, but not a growfs(8). You modified the partition table but did not expand the UFS filesystem.

It could be related.

EDIT: Sorry, I didn't see it was enabled in rc.conf(5) ignore my message.
 
Did you label the root partition on your new card? It is supposed to have the label "rootfs" based on your picture.
None of your commands show labeling the root partition.
I don't know about what you are talking about :) I will study it now. Thanks for your comment.
 
Did you label the root partition on your new card? It is supposed to have the label "rootfs" based on your picture.
None of your commands show labeling the root partition.
I still don't understand.
For example, this is my produccion server (another Raspberry Pi 4 with FreeBSD 13 running perfectly well) and If I do "gpart show" I I also don't see a label as you mentioned, but the Raspbery works and reboots perfectly well.

screenshot.png



joan
 
SOLVED!

1. I did the backup image of my microSD with dd.
2. I deleted swap partition (gpart delete -i 2 mmcsd0s2)
3. I commented the line of swap in /etc/fstab
4. I resized the root / (gpart resize -i 1 -s 233G -a 4k mmcsd0s2)
5. I created swap again (gpart add -t freebsd-swap -a 4k mmcsd0s2)
6. On another computer with FreeBSD, I inserted the microSD and I did growfs /dev/da0s2a
7. I booted the Raspberry and now I have more capacity :)

final.png


I did an article (catalan language) explaining how I did: https://joancatala.net/node/1641

Thanks to everybody for all your comments.
 
Back
Top