Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12595 Discussions

Resizing Linux image for 200GB SD card

Honored Contributor II

Hi all, 


I'm trying to use a 200GB SD card with the SoCKit dev board because I need to do a lot of software processing on the FPGA. How do I expand the Linux image so that all the unallocated memory is added to the Linux filesystem partition?  


attachment: Original status- burned a 2GB Linux image to 200GB SD card. 


things i've tried: 

I've looked at Raspbian solutions but they don't have an interfering FAT16 partition sitting between the OS partition and the unallocated memory.  

I got the prebuilt Linux image from rocketboards and burned to SD card. I've created individual images of the three partitions. I used GParted to relocate the fat16 partition to the end and merged unallocated memory to the Linux partition. I re-burned the partitions with the individual images. No go. 


I'm thinking the MBR is still pointing to the original start sector# for the FAT16 partition.  

I've read about creating a new partition and having the /var and /usr folders of the Linux system in the new partition but I'll be experimenting with a lot of different software libraries and this would over-complicate the process, so not preferable.  


I'd really appreciate some guidance on this. 


0 Kudos
2 Replies
Honored Contributor II

Hi rabia7, 


the main problem is that the altera layout of the image has the linux rootfs located in the middle. 


The easiest way out of this is to  


- copy /dev/sdc2 into am image file 

umount /dev/sdc2 

dd if=/dev/sdc2 of=rootfs.img 


- use fdisk /dev/sdc  

- delete partition 2 

- create new partition 2 behind partition 1 up to the end of the sd card 


- copy the image back to /dev/sdc2 

dd if=rootfs.img of=/dev/sdc2 

sync && sync && sleep 1 

- resize file system in /dev/sdc2 to full size of partition 

e2fsck /dev/sdc2 

resize2fs /dev/sdc2 


This way you loose 4.3 GB but you gain nearly 200 GB. 

You can, of course use the same trick to move the FAT32 partition to sector 4096 and use the whole rest for Linux. 


(I copied the commands from some of my scripts. They mostly need to be run as sudo. Maybe I missed some detail, so be careful ;-) 


good luck 

0 Kudos
Honored Contributor II

Hi Joachim, 


It worked. :-) 


Thanks so much for providing the solution. I had some issues with orphan nodes detected during the 'e2fsck' and I had to try reformatting the SD card a few times but finally, I managed to reformat the huge memory to Linux filesystem.  


Thanks again for your help. 


0 Kudos