Wylistowanie dostępnych dysków:
kacper@dell:~$ sudo fdisk -l Disk /dev/sdb: 28,88 GiB, 31004295168 bytes, 60555264 sectors Disk model: USB DISK 3.0 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: 0x45e29cc2 kacper@dell:~$
Wybieramy dysk który chcemy sformatować /dev/sdb
kacper@dell:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty MBR (DOS) partition table
s create a new empty Sun partition table
Command (m for help): g
Created a new GPT disklabel (GUID: 812597D3-03AF-4EAE-878A-5895036EDE60).
The device contains 'dos' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-60555230, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-60555230, default 60553215): +12G
Created a new partition 1 of type 'Linux filesystem' and of size 12 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
kacper@dell:~$
Nadawanie systemu plików
kacper@dell:~$ sudo mkfs.ext4 /dev/sdb1 mke2fs 1.47.0 (5-Feb-2023) Creating filesystem with 3145728 4k blocks and 786432 inodes Filesystem UUID: a50e3ba3-e594-4a46-a147-82d235c6b2f6 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done kacper@dell:~$
Montowanie dysku:
kacper@dell:~$ mkdir disk kacper@dell:~$ sudo mount /dev/sdb1 ./disk/ kacper@dell:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sdb 8:16 1 28,9G 0 disk └─sdb1 8:17 1 12G 0 part /home/kacper/disk kacper@dell:~$
Jeżeli checmy żeby dysk był montowany razem z uruchomieniem systemu operacyjnego to wpisujemy go do pliku fstab.
kacper@dell:~$ sudo nano /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/nvme0n1p2 during installation UUID=db7ddba8-c421-47d7-a760-eb7f39ee1cee / ext4 errors=remount-ro 0 1 # /boot/efi was on /dev/nvme0n1p1 during installation UUID=361E-C212 /boot/efi vfat umask=0077 0 1 /swapfile none swap sw 0 0 /dev/sdb1 /home/kacper/disk ext4 auto,user,exec,rw,async,atime 0 0
Żeby przetestować wpis fstab można wykonać polecenie sudo mount -a