侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

linux 高级磁盘管理

2023-12-20 星期三 / 0 评论 / 0 点赞 / 122 阅读 / 5248 字

1 磁盘分区 服务器添加一块磁盘后需要进行磁盘管理操作才可以使用。第一步需要磁盘分区 在/dev/下面按ll sd然后按两次tab键会看到以sd开头的所有文件,例如: [root@myvm dev

    1    磁盘分区

        服务器添加一块磁盘后需要进行磁盘管理操作才可以使用。第一步需要磁盘分区

       在/dev/下面按ll sd然后按两次tab键会看到以sd开头的所有文件,例如:

[root@myvm dev]# ll sd
sda   sda1  sda2  sda3  sdb

sda是第一块磁盘,sda1是磁盘的第一个分区,sda2 表示第二个分区以此类推。其中sdb 就是我们新插入的第二个磁盘,再插一个磁盘就是sdc。

[root@wzlvm /]# 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 0x1a9ca4c2.
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): 

按m键进入帮助

Command (m for help): m
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)

按n 添加分区

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

按p进入主分区

Partition number (1-4): 

按1 选择第一块分区

First cylinder (1-652, default 1): 

按1(不按1,系统默认为1)意思是从第一个扇区开始

Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): 

选择大小 +2G 表示这个分区分2个G。

到此为止第一个分区已经结束,接着循环分完所有的磁盘就可以了。

到最后选择w保存所有分区

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

下面在查看一下刚刚的分区

[root@wzlvm /]# fdisk -l

Disk identifier: 0x1a9ca4c2

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb2             263         652     3132675   83  Linux

2    分区格式化

mkfs -t ext4 /dev/sdb1

用上面的代码对每一个新的分区进行格式化

3    磁盘挂载

    在磁盘中建立对应的磁盘挂载点,例如/data/sdb1和/data/sdb2

mount /dev/sdb1 /data/sdb1

mount /dev/sdb2 /data/sdb2

检查是否挂载成功

root@wzlvm data]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  1.4G   16G   9% /
tmpfs           495M     0  495M   0% /dev/shm
/dev/sda1       1.9G   32M  1.8G   2% /boot
/dev/sr0        3.7G  3.7G     0 100% /data/local_cdrom
/dev/sdb1       2.0G  3.1M  1.9G   1% /data/sdb1
/dev/sdb2       2.9G  4.5M  2.8G   1% /data/sdb2

能看到自己挂载的sdb1,sdb2  就说明成功了。具体可以继续进入对应的路径下建文件试试。

4    磁盘挂载后开机自动挂载

    磁盘挂载完成后,在当前是可以用的,但是系统重启以后磁盘分区挂载不上,需要设置开机自动挂载。

在/etc/fstab文件里面设置

/dev/sdb2               /data/sdb2              ext4    defaults        0 0

设置保存完成之后一定要用mount -a进行检查,如果不报错再重启测试。

广告 广告

评论区