RHEL-RH134-UNIT4--管理系统中的简单分区和文件系统

######create partition########
[root@server8 Desktop]# fdisk -l  ##查看所有分区信息


Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00013f3e


   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux


Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x77806af8


   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   8e  Linux LVM

/dev/vdb2          411648      821247      204800   83  Linux



[root@server8 Desktop]# fdisk /dev/vdb  ##对vdb硬盘进行分区划分
Welcome to fdisk (util-linux 2.23.2).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.




Command (m for help): n  ##新建分区,回车表示输入默认提示信息
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): 
Using default response p
Partition number (3,4, default 3): 
First sector (821248-20971519, default 821248): 
Using default value 821248
Last sector, +sectors or +size{K,M,G} (821248-20971519, default 20971519): +100M    ##第三分区划分100M
Partition 3 of type Linux and of size 100 MiB is set





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


Calling ioctl() to re-read partition table.
Syncing disks.
[root@server8 Desktop]# partprobe  ##与系统同步分区信息,使系统可读
[root@server8 Desktop]# cat /proc/partitions  ##查看分区信息
major minor  #blocks  name


 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     204800 vdb1
 253       18     204800 vdb2
 253       19     102400 vdb3

[root@server8 Desktop]# 




[root@server8 Desktop]# df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3811248   6662652  37% /
devtmpfs          927072       0    927072   0% /dev
tmpfs             942660     472    942188   1% /dev/shm
tmpfs             942660   17004    925656   2% /run
tmpfs             942660       0    942660   0% /sys/fs/cgroup


[root@server8 Desktop]# mkdir /software   ##创建挂载点
[root@server8 Desktop]# mkfs.xfs /dev/vdb1  ##对/dev/vdb1分区进行格式划为xfs文件系统
meta-data=/dev/vdb1              isize=256    agcount=4, agsize=12800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=51200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@server8 Desktop]# mount /dev/vdb1 /software  ##对/dev/vdb1分区进行挂载
[root@server8 Desktop]# df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3811232   6662668  37% /
devtmpfs          927072       0    927072   0% /dev
tmpfs             942660     472    942188   1% /dev/shm
tmpfs             942660   17004    925656   2% /run
tmpfs             942660       0    942660   0% /sys/fs/cgroup
/dev/vdb1         201388   10400    190988   6% /software
[root@server8 Desktop]# vi /etc/fstab   ##保存挂载信息至/etc/fstab,便于系统启动时进行挂载
[root@server8 Desktop]# mount -a
mount: mount point xfs does not exist
[root@server8 Desktop]# cat /etc/fstab 


#
# /etc/fstab
# Created by anaconda on Wed May  7 01:22:57 2014
#
# 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=9bf6b9f7-92ad-441b-848e-0257cbb883d1 /                       xfs     defaults        1 1
/dev/vdb1    xfs defaults 0 0 
[root@server8 Desktop]# vi /etc/fstab 
[root@server8 Desktop]# mount -a    ##对/etc/fstab文件中未挂载的文件系统进行全部挂载
[root@server8 Desktop]# 




#########SWAP分区划分及挂载###############


[root@foundation8 home]# fdisk /dev/sda     ##对/dev/sda硬盘划分swap分区
Welcome to fdisk (util-linux 2.23.2).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.




Command (m for help): p


Disk /dev/sda: 320.1 GB, 320072933376 bytes, 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00027560


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda3         8892416   625141759   308124672   83  Linux


Command (m for help): n  ##新增分区
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): 
Using default response p
Partition number (2,4, default 2): 2  ##第二个分区id
First sector (1026048-625142447, default 1026048): 
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-8892415, default 8892415): +4G
Value out of range.
Last sector, +sectors or +size{K,M,G} (1026048-8892415, default 8892415): +4G  ##超出分区总大小
Value out of range.
Last sector, +sectors or +size{K,M,G} (1026048-8892415, default 8892415):    ##默认将第二分区全部划分完
Using default value 8892415
Partition 2 of type Linux and of size 3.8 GiB is set


Command (m for help): e 
e: unknown command
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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): t  ##更改分区格式为swap
Partition number (1-3, default 3): 2 
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'


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


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@foundation8 home]# fdisk -l  


