Comment ajouter un disque externe vierge à un serveur Débian ?

24 x served & 4 x viewed

Etape 1 : Localisation du disque avec la command fdisk :

# fdisk -l
Disk /dev/sda: 238,5 GiB, 256060514304 bytes, 500118192 sectors
Disk model: SMI             
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: gpt
Disk identifier: B9D6E0E3-54C2-41BC-BBF8-3464FCE6A229

Device         Start       End   Sectors  Size Type
/dev/sda1       2048    999423    997376  487M EFI System
/dev/sda2     999424  98656255  97656832 46,6G Linux filesystem
/dev/sda3   98656256 469749759 371093504  177G Linux filesystem
/dev/sda4  469749760 500117503  30367744 14,5G Linux swap


Disk /dev/sdb: 111,8 GiB, 120034123776 bytes, 234441648 sectors
Disk model: KINGSTON SA400S3
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: 0x7ac27f0a

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdb1        2048 234441647 234439600 111,8G 83 Linux


Disk /dev/sdc: 931,5 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Portable SSD T5 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x7beb508f

Device     Boot Start        End    Sectors   Size Id Type
/dev/sdc1        2048 1953522112 1953520065 931,5G  7 HPFS/NTFS/exFAT

# fdisk -l  /dev/sdc1
Disk /dev/sdc1: 931,5 GiB, 1000202273280 bytes, 1953520065 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device      Boot      Start        End    Sectors  Size Id Type
/dev/sdc1p1      4294967295 8589934589 4294967295    2T ff BBT
/dev/sdc1p2      4294967295 8589934589 4294967295    2T ff BBT
/dev/sdc1p3      4294967295 8589934589 4294967295    2T ff BBT
/dev/sdc1p4      4294967295 6854241533 2559274239  1,2T ff BBT

La premiere commande localise mon nouveau disque, avec la seconde j’ai plus de détail.

Etape 2 : Formatage, pas question de laisser en mode Windows

# sudo mkfs.ext3 /dev/sdc1
mke2fs 1.44.5 (15-Dec-2018)
/dev/sdc1 contains a exfat file system labelled 'Samsung_T5'
Proceed anyway? (y,N) y
Creating filesystem with 244190008 4k blocks and 61054976 inodes
Filesystem UUID: 6db583fc-825f-4a0c-9ea5-dbb79bd6ae9f
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done 

Ou mieux en ext4 :

# sudo mkfs.ext4 /dev/sdc1
mke2fs 1.44.5 (15-Dec-2018)
/dev/sdc1 contains a ext3 file system
	created on Fri Nov 13 11:49:54 2020
Proceed anyway? (y,N) y
Creating filesystem with 244190008 4k blocks and 61054976 inodes
Filesystem UUID: bf1d9240-ba6d-4230-8e4e-dd20218231e8
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done  

Etape 3 : Le montage automatique :

# mkdir /media/usbdisk-1

Voir le uuid :

# ls -l /dev/disk/by-uuid/*
lrwxrwxrwx 1 root root 10 nov.  10 10:20 /dev/disk/by-uuid/1D2E-E63C -> ../../sda1
lrwxrwxrwx 1 root root 10 nov.  10 10:20 /dev/disk/by-uuid/5fa91220-4d17-485d-bb7d-3e41fc04e15b -> ../../sda2
lrwxrwxrwx 1 root root 10 nov.  10 10:20 /dev/disk/by-uuid/64b51c15-9706-4ac5-a369-774ce9539762 -> ../../sda3
lrwxrwxrwx 1 root root 10 nov.  13 15:05 /dev/disk/by-uuid/bf1d9240-ba6d-4230-8e4e-dd20218231e8 -> ../../sdc1
lrwxrwxrwx 1 root root 10 nov.  10 10:20 /dev/disk/by-uuid/c8478b72-fcaf-4dc7-87a7-5156cc19efab -> ../../sdb1
lrwxrwxrwx 1 root root 10 nov.  10 10:20 /dev/disk/by-uuid/d4f59815-be3d-437c-b204-ca794d170ce9 -> ../../sda4

Ajouter dans /etc/fstab :

UUID=bf1d9240-ba6d-4230-8e4e-dd20218231e8 /media/usbdisk-1 ext4 errors=remount-ro 0 1

Monter le disque ensuite :

# mount /media/usbdisk-1
# df -h
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
udev               3,9G       0  3,9G   0% /dev
tmpfs              783M     66M  718M   9% /run
/dev/sda2           46G    7,3G   37G  17% /
tmpfs              3,9G    8,0K  3,9G   1% /dev/shm
tmpfs              5,0M       0  5,0M   0% /run/lock
tmpfs              3,9G       0  3,9G   0% /sys/fs/cgroup
/dev/sdb1          110G     43G   62G  42% /mnt/backup
/dev/sda1          487M    5,2M  481M   2% /boot/efi
/dev/sda3          174G     30G  135G  19% /home
tmpfs              783M    4,0K  783M   1% /run/user/112
tmpfs              783M       0  783M   0% /run/user/1000
/dev/sdc1          916G     77M  870G   1% /media/usbdisk-1

