Ubuntu磁盘分区和挂载

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

 

 

 

参考文献:https://www.cnblogs.com/sinsenliu/p/9482415.html

                  https://blog.csdn.net/love_yu_er/article/details/88634274

posted @ 2022-03-02 22:37  anech  阅读(1592)  评论(0编辑  收藏  举报