Default way to resizing SD card with raspi-config is not going to work on USB SSD disk so we have to do this old fashion i.e. command line fdisk. Let change partition table with fdisk. You need to remove exiting partition entries and then create a new partition that takes the all the free space on the disk we have. This will only change the disk partition table not the data on the disk.
First Part of this post about: Boot Raspberry Pi from USB SSD
Run fdisk -l to list all the partitions and all the disks attached to your raspberry pi.
1 2 3 4 5 6 7 |
fdisk -l ........ Device Boot Start End Sectors Size Id Type /dev/sda1 8192 532480 524289 256M c W95 FAT32 (LBA) /dev/sda2 540672 6365183 5824512 2.8G 83 Linux ...... |
If you are not sure which disk is your root partition then you have to check it to be sure, first run df -h command to see whcih one is your root mount / and then you can check with findmnt command where root partition is sitting on actual disk.
Output from findmnt
You can see my / (root) partition is sitting on /dev/sda2
1 2 3 4 |
root@pihome:~# findmnt TARGET SOURCE FSTYPE OPTIONS / /dev/sda2 ext4 rw,noatime ├─/dev devtmpfs devtmpfs rw,relatime,size=494908k,nr_inodes=123727,mode=755 |
Output from df -h
Size of the partition and used capacity along with available capacity.
1 2 3 4 5 |
root@pihome:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/root 2.8G 1.8G 886M 67% / devtmpfs 484M 0 484M 0% /dev ... |
Lets get to work and extend /dev/sda2 partition to use full disk. Run fdisk /dev/sda command and follow steps below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
root@pihome:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.33.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/sda: 7.5 GiB, 8027897856 bytes, 15679488 sectors Disk model: DataTraveler 410 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: 0xd02483c7 Device Boot Start End Sectors Size Id Type /dev/sda1 8192 532480 524289 256M c W95 FAT32 (LBA) /dev/sda2 540672 6365183 5824512 2.8G 83 Linux |
- p – Print exiting partition table and take note of /dev/sda2 start (in my case it was 540672 but this is very important)
- d and then 2 – to delete exiting partition /dev/sda2
- n – p – 2 create new partition, set it primary, and its number 2
- First sector – this is the magic number in my case it was 540672 and press enter.
- You may get this message if you do type n to Partition #2 contains a ext4 signature. Do you want to remove the signature?
- w to save partition table and exit fdisk
- reboot the pi
List of steps to Create Partition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
root@pihome:~# fdisk -uc /dev/sda Welcome to fdisk (util-linux 2.33.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/sda: 7.5 GiB, 8027897856 bytes, 15679488 sectors Disk model: DataTraveler 410 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: 0xd02483c7 Device Boot Start End Sectors Size Id Type /dev/sda1 8192 532480 524289 256M c W95 FAT32 (LBA) /dev/sda2 540672 6365183 5824512 2.8G 83 Linux Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 has been deleted. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): 2 First sector (2048-15679487, default 2048): 540672 Last sector, +/-sectors or +/-size{K,M,G,T,P} (540672-15679487, default 15679487 ): Created a new partition 2 of type 'Linux' and of size 7.2 GiB. Partition #2 contains a ext4 signature. Do you want to remove the signature? [Y]es/[N]o: n Command (m for help): p Disk /dev/sda: 7.5 GiB, 8027897856 bytes, 15679488 sectors Disk model: DataTraveler 410 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: 0xd02483c7 Device Boot Start End Sectors Size Id Type /dev/sda1 8192 532480 524289 256M c W95 FAT32 (LBA) /dev/sda2 540672 15679487 15138816 7.2G 83 Linux Command (m for help): w The partition table has been altered. Syncing disks. root@pihome:~# reboot |
Resize Partition
After rebooting you can see disk size is still old one, now we need to resize file system with resize2fs command
Run df -h command to check size of the partition and used capacity along with available capacity, now run sudo resize2fs /dev/sda2 to resize root partition (This make take some time). Once partition is resized you can check disk capacity again with df -h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
root@pihome:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/root 2.8G 1.8G 887M 67% / devtmpfs 484M 0 484M 0% /dev ... root@pihome:~# sudo resize2fs /dev/sda2 resize2fs 1.44.5 (15-Dec-2018) Filesystem at /dev/sda2 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/sda2 is now 1892352 (4k) blocks long. root@pihome:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/root 7.1G 1.8G 5.2G 26% / devtmpfs 484M 0 484M 0% /dev ... |
You can buy PiHome SSD disk with all os and
Note: You can buy PiHome Smart Heating SSD disk with the full LAMP stack (Apache, PHP 7.x and MySQL/MariaDB and phpMyAdmin) pre-installed and configured, PiHome SSD is tested with Raspberry pi and compatible with updates from PiHome.
One comment