0

I've got an img file (4,02GB) containing a Linux OS. My goal is to shrink this img filed down to < 4GB. The img contains a linux partition that only holds about 2,5GB of data.

I need to be able to copy that img file to an eMMC that is just under 4GB. So compressing the image for storage is not what I want. I want a smaller image that can be copied using dd to the eMMC.

When I load the image on a 8GB SD Card (using dd) it looks like this :

root@udoo:/# fdisk /dev/mmcblk0

Command (m for help): p

Disk /dev/mmcblk0: 8026 MB, 8026849280 bytes
4 heads, 16 sectors/track, 244960 cylinders, total 15677440 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
Disk identifier: 0x00052161

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048       67583       32768    e  W95 FAT16 (LBA)
/dev/mmcblk0p2           67584     7849983     3891200   83  Linux

and fdisk output

root@udoo:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       3.6G  2.5G  920M  74% /
devtmpfs        342M  4.0K  342M   1% /dev
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            101M  236K  101M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            502M   72K  502M   1% /run/shm
none            100M   20K  100M   1% /run/user
/dev/mmcblk0p1   32M  6.3M   26M  20% /boot

I can use a linux OS to mount the SD card , shrink the filesystem and re-create the partitions, but how do I export that into a new img file ? AFAIK, performing a dd if=/dev/mmcblk0 of=/file.img operation will always result in an image file that is the same size as the SD card (in this case 8gb).

What would be the best way to do this ?

Is there a way to create a blank 3.5GB img file and add the 2 partitions (/dev/mmcblk0p1 en /dev/mmcblk0p2) somehow to reach my goal ?

ddewaele
  • 333
  • 1
  • 4
  • 12
  • Have you checked http://superuser.com/questions/610819/how-to-resize-img-file-created-with-dd ? – Henrik Pingel Mar 15 '16 at 13:58
  • yes .... but there the suggestion is to simply compress the image for storage. I want to have a smaller img file that can be written to an eMMC that is just under 4gb (added this to the question). I'm also not using virtualization so the second part also doesn't apply. – ddewaele Mar 15 '16 at 14:05
  • There is a 2nd answer `resize2fs -M xxx.img` which would be my first attempt. – Henrik Pingel Mar 15 '16 at 14:11
  • The image contains 2 partitions. how does the resize2fs what filesystem it needs to resize ? – ddewaele Mar 15 '16 at 18:28

0 Answers0