How resize the root partition?

I am new to Linux and started learning recently. I am using DE0-Nano-SoC / Atlas board.
I have a problem with increase the root partition.

DF command shows

root@socfpga:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 975.9M 188.6M 736.1M 20% /
devtmpfs 246.9M 4.0K 246.9M 0% /dev
tmpfs 503.0M 40.0K 503.0M 0% /var/volatile
tmpfs 503.0M 0 503.0M 0% /media/ram

FDISK command shows

root@socfpga:~# fdisk -l

Disk /dev/mmcblk0: 7744 MB, 7744782336 bytes
4 heads, 16 sectors/track, 236352 cylinders, total 15126528 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: 0xd68e23ba

    Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1 2121728 3799447 838860 b W95 FAT32
/dev/mmcblk0p2 14336 2111487 1048576 83 Linux
/dev/mmcblk0p3 2048 4095 1024 a2 Unknown

Partition table entries are not in disk order

I want to increase the size of /dev/mmcblk0p2

Tried two methods:

  1. This partition p2 is between partition p1 ans p3, command resize2fs corrupts working image
  2. Partition table entry are not in order. fdisk with ‘t’ option to correct this also corrupt the working image. cant go beyond this.

Some one please help.

If you only need more space for storing data, you can just create another partition on the free space on your sd card.
I have created a fat32 partition for logging purpose on my 8GB sd card. I selected fat32 so the files can later be accessed by both linux and windows.
Start gparted (as su) on a linux machine (e.g. centos, ubuntu) and make sure you select correct device, e.g. /dev/sdc.
Create and format the new partition:

Put the sd card back into the evaluation board, and mount it. Assuming your new partition is named mmcblk0p4:
mkdir /mnt/DATA_FLASH
mount -t vfat /dev/mmcblk0p4 /mnt/DATA_FLASH

-AD

1 Like

Hi AD,

Thanks.

I tried you suggestion, did not work. Pls let me know what did i

This was the error while mounting

root@socfpga:~# mount -t vfat /dev/mmcblk0p4 /mnt/DATA_FLASH
FAT-fs (mmcblk0p4): bogus number of reserved sectors
FAT-fs (mmcblk0p4): Can’t find a valid FAT filesystem
mount: wrong fs type, bad option, bad superblock on /dev/mmcblk0p4,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

Just for reference attached here the following

root@socfpga:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 975.9M 188.6M 736.1M 20% /
devtmpfs 246.9M 4.0K 246.9M 0% /dev
tmpfs 503.0M 40.0K 503.0M 0% /var/volatile
tmpfs 503.0M 0 503.0M 0% /media/ram

root@socfpga:~# fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x522d2045

    Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1 2121728 3799447 838860 b W95 FAT32
/dev/mmcblk0p2 14336 2111487 1048576 83 Linux
/dev/mmcblk0p3 2048 4095 1024 a2 Unknown
/dev/mmcblk0p4 3801088 7743487 1971200 b W95 FAT32

Partition table entries are not in disk order

Try to mount the other win partition:
mkdir /mnt/TEST
mount -t vfat /dev/mmcblk0p1 /mnt/TEST
If this is OK, you might not have formatted mmcblk0p4:
You must click the “V” button after “Add”

-AD

Yeah. I did it using gparted too. You resize the fat32 partition or the ext3 partition and click the green tickso the changes take place.

This process can be used to extend the root partition of the Atlas SoC SD card.

$ sudo fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1-3, default 3): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2,4, default 2): 2
First sector (1046528-7821311, default 1046528): 
Last sector, +sectors or +size{K,M,G,T,P} (1046528-7821311, default 7821311): 

Created a new partition 2 of type 'Linux' and of size 3.2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

$ sudo e2fsck -f /dev/mmcblk0p2 
e2fsck 1.42.13 (17-May-2015)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mmcblk0p2: 61224/626560 files (0.1% non-contiguous), 416954/655360 blocks

$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/mmcblk0p2 to 846848 (4k) blocks.
The filesystem on /dev/mmcblk0p2 is now 846848 (4k) blocks long.

Hi AD,

I have once again gone through the whole process and did press “V” button you have highlighted with red circle. The following image is how it looks after this process.

FDISK Command

root@socfpga:~# fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0x522d2045

    Device Boot      Start        End              Blocks      Id     System

/dev/mmcblk0p1 2121728 3799447 838860 b W95 FAT32
/dev/mmcblk0p2 14336 2111487 1048576 83 Linux
/dev/mmcblk0p3 2048 4095 1024 a2 Unknown
/dev/mmcblk0p4 3811328 7735295 1961984 b W95 FAT32

Partition table entries are not in disk order

Created directories and mounted mmcblk0p1 as TEST Successful

