fdisk for partitioning
fdisk is based on MBR. So, GPT cannot use fdisk.
fdisk
- only super user can use it.
- fdisk -l can show all the information about disc.
- logical partition always starts with 5.
- sudo fdisk /dev/sd* you can enter the pointed disc. press 'm' for some help
- after updating, use 'partprobe' to let the kernel update the partition table.
d # delete a partition
n # create a new partition. After using all the space for extended partition, you can create logical ones beginning with 5.
# you can use + size {K,M,G,T,P} to decide what the size of the partition is
w # write the changes to the disc(save)
q # leave without saving.
t # to change the id of a partition.
Linux file system basics
format : the process of creating files.
A device without file system is called raw device.
Common file systems:
fat32 , NTFS , ext2 , ext3 , ext4 , xfs , HFS
Windows: NTFS
Linux: ext3 ext4
what Linux supports?
ext2 ext3 ext4 fat32 ntfs and etc...
to create file sysytem
mke2fs -t ext4 /dev/sda3
common parameters:
-b blocksize # appoint the size of the system block
-c # check the broken block
-L label # appoint the label (卷标)
-j #establish system log.
mkfs
It is much simple, but supports few parameters.
mkfs ext4 /dev/sda1
dumpe2fs
get the information about the file system
dumpe2fs /dev/sda2
Journal
with a log,
- before doing sth, write it down to the log.
- execute
- if succeed, the detailed affairs would be deleted.
Of course, the system will get slower with a log. But the system can be much more stable.
e2label
label a partition.
e2label /dev/sda2 #show the label
e2label /dev/sda2 LinuxLabel # name the partition
fsck
check and recover the partition.
fsck /dev/sdb1 # the partition must be uninstalled at first
-y #recover directly without reminding.
-t # if the system was badly hurt, use it.
For those broken data without record, fsck will put them in lost+found file.
MOUNT
mount
you can mount everywhere, but /mnt is recommended.
mount /dev/sda3(partition to mount) /mnt(mount point)
-t type of file system
-o 指定挂载选项
ro, rw 以只读或读写形式挂载,默认是rw
sync 代表不使用缓存,而是对所有操作直接写入磁盘
async 代表使用缓存,默认是async
noatime 代表每次访问文件时不更新文件的访问时间
remount 重新挂载文件系统
umount
umount 文件系统/挂载点
umount /dev/sda3 或者 umount /mnt/
fuser -m /dev/sdb1
哪些进程在使用。
lsof /mnt/
哪些文件杯打开了。
mount automatically
/etc/fstab
/dev/sda3 /mnt ext4 defaults 0 0
对文件系统进行修改,一定先卸载。有卷标也可以用卷标。
ubuntu下的mount
仍然是在/etc/fstab里面配置,但是,要用的dev的UUID.
sudo blkid /dev/sdb7 #得到分区的uuid.
/dev/sdb7: LABEL="Entertaiment" UUID="1B10038D4BDFC08D" TYPE="ntfs" PARTUUID="ca77db74-07"
etc/fstab下这样配置
UUID=1B10038D4BDFC08D /mnt ntfs defaults 0 2
其中第一列为UUID, 第二列为挂载目录(该目录必须为空目录),第三列为文件系统类型,第四列为参数,第五列0表示不备份,最后一列必须为2或0(除非引导分区为1)
最后 mount -a 即可