I'm using Igor's ubuntu trusty image with kernel 3.4.105 (http://www.igorpecovnik.com/2014/11/18/olimex-lime-debian-sd-image/ (http://www.igorpecovnik.com/2014/11/18/olimex-lime-debian-sd-image/)). This image auto-resizes the rootfs to occupy the complete SD card, on first login.
I have installed custom software onto this SD card, and now I want to clone it. But, I need to shrink the rootfs to 2GB before doing so.
Here's what I did:
- sudo fdisk /dev/mmcblk0
- Command (m for help): p
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 15523839 7760896 83 Linux
- Command (m for help): d
- Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-15523839, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-15523839, default 15523839): 7500000
- Command (m for help): p
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 7500000 3748976+ 83 Linux
- Command (m for help): w
The partition table has been altered!
- reboot
However, the board doesn't boot up after this.
What am I doing wrong? I'm a newbie, please help.
That looks to reduce the size for the fs but isn't re-making the fs i.e. moving data and its inode etc info, so corrupts it.
I'd use a loopback device of the size you want on a PC, copy data across file-by-file, remake the SD card and copy data back.
John
Thanks for your reply John. I will try as you have said.
For curiosity's sake, how is it that the above method works with raspberry pi?(http://elinux.org/RPi_Resize_Flash_Partitions#Manually_resizing_the_SD_card_on_Raspberry_Pi (http://elinux.org/RPi_Resize_Flash_Partitions#Manually_resizing_the_SD_card_on_Raspberry_Pi))
I don't know if it works for shrinking. It may, for a smallish change, but at some point it definitely won't. There again I expect hardly anyone uses it for shrinking.
BTW, I didn't see where you ran resize2fs - did you try it?
John
I didn't run resize2fs. I thought that was supposed to be done after the reboot. (But my board didn't reboot at all. :( )
Do you suggest running resize2fs before rebooting?
I tried resize2fs, but this still doesn't work:
root@micro:~# resize2fs /dev/mmcblk0p1
resize2fs 1.42.5 (29-Jul-2012)
The filesystem is already 1940224 blocks long. Nothing to do!
The board keeps rebooting continuously.
You're not doing it the way that link you posted does are you?
You'll have already corrupted things so will have to start over.
John