Skip to content

Instantly share code, notes, and snippets.

@tuxmartin
Last active April 13, 2016 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxmartin/c27ac0e7a4d9d7178eff to your computer and use it in GitHub Desktop.
Save tuxmartin/c27ac0e7a4d9d7178eff to your computer and use it in GitHub Desktop.
Raspberry Pi - expand partion and filesystem
root@martin:~# fdisk -l /dev/sdb
Disk /dev/sdb: 14.5 GiB, 15523119104 bytes, 30318592 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: 0x9ed9cab6
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 133119 131072 64M c W95 FAT32 (LBA)
/dev/sdb2 133120 7679999 7546880 3.6G 83 Linux
root@martin:~#
root@martin:~# fsck /dev/sdb2
fsck from util-linux 2.26.2
e2fsck 1.42.12 (29-Aug-2014)
PI_ROOT: clean, 45798/236176 files, 310243/943360 blocks
root@martin:~#
root@martin:~# umount /dev/sdb1
root@martin:~#
root@martin:~# umount /dev/sdb2
root@martin:~#
root@martin:~# echo ", +" | sfdisk -N 2 /dev/sdb
Checking that no-one is using this disk right now ... OK
Disk /dev/sdb: 14.5 GiB, 15523119104 bytes, 30318592 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: 0x9ed9cab6
Old situation:
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 133119 131072 64M c W95 FAT32 (LBA)
/dev/sdb2 133120 7679999 7546880 3.6G 83 Linux
/dev/sdb2:
New situation:
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 133119 131072 64M c W95 FAT32 (LBA)
/dev/sdb2 133120 30318591 30185472 14.4G 83 Linux
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@martin:~#
root@martin:~# fdisk -l /dev/sdb
Disk /dev/sdb: 14.5 GiB, 15523119104 bytes, 30318592 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: 0x9ed9cab6
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 133119 131072 64M c W95 FAT32 (LBA)
/dev/sdb2 133120 30318591 30185472 14.4G 83 Linux
root@martin:~#
#!/bin/bash
export LANG=c
SIZE=`sfdisk -l image.raw | awk -F' ' '/Disk/ {print $5}' | xargs`
echo DISK SIZE - $SIZE bytes
DISK="/dev/sda"
DISK_ESC=`echo $DISK | sed -e 's_/_\\/_g'`
awk -v search="$s" '$0 ~ search' "$i"
sfdisk -d /dev/sda | awk '/\/dev\/sda/ {print}' | awk 'NR==2'
sfdisk -d /dev/sda | awk -F ' ' -v disk=`echo $DISK | sed -e 's_/_\\/_g'` '/disk// {print}' | awk 'NR==2'
sfdisk -d /dev/sda | awk -v disk=`echo $DISK | sed -e 's_/_\\/_g'` 'NR==2' | awk 'NR==2'
echo ", +" | sfdisk -N 2 $DISK
e2fsck -f
echo ", +" | sfdisk -N 2 /dev/mmcblk0
e2fsck -f /dev/mmcblk0p2
resize2fs /dev/mmcblk0p2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment