ResizeRaspberryPiImage: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(add raspberry pi resize image page)
 
m (fix wrong start sector)
 
(2 intermediate revisions by the same user not shown)
Line 19: Line 19:
</syntaxhighlight>
</syntaxhighlight>


* Make loopback devices for the image:
* Make loop device for the image:


<syntaxhighlight>
<syntaxhighlight>
Line 32: Line 32:
fdisk -u -l /dev/loop0
fdisk -u -l /dev/loop0


Disk /dev/loop0: 5.2 GiB, 5628755968 bytes, 10993664 sectors
Disk /dev/loop1: 7.44 GiB, 7985954816 bytes, 15597568 sectors
Units: sectors of 1 * 512 = 512 bytes
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disklabel type: dos
Disk identifier: 0xcd48578f
Disk identifier: 0x870ea24b


Device      Boot Start     End Sectors  Size Id Type
Device      Boot   Start     End Sectors  Size Id Type
/dev/loop0p1       8192   96042  87851 42.9M c W95 FAT32 (LBA)
/dev/loop0p1         8192 1056767  1048576  512M c W95 FAT32 (LBA)
/dev/loop0p2      98304 6799359 6701056 3.2G 83 Linux
/dev/loop0p2      1056768 11403263 10346496 4.9G 83 Linux
</syntaxhighlight>
</syntaxhighlight>


Line 54: Line 54:
# Type p to select primary partition
# Type p to select primary partition
# Type 2 to select partition number
# Type 2 to select partition number
# Type 98304 as first sector
# Type 1056768 as first sector
# Type Enter to select default last sector
# Type Enter to select default last sector
# Type N to keep the signature
# Type N to keep the signature
Line 64: Line 64:
e2fsck -f /dev/loop0p2
e2fsck -f /dev/loop0p2
resize2fs /dev/loop0p2
resize2fs /dev/loop0p2
</syntaxhighlight>
* Detach loop device:
<syntaxhighlight>
losetup -d /dev/loop0
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 19:27, 6 January 2024

How to increase RaspberryPi OS initial image size ?

If you download raspberry-pi-os image you might want to increase the initial size to able to add or modify the content of the image.

  • Let's now download some image:
wget https://downloads.raspberrypi.com/raspios_arm64/images/raspios_arm64-2023-12-06/2023-12-05-raspios-bookworm-arm64.img.xz
  • Let's extract the image:
unxz --keep 2023-12-05-raspios-bookworm-arm64.img.xz
  • Lets add at least 2G space to the image:
dd if=/dev/zero bs=1M count=2048 >> 2023-12-05-raspios-bookworm-arm64.img
  • Make loop device for the image:
losetup -fP  2023-12-05-raspios-bookworm-arm64.img
losetup -a
/dev/loop0: []: (~/my/downloaded/image/2023-12-05-raspios-bookworm-arm64.img)
  • Check the partition layout and note the start sector of the root partition (here /dev/loop0p2):
fdisk -u -l /dev/loop0

Disk /dev/loop1: 7.44 GiB, 7985954816 bytes, 15597568 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: 0x870ea24b

Device       Boot   Start      End  Sectors  Size Id Type
/dev/loop0p1         8192  1056767  1048576  512M  c W95 FAT32 (LBA)
/dev/loop0p2      1056768 11403263 10346496  4.9G 83 Linux
  • Recreate second partition to use extra space:
fdisk /dev/loop0

# Type d to proceed to delete a partition.
# Type 2 to select the 2nd partition and press enter.
# Type n to add the partition
# Type p to select primary partition
# Type 2 to select partition number
# Type 1056768 as first sector
# Type Enter to select default last sector
# Type N to keep the signature
# Type w to save partition table and exit
  • Finally resize partition:
e2fsck -f /dev/loop0p2
resize2fs /dev/loop0p2
  • Detach loop device:
losetup -d /dev/loop0