Skip to content

Instantly share code, notes, and snippets.

@yangxuan8282
Last active March 14, 2017 16:39
Show Gist options
  • Save yangxuan8282/879ec27a07a7c3b5225901c5dfe9e4be to your computer and use it in GitHub Desktop.
Save yangxuan8282/879ec27a07a7c3b5225901c5dfe9e4be to your computer and use it in GitHub Desktop.
bash scripts migrating NOOBs to Raspbian, run it with `curl -SL https://git.io/vy1Ln | bash`
#!/bin/bash
# FROM https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=106529
# RUN `bash migrate_noobs.sh`
# ABOUT migrating NOOBs to Raspbian
# you need prepare 2 SD cards, card A running NOOBs that you want to migrate, put this card in pi card slot
# card B plug into card reader, insert this into pi usb port, all data in this card will be erased
# and remove all other storage
BOOT_PARTITION=`mount|grep ' /boot '|cut -d' ' -f 1`
ROOT_PARTITION=`mount|grep ' / '|cut -d' ' -f 1`
SDCARD=/dev/sda
sudo umount "$SDCARD"1 "$SDCARD"2 || /bin/true
sudo fdisk "$SDCARD" <<EOF
o
n
p
1
+63M
t
c
n
p
2
w
EOF
sudo mkfs.vfat "$SDCARD"1
sudo mkfs.ext4 -F "$SDCARD"2
sudo dd if=$BOOT_PARTITION of="$SDCARD"1
sudo mount "$SDCARD"2 /mnt
sudo rsync -aAXv --progress --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /mnt
sudo sed -i "s|$BOOT_PARTITION|/dev/mmcblk0p1|g" /mnt/etc/fstab
sudo sed -i "s|$ROOT_PARTITION|/dev/mmcblk0p2|g" /mnt/etc/fstab
sudo umount /mnt
sudo mount "$SDCARD"1 /mnt
sudo sed -i "s|$ROOT_PARTITION|/dev/mmcblk0p2|g" /mnt/cmdline.txt
sudo umount /mnt
echo "
✔ Done, Enjoy your Raspbian ❤
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment