mdoldan
Posts: 3
Joined: Sun Jul 08, 2018 8:33 pm

Raspian Stretch Lite Version 9 Expand USB File System

Sun Jul 08, 2018 9:04 pm

I'm booting my Raspberry PI 3 from a USB and after reading and trying a number of outdated documents I found it as simple as the following.

I cloned a 8gb USB image of Raspian Stretch Lite to a 32gb USB and booted my Pi with it.

By the way I did all this from sudo su so I don't have to keep typing sudo (your choice)

First enter: fdisk -l

Code: Select all

Disk /dev/sda: 29.8 GiB, 32026656768 bytes, 62552064 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: 0x8ff0b05a

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        8192    96663    88472 43.2M  c W95 FAT32 (LBA)
/dev/sda2       98304 15634431 15536128  7.4G 83 Linux
You can see only 8gb is allocated between sda1 and sda2 but /dev/sda says its 29.8GiB

Then enter: df -h

Code: Select all

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.3G  1.2G  5.9G  17% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M  6.3M  458M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/sda1        43M   22M   21M  51% /boot
tmpfs            93M     0   93M   0% /run/user/0
Again only 8gb used.

Now enter: resize2fs /dev/sda2

If the system doesn't reboot after a few minutes enter: reboot

Log in and sudo su again.

Then enter: fdisk -l

Code: Select all

Disk /dev/sda: 29.8 GiB, 32026656768 bytes, 62552064 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: 0x8ff0b05a

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        8192    96663    88472 43.2M  c W95 FAT32 (LBA)
/dev/sda2       98304 62552063 62453760 29.8G 83 Linux
Notice sda2 is now 29.8G
However, df -h still only shows 8gb

Code: Select all

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.3G  1.2G  5.9G  17% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   12M  452M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/sda1        43M   22M   21M  51% /boot
tmpfs            93M     0   93M   0% /run/user/0
Enter resize2fs /dev/sda

If the system doesn't reboot after a few minutes enter: reboot

When you log in again run df -h and it should look something like this:

Code: Select all

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        30G  1.2G   27G   4% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   12M  452M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/sda1        43M   22M   21M  51% /boot
tmpfs            93M     0   93M   0% /run/user/0
That's it!

alphanumeric
Posts: 2144
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Raspian Stretch Lite Version 9 Expand USB File System

Mon Jul 09, 2018 12:26 pm

Can you not do that from raspi-config?

donbrew
Posts: 53
Joined: Sun Sep 04, 2016 2:32 pm

Re: Raspian Stretch Lite Version 9 Expand USB File System

Wed Jul 11, 2018 3:00 pm

Raspbian usually expands the file system automatically on the first boot. Or, sudo raspi-config > Advanced Options (7) > Expand Filesytem (A1).

mdoldan
Posts: 3
Joined: Sun Jul 08, 2018 8:33 pm

Re: Raspian Stretch Lite Version 9 Expand USB File System

Sat Jul 14, 2018 2:27 pm

Yes Raspian expands the file system on first boot of a clean image. I'm referring to when you've made an image of an existing system you've already booted and made changes to, loaded software, configured services, etc. and you want to move it to a larger storage device.

As the title says it is a USB file system and raspi-config fails because it's not an SD card.

I just cloned an 8gb USB to a 64gb USB and after boot the partition is not resized:

Code: Select all

Disk /dev/sda: 58.8 GiB, 63065554944 bytes, 123174912 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: 0x8ff0b05a

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        8192    96663    88472 43.2M  c W95 FAT32 (LBA)
/dev/sda2       98304 15634431 15536128  7.4G 83 Linux
[email protected]:~#
[email protected]:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.3G  1.2G  5.9G  17% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   12M  452M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/sda1        43M   22M   21M  51% /boot
tmpfs            93M     0   93M   0% /run/user/0
It sees the size is larger but does not automatically expand.

When I try to run raspi-config - Advanced - Expand File System I get the following error:

Code: Select all

sda2 is not an SD card. Don't know how to expand
I did miss a step to make raspi-config work you need to execute the following from sudo:

Code: Select all

cp /usr/bin/raspi-config ~
sed -i 's/mmcblk0p/sda/' ~/raspi-config
sed -i 's/mmcblk0/sda/' ~/raspi-config
~/raspi-config
Expand the from raspi-config partition and reboot. Then follow the original instructions.

Return to “Raspbian”