root@socfpga:~# cd /mnt
root@socfpga:/mnt# ls
DATA_FLASH TEST card cf net ram
root@socfpga:/mnt#

root@socfpga:~# mount -t vfat /dev/mmcblk0p1 /mnt/TEST
root@socfpga:~# cd /mnt/TEST
root@socfpga:/mnt/TEST# ls
System Volume Information socfpga.dtb zImage
de0_nano_soc.rbf u-boot.scr

BUT MOUNTING mmcblk0p4 is NOT successful see below

root@socfpga:~# mount -t vfat /dev/mmcblk0p4 /mnt/DATA_FLASH
FAT-fs (mmcblk0p4): bogus number of reserved sectors
FAT-fs (mmcblk0p4): Can’t find a valid FAT filesystem
mount: wrong fs type, bad option, bad superblock on /dev/mmcblk0p4,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

SO I tried whether I can mount the mmcblk0p3 which is also failure
root@socfpga:~# mkdir /mnt/TST
root@socfpga:~# mount -t vfat /dev/mmcblk0p3 /mnt/TST
FAT-fs (mmcblk0p3): bogus logical sector size 5349
FAT-fs (mmcblk0p3): Can’t find a valid FAT filesystem
mount: wrong fs type, bad option, bad superblock on /dev/mmcblk0p3,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

Rgds

This is from the original Terasic DE=-Nano-SoC:
Create and format a new partition:

Then on eval board:
socfpga login: root
root@socfpga:~# fdisk -l

Disk /dev/mmcblk0: 3997 MB, 3997171712 bytes
4 heads, 16 sectors/track, 121984 cylinders, total 7806976 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: 0x0002d9c3

    Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1 2121728 3799447 838860 b W95 FAT32
/dev/mmcblk0p2 14336 2111487 1048576 83 Linux
/dev/mmcblk0p3 2048 4095 1024 a2 Unknown
/dev/mmcblk0p4 3801088 7806975 2002944 b W95 FAT32

Partition table entries are not in disk order
root@socfpga:~# mkdir /mnt/DATA_FLASH
root@socfpga:~# mount -t vfat /dev/mmcblk0p4 /mnt/DATA_FLASH
root@socfpga:~# touch /mnt/DATA_FLASH/test.txt
root@socfpga:~# ls -l /mnt/DATA_FLASH/
-rwxr-xr-x 1 root root 0 Sep 28 08:05 test.txt
root@socfpga:~#

root@socfpga:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 975.9M 203.5M 721.2M 22% /
devtmpfs 246.9M 4.0K 246.9M 0% /dev
tmpfs 503.0M 40.0K 503.0M 0% /var/volatile
tmpfs 503.0M 0 503.0M 0% /media/ram
/dev/mmcblk0p4 1.9G 4.0K 1.9G 0% /mnt/DATA_FLASH


The new partition is OK on my sd card.

You cant expect to mount mmcblk0p3 which is “unknown”.
-AD

Hi AD,

It did not work, I tried again. See the screen shots.
root@socfpga:~# fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders, total 7744512 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: 0xd68e23ba

    Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1 2121728 3799447 838860 b W95 FAT32
/dev/mmcblk0p2 14336 2111487 1048576 83 Linux
/dev/mmcblk0p3 2048 4095 1024 a2 Unknown
/dev/mmcblk0p4 3801088 7744511 1971712 b W95 FAT32

Partition table entries are not in disk order

root@socfpga:~# mount -t vfat /dev/mmcblk0p4 /mnt/DATA_FLASH
FAT-fs (mmcblk0p4): invalid media value (0xdf)
FAT-fs (mmcblk0p4): Can’t find a valid FAT filesystem
mount: wrong fs type, bad option, bad superblock on /dev/mmcblk0p4,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

BUT

root@socfpga:~# touch /mnt/DATA_FLASH/test.txt

seem to have written a empty file. And

root@socfpga:~# ls -l /mnt/DATA_FLASH/
-rw-r–r-- 1 root root 0 Sep 28 04:45 test.txt

also worked

BUT

root@socfpga:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 975.9M 188.6M 736.1M 20% /
devtmpfs 246.9M 4.0K 246.9M 0% /dev
tmpfs 503.0M 48.0K 503.0M 0% /var/volatile
tmpfs 503.0M 0 503.0M 0% /media/ram

doesn’t show the /dev/mmcblk0p4

I am using DE0_Nano_SoC_Linux_Console_3.13 image, what is yours

and

I am using gparted-live-0.27.0-1-i686.iso What is your GPARTED version if different is there a link I can download.

Rgds
BMB

BMB, I am using CentOS 7, gparted 0.19.1, and the original sd card (not sure which version).
Your test.txt file has been created in the root partition (/dev/mmcblk0p2 …) since the mount did not work.
Not sure what the problem is, maybe you should start with a fresh image (and a new sd card)?
-AD

