Cách thêm ổ đĩa cho dữ liệu linux

JustinJustin
2 min read

Sau khi thêm Hard Disk từ console

Kiểm tra và thấy 20G sdb đã được thêm

lsblk

NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0                         2:0    1    4K  0 disk
loop0                       7:0    0 91.9M  1 loop /snap/lxd/24061
loop1                       7:1    0 63.3M  1 loop /snap/core20/1828
loop2                       7:2    0 49.9M  1 loop /snap/snapd/18357
sda                         8:0    0   20G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0  1.8G  0 part /boot
└─sda3                      8:3    0 18.2G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0 18.2G  0 lvm  /
sdb                         8:16   0   20G  0 disk
sr0                        11:0    1 1024M  0 rom
sr1                        11:1    1  1.4G  0 rom

Mặc định sdb chưa được mount vào bất cứ partition nào → mình sẽ tạo một partition /DATA và mount sdb vào

Tạo thư mục /DATA

mkdir /DATA

Format Disk

mkfs.ext4 -m 0 /dev/sdb

mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 5242880 4k blocks and 1310720 inodes
Filesystem UUID: 49008513-a49b-47e7-9d4d-d39b43139b05
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
echo "/dev/sdb /DATA ext4 defaults 0 0" | tee -a /etc/fstab

Kiểm tra

root@rancher-server:~# cat /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/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-dg01pz1e46ZMw1SrfvxvQxE0u31izNwJ4SxsSGkMucMUr7JvnJe5pTRN3Tv0H5bS / ext4 defaults 0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/f6ba7c53-395e-4b06-bd5b-e5fb9688b0d5 /boot ext4 defaults 0 1
/swap.img       none    swap    sw      0       0
/dev/sdb /data ext4 defaults 0 0

Tiến hành mount

mount -a

Check again

root@rancher-server:~# lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0                         2:0    1    4K  0 disk
loop0                       7:0    0 91.9M  1 loop /snap/lxd/24061
loop1                       7:1    0 63.3M  1 loop /snap/core20/1828
loop2                       7:2    0 49.9M  1 loop /snap/snapd/18357
loop3                       7:3    0 38.8M  1 loop /snap/snapd/21759
loop4                       7:4    0 63.7M  1 loop /snap/core20/2434
loop5                       7:5    0 91.9M  1 loop /snap/lxd/29619
sda                         8:0    0   20G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0  1.8G  0 part /boot
└─sda3                      8:3    0 18.2G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0 18.2G  0 lvm  /
sdb                         8:16   0   20G  0 disk /DATA
sr0                        11:0    1 1024M  0 rom
sr1                        11:1    1  1.4G  0 rom
0
Subscribe to my newsletter

Read articles from Justin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Justin
Justin