ubuntu 格式化、挂载硬盘
在linux下加载一块硬盘从总体上分为以下几个步骤:
1、用fdisk对硬盘进行分区
2、用mkfs.ext4对硬盘进行格式化
3、建立一个挂接目录(如果需要挂接到已存在的目录,此步骤可以省略)
4、用mount将该分区挂接到指定的目录
5、如果想实现启动时自动挂接,那么还需要修改fstab文件
具体操作如下:
[root@redhad ~]# fdisk -l --查看硬盘分区信息 Disk /dev/sda: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 3661 29406951 83 Linux /dev/sda2 3662 3915 2040255 82 Linux swap Disk /dev/sdb: 1073 MB, 1073741824 bytes --可以看到有一块空闲的硬盘还未分区 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sdb doesn't contain a valid partition table [root@redhad ~]# fdisk /dev/sdb --使用fdisk工具对sdb进行分区 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): m --列出fdisk工具的参数 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): n --输入“n”增加一个分区 Command action --选择是建立主分区还是扩展分区 e extended p primary partition (1-4) p --输入“p”建立主分区 Partition number (1-4): 1 --输入分区号 First cylinder (1-130, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): 130 Command (m for help): w --写入分区表并退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@redhad ~]# mkfs.ext4 /dev/sdb1 --将新建立的分区进行格式化 mke2fs 1.35 (28-Feb-2004) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 130560 inodes, 261048 blocks 13052 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 16320 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@redhad ~]# mkdir /newdisk --建立一个新的挂接目录 [root@redhad ~]# mount /dev/sdb1 /newdisk --将sdb1挂接到/newdisk下 [root@redhad ~]# df -lh --查看目前硬盘空闲,新建硬盘已经成功挂接 Filesystem Size Used Avail Use% Mounted on /dev/sda1 28G 2.4G 24G 9% / none 506M 0 506M 0% /dev/shm /dev/sdb1 1004M 18M 936M 2% /newdisk
到此为止,我们的新硬盘已经加载成功了,但是这里有一个问题,一旦我们重新启动系统,还需要用mount命令重新挂接才能访问新硬盘,如果我需要挂接的工作在系统启动过程中完成,那么我需要用vi配置/etc/fstab文件,将/dev/sdb1/newdiskext4defaults11添加到/etc/fstab的最后,然后重新启动系统即可。
第一列为设备号或该设备的卷标
第二列为挂载点
第三列为文件系统
第四列为文件系统参数
第五列为是否可以用demp命令备份。0:不备份,1:备份,2:备份,但比1重要性小。设置了该参数后,Linux中使用dump命令备份系统的时候就可以备份相应设置的挂载点了。
第六列为是否在系统启动的时候,用fsck检验分区。因为有些挂载点是不需要检验的,比如:虚拟内存swap、/proc等。0:不检验,1:要检验,2要检验,但比1晚检验,一般根目录设置为1,其他设置为2就可以了。
解除挂载
umount /dev/sdb1
查看分区是ext3还是ext4系统
df -hT
相关推荐
Attend 2020-06-27
jiangtie 2020-05-11
clamzxf 2020-03-28
chenchuang 2020-03-27
Summer的小屋 2020-03-26
jiangtie 2020-01-07
ykmail 2013-07-30
hengxie00 2014-12-05
拿什么来拯救自己 2015-08-10
Proudoffaith 2019-10-23
RealJianyuan 2016-11-04
wintelx 2015-08-10
cuixingwudi 2014-12-05
silenter00 2012-10-22
libowenhit 2012-03-16
小惠 2013-06-27
andylanzhiyong 2013-06-07
andylanzhiyong 2019-12-24
pointfish 2019-12-14