欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Linux新加磁盘挂载和重启自动挂载

程序员文章站 2022-12-02 22:03:21
提示两点:*新加的硬盘需要重启服务器fdisk -l才能看到*下面操作要用root账户大概是这样的,查看-分区-格式化-挂载-重启自动挂载1、加硬盘后重启服务器查看[root@test199 ~]# fdisk -l Disk /dev/sdb: 214.7 GB, 214748364800 byt ......

提示两点:
*新加的硬盘需要重启服务器fdisk -l才能看到
*下面操作要用root账户
大概是这样的,查看-分区-格式化-挂载-重启自动挂载
1、加硬盘后重启服务器查看
[root@test199 ~]# fdisk -l

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cd039

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 536 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 536 10444 79584256 83 Linux
2、分区
fdisk可以用m命令来看fdisk命令的内部命令;
a:命令指定启动分区;
d:命令删除一个存在的分区;
l:命令显示分区ID号的列表;
m:查看fdisk命令帮助;
n:命令创建一个新分区;
p:命令显示分区列表;
t:命令修改分区的类型ID号;
w:命令是将对分区表的修改存盘让它发生作用。

[root@test199 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x515ae162.
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)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): n
Command action
e extended //输入e为创建扩展分区
p primary partition (1-4) //输入p为创建逻辑分区
p
Partition number (1-4): 1 //在这里输入l,就进入划分逻辑分区阶段了
First cylinder (1-26108, default 1): //注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费;
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-26108, default 26108): 我这直接回车了全部用上。注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定 End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入 +10000M ;
Using default value 26108

Command (m for help): w //最后输入w回车保存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
保存后查看一下
[root@test199 ~]# fdisk -l

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x515ae162

Device Boot Start End Blocks Id System
/dev/sdb1 1 26108 209712478+ 83 Linux

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cd039

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 536 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 536 10444 79584256 83 Linux
3、格式化
[root@test199 ~]# mkfs.ext3 /dev/sdb1 //注:将/dev/sdb1格式化为ext3类型,确认好,我上面/dev/sdb1是新加的200GB硬盘,这一步直接回车就可以了,格式化完会自动跳出来
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13107200 inodes, 52428119 blocks
2621405 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1600 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
4、挂载
--先创建个目录、再挂载到目录上
[root@test199 ~]# mkdir /data
[root@test199 ~]# mount /dev/sdb1 /data
[root@test199 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 75G 21G 51G 29% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sdb1 197G 188M 187G 1% /data
5、重启开机自动挂载,要写到fstab里面(就是最后一行了),否则重启后找不到那个新家的硬盘了
[root@test199 ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Apr 16 01:33:57 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f87d8e1f-9a62-4cb8-93a8-a4793465eb23 / ext4 defaults 1 1
UUID=cdb27acf-3bbb-4f03-b20c-cfbc9d8450b9 /boot ext4 defaults 1 2
UUID=63399012-86b0-43e7-8cee-a0ace153dd7e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/sdb1 /data ext3 defaults 0 0
至此OK!