Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
install_raspbian_on_f2fs_root [30.01.2017 16:17] – created Pascal Suter | install_raspbian_on_f2fs_root [22.12.2020 18:33] (current) – Pascal Suter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Install Raspbian on f2fs root ====== | ====== Install Raspbian on f2fs root ====== | ||
this may be combined with [[solve raspbian SD card corruption issues with read-only mounted root partition]] in order to minimize SD card corruption on a raspberry pi or if your raspberry is usually shut down regularily, you might still want to consider this because f2fs was specifically optimized for flash memory storage and supposedly should help to extend the life of such storage devices significantly. | this may be combined with [[solve raspbian SD card corruption issues with read-only mounted root partition]] in order to minimize SD card corruption on a raspberry pi or if your raspberry is usually shut down regularily, you might still want to consider this because f2fs was specifically optimized for flash memory storage and supposedly should help to extend the life of such storage devices significantly. | ||
+ | |||
+ | before you begin **disable automount in gnome**. i've seen it more than once in the recent past, that gnome auto-mounted a f2fs partition thinking it was ext4 and then destroyed the contents of the filesystem. so disable it while you do all this. | ||
+ | gsettings set org.gnome.desktop.media-handling automount ' | ||
+ | |||
+ | to re-enable it when you are done you can simply run | ||
+ | gsettings set org.gnome.desktop.media-handling automount ' | ||
+ | | ||
+ | ===== the script ===== | ||
+ | i have created a little bash script that does it all.. it takes the path to the raspberry OS image and the path to the sd card block device as parameters and then erases the card, creates partitins, copies the files from the image and finally adjusts what is necessary in order to adopt to the different filesystem and partition uuid' | ||
+ | |||
+ | for the script to run you need to have the following tools installed on your linux: '' | ||
+ | |||
+ | here is the script, just run it without any parameters to get the usage info: | ||
+ | <code bash raspberry_f2fs.sh> | ||
+ | #!/bin/bash | ||
+ | if [ " | ||
+ | echo "this script needs to be run as root in order to modify partitions etc. please provide your root password for sudo to execute this script as root" | ||
+ | sudo -s /bin/bash " | ||
+ | exit $? | ||
+ | fi | ||
+ | |||
+ | image=$1 | ||
+ | card=$2 | ||
+ | |||
+ | if [ -z $1 ]; then | ||
+ | echo " | ||
+ | echo " | ||
+ | exit 100 | ||
+ | fi | ||
+ | |||
+ | if [ ! -f $image ]; then | ||
+ | echo " | ||
+ | echo "file $image not found," | ||
+ | echo "first parameter should be the raspberry os image" | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | if ! kpartx -l $image | ||
+ | echo " | ||
+ | echo "image $image not readable by kpartx or kpartx not found" | ||
+ | echo "first parameter should be the raspberry os image, and make sure kpartx is installed" | ||
+ | exit 2 | ||
+ | fi | ||
+ | |||
+ | if [ ! -b $card ]; then | ||
+ | echo " | ||
+ | echo "$card is not a block device" | ||
+ | echo " | ||
+ | exit 3 | ||
+ | fi | ||
+ | echo | ||
+ | read -p "I will now ERASE EVERYTHING on $card, do you want to continue! (yN)" -n 1 -r | ||
+ | echo | ||
+ | if [[ ! $REPLY =~ ^[Yy]$ ]]; then | ||
+ | echo " | ||
+ | exit 101 | ||
+ | fi | ||
+ | |||
+ | # ok we are good to go :) | ||
+ | |||
+ | set -e | ||
+ | function clean_up(){ | ||
+ | umount /tmp/sd | ||
+ | umount /tmp/img | ||
+ | kpartx -d $image | ||
+ | rmdir / | ||
+ | echo | ||
+ | echo " | ||
+ | } | ||
+ | trap clean_up EXIT SIGINT | ||
+ | |||
+ | echo "make sure the card is unmounted" | ||
+ | set +e | ||
+ | umount $card* 2>/ | ||
+ | set -e | ||
+ | |||
+ | echo "erase old partitions" | ||
+ | wipefs -af $card | ||
+ | echo " | ||
+ | parted -s $card mklabel msdos | ||
+ | parted -s $card mkpart primary fat32 0% 256MB | ||
+ | parted -s $card mkpart primary 256MB 100% | ||
+ | partprobe $card | ||
+ | sleep 2 | ||
+ | |||
+ | if echo " | ||
+ | partbase=" | ||
+ | else | ||
+ | partbase=$card | ||
+ | fi | ||
+ | |||
+ | echo " | ||
+ | mkfs.vfat ${partbase}1 | ||
+ | |||
+ | echo " | ||
+ | mkfs.f2fs -f ${partbase}2 | ||
+ | |||
+ | echo " | ||
+ | mkdir -p / | ||
+ | mount ${partbase}1 /tmp/sd | ||
+ | |||
+ | echo "load image as loopback device and mount boot partition" | ||
+ | out=$(kpartx -av $image) | ||
+ | echo " | ||
+ | loopdev=$(echo " | ||
+ | mount / | ||
+ | |||
+ | echo "copy the contents of the boot partition" | ||
+ | rsync -av /tmp/img/ /tmp/sd/ | ||
+ | |||
+ | echo " | ||
+ | partuuidbase=$(blkid $card | sed -e ' | ||
+ | sed -i " | ||
+ | sed -i ' | ||
+ | sed -i ' | ||
+ | |||
+ | echo | ||
+ | echo | ||
+ | echo "I am done with the boot partition, now is the time to configure your network for headless operation if you want to.." | ||
+ | echo | ||
+ | read -p "do you want to configure a wireless lan? if so, type \" | ||
+ | echo | ||
+ | if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
+ | cat > / | ||
+ | ctrl_interface=DIR=/ | ||
+ | update_config=1 | ||
+ | country=«your_ISO-3166-1_two-letter_country_code» | ||
+ | |||
+ | network={ | ||
+ | ssid=" | ||
+ | psk=" | ||
+ | } | ||
+ | EOF | ||
+ | nano / | ||
+ | fi | ||
+ | echo | ||
+ | read -p "do you want to enable the ssh-server on this raspberry right from the start? if so, type \" | ||
+ | echo | ||
+ | if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
+ | touch /tmp/sd/ssh | ||
+ | ssh=1 | ||
+ | else | ||
+ | ssh=0 | ||
+ | fi | ||
+ | |||
+ | echo | ||
+ | echo "we are done with the boot partition" | ||
+ | echo " | ||
+ | umount /tmp/sd | ||
+ | umount /tmp/img | ||
+ | mount ${partbase}2 /tmp/sd | ||
+ | mount / | ||
+ | |||
+ | echo "copy the contents of the root partition to the card, this can take a few minutes..." | ||
+ | rsync --progress -aAHhvxX /tmp/img/ /tmp/sd/ | ||
+ | echo "done copying" | ||
+ | |||
+ | echo " | ||
+ | sed -i " | ||
+ | sed -i ' | ||
+ | rm -f / | ||
+ | |||
+ | if [ $ssh -eq 1 ]; then | ||
+ | echo " | ||
+ | mkdir -p / | ||
+ | chmod 700 / | ||
+ | touch {/ | ||
+ | chmod 600 {/ | ||
+ | chown -R 1000 / | ||
+ | echo "done, to add your private key, boot the raspberry pi and login as user pi with password \" | ||
+ | fi | ||
+ | echo | ||
+ | echo | ||
+ | echo "done preparing the root partition" | ||
+ | echo | ||
+ | read -p "do you want to configure a fixed ip address? if so, type \" | ||
+ | echo | ||
+ | if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
+ | nano / | ||
+ | fi | ||
+ | echo | ||
+ | read -p "do you want to change the hostname to something meaningful right now? if so, type \" | ||
+ | echo | ||
+ | if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
+ | nano / | ||
+ | fi | ||
+ | echo | ||
+ | echo 'okay, we are done, time to clean up! mind you, this can take some time as we weill have to wait for everything to be written to the SD card. do not abort!' | ||
+ | umount /tmp/sd | ||
+ | umount /tmp/img | ||
+ | kpartx -d $image | ||
+ | rmdir / | ||
+ | echo | ||
+ | echo "you are all set, you can now remove the sd card and put it into your raspberry, boot it up and start using it" | ||
+ | echo 'if you want to insert this card into your pc in the future to modify some things on it, I strongly recommend to disable gnomes automount temporarily, | ||
+ | echo "to do that you can simply run this command:" | ||
+ | echo " | ||
+ | echo "to re-enable simply use ' | ||
+ | trap - EXIT | ||
+ | </ | ||
+ | |||
+ | ===== to do it manually ===== | ||
+ | if you still want to do it manually, here are the steps. you can of course also create the partitions manually, rather than burning the image and booting it on the raspberry to resize the root partition to the full size of the sdcard. | ||
here is a quick step by step howto how i installed raspbian from the minimal image onto an f2fs sd card | here is a quick step by step howto how i installed raspbian from the minimal image onto an f2fs sd card | ||
Line 11: | Line 214: | ||
- mount it < | - mount it < | ||
mount -t f2fs /dev/sdf2 / | mount -t f2fs /dev/sdf2 / | ||
- | - mount second partition from image (see also [[]]): < | + | - mount second partition from image (see also [[mount_a_single_partition_from_a_dd_disk_image]]): < |
kpartx -av raspbianimage.img | kpartx -av raspbianimage.img | ||
mount / | mount / | ||
</ | </ | ||
- now copy the os to the sd card < | - now copy the os to the sd card < | ||
- | - edit fstab: < | + | |
+ | | ||
- unmount it all again < | - unmount it all again < | ||
- mount boot partition and edit boot options:< | - mount boot partition and edit boot options:< | ||
- | nano / | + | nano / |
- cleanup: < | - cleanup: < | ||
rmdir /tmp/sd /tmp/image | rmdir /tmp/sd /tmp/image | ||
</ | </ | ||
- insert the sd card into your raspberry pi and finally start configuring it :) | - insert the sd card into your raspberry pi and finally start configuring it :) |