Disk /dev/sda: 320.1 GB, 320072933376 bytes, 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00027560


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048     8892415     3933184   82  Linux swap / Solaris
/dev/sda3         8892416   625141759   308124672   83  Linux
[root@foundation8 home]# mkswap /dev/sda2  ##将/de/sda2格式化为swap
mkswap: /dev/sda2: warning: wiping old swap signature.
Setting up swapspace version 1, size = 3933180 KiB
no label, UUID=71864c0a-d995-4e50-b31f-f2f5057c682c
[root@foundation8 home]# blkid 
/dev/sda1: UUID="d8262a7b-bbd5-4efd-956d-59e997072ed5" TYPE="xfs" 
/dev/sda2: UUID="71864c0a-d995-4e50-b31f-f2f5057c682c" TYPE="swap" 
/dev/sda3: UUID="5e5d43d6-7cda-4622-8f75-ce43e1549051" TYPE="xfs" 
/dev/loop0: UUID="2015-10-30-11-11-49-00" LABEL="RHEL-7.2 Server.x86_64" TYPE="iso9660" PTTYPE="dos" 
[root@foundation8 home]# swapon -a /dev/sda2   ##对/dev/sda2进行激活
swapon: cannot find the device for UUID=8ff2b05e-dea9-4aae-9efc-5f9964a89134
[root@foundation8 home]# swapon -a
swapon: cannot find the device for UUID=8ff2b05e-dea9-4aae-9efc-5f9964a89134
[root@foundation8 home]# partprobe 
[root@foundation8 home]# swapon -a /dev/sda2
swapon: cannot find the device for UUID=8ff2b05e-dea9-4aae-9efc-5f9964a89134
swapon: /dev/sda2: swapon failed: Device or resource busy
[root@foundation8 home]# cd
[root@foundation8 ~]# swapon -a /dev/sda2
swapon: cannot find the device for UUID=8ff2b05e-dea9-4aae-9efc-5f9964a89134
swapon: /dev/sda2: swapon failed: Device or resource busy
[root@foundation8 ~]# swapon -s   ##查看swap分区
Filename Type Size Used Priority
/dev/sda2                               partition 3933180 0 -1
[root@foundation8 ~]# vi /etc/fstab   ##写入fstab开机自动挂载


[root@foundation8 ~]# swapon -s  ##查看swap是否正在挂载
Filename Type Size Used Priority
/dev/sda2                               partition 3933180 0 -1
[root@foundation8 ~]# swapoff /dev/sda2     ##卸载swap分区
[root@foundation8 ~]# vi /etc/fstab ^C    ##取消开机挂载
[root@foundation8 ~]# 
[root@foundation8 ~]# 
[root@foundation8 ~]# swapon -s  
[root@foundation8 ~]# fdisk /dev/sda   ##进入sda
Welcome to fdisk (util-linux 2.23.2).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.




Command (m for help): p


Disk /dev/sda: 320.1 GB, 320072933376 bytes, 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00027560


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048     8892415     3933184   82  Linux swap / Solaris
/dev/sda3         8892416   625141759   308124672   83  Linux


Command (m for help): d   ##删除分区
Partition number (1-3, default 3): 2  #删除第二块
Partition 2 is deleted


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


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@foundation8 ~]# partprobe   ##更新分区表
[root@foundation8 ~]# cat /proc/partitions 
major minor  #blocks  name


   8        0  312571224 sda
   8        1     512000 sda1
   8        3  308124672 sda3
  11        0    1048575 sr0
   7        0    3948544 loop0
[root@foundation8 ~]# 




#####指定目录对于某用户、组的使用大小###########


[root@foundation8 ~]#mount -o usrquota,grpquota /dev/vdb1 /pub   ##指定用户、组挂载
[root@foundation8 ~]#quotaon -ugv /dev/vdb1   ##激活用户、组参数设定
[root@foundation8 ~]#edquota -u westos  ##指定用户,更改hard为想要的大小
[root@foundation8 ~]#su - westos
[root@foundation8 ~]#dd if=/dev/zero of=/pub/file1 bs=1M count=10
[root@foundation8 ~]#dd if=/dev/zero of=/pub/file1 bs=1M count=100
[root@foundation8 ~]#dd if=/dev/zero of=/pub/file1 bs=1M count=300  ##300M无法写入


