-1

I have an 8GB image that is burned to a 32GB USB drive.

How can I automate this filesystem expansion process? Is there a script I can create to expand the USB correctly and fully? How can I find the exact partition size needed? I noticed when I manually expand the filesystem it only increases the size in /dev/sda2 not /dev/sda1.

1) I have seen a suggestion to use

parted /dev/sda resizepart 1 102400 # resize /dev/sda1 to 100GB
resize2fs /dev/sda1 # resize filesystem

In this method, I am unsure how to calculate the value needed to ensure full expansion. I have used fdisk -l but unsure how to use the data here for the command above.

2) I have looked at the /usr/bin/raspi-config file and don't fully understand what I need to extract from the --expand-rootfs section of the file for my needs.

--- RESULTS FROM fdisk -l ---

8GB Image manually expanded on 32GB USB

Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       2048 62332927 62330880 29.7G  c W95 FAT32 (LBA)

Disk /dev/sda: 28.7 GiB, 30752000000 bytes, 60062500 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8f1eafaf

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1         8192   131071   122880   60M  c W95 FAT32 (LBA)
/dev/sda2       131072 60062499 59931428 28.6G 83 Linux

8GB Image awaiting expansion on 32GB USB

Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       8192 62333951 62325760 29.7G  c W95 FAT32 (LBA)

Disk /dev/sda: 28.7 GiB, 30752636928 bytes, 60063744 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb9da48fc

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1         8192   131071   122880   60M  c W95 FAT32 (LBA)
/dev/sda2       131072 15523839 15392768  7.3G 83 Linux
2
  • 2
    Rasbpian already does this on first boot!
    – Milliways
    Mar 5, 2020 at 0:23
  • @Milliways it expands the filesystem on boot? I can assure you it does not. My Image is 8GB but it is burned to a 32GB USB. I Need to fill the remaining space. Manually entering "raspi-config" and expand filesystem completes the task. I need to automate the process
    – presish
    Mar 5, 2020 at 0:26

1 Answer 1

3

On the very first boot of a virgin Raspbian image there is running a script that you can find in /boot/cmdline.txt before booting first time. This is from Rasbian Buster Lite 2020-02-13:

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

As you see there is /usr/lib/raspi-config/init_resize.sh called but after the first boot this entry in /boot/cmdline.txt is removed so you will not find it on following bootups. If your image does not resize the partition on first boot then either it isn't a Raspbian image or it has already booted before.

You may have a look at this script how resizing of a partition works. Maybe you can just copy it?

3
  • Is this only for SD card booting? Recall I am booting from the USB
    – presish
    Mar 6, 2020 at 20:02
  • @presish This is for the Raspbian image. There is the init_resize.sh script located, no matter if you flash it to the SD Card or to an USB stick. But I don't know if the script detects on what storage it is running. Maybe you have to modify it.
    – Ingo
    Mar 7, 2020 at 0:04
  • Yes I believe it needs modification. I used it on the USB and did not work. Will need to look into this more unless you know what needs to be modified
    – presish
    Mar 7, 2020 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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