Linux, storage registration(NVME,HDD like) - githeim/windheim_archive GitHub Wiki

Find new Disk(SSD)

Find target disk device node

$ sudo fdisk -l
...
Disk /dev/nvme0n1: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors 
Disk model: Samsung SSD 980 PRO 1TB                                    
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/loop0: 16 MiB, 16777216 bytes, 32768 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: 0x00000000                                            
                                                                       
                                                                       
Disk /dev/loop1: 40.64 MiB, 42602496 bytes, 83208 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/loop2: 49.2 MiB, 51396608 bytes, 100384 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                      
...

in this case /dev/nvme0n1

Format new disk(SSD)

Like following , press key 'n', 'p', 'w'

$ sudo fdisk /dev/nvme0n1
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xa4bf1bb7.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-1953525167, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525167, default 1953525167): 

Created a new partition 1 of type 'Linux' and of size 931.5 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Format to ext4

$ sudo mkfs -t ext4 /dev/nvme0n1
mke2fs 1.45.5 (07-Jan-2020)
Found a dos partition table in /dev/nvme0n1
Proceed anyway? (y,N) y
Discarding device blocks: done                            
Creating filesystem with 244190646 4k blocks and 61054976 inodes
Filesystem UUID: 636fb765-2470-4e8d-82a4-24a09833b523
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     
$

Find Disk Partition UUID

$ sudo blkid
/dev/loop0: SEC_TYPE="msdos" LABEL="L4T-README" UUID="6536-E270" TYPE="vfat"
/dev/mmcblk0p1: UUID="29ac2e29-fdfa-47d4-a3ae-607b997be9dd" TYPE="ext4" PARTLABEL="APP" PARTUUID="3e365e90-a6ce-49cc-9191-a205540ef56b"
/dev/nvme0n1p1: UUID="277ef2f2-2d33-41f9-b670-5f09a839b015" TYPE="ext4" PARTUUID="4cb027a8-01"
/dev/zram0: UUID="239a186c-6d8f-44cc-9a0b-59bd5291ec40" TYPE="swap"
/dev/zram1: UUID="81e61b32-7e73-4ef6-bcfd-4ffa485a8d6f" TYPE="swap"
/dev/zram2: UUID="4e35ac91-f964-4664-8003-62258cc28811" TYPE="swap"

The Partition to change is ''' UUID="277ef2f2-2d33-41f9-b670-5f09a839b015" '''

Add fstab script

edit the file

/etc/fstab

# <file system> <mount point>             <type>          <options>                               <dump> <pass>              
/dev/root            /                     ext4           defaults                                     0 1                   
UUID=277ef2f2-2d33-41f9-b670-5f09a839b015 /media/nvme   ext4    defaults        0       1                                    

apply the changes

$ sudo mount -av
⚠️ **GitHub.com Fallback** ⚠️