[SOLVED] Resize partition with aafirstboot

Post Reply
Sebas_Ledesma
Posts: 120
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 8 times
Been thanked: 6 times
Contact:

[SOLVED] Resize partition with aafirstboot

Post by Sebas_Ledesma » Fri Jun 19, 2020 8:05 am

Hi:

I can't make that the aafirstboot resizes the partition to full use of the eMMC in our product.

1 - I've prepared the source memory: erased source code, temporaries files, etc.
2 - Downloaded from here
https://raw.githubusercontent.com/hardk ... afirstboot
the aafirstboot into my home directory. I've added execution permissions, changed ownership to root and copied to /

Code: Select all

sudo cp -p aafirstboot /
3 -I've did a

Code: Select all

sudo touch /.first_boot

4 - The /etc/rc.local contains the reference aafirstboot. It will execute it if it exists.
5 - Shutting down, extracted the memory and with a memory card readed mounted in a Linux PC. I've unmounted the /dev/sdb device and used GParted to reduce the Linux Partition to 6.5 GB (aprox).
6 - After GParted finished, I've extracted the memory and re-installed in the Odroid. It booted well, the script executed: it deleted the .first_boot file and it deleted itself.
7- I've opened a terminal and checked the partition size and stills is around 6.5GB (instead of 15.x GB).

This is the output of fdisk -l

Code: Select all

Disk /dev/mmcblk0: 14.7 GiB, 15758000128 bytes, 30777344 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: 0xd3630000

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        2048   264191   262144  128M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      264192 13895679 13631488  6.5G 83 Linux
I'm using Ubuntu 18.04.4 LTS (GNU/Linux 3.16.81-49 aarch64). I've updated it today just in case.

I've noticed that in the aafirstboot script the line

Code: Select all

p2_finish=`fdisk -l /dev/mmcblk0 | grep sectors | awk '{printf $5}'`
Will assign (in my system) the value 15758000128* instead of 15758000128 the total bytes available or 30777344 the total sectors available.
This is because two lines of the output of fdisk contains the word 'sectors'.

So I've tried these two modifications for that line:

Code: Select all

p2_finish=`fdisk -l /dev/mmcblk0 | grep Disk| awk '{printf $5}'`
This version indentifies the single line that describes the Disk, and gets the total bytes.
and

Code: Select all

p2_finish=`fdisk -l /dev/mmcblk0 | grep Disk| awk '{printf $7}'`
This version indentifies the single line that describes the Disk, and gets the total sectors.

In both cases the script is executed, deletes the .first_boot and then deletes itself, but in both cases the partition remains at 6.5G

Any hints?
Thanks in advance.

Sebas
Last edited by Sebas_Ledesma on Thu Jun 25, 2020 3:21 am, edited 2 times in total.

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Resize partition with aafirstboot

Post by odroid » Fri Jun 19, 2020 10:53 am

Very weird.

If you flashed this image, the sd/emmc resizing job should be done in the first booting process automatically.
https://wiki.odroid.com/odroid-c2/os_images/ubuntu/v3.1

Did you flash a different OS image?

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Resize partition with aafirstboot

Post by mad_ady » Fri Jun 19, 2020 2:44 pm

Try extracting aafirstboot from a HK image instead of github. I remember the current version is slightly different.

User avatar
odroid
Site Admin
Posts: 34642
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 824 times
Been thanked: 712 times
Contact:

Re: Resize partition with aafirstboot

Post by odroid » Fri Jun 19, 2020 5:01 pm

I overlooked the OP who wants to make their own OS image. Sorry.
I've extracted it from one of our latest images.

Code: Select all

#!/bin/bash
### BEGIN INIT INFO
# Provides:          aafirstboot
# Required-Start:    $remote_fs $all
# Required-Stop:
# Default-Start:     2 3 4 5 S
# Default-Stop:
# Short-Description: First boot system setup
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

dev_p2=`blkid -U e139ce78-9841-40fe-8823-96a304a09859`

case "$1" in
    start)

		if [ -f /.first_boot ]; then

			if [[ $dev_p2 == "/dev/sd"* ]]; then
				dev=${dev_p2%?}
				p2_start=`fdisk -l $dev | grep Linux | awk '{print $2}'`
				p2_finish=$((`fdisk -l $dev | grep Disk | grep sectors | awk '{printf $7}'` - 2048))

			else
				#eMMC/SD
				dev=${dev_p2%??}
				p2_start=`fdisk -l $dev | grep p2 | awk '{print $2}'`
				p2_finish=$((`fdisk -l $dev | grep Disk | grep sectors | awk '{printf $7}'` - 2048))
			fi
	
			# ok, its the very first boot, we need to resize the disk.
			
			fdisk $dev <<EOF &>> /resize.log
p
d
2
n
p
2
$p2_start
$p2_finish
p
w
EOF
			[ ! -f /etc/ssh/ssh_host_rsa_key ] && dpkg-reconfigure openssh-server
			
			
			log_daemon_msg "Resizing /" &&
			resize2fs $dev_p2 &&
			rm -fr /aafirstboot
			rm -fr /.first_boot
			sync
		fi

	;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac
These users thanked the author odroid for the post:
Sebas_Ledesma (Sat Jun 20, 2020 3:16 am)

User avatar
mad_ady
Posts: 8155
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 568 times
Been thanked: 404 times
Contact:

Re: Resize partition with aafirstboot

Post by mad_ady » Fri Jun 19, 2020 5:15 pm

It's nice that this version supports flashing to usb disk too :)

Sebas_Ledesma
Posts: 120
Joined: Thu Jun 08, 2017 2:49 am
languages_spoken: english
ODROIDs: c2
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: [SOLVED] Resize partition with aafirstboot

Post by Sebas_Ledesma » Sat Jun 20, 2020 3:19 am

I've tried the new script and it worked.
I've repeated the test (now I've downsized to 6GB the linux partition) and after booting the odroid it resized correctly.

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


Command (m for help): Disk /dev/mmcblk0: 14.7 GiB, 15758000128 bytes, 30777344 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: 0xd3630000

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 2048 264191 262144 128M c W95 FAT32 (LBA)
/dev/mmcblk0p2 264192 12847103 12582912 6G 83 Linux

Command (m for help): Partition number (1,2, default 2):
Partition 2 has been deleted.

Command (m for help): Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): Partition number (2-4, default 2): First sector (264192-30777343, default 264192): Last sector, +sectors or +size{K,M,G,T,P} (264192-30777343, default 30777343):
Created a new partition 2 of type 'Linux' and of size 14.6 GiB.
Partition #2 contains a ext4 signature.

Command (m for help):
Disk /dev/mmcblk0: 14.7 GiB, 15758000128 bytes, 30777344 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: 0xd3630000

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 2048 264191 262144 128M c W95 FAT32 (LBA)
/dev/mmcblk0p2 264192 30775296 30511105 14.6G 83 Linux

Command (m for help): The partition table has been altered.
Syncing disks.
Now I've delivered the new image to the production guys.

Thanks
Sebas
These users thanked the author Sebas_Ledesma for the post:
odroid (Mon Jun 22, 2020 10:19 am)

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 1 guest