C’est fini !

 

Rock64 / Débian : Ajouter un disque dur externe

182 x served & 46 x viewed

Je viens de prendre un disque dur externe car j’ai pas trop confiance dans les cartes SD ( désolé Michel).

Etape 1 : Le formatage, pour cela il faut fdisk !

rock64@rock64:~$ cat /etc/debian_version 
9.9

rock64@rock64:~$ sudo whereis fdisk
fdisk: /sbin/fdisk /usr/share/man/man8/fdisk.8.gz

rock64@rock64:~$ dpkg -S /sbin/fdisk
util-linux: /sbin/fdisk

rock64@rock64:~$ sudo fdisk -l               
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mtdblock0: 4 MiB, 4128768 bytes, 8064 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 /dev/mmcblk1: 59.5 GiB, 63864569856 bytes, 124735488 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: gpt
Disk identifier: 9CFDF7D8-766C-43DE-9354-57097D428E8F

Device          Start       End   Sectors  Size Type
/dev/mmcblk1p1     64      8063      8000  3.9M Linux filesystem
/dev/mmcblk1p2   8064      8191       128   64K Linux filesystem
/dev/mmcblk1p3   8192     16383      8192    4M Linux filesystem
/dev/mmcblk1p4  16384     24575      8192    4M Linux filesystem
/dev/mmcblk1p5  24576     32767      8192    4M Linux filesystem
/dev/mmcblk1p6  32768    262143    229376  112M Microsoft basic data
/dev/mmcblk1p7 262144 124735454 124473311 59.4G Linux filesystem


Disk /dev/sda: 1.8 TiB, 2000398933504 bytes, 3907029167 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: 0x88185100

Device     Boot Start        End    Sectors  Size Id Type
/dev/sda1  *       64 3907024128 3907024065  1.8T  7 HPFS/NTFS/exFAT

rock64@rock64:~$ sudo mkfs.ext3 /dev/sda1
mke2fs 1.43.4 (31-Jan-2017)
/dev/sda1 contains a ntfs file system labelled 'Seagate Portable Drive'
Proceed anyway? (y,N) y
Creating filesystem with 488378008 4k blocks and 122101760 inodes
Filesystem UUID: 42a1cde2-2269-4582-b4a0-2bb6272b0990
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

Allocating group tables: done       

A noter qu’en cas de crash durant le formatage, je conseille alors :

rock64@rock64:~$ sudo mkfs -t ext4 /dev/sda1
[sudo] password for rock64: 
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 488378008 4k blocks and 122101760 inodes
Filesystem UUID: 3e48d36d-20e7-45b8-abea-97a6b234cfcc
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information:   

Et si la connexion n’est pas stable pendant le formatage :

rock64@rock64:~$ sudo apt-get install screen
...
rock64@rock64:~$ sudo screen -dmS "format"  mkfs -t ext4 /dev/sda1
...

Etape 2 : Préparation du montage sur l’OS :

rock64@rock64:~$ sudo mkdir /disk1

rock64@rock64:~$ sudo mount /dev/sda1 /disk1

rock64@rock64:~$ df -H

Filesystem      Size  Used Avail Use% Mounted on
udev            2.1G     0  2.1G   0% /dev
tmpfs           412M  5.6M  406M   2% /run
/dev/mmcblk1p7   63G   41G   20G  68% /
tmpfs           2.1G     0  2.1G   0% /dev/shm
tmpfs           5.3M  4.1k  5.3M   1% /run/lock
tmpfs           2.1G     0  2.1G   0% /sys/fs/cgroup
/dev/mmcblk1p6  118M  1.1M  117M   1% /boot/efi
tmpfs           412M     0  412M   0% /run/user/1000
/dev/sda1       2.0T   80M  1.9T   1% /disk1

Etape 3 : Modification du fstab :

rock64@rock64:~$ sudo vi /etc/fstab 

Etape 3 bis: On peut aussi utiliser les labels:

rock64@rock64:~$ sudo e2label /dev/sda1 nextcloud
rock64@rock64:~$ sudo vi /etc/fstab 
rock64@rock64:~$ sudo cat /etc/fstab 
LABEL=boot /boot/efi vfat defaults,sync 0 0
LABEL=nextcloud /disk1 ext4 defaults 1 1

ATTENTION, il faut tester le fichier /etc/fstab AVANT le reboot … sinon c’est LA MORT

rock64@rock64:~$ sudo mount -a /etc/fstab 

Voir même un petit text de copie :

rock64@rock64:~$ sudo cp -r /var/www/html/nextcloud/ /disk1/.