Hi AD,

Thanks for the info.

I have downloaded gparted-live-0.19.1-1-i686-pae.iso and followed the steps you have posted earlier.

IT WORKS perfectly as described by you.

To counter check with gparted-live-0.27.0-1-i686.iso, I tried again it does not work.

Conclusion: gparted-live-0.27.0-1-i686.iso is not able to do the job.

I will go and study the documentation for this version, If I get any clue, will post it here.

Thanks again.

Rgds
BMB

Hi RLAKE

I tried the method you have suggested. Not successful and following is the info.

My board image is DE0_Nano_SoC_Linux_Console_3.13. Which has partition structure like this

root@socfpga:~# fdisk -l

Disk /dev/mmcblk0: 7744 MB, 7744782336 bytes
4 heads, 16 sectors/track, 236352 cylinders, total 15126528 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: 0xd68e23ba

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2121728 3799447 838860 b W95 FAT32
/dev/mmcblk0p2 14336 2111487 1048576 83 Linux
/dev/mmcblk0p3 2048 4095 1024 a2 Unknown

Partition table entries are not in disk order

I could not perform fdisk operation as suggested on partition 2 as this operation corrupts and after board will not boot and also p1 can not be moved from the start 2121728. As suggested by AD to additional space beyond 3799447 using gparted works.

I wanted to try the method you have suggested so I have downloaded Atlas image from Terasic

Now I have atlas_sdcard_v1.1.img

After boot fdisk -l show the partition as below
root@atlas_sockit:~# fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders
Units = cylinders of 64 * 512 = 32768 bytes

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 353 16352 512000 b Win95 FAT32
Partition 1 does not end on cylinder boundary
/dev/mmcblk0p2 16353 98304 2622464 83 Linux
Partition 2 does not end on cylinder boundary
/dev/mmcblk0p3 33 352 10240 a2 Unknown
Partition 3 does not end on cylinder boundary

Partition table entries are not in disk order

I have deleted the partition 2 and created new partition Start with 16353 and End on 121008 and then completed ‘w’ operation.

following are messages after that
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
fdisk: WARNING: rereading partition table failed, kernel still uses old table: Device or resource busy

checked with fdisk

root@atlas_sockit:~# fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
4 heads, 16 sectors/track, 121008 cylinders
Units = cylinders of 64 * 512 = 32768 bytes

    Device Boot      Start         End      Blocks  Id System

/dev/mmcblk0p1 353 16352 512000 b Win95 FAT32
Partition 1 does not end on cylinder boundary
/dev/mmcblk0p2 16353 121008 3348992 83 Linux
/dev/mmcblk0p3 33 352 10240 a2 Unknown
Partition 3 does not end on cylinder boundary

tried to perform the second step

root@atlas_sockit:~# e2fsck -f /dev/mmcblk0p2
e2fsck 1.42.9 (28-Dec-2013)
/dev/mmcblk0p2 is mounted.
e2fsck: Cannot continue, aborting.

tried to umount

root@atlas_sockit:~# umount /dev/mmcblk0p2
umount: /: target is busy
(In some cases useful info about processes that
use the device is found by lsof(8) or fuser(1).)

can not go further

Hi - I neglected to mention that these steps should be performed when the SD card was on the host system, not while running on the board itself. If your host system automatically mounts the file systems be sure to unmount before attempting to resize the partition.

Hi

Yes It works for atlas_sdcard_v1.1.img.

The /dev/mmcblk0p2 partition is at the last and this method works alright.

In DE0_Nano_SoC_Linux_Console_3.13, the /dev/mmcblk0p2 partition is in between two important partitions, this method do not work. i think need to do something which i dont know.

It’s worked for me thanks :smiley:

Hello ArthurDent. I have a problem please help me.
I did your way. I had a new partition /mnt/DATA_FLASH = 5GB. But when I installed a package that was still installed in /root partition. And my root partition is just 1GB not enough for me to install ffmpeg package. Can you tell me how to handle this? Thank you.

If the root partition was the last partition on your sd card (before you added DATA_FLASH) you can delete the DATA_FLASH partition and then resize your root partition. I think gparted can do that.
If the root is not the last partition then it is more tricky - creating logical volumes might be an option…
-AD

Thanks for you response ArthurDent!


As far as my picture I uploaded. My root partition is ext3 and I can’t resize this partition because a “unknown” partition. I think the is a u-boot partition. Therefore, when I tried to remove it, the system was broken. So I created another partition size 5GB via your command:
$ mkdir /mnt/DATA_FLASH
$ mount -t vfat /dev/mmcblk0p4 /mnt/DATA_FLASH
My problem is my root partition still not enough space for install ffmpeg package. When I install this package it always install that into “/” partition. Please direct me more clearly. Thanks a lot.