Skip to content

Instantly share code, notes, and snippets.

@joews
Created April 14, 2014 18:19
Show Gist options
  • Save joews/10671144 to your computer and use it in GitHub Desktop.
Save joews/10671144 to your computer and use it in GitHub Desktop.
Shink Raspberry Pi root partition (Arch) with OSX

Shink Raspberry Pi root partition (Arch) with OSX

A reminder of how to shrink the root partition of a fresh Arch Linux installation on a Raspberry Pi.

I wanted to make more room on a 4GB SD card for a Linux From Scratch build, so I resized the root partition down to 700mb and created a new 3GB logical partition next to it.

I didn't have another Linux machine available, so I used OSX Mavericks to write the original Arch image to the SD card and do the initial filesystem resize. Everything else was done on the Pi itself.

# OSX
❯ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *251.0 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 250.1 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *4.0 GB disk1
1: Windows_FAT_32 NO NAME 94.4 MB disk1s1
2: Linux 1.8 GB disk1s5
~/personal/rpi-lfs/images master
❯ sudo -s
Password:
~/personal/rpi-lfs/images master
❯ diskutil unmountDisk /dev/disk1
Unmount of all volumes on disk1 was successful
~/personal/rpi-lfs/images master
❯ dd if=ArchLinuxARM-2014.04-rpi.img of=/dev/rdisk1 bs=1m
1870+0 records in
1870+0 records out
1960837120 bytes transferred in 205.795374 secs (9528091 bytes/sec)
~/personal/rpi-lfs/images master
❯ sudo e2fsck -f /dev/disk1s5
e2fsck 1.42.9 (28-Dec-2013)
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/disk1s5: 28388/108864 files (1.1% non-contiguous), 122680/434944 blocks
~/personal/rpi-lfs/images master
❯ resize2fs /dev/disk1s5 700M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/disk1s5 to 179200 (4k) blocks.
The filesystem on /dev/disk1s5 is now 179200 blocks long.
❯ diskutil unmountDisk /dev/disk1
Unmount of all volumes on disk1 was successful
# No longer need root
~/personal/rpi-lfs/images master
❯ exit
# Put the disk in the Pi!
# Remove the pi's old key from ~/.ssh/known_hosts if necessary
~/personal/rpi-lfs/images master
❯ ssh root@pi
The authenticity of host 'pi (192.168.1.17)' can't be established.
RSA key fingerprint is 7a:4d:20:a6:66:89:88:42:07:ad:6b:79:2e:5c:e2:83.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'pi,192.168.1.17' (RSA) to the list of known hosts.
root@pi's password:
Welcome to Arch Linux ARM
Website: http://archlinuxarm.org
Forum: http://archlinuxarm.org/forum
IRC: #archlinux-arm on irc.Freenode.net
[root@alarmpi ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 657M 428M 180M 71% /
devtmpfs 84M 0 84M 0% /dev
tmpfs 232M 0 232M 0% /dev/shm
tmpfs 232M 300K 231M 1% /run
tmpfs 232M 0 232M 0% /sys/fs/cgroup
tmpfs 232M 0 232M 0% /tmp
/dev/mmcblk0p1 90M 25M 66M 28% /boot
tmpfs 47M 0 47M 0% /run/user/0
[root@alarmpi ~]# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.24.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/mmcblk0: 3.8 GiB, 4016046080 bytes, 7843840 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: 0x417ee54b
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
/dev/mmcblk0p2 186368 3667967 1740800 5 Extended
/dev/mmcblk0p5 188416 3667967 1739776 83 Linux
Command (m for help): d
Partition number (1,2,5, default 5): 5
Partition 5 has been deleted.
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help): p
Disk /dev/mmcblk0: 3.8 GiB, 4016046080 bytes, 7843840 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: 0x417ee54b
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e
Partition number (2-4, default 2):
First sector (186368-7843839, default 186368):
Last sector, +sectors or +size{K,M,G,T,P} (186368-7843839, default 7843839):
Created a new partition 2 of type 'Extended' and of size 3.7 GiB.
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (188416-7843839, default 188416):
Last sector, +sectors or +size{K,M,G,T,P} (188416-7843839, default 7843839): +700M
Created a new partition 5 of type 'Linux' and of size 700 MiB.
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (1626112-7843839, default 1626112):
Last sector, +sectors or +size{K,M,G,T,P} (1626112-7843839, default 7843839):
Created a new partition 6 of type 'Linux' and of size 3 GiB.
Command (m for help): p
Disk /dev/mmcblk0: 3.8 GiB, 4016046080 bytes, 7843840 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: 0x417ee54b
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
/dev/mmcblk0p2 186368 7843839 3828736 5 Extended
/dev/mmcblk0p5 188416 1624063 717824 83 Linux
/dev/mmcblk0p6 1626112 7843839 3108864 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
[root@alarmpi ~]# reboot
Connection to pi closed by remote host.
Connection to pi closed.
# Wait a minute or two for the pi to come back online
❯ ssh root@pi
root@pi's password:
Welcome to Arch Linux ARM
Website: http://archlinuxarm.org
Forum: http://archlinuxarm.org/forum
IRC: #archlinux-arm on irc.Freenode.net
Last login: Mon Apr 14 12:08:42 2014 from 192.168.1.11
[root@alarmpi ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 657M 428M 180M 71% /
devtmpfs 84M 0 84M 0% /dev
tmpfs 232M 0 232M 0% /dev/shm
tmpfs 232M 304K 231M 1% /run
tmpfs 232M 0 232M 0% /sys/fs/cgroup
tmpfs 232M 0 232M 0% /tmp
/dev/mmcblk0p1 90M 25M 66M 28% /boot
tmpfs 47M 0 47M 0% /run/user/0
[root@alarmpi ~]# mkfs.ext4 /dev/mmcblk0p6
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
194688 inodes, 777472 blocks
38873 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=796917760
24 block groups
32768 blocks per group, 32768 fragments per group
8112 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@alarmpi ~]# mkdir -p /mnt/lfs
[root@alarmpi ~]# mount /dev/mmcblk0p6 /mnt/lfs/
[root@alarmpi ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 657M 428M 180M 71% /
devtmpfs 84M 0 84M 0% /dev
tmpfs 232M 0 232M 0% /dev/shm
tmpfs 232M 304K 231M 1% /run
tmpfs 232M 0 232M 0% /sys/fs/cgroup
tmpfs 232M 0 232M 0% /tmp
/dev/mmcblk0p1 90M 25M 66M 28% /boot
tmpfs 47M 0 47M 0% /run/user/0
/dev/mmcblk0p6 2.9G 4.5M 2.7G 1% /mnt/lfs
@clankill3r
Copy link

How did you use e2fsck on a mac? I get command not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment