Table des matières
Construisez votre propre NAS
Un NAS est un périphérique de stockage de films, photos, musique et autre, accessible depuis n'importe où sur le réseau auquel il est connecté.
Pré-requis
-
Un Raspberry avec sa carte Sd, installé et accessible pas SSH.
-
2 Clés USB externes ou 2 disques avec un hub USB 3.0 alimenté
-
Gigabit Ethernet (recommended)
Première étape
-
Assurez-vous que tout est à jour avec
pi@framboise:~ $ sudo apt update && sudo apt -y upgrade
puis redémarrez.
-
Branchez vos lecteurs de disque USB sur le hub USB 3.0 alimenté connecté à votre Raspberry Pi. Laissez au système quelques secondes puis entrez :
pi@framboise4:~ $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 250G 0 disk └─sda1 8:1 1 250G 0 part sdb 8:16 1 250G 0 disk └─sdb1 8:17 1 250G 0 part mmcblk0 179:0 0 59,6G 0 disk ├─mmcblk0p1 179:1 0 256M 0 part /boot └─mmcblk0p2 179:2 0 59,4G 0 part /
Cette commande informe sur les périphériques connectés au système.Celui qui commence par «mmcblk0» est la carte microSD contenant Raspbian. sda et sdb sont les deux disques USB. B).
Autres étapes
La méthode RAID protège les données en les dupliquant sur plusieurs disques. Nous le plus simple : RAID 1, ou mise en miroir. Tout ce qui est écrit sur un disque est automatiquement écrit sur l'autre.
En cas de panne d'un disque, votre NAS continue de fonctionner et vous ne perdez rien : remplacez le disque défectueux dès que possible et la matrice est «reconstruite».
-
Partitionnez les disques avec fdisk :
pi@framboise4:~ $ sudo fdisk /dev/sda Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 250 GiB, 268436504576 bytes, 524290048 sectors Disk model: STORAGE DEVICE Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xdecc595d Device Boot Start End Sectors Size Id Type /dev/sda1 2048 524290047 524288000 250G 83 Linux Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (2048-524290047, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-524290047, default 524290047): Created a new partition 1 of type 'Linux' and of size 250 GiB. Partition #1 contains a vfat signature. Do you want to remove the signature? [Y]es/[N]o: y The signature will be removed by a write command. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. pi@framboise4:~ $
À la demande de commande,
-
Tapez p pour voir les partitions existantes.
-
S'il y a une partition,tapez d pour l'effacer
-
Tapez n pour une créer nouvelle partition puis répondez ↵ Entrée aux questions pour accepter les valeurs par défaut et Y s'il est proposé d'effacer une signature.
-
Au retour à l'invite de commande, tapez w pour écrire les modifications sur le disque.
-
fdisk quitte et revient à l'invite de commande
Répétez le processus pour le deuxième lecteur :pi@framboise4:~ $ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sdb: 250 GiB, 268436504576 bytes, 524290048 sectors Disk model: STORAGE DEVICE Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xdecc595d Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 524290047 524288000 250G 83 Linux Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (2048-524290047, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-524290047, default 524290047): Created a new partition 1 of type 'Linux' and of size 250 GiB. Partition #1 contains a vfat signature. Do you want to remove the signature? [Y]es/[N]o: y The signature will be removed by a write command. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. pi@framboise4:~ $
Installez mdadm, le logiciel de gestion RAID :pi@framboise4:~ $ sudo apt install mdadm
Demandez maintenant à mdadm de créer la matrice RAID-1 (répondez Y pour accepter) :pi@framboise4:~ $ sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sda1 /dev/sdb1 mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 mdadm: size set to 262011904K mdadm: automatically enabling write-intent bitmap on large array Continue creating array? y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started.
Raspbian voit désormais les deux disques physiques comme un seul périphérique. Partitionnez le nouveau lecteur virtuel (ici, nous créons 3 partitions) :pi@framboise4:~ $ sudo fdisk /dev/md0 Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. The old ext4 signature will be removed by a write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xd399b01c. Command (m for help): p Disk /dev/md0: 249,9 GiB, 268300189696 bytes, 524023808 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 Disklabel type: dos Disk identifier: 0xd399b01c Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (2048-524023807, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-524023807, default 524023807): +100G Created a new partition 1 of type 'Linux' and of size 100 GiB. Command (m for help): p Disk /dev/md0: 249,9 GiB, 268300189696 bytes, 524023808 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 Disklabel type: dos Disk identifier: 0xd399b01c Device Boot Start End Sectors Size Id Type /dev/md0p1 2048 209717247 209715200 100G 83 Linux Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (2-4, default 2): First sector (209717248-524023807, default 209717248): Last sector, +/-sectors or +/-size{K,M,G,T,P} (209717248-524023807, default 524023807): +96G Created a new partition 2 of type 'Linux' and of size 96 GiB. Command (m for help): p Disk /dev/md0: 249,9 GiB, 268300189696 bytes, 524023808 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 Disklabel type: dos Disk identifier: 0xd399b01c Device Boot Start End Sectors Size Id Type /dev/md0p1 2048 209717247 209715200 100G 83 Linux /dev/md0p2 209717248 411043839 201326592 96G 83 Linux Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (3,4, default 3): First sector (411043840-524023807, default 411043840): Last sector, +/-sectors or +/-size{K,M,G,T,P} (411043840-524023807, default 524023807): Created a new partition 3 of type 'Linux' and of size 53,9 GiB. Command (m for help): p Disk /dev/md0: 249,9 GiB, 268300189696 bytes, 524023808 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 Disklabel type: dos Disk identifier: 0xd399b01c Device Boot Start End Sectors Size Id Type /dev/md0p1 2048 209717247 209715200 100G 83 Linux /dev/md0p2 209717248 411043839 201326592 96G 83 Linux /dev/md0p3 411043840 524023807 112979968 53,9G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Créez les répertoires de montage :pi@framboise4:~ $ sudo mkdir -p /media/{home,data,nas}
Formatez et montez les partitions du nouveau lecteur virtuel :pi@framboise4:~ $ sudo mkfs.ext4 -O ^has_journal -L home /dev/md0p1 mke2fs 1.44.5 (15-Dec-2018) /dev/md0p1 contains a ext4 file system labelled 'home' created on Sat Aug 22 20:02:26 2020 Proceed anyway? (y,N) y Creating filesystem with 26214400 4k blocks and 6553600 inodes Filesystem UUID: e659b8c1-36fb-4bb3-9e8f-50c2db9d2335 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done pi@framboise4:~ $ sudo mkfs.ext4 -O ^has_journal -L data /dev/md0p2 mke2fs 1.44.5 (15-Dec-2018) Creating filesystem with 25165824 4k blocks and 6291456 inodes Filesystem UUID: 41d98dbc-d710-4a9c-bfb4-0fb6463238a1 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done pi@framboise4:~ $ sudo mkfs.ext4 -O ^has_journal -L nas /dev/md0p3 mke2fs 1.44.5 (15-Dec-2018) Creating filesystem with 14122496 4k blocks and 3530752 inodes Filesystem UUID: 93e7445d-5004-4517-ad3b-c6f5b128d653 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done
Montez les nouvelles partitions :Conclusion
Problèmes connus
Voir aussi
-