raspberry:raspberry-sd
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| raspberry:raspberry-sd [2023/10/12 13:38] – [Make it boot] oscar | raspberry:raspberry-sd [2026/12/01 03:46] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Raspberry SD card ====== | ||
| - | The Raspberry is notorious for developing SD card IO issues after extensive SD card usage. With some simple adjustments and precautions the lifetime of the SD card can be increased significantly. Some guidelines: | ||
| - | * Use a SD card from a reliable brand, with minimal Class 10. Initially I encountered isues with some cheap ' | ||
| - | * Use a SD card that is over dimensioned (16 of 32 Gb). | ||
| - | * Change the file system type of the root filesysteem (/) to F2FS, which is targeted to flash memory types. | ||
| - | * Use a in memory ramdisk (tmpfs)for /tmp, /var/log in /etc/fstab. | ||
| - | * Mount the root filesystem (/) with options noatime and nodiratime | ||
| - | * Disable swapfile | ||
| - | With these measures I have two Raspberry Pi's running without problems 7x24 for about 2 years. They even survived two power failures. | ||
| - | |||
| - | ===== F2FS File System ===== | ||
| - | F2FS (Flash-Friendly File System) is a flash file system for the Linux kernel initially developed by Samsung. The F2FS file system takes into account the characteristics of NAND flash memory storage devices (such as solid-state disks,eMMC, and SD cards). Benefits are: | ||
| - | * Increase life span of flash storage due to less write required | ||
| - | * Increased I/O speed | ||
| - | * Doesn' | ||
| - | ==== Migrate EXT4 to F2FS ==== | ||
| - | Our plan is now to replace the EXT4 file system of the root partition, by a F2FS file system, which is SD card friendly and is said to extend the card's durability. | ||
| - | ==== Preparations ==== | ||
| - | Required are: a Raspberry Pi (this example based on Raspbian Stretch). A second computer running Linux. Both should have support for the F2FS file system type available. in order sto install F2FS support run the next command in a terminal: | ||
| - | < | ||
| - | sudo apt-get install f2fs-tools | ||
| - | </ | ||
| - | On the Raspberry Pi, type the following command in a Terminal: | ||
| - | < | ||
| - | sudo lsblk -o NAME, | ||
| - | |||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | </ | ||
| - | The micro SD card on the Raspberry Pi is, as usual, named mmcblk0. It consists of two partitions: | ||
| - | mmcblk0p1 containing a vfat file system, mounted on /boot and | ||
| - | mmcblk0p2 containing an ext4 file system, mounted on / (root). | ||
| - | |||
| - | Since the root partition of the SD card cannot be re-formatted on the running system, the system needs to be shut down, and, because the root partition will be on a f2fs file system when booted again, we need to shutdown the Raspberry Pi and perform the migration on the other computer. Then remove the micro SD card from the Raspbrry Pi and insert it into the second computer' | ||
| - | < | ||
| - | sudo lsblk -o NAME, | ||
| - | | ||
| - | | ||
| - | . . . | ||
| - | | ||
| - | | ||
| - | | ||
| - | . . . | ||
| - | </ | ||
| - | Now I prefer to make some more usable mount point names. Mount the boot partition off the Raspberry Pi, (/dev/sdb1 with a 60 MB vfat file system) to the temporary directory / | ||
| - | < | ||
| - | sudo umount /dev/sdb1 | ||
| - | sudo umount /dev/sdb2 | ||
| - | sudo mkdir / | ||
| - | sudo mkdir / | ||
| - | sudo mount -t vfat /dev/sdb1 / | ||
| - | sudo mount -t ext4 /dev/sdb2 / | ||
| - | </ | ||
| - | Now, the SD card mount is much better readable: | ||
| - | < | ||
| - | sudo lsblk -o NAME, | ||
| - | |||
| - | | ||
| - | | ||
| - | | ||
| - | </ | ||
| - | ==== Backup root partition data ==== | ||
| - | Since the conversion of the partition will destroy all the data. So we need to temporary backup the contents of the root partition. We copy with the -a option is important to ensure that really everything, including e.g. hidden/ | ||
| - | < | ||
| - | sudo mkdir / | ||
| - | sudo cp -a / | ||
| - | </ | ||
| - | ==== Create the f2fs partition ==== | ||
| - | Now unmount the /dev/sdb2 partition and format it with the the f2fs file system. | ||
| - | < | ||
| - | sudo umount /dev/sdb2 | ||
| - | sudo mkfs.f2fs /dev/sdb2 | ||
| - | </ | ||
| - | ==== Restore root partition data ==== | ||
| - | The partition has now a f2fs file system, but is empty, because by formatting all it's content got lost. Thus, we need to Re-mount the partition to it's previous mount point and copy the data that we backed up. | ||
| - | < | ||
| - | sudo mount -t f2fs /dev/sdb2 / | ||
| - | </ | ||
| - | Now with the f2fs type option. The SD card mount will then look like this: | ||
| - | < | ||
| - | | ||
| - | | ||
| - | | ||
| - | </ | ||
| - | We can now restore the root file system' | ||
| - | < | ||
| - | sudo cp -a / | ||
| - | </ | ||
| - | ==== Make it boot ==== | ||
| - | Make the Raspberry Pi SD card bootable with this new partition type. Edit the SD card's /etc/fstab file and adapt the root file system' | ||
| - | < | ||
| - | sudo vi / | ||
| - | . . . | ||
| - | / | ||
| - | / | ||
| - | / | ||
| - | / | ||
| - | tmpfs / | ||
| - | tmpfs / | ||
| - | |||
| - | 1 | ||
| - | . . . | ||
| - | </ | ||
| - | |||
| - | Then edit the cmdline.txt file on the SD card's boot partition and adapt the root file system type parameter to f2fs: | ||
| - | < | ||
| - | sudo vi / | ||
| - | ---------------------------------------- | ||
| - | console=serial0, | ||
| - | </ | ||
| - | |||
| - | That's it. You can now unmount the SD card's file systems, eject the card and insert it into the Raspberry Pi's card drive. The Pi will hopefully boot normally. | ||
| - | |||
| - | ===== Fstab Adjustments ===== | ||
| - | Usually temporary files and log files are written quite intensive, wearing out the SD card. By putting these files in memory (ramdisk), the fsash wear is eliminated. Only downside of this approach is that log files vanish when the Raspberry reboots. | ||
| - | Use a in memory ramdisk (tmpfs)for /tmp, /var/log in /etc/fstab. | ||
| - | Mount the root filesystem (/) with options noatime and nodiratime, which eliminates the update of the file properties when a file is last accessed. | ||
| - | < | ||
| - | sudo nano /etc/fstab | ||
| - | proc /proc | ||
| - | / | ||
| - | / | ||
| - | tmpfs / | ||
| - | tmpfs / | ||
| - | </ | ||
| - | |||
| - | ===== Disable Swapfile ===== | ||
| - | Debian/ | ||
| - | < | ||
| - | sudo dphys-swapfile swapoff | ||
| - | </ | ||
| - | There is no necessity to uninstall, however if you are not using it, and do want the space, you can safely remove it. Alternate command to remove: | ||
| - | < | ||
| - | sudo dphys-swapfile uninstall | ||
| - | </ | ||
| - | |||
| - | |||
raspberry/raspberry-sd.1697117915.txt.gz · Last modified: by oscar
