1、加掛硬盤
sudo lshw -c disk
看看有多少個硬盤,一般會顯示 disk:0(設備名為 /dev/vda) disk:1 (設備名為 /dev/vdb)
2、查看分區
ubuntu@VM-0-3-ubuntu:~$ sudo fdisk -l
Disk /dev/vda: 50 GiB, 53687091200 bytes, 104857600 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: 884D39AE-2030-4231-B486-520515A9ADD7 Device Start End Sectors Size Type /dev/vda1 2048 4095 2048 1M BIOS boot /dev/vda2 4096 104857566 104853471 50G Linux filesystem Disk /dev/vdb: 400 GiB, 429496729600 bytes, 838860800 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: 0x6c356be3 Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 838860799 838858752 400G 83 Linux
3、分區
sudo fdisk /dev/vdb
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-838860799, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-838860799, default 838860799): Created a new partition 1 of type 'Linux' and of size 400 GiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
4、格式化硬盤
sudo mkfs -t ext4 /dev/vdb1 把創建的新硬盤分區格式化成ext4
5、掛載新分區
創建目錄/home/d sudo mkdir -p /home/d 掛載新分區到/home/d下 sudo mount /dev/vdb1 /home/d 例如: ubuntu@VM-0-3-ubuntu:~$ sudo mkdir -p /home/d ubuntu@VM-0-3-ubuntu:~$ sudo mount /dev/vdb1 /home/d ubuntu@VM-0-3-ubuntu:~$ sudo df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 394M 780K 393M 1% /run /dev/vda2 50G 4.3G 43G 10% / tmpfs 2.0G 24K 2.0G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup tmpfs 394M 0 394M 0% /run/user/1000 /dev/vdb1 393G 73M 373G 1% /home/d
但是如果重啟這種掛載關系就會消失了
6、設置自動掛載
編輯/etc/fstab文件 sudo vim /etc/fstab 在打開的文件中加入 /dev/vdb1 /home/d ext4 defaults 0 0 命令生效 sudo mount -a 查看掛載 sudo df -h 解除掛載 unmount 設備名 unmount /dev/vdb1 查詢指定目錄的磁盤占用情況,默認是當前目錄 sudo du -ach --max-depth=1 /home/d - s:指定目錄占用大小匯總 - h:帶計量單位 - a:含文件 --max-depth=1 :子目錄深度 - c:列出明細的同時,增加匯總值 以樹狀顯示目錄結構 sudo tree /home/d