#######软raid创建###########
fdisk /dev/vdb  ##创建3块一样的1G分区
partprobe  ##格式化
watch -n 1 /proc/mdstat  ##查看raid划分情况
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}  ##-C 创建新硬盘  -l raid级别  -n 使用几块 -x 冗余几块 后面跟实际划分的硬盘


mdadm -d /dev/md0  ##查看md0下各硬盘状态
mdadm -f /dev/md0 /dev/vdb3  ##模拟vdb3坏掉
mdadm -r /dev/md0 /dev/vdb3  ##移除第三块硬盘
mdadm -a /dev/md0 /dev/vdb3  ##添加的三块硬盘
watch -n 1 'cat /proc/mdstat;echo ======;df -h'  ##查看raid时时变化情况


###########加减密#############
fdisk /dev/vdb  ##划分一块分区
cryptsetup luksFormat /dev/vdb1  ##对分区进行加密
cryptsetup open /dev/vdb1 westos ##对分区进行解密并生成解密后的分区名称
mkfs.xfs /dev/mapper/westos ##格式化文件系统
mount /dev/mapper/westos /mnt  ##挂载


umount /mnt ##卸载
cryptsetup close westos  ##关闭加密
mount /dev/vdb1 /mnt ##尝试挂载初始盘
cryptsetup open /dev/vdb1 westos  ##重新解密
mount /dev/mapper/westos /mnt  ##挂载




############crypt具体操作#############


[root@server8 Desktop]# fdisk -l


Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00013f3e


   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux


Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


[root@server8 Desktop]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x7a3b6f49.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 1
Invalid partition type `1'


Command (m for help): 
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +500M
Partition 1 of type Linux and of size 500 MiB is set


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




Calling ioctl() to re-read partition table.
Syncing disks.
[root@server8 Desktop]# 




[root@server8 Desktop]# cryptsetup luksFormat /dev/vdb1


WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.


Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase: 
Password quality check failed:
 The password is shorter than 8 characters


[root@server8 Desktop]# cryptsetup luksFormat /dev/vdb1


WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.


Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase: 
Password quality check failed:
 The password fails the dictionary check - it is based on a dictionary word
[root@server8 Desktop]# cryptsetup luksFormat /dev/vdb1


WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.


Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase: 
[root@server8 Desktop]# 
[root@server8 Desktop]# 
[root@server8 Desktop]# 
[root@server8 Desktop]# 
[root@server8 Desktop]# 
[root@server8 Desktop]# cryptsetup open /dev/vdb1 westos
Enter passphrase for /dev/vdb1: 
[root@server8 Desktop]# 
[root@server8 Desktop]# 
[root@server8 Desktop]# cd /dev/mapper/
[root@server8 mapper]# ls
control  westos
[root@server8 mapper]# ls -lrt
total 0
crw-------. 1 root root 10, 236 Apr 22 21:00 control
lrwxrwxrwx. 1 root root       7 Apr 22 21:17 westos -> ../dm-0
[root@server8 mapper]# mkfs.xfs /dev/mapper/westos 
meta-data=/dev/mapper/westos     isize=256    agcount=4, agsize=31872 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=127488, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@server8 mapper]# 
[root@server8 mapper]# 
[root@server8 ~]# mount  /dev/mapper/westos /mnt
[root@server8 ~]# cd /mnt
[root@server8 mnt]# ls
[root@server8 mnt]# touch file{1..10}
[root@server8 mnt]# 
[root@server8 ~]# umount /mnt
[root@server8 ~]# 
[root@server8 ~]# 
[root@server8 ~]# cryptsetup close westos
[root@server8 ~]# mount /dev/vdb1 /mnt
mount: unknown filesystem type 'crypto_LUKS'
[root@server8 ~]# umount /mnt
[root@server8 ~]# 
[root@server8 ~]# 
[root@server8 ~]# cryptsetup close westos
[root@server8 ~]# mount /dev/vdb1 /mnt
mount: unknown filesystem type 'crypto_LUKS'
[root@server8 ~]# cryptsetup open westos
Command requires device and mapped name as arguments.
[root@server8 ~]# cryptsetup open /dev/vdb1 westos
Enter passphrase for /dev/vdb1: 
[root@server8 ~]# 
[root@server8 ~]# mount /dev/mapper/westos /mnt
[root@server8 ~]# cd /mnt
[root@server8 mnt]# ls
file0  file1  file10  file2  file3  file4  file5  file6  file7  file8  file9

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值