分区:
文件系统:
df [选项] [挂载点]
选项:
du [选项] [目录或文件名]
选项:
root@ubuntu:/# df -h
Filesystem Size Used Avail Use% Mounted on
udev 469M 0 469M 0% /dev
tmpfs 98M 7.5M 91M 8% /run
/dev/sda1 19G 3.7G 15G 21% / #统计/目录大小为3.7G
tmpfs 488M 224K 488M 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 488M 0 488M 0% /sys/fs/cgroup
tmpfs 98M 80K 98M 1% /run/user/1000
root@ubuntu:/# du -sh /
du: cannot access '/proc/5548/task/5548/fd/4': No such file or directory
du: cannot access '/proc/5548/task/5548/fdinfo/4': No such file or directory
du: cannot access '/proc/5548/fd/3': No such file or directory
du: cannot access '/proc/5548/fdinfo/3': No such file or directory
du: cannot access '/run/user/1000/gvfs': Permission denied
3.6G / # 统计/目录大小为3.6G
du命令和df命令的区别
fsck [选项] 分区设备文件名
选项:
dumpe2fs 分区设备文件名
root@ubuntu:/# dumpe2fs /dev/sda1
dumpe2fs 1.42.13 (17-May-2015)
Filesystem volume name: #文件系统名称
Last mounted on: /
…………
Inode count: 1245184
Block count: 4980480 #数据块总数
Reserved block count: 249024
Free blocks: 3917535 #可用数据块总数
Free inodes: 1058545 #可用inode总数
First block: 0
Block size: 4096 #每个数据块大小
…………
First inode: 11
Inode size: 256 #每个inode的大小
…………
mount [-l] #查询系统中已经挂载的设备,-l会显示卷标名称
mount -a #依据配置文件/etc/fstab的内容,自动挂载
mount [-t 文件系统] [-L 卷标名] [-o 特殊选项] 设备文件名 挂载点
选项:
root@ubuntu:/home/karen# mkdir /mnt/cdrom #建立挂载点
root@ubuntu:/home/karen# mount /dev/cdrom /mnt/cdrom #挂载光盘
root@ubuntu:/home/karen# mount /dev/sr0 /mnt/cdrom #/dev/cdrom与/dev/sr0路径相同
root@ubuntu:/home/karen# cd /mnt/cdrom #进入光盘目录
root@ubuntu:/home/karen# umount /dev/sr0 #卸载光盘
卸载光盘
umount 设备文件名
root@ubuntu:~# fdisk -l #查找分区
…………
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 39845887 39843840 19G 83 Linux
/dev/sda2 39847934 41940991 2093058 1022M 5 Extended
/dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris
Disk /dev/sdb: 14.4 GiB, 15500083200 bytes, 30273600 sectors #U盘分区为/dev/sdb
root@ubuntu:~# mkdir /mnt/usb #建立挂载点
root@ubuntu:~# mount -t vfat /dev/sdb1 /mnt/usb #将分区与挂载点连接
root@ubuntu:~# cd /mnt/usb #进入U盘目录
root@ubuntu:/mnt/usb# ls #显示U盘目录
root@ubuntu:~# umount /dev/sr0 #卸载U盘
mount -t ntfs-3g 分区设备文件名 挂载点
)root@ubuntu:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors #原硬盘,分区如下3个
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: 0x258438e2
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 39845887 39843840 19G 83 Linux
/dev/sda2 39847934 41940991 2093058 1022M 5 Extended
/dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 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
root@ubuntu:~# fdisk /dev/sdb #为新硬盘/dev/sdb设置分区
…………
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-20971519, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): p #显示分区列表
…………
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 4196351 4194304 2G 83 Linux #此时新建主分区/dev/sdb1已存在分区列表中
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e #新建扩展分区
Partition number (2-4, default 2): 2
First sector (4196352-20971519, default 4196352):
Last sector, +sectors or +size{K,M,G,T,P} (4196352-20971519, default 20971519):
Created a new partition 2 of type 'Extended' and of size 8 GiB. #将剩余所有容量分配给扩展分区
Command (m for help): p
…………
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 4196351 4194304 2G 83 Linux
/dev/sdb2 4196352 20971519 16775168 8G 5 Extended #此时新建的扩展分区/dev/sdb2已存在分区列表中
Command (m for help): n #新建逻辑分区
All space for primary partitions is in use.
Adding logical partition 5
First sector (4198400-20971519, default 4198400):
Last sector, +sectors or +size{K,M,G,T,P} (4198400-20971519, default 20971519): +2G #大小为2G
Created a new partition 5 of type 'Linux' and of size 2 GiB.
Command (m for help): p
…………
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 4196351 4194304 2G 83 Linux
/dev/sdb2 4196352 20971519 16775168 8G 5 Extended
/dev/sdb5 4198400 8392703 4194304 2G 83 Linux #新建的逻辑分区已存在,并且是从扩展分区中分配的
Command (m for help): w #设置完成后,保存才能生效
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@ubuntu:~# partprobe
当分区表被占用,保存时系统提示重启,此时可不重启,直接执行partprobe重新读取分区表信息
root@ubuntu:~# mkfs -t ext4 /dev/sdb1 #格式化主分区
root@ubuntu:~# mkdir /disk1
root@ubuntu:~# mount /dev/sdb1 /disk1/
root@ubuntu:~# mount #查看分区是否被正确挂载
…………
/dev/sdb1 on /disk1 type ext4 (rw,relatime,data=ordered) #此时sdb1已挂载
root@ubuntu:~# df #或者使用df命令也可查询分区是否被正确挂载
Filesystem 1K-blocks Used Available Use% Mounted on
udev 478448 0 478448 0% /dev
tmpfs 99764 6316 93448 7% /run
/dev/sda1 19478204 4848700 13617024 27% /
tmpfs 498812 212 498600 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 498812 0 498812 0% /sys/fs/cgroup
tmpfs 99764 52 99712 1% /run/user/1000
/dev/sdb1 1998672 3072 1874360 1% /disk1
root@ubuntu:~# vim /etc/fstab
…………
UUID=48994d4b-1105-4e46-bf01-a5e756142137 / ext4 errors=remount-ro 0 1
/dev/sdb1 /disk1 ext4 defaults 1 2
- 第一字段:分区设备文件名或UUID(硬盘通用唯一识别码)
- 第二字段:挂载点
- 第三字段:文件系统名称
- 第四字段:挂载参数
- 第五字段:指定分区是否被dump备份,0代表不备份,1代表每天备份,2代表不定期备份
- 第六字段:指定分区是否被fsck检测,0代表不检测,其他数字代表检测的优先级,那么当然1的优先级比2高
root@ubuntu:~# mount -o remount,rw / #只能用于/etc/fstab文件的报错