Linux磁盘操作实验(2)

Linux磁盘操作实验(2)

  1. 增加2快SCSI硬盘并构建LVM逻辑卷,并通过磁盘配额的方式限制用户
[root@localhost ~]# fdisk -l                   查看新添加的2块硬盘

磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00099141

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     8390655     4194304   82  Linux swap / Solaris
/dev/sda2   *     8390656   104857599    48233472   83  Linux

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区  创建硬盘分区,并修改分区类型为8e
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x45e52de5 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# fdisk /dev/sdc            同上
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0xbec258cf 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):t 
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdc1       创建物理卷
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdc1" successfully created.
[root@localhost ~]# vgcreate abc /dev/sd[bc]1     创建卷组
  Volume group "abc" successfully created
[root@localhost ~]# lvcreate -L 39.99G -n abc2 abc        创建逻辑卷
  Rounding up size to full physical extent 39.99 GiB
  Logical volume "abc2" created.
[root@localhost ~]# mkfs.xfs /dev/abc/abc2            格式化
meta-data=/dev/abc/abc2          isize=512    agcount=4, agsize=2620928 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10483712, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=5119, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# vim /etc/fstab        设置自动挂载(设置如下图)
[root@localhost ~]# init 6              重启
[root@localhost ~]# chmod 777 /opt           给用户最大权限
[root@localhost ~]# xfs_quota -x -c 'limit -u bsoft=80m bhard=100m isoft=50 ihard=60 wt' /abc2                   这里设置软容量80m,硬容量100m,文件数软50个,硬60个
[root@localhost ~]# xfs_quota -c 'quota -uv wt' /abc2     看一下用户wt的容量限制
Disk quotas for User wt (1000)
Filesystem              Blocks      Quota      Limit  Warn/Time      Mounted on
/dev/mapper/abc-abc2          0      81920     102400   00 [--------] /abc2
[wt@localhost abc2]$ dd if=/dev/zero of=/abc2/test.txt bs=10M count=10  这里验证一下,一次写10m,一共10次
记录了10+0 的读入
记录了10+0 的写出
104857600字节(105 MB)已复制,0.192676 秒,544 MB/秒
[wt@localhost abc2]$ touch 1.txt      这里因为容量满了不能再创建新文件了
touch: 无法创建"1.txt": 超出磁盘限额
[wt@localhost abc2]$ rm -f test.txt       把test文件删了
[wt@localhost abc2]$ touch {1.2..50}.txt
[wt@localhost abc2]$ touch [1.2..30].txt
[wt@localhost abc2]$ touch {1.2.3...50}.txt        创建3个txt文件没问题
[root@localhost ~]# xfs_quota -x -c 'report -abih'      最后再看一下磁盘文件数和容量
User quota on /abc2 (/dev/mapper/abc-abc2)
                        Blocks                            Inodes              
User ID      Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
root            0      0      0  00 [------]      3      0      0  00 [------]
wt              0    80M   100M  00 [------]      3     50     60  00 [------]

Group quota on /abc2 (/dev/mapper/abc-abc2)
                        Blocks                            Inodes              
Group ID     Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
root            0      0      0  00 [------]      3      0      0  00 [------]
wt              0      0      0  00 [------]      3      0      0  00 [------]

自动挂载格式:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Guiled7/article/details/121340440