Given sd_card.img that is 512000000 bytes (i.e. 488MB):
$ file sd_card.img
sd_card.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x0,1,1), end-CHS (0xdf,15,54), startsector 63, 999873 sectors, extended partition table (last)
fdisk shows:
Selected partition 1 Device: sd_card.img1 Start: 63 End: 999935 Sectors: 999873 Cylinders: 1158 Size: 488.2M Id: c Type: W95 FAT32 (LBA) Start-C/H/S: 0/1/1 End-C/H/S: 223/15/54 I attempted to resize it with the following commands.
$ cp sd_card.img test.img
$ dd if=/dev/zero of=test_zeros bs=1 count=1 seek=2G
$ cat test_zeros >> test.img
$ sudo parted test.img resizepart 1 2.5GB
$ file test.img
test.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x0,1,1), end-CHS (0x12f,239,61), startsector 63, 4882750 sectors
fdisk shows:
Selected partition 1 Device: test.img1 Start: 63 End: 4882812 Sectors: 4882750 Cylinders: 334 Size: 2.3G Id: c Type: W95 FAT32 (LBA) Start-C/H/S: 0/1/1 End-C/H/S: 303/239/61 Then I write the image to the 32GB SD card:
dd if=test.img of=/dev/mmcblk0 conv=fsync status=progress When the SD card is mounted...
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS mmcblk0 179:0 0 29.7G 0 disk `-mmcblk0p1 179:1 0 2.3G 0 part /run/media/mmcblk0p1 This looks promising, but df -h is not so much. This is what it shows with the original sd_card.img written to the SD card and after this modification:
Filesystem Size Used Avail Use% Mounted on /dev/mmcblk0p1 485M 159M 326M 33% /run/media/mmcblk0p1 Since lsblk displays block device size and df displays filesystem size, it suggests something is wrong with the partition.
Unfortunately, easier methods do not work well with FAT32 partitions, which I am limited to. After installing necessary libraries, I tried sudo gparted sd_card.img but it did not work, various operations instead showing sd_card.img1 and stating the file did not exist.
Any suggestions on what the issue in my procedure might be or otherwise how to do this properly?
Note: GNU Parted 3.4
Update
Following @eyoung100's suggestion, I wrote my original sd_card.img to the SD card and then used the command line tool parted, which is installed with GParted, in an attempt to expand the free space.
sudo parted
select /dev/mmcblk0
print free
Number Start End Size Type File system Flags 1 32.3kB 512MB 512MB primary fat32 lba 512MB 31.9GB 31.4GB Free Space resizepart 1 100%
print free
Number Start End Size Type File system Flags 1 32.3kB 31.9GB 31.9GB primary fat32 lba quit
Because GParted does not do anything until it is told to Apply changes, I wonder about quitting without saving anything, but when I boot from the SD card the changes are displayed so I think parted is more of a "gloves off" version where you really need to know what you are doing.
# df -h
Filesystem Size Used Avail Use% Mounted on /dev/mmcblk0p1 485M 172M 313M 36% /run/media/mmcblk0p1 # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS mmcblk0 179:0 0 29.7G 0 disk `-mmcblk0p1 179:1 0 29.7G 0 part /run/media/mmcblk0p1 So as previously mentioned, the changes I make in parted are actualized, but they are not found in usable space or the output of df -h. The actual size of the FAT32 partition remains ~488MB.
# fdisk -x /dev/mmcblk0
Disk /dev/mmcblk0: 29.72 GiB, 31914983424 bytes, 62333952 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: 0xe847ab93 Device Boot Start End Sectors Id Type Start-C/H/S End-C/H/S Attrs /dev/mmcblk0p1 63 62333951 62333889 c W95 FAT32 (LBA) 0/1/1 1023/254/63 When this sd_card.img is inserted into another device to boot of off, it gets mounted by that device. I am not sure how yet, but I see this>
# cat /run/systemd/transient/run-media-mmcblk0p1.mount
# This is a transient unit file, created programmatically via the systemd API. Do not edit. [Unit] After=dev-mmcblk0p1.device BindsTo=dev-mmcblk0p1.device [Mount] What=/dev/mmcblk0p1 Options=umask=007,gid=6 [Unit] [email protected] [email protected]
gpartedthen input your sudo password and let gparted determine the available devices and complete your task.gparted sd_card.imgit shows me the graphical view of my .img file with accurate information.gpartedcan you see your SD card in the device list on the top left?