Skip to content

Instantly share code, notes, and snippets.

@zooyf
Created December 25, 2018 12:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zooyf/13e9507a30ee425fb213f6a1ac4e393d to your computer and use it in GitHub Desktop.
mount disk. 挂载磁盘
1.分区(new disk)
查看
> fdisk -l
Disk /dev/vda: 60 GiB, 64424509440 bytes, 125829120 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: 0xd6804155
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 125827071 125825024 60G 83 Linux
Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 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: 0x359c0685
> fdisk /dev/vdb
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
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): 1
First sector (2048-41943039, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):
Created a new partition 1 of type 'Linux' and of size 20 GiB.
Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
2.格式化
> fdisk -l
> mkfs -t ext4 /dev/vdb1
3.挂载
方法一,手动挂载,重启不自动挂载:
> mount /dev/vdb1 /tmp/mt
备份数据
> mv docs docs_bak
> mkdir docs
> mount /dev/vdb1 /tmp/mount_test
> cd docs
> cp -r ../docs_bak/* .
方法二,自动挂载,重启后自动挂载:
> vim /etc/fstab
将挂载内容插入到最后
/dev/vdb1 /tmp/mount_test ext4 defaults 0 0
> mount -a
4.查看挂载
> df -lh
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 396M 3.1M 393M 1% /run
/dev/vda1 99G 20G 75G 21% /
tmpfs 2.0G 4.0K 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 396M 0 396M 0% /run/user/0
/dev/vdb1 493G 1.5G 466G 1% /tmp/mount_test
PS:
卸载
> vim /etc/fstab
删除要卸载的内容
> umount /tmp/mount_test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment