killwater
Posts: 13
Joined: Sat Jan 13, 2018 11:05 pm

HDD partitioning for Raspbian installation.

Thu Jan 18, 2018 10:17 pm

Hello
I am trying to set up pi to boot Raspbian from HDD. The problem is that I have a partition already on the disk with data that I need (and a lot of it). I was thinking of making a swap partition 1GB at the beginning of the HDD then another one after it 16GB for Raspbian (I use GParted). My understanding is that this approach may not work because image file contains a partition table that will override my setup and destroy the data. Is there a safe way to do it?

User avatar
procount
Posts: 2211
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: HDD partitioning for Raspbian installation.

Thu Jan 18, 2018 10:47 pm

You are right - do not write a Raspbian image directly to your HDD because you will lose your original partition table and data.

Raspbian will need 2 partitions: a FAT boot partition and an ext4 ROOTFS partition.
The boot partition need only be about 60MB. Your rootfs can be 16GB.
You can create these (along with your swap partition if you like) using gparted. I suggest making the 1st partition the boot partition, so you can read it from Windows if you ever need to edit it.
Now, to get Raspbian onto those partitions, I can suggest a couple of ways:
1) Flash a Raspbian image to a 16GB SD card using Etcher, then copy the files from the 2 partitions onto the respective partitions of your HDD (Use rsync or similar)
2) Take the NOOBS files for Raspbian (boot.tar.xz and root.tar.xz) and expand them onto the respective partitions of your HDD.

In both cases you will have a few fixups to do in /boot/cmdline.txt and /etc/fstab to tell it which partitions the boot and rootfs are using.

I assume you already know how to enable USB booting on a RPi3?
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
davidcoton
Posts: 5027
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: HDD partitioning for Raspbian installation.

Thu Jan 18, 2018 10:50 pm

Whichever way you find, make a backup of your data first. (Surely you make regular backups of anything important anyway?)

I do not know of a method to install an OS while keeping an existing data partition, and I would regard any suggested method as risky.

Edit: But I do trust procount's knowledge and understanding. Still make a backup first.
Last edited by davidcoton on Thu Jan 18, 2018 11:31 pm, edited 1 time in total.
Signature retired

User avatar
procount
Posts: 2211
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: HDD partitioning for Raspbian installation.

Thu Jan 18, 2018 11:08 pm

davidcoton wrote:
Thu Jan 18, 2018 10:50 pm
Edit: But I do trust procount's knowledge and understanding.
I wouldn't! ;) So make a backup first (forgot that bit) or try it out on a usb stick first.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

killwater
Posts: 13
Joined: Sat Jan 13, 2018 11:05 pm

Re: HDD partitioning for Raspbian installation.

Sat Jan 20, 2018 7:20 pm

Hello
First of all thank you for the tips.
I tried to follow the 2nd method proposed by procount but unfortunately it did not work. Here is what I did:
1. Enabled the usb boot. Returned code from terminal is 17:3020000a. Rebooted.
2. Created partition BOOT - 100MiB FAT32 UUID:A34A-27AD
3. Created partion swap - 1GiB
4. Created partition root - 14.65 GiB ext4 UUID: 5f3943f8-e4ed-4e9a-abb9-a8406baa3ad2
5. Downloaded noobs zip file from the website. Unizpped.
6. From os/Raspbian in noobs folder I unzipped root.tar.xz to root partition and boot.tar.xz to BOOT partition.
7. Modified root/etc/fstab to look like:

Code: Select all

proc            /proc           proc    defaults          0       0
PARTUUID=A34A-27AD  /boot           vfat    defaults          0       2
PARTUUID=5f3943f8-e4ed-4e9a-abb9-a8406baa3ad2  /               ext4    defaults,noatime  0       1
8. Modified boot/cmdline.txt to look like:

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=5f3943f8-e4ed-4e9a-abb9-a8406baa3ad2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh splash plymouth.ignore-serial-consoles
9. Reboot - it boots from SD. Removed SD - does not boot at all but there is power provided to the HDD.

User avatar
procount
Posts: 2211
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: HDD partitioning for Raspbian installation.

Sat Jan 20, 2018 9:22 pm

It looks like you have your PARTUUIDs and UUIDs mixed up.

https://raspberrypi.stackexchange.com/q ... d-partuuid
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

fbe
Posts: 642
Joined: Thu Aug 17, 2017 9:08 pm

Re: HDD partitioning for Raspbian installation.

Sat Jan 20, 2018 9:34 pm

Your PARTUUID values may be wrong. Boot from SD card with your HDD connected.
Check the output of:

Code: Select all

lsblk -o NAME,SIZE,FSTYPE,PARTUUID
What type does the partition with data have, that you kept on your HDD?

Code: Select all

init=/usr/lib/raspi-config/init_resize.sh
is not needed in cmdline.txt on your HDD boot partition. You should better create the root partition with the size you need.

killwater
Posts: 13
Joined: Sat Jan 13, 2018 11:05 pm

Re: HDD partitioning for Raspbian installation.

Sun Jan 21, 2018 1:21 pm

Hello
Again thank you for help. Much appreciated.
I have applied the suggested changes:
boot

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=d3e1c6dd-04 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
root

Code: Select all

proc            /proc           proc    defaults          0       0
PARTUUID=d3e1c6dd-01  /boot           vfat    defaults          0       2
PARTUUID=d3e1c6dd-04  /               ext4    defaults,noatime  0       1
The partitions I currently have :

Code: Select all

NAME          SIZE FSTYPE PARTUUID
sda         698.7G        
├─sda1        100M vfat   d3e1c6dd-01
├─sda2          1G swap   d3e1c6dd-02
├─sda3          1K        d3e1c6dd-03
├─sda4       14.7G ext4   d3e1c6dd-04
├─sda5      190.2G ntfs   d3e1c6dd-05
└─sda6       13.2G ext4   d3e1c6dd-06
The worrying thing is when I remove SD card then the HDD powers up but I do not get rainbow square test.
Also I tried to boot my SD card from USB memory card reader - it boots to something like half way and then green light starts blinking in regular interval.

Return to “Beginners”