ex1tium
Posts: 1
Joined: Fri May 24, 2013 10:25 am
Location: Tornio, Finland

Using raspi-config to expand root partition with USB install

Fri May 24, 2013 10:41 am

Hi,

My original 16gb SD card broke this morning so I decided to finally try USB install. I managed to get Raspbian to boot from my 8gb USB stick by making changes to cmdline.txt on SD card. However I have no clue how to modify /usr/bin/raspi-config script to expand my root partition in USB stick since it thinks the system is installed on SD. I was hoping some of you could help me to find the answers.

Code: Select all

do_expand_rootfs() {
  if ! [ -h /dev/root ]; then
    whiptail --msgbox "/dev/root does not exist or is not a symlink. Don't know how to expand" 20 60 2
    return 0
  fi

  ROOT_PART=$(readlink /dev/root)
  PART_NUM=${ROOT_PART#mmcblk0p}
  if [ "$PART_NUM" = "$ROOT_PART" ]; then
    whiptail --msgbox "/dev/root is not an SD card. Don't know how to expand" 20 60 2
    return 0
  fi

  # NOTE: the NOOBS partition layout confuses parted. For now, let's only
  # agree to work with a sufficiently simple partition layout
  if [ "$PART_NUM" -ne 2 ]; then
    whiptail --msgbox "Your partition layout is not currently supported by this tool. You are probably using NOOBS, in which case your r$
    return 0
  fi

  LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:)

  if [ "$LAST_PART_NUM" != "$PART_NUM" ]; then
    whiptail --msgbox "/dev/root is not the last partition. Don't know how to expand" 20 60 2
    return 0
  fi

  # Get the starting offset of the root partition
  PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d:)
  [ "$PART_START" ] || return 1
  # Return value will likely be error for fdisk as it fails to reload the
  # partition table because the root fs is mounted
  fdisk /dev/mmcblk0 <<EOF
p
d
$PART_NUM
n
p
$PART_NUM
$PART_START

p
w
EOF
  ASK_TO_REBOOT=1
I believe this is the script that does the trick in raspi-config. How do I modify it to suit my needs?

Here is

Code: Select all

sudo fdisk -l

Code: Select all

Disk /dev/mmcblk0: 1966 MB, 1966080000 bytes
21 heads, 30 sectors/track, 6095 cylinders, total 3840000 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
Disk identifier: 0x4b505898

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048     3839999     1918976    c  W95 FAT32 (LBA)

Disk /dev/sda: 8056 MB, 8056209408 bytes
248 heads, 62 sectors/track, 1023 cylinders, total 15734784 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
Disk identifier: 0x00014d34

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/sda2          122880     3788799     1832960   83  Linux
and

Code: Select all

df -l

Code: Select all

Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs           1804128 1460532    251948  86% /
/dev/root        1804128 1460532    251948  86% /
devtmpfs           86184       0     86184   0% /dev
tmpfs              18888     224     18664   2% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs              37760       0     37760   0% /run/shm
/dev/mmcblk0p1   1915216   18924   1896292   1% /boot

niaolianyu
Posts: 1
Joined: Thu May 22, 2014 2:43 am

Re: Using raspi-config to expand root partition with USB ins

Thu May 22, 2014 4:11 am

cp /usr/bin/raspi-config ~
sed -i 's/mmcblk0p/sda/' ~/raspi-config
sed -i 's/mmcblk0/sda/' ~/raspi-config
sudo ~/raspi-config

try it
work fine

ArkoXS
Posts: 4
Joined: Thu Jan 26, 2012 4:01 pm

Re: Using raspi-config to expand root partition with USB ins

Fri Jun 13, 2014 12:46 pm

Substitution of mmcblk0 by sda worked for me to.
Thx for the quick fix.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Using raspi-config to expand root partition with USB ins

Fri Jun 13, 2014 1:36 pm

niaolianyu wrote:cp /usr/bin/raspi-config ~
sed -i 's/mmcblk0p/sda/' ~/raspi-config
sed -i 's/mmcblk0/sda/' ~/raspi-config
sudo ~/raspi-config

try it
work fine
FYI, you can do this more simply as:

Code: Select all

$ sed -e 's/mmcblk0p/sda/' -e 's/mmcblk0/sda/' /usr/bin/rasp-config > ~/raspi-config
$ chmod +x !$
$ sudo !$
Or, even more simply, as:

Code: Select all

$ sudo bash
# sed -E 's/mmcblk0p?/sda/' /usr/bin/rasp-config | bash
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Beginners”