Pi USB disk
Thu, Jan 3, 2019 · 3 minute readlinuxpi
Have an old laptop?
Reuse it’s disk as a USB drive for your Pi.
Assumes that the old drive is SATA (most relatively modern laptops will be).
You will need a USB to SATA adapter cable, such as this one.
Run lsblk to identify the disk and any partitions that currently exist.
In this example the disk is sdb and has 4 partitions - it came from an old HP laptop that was no longer capable of running Windows.
root@pib:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 111.8G 0 disk
├─sda1 8:1 0 94M 0 part /boot
└─sda2 8:2 0 111.7G 0 part /
sdb 8:16 0 298.1G 0 disk
├─sdb1 8:17 0 300M 0 part
├─sdb2 8:18 0 277.6G 0 part
├─sdb3 8:19 0 15.2G 0 part
└─sdb4 8:20 0 5G 0 part
Use parted to remove exiting partitions (rm) and create a new one (mkpart) using the whole disk.
root@pib:~# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Hitachi HTS723232A7A364 (scsi)
Disk /dev/sdb: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 316MB 315MB primary ntfs boot
2 316MB 298GB 298GB primary ntfs
3 298GB 315GB 16.4GB primary ntfs
4 315GB 320GB 5363MB primary fat32 lba
(parted) rm 4
(parted) rm 3
(parted) rm 2
(parted) rm 1
(parted) print
Model: Hitachi HTS723232A7A364 (scsi)
Disk /dev/sdb: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
(parted) mkpart primary ext4 0% 100%
(parted) print
Model: Hitachi HTS723232A7A364 (scsi)
Disk /dev/sdb: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 320GB 320GB primary ext4 lba
(parted) quit
Information: You may need to update /etc/fstab.
Format the new partition and mount it.
If the disk came from a laptop that was running Windows you will probably see the warning about SYSTEM filesystem.
root@pib:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 111.8G 0 disk
├─sda1 8:1 0 94M 0 part /boot
└─sda2 8:2 0 111.7G 0 part /
sdb 8:16 0 298.1G 0 disk
└─sdb1 8:17 0 298.1G 0 part
root@pib:~# mkfs.ext4 /dev/sdb1
mke2fs 1.43.4 (31-Jan-2017)
/dev/sdb1 contains a ntfs file system labelled 'SYSTEM'
Proceed anyway? (y,N) y
Creating filesystem with 78142464 4k blocks and 19537920 inodes
Filesystem UUID: 3ce5b730-fc17-4114-86e0-d43fdc0755fe
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks):
done
Writing superblocks and filesystem accounting information: done
root@pib:~# mkdir -p /disk/sdb
root@pib:~# mount /dev/sdb1 /disk/sdb
root@pib:~# df -k /disk/sdb
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 306615224 65564 290904784 1% /disk/sdb
Get the partition UUID and add entry to fstab (if you want disk to mount when Pi boots).
root@pib:~# blkid -o export
...
DEVNAME=/dev/sdb1
UUID=3ce5b730-fc17-4114-86e0-d43fdc0755fe
TYPE=ext4
PARTUUID=ad98c14a-01
## example fstab entry
PARTUUID=ad98c14a-01 /disk/sdb ext4 defaults,noatime 0 1