Ubuntu Server 20.04添加硬盤

Ubuntu Server 20.04添加硬盤


需要使用命令:

  1. fdisk https://www.runoob.com/linux/linux-comm-fdisk.html
  2. df https://www.runoob.com/linux/linux-comm-df.html
  3. mount https://www.runoob.com/linux/linux-comm-mount.html

操作步驟:

  1. 關機狀態下添加硬盤,並連接

  2. 查看當前硬盤情況

# 查看硬盤命令
fdisk -l
# 輸出以下信息,/dev/sdb是新增硬盤
Disk /dev/sdb: 120 GiB, 128849018880 bytes, 251658240 sectors
Disk model: Virtual disk
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/sda: 64 GiB, 68719476736 bytes, 134217728 sectors
Disk model: Virtual disk
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: 7DD81767-EF31-4B0B-B2A8-99CDF9B4E0D1

Device       Start       End   Sectors  Size Type
/dev/sda1     2048   1050623   1048576  512M EFI System
/dev/sda2  1050624   3147775   2097152    1G Linux filesystem
/dev/sda3  3147776 134215679 131067904 62.5G Linux filesystem
  1. 對新增硬盤進行分區
# 對/dev/sdb磁盤進行分區
root@iscsi-node2:~# fdisk /dev/sdb

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 0x11ba9e24.
# 按m獲取幫助
# 按p進行分區
Command (m for help): p
Disk /dev/sdb: 120 GiB, 128849018880 bytes, 251658240 sectors
Disk model: Virtual disk
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: 0x11ba9e24
# 新建分區,如果只分一個區,直接按回車
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
# 分區編號,最大4
Partition number (1-4, default 1):
# 起始位置
First sector (2048-251658239, default 2048):
# 結束位置
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-251658239, default 251658239):

Created a new partition 1 of type 'Linux' and of size 120 GiB.
# 保存操作
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
# 查看分區結果
fdisk -l
# 剛纔新建的分區
Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 251658239 251656192  120G 83 Linux
  1. 格式化分區並掛載
# 格式化分區
mkfs -t ext4 /dev/sdb1
# 格式化信息
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 31457024 4k blocks and 7864320 inodes
Filesystem UUID: 04b8d583-8ee9-4417-8290-6b87706cb533
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
# 區塊保持默認,按回車即可
Creating journal (131072 blocks):
done
Writing superblocks and filesystem accounting information: done
# 新建目錄
mkdir /data
# 將/data掛載到/dev/sdb1
mount /dev/sdb1 /data
# 查看硬盤掛載情況
df -h
# 輸出
Filesystem                         Size  Used Avail Use% Mounted on
udev                               1.9G     0  1.9G   0% /dev
tmpfs                              394M  1.2M  393M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   31G  6.8G   23G  24% /
tmpfs                              2.0G     0  2.0G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/loop1                          62M   62M     0 100% /snap/core20/1242
/dev/loop0                          56M   56M     0 100% /snap/core18/2128
/dev/loop3                          71M   71M     0 100% /snap/lxd/21029
/dev/loop2                          56M   56M     0 100% /snap/core18/2253
/dev/loop4                          33M   33M     0 100% /snap/snapd/12704
/dev/loop6                          43M   43M     0 100% /snap/snapd/14066
/dev/loop5                          68M   68M     0 100% /snap/lxd/21835
/dev/sda2                          976M  204M  706M  23% /boot
/dev/mapper/ubuntu--vg-lv--0        31G   49M   29G   1% /home
/dev/sda1                          511M  5.3M  506M   2% /boot/efi
tmpfs                              394M     0  394M   0% /run/user/0
# 硬盤已經掛載成功
/dev/sdb1                          118G   61M  112G   1% /data
# 設置開機自動掛載硬盤
vim /etc/fstab
# 在文件最後一行加上掛載信息,注意以tab鍵隔開
# 字段含義
# 1.掛載點
# 2.文件系統名稱
# 3.掛載參數,掛載權限
# 4.指定分區是否被dump備份,0代表不備份,1代表每天備份,2代表不定期備份。
# 5.指定分區是否被fsck檢測,0代表不檢測,其他數字代表檢測的優先級。

# /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-oS0noblJQCb8zJExHTVlbanUrtLVBWVYDfN1QUh180IqIvTkwGhrVkD2kE3Tr2MZ / ext4 defaults 0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/949b0970-87cc-487b-8f66-c7dffe6bc83e /boot ext4 defaults 0 1
# /boot/efi was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/D39A-F6AC /boot/efi vfat defaults 0 1
# /home was on /dev/ubuntu-vg/lv-0 during curtin installation
/dev/disk/by-id/dm-uuid-LVM-oS0noblJQCb8zJExHTVlbanUrtLVBWVYnsoitThvBbZTKLxkpCwMXMMf210dTWX1 /home ext4 defaults 0 1
/swap.img       none    swap    sw      0       0
# New HardDisk
/dev/disk/by-uuid/04b8d583-8ee9-4417-8290-6b87706cb533  /data   ext4    defaults 0 1
# 或者以分區開始
# /dev/sdb1  /data   ext4    defaults 0 1
# 檢查掛載
mount -a
# 命令沒有報錯,則表示掛載成功,可以嘗試重啓主機測試是否自動掛載
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章