1、为主机新增两块30GB的SCSI硬盘
[root@localhost ~]# fdisk -l
磁盘 /dev/sdb:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/sdc:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
2、划分3个主分区,各5GB,剩余空间作为扩展分区
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 83 Linux
/dev/sdb3 20973568 31459327 5242880 83 Linux
/dev/sdb4 31459328 62914559 15727616 5 Extended
3、在扩展分区中建立2个逻辑分区,容量分别为2GB、10GB
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 83 Linux
/dev/sdb3 20973568 31459327 5242880 83 Linux
/dev/sdb4 31459328 62914559 15727616 5 Extended
/dev/sdb5 31461376 35655679 2097152 83 Linux
/dev/sdb6 35657728 56629247 10485760 83 Linux
4、将第一个逻辑分区的类型改为swap
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 83 Linux
/dev/sdb3 20973568 31459327 5242880 83 Linux
/dev/sdb4 31459328 62914559 15727616 5 Extended
/dev/sdb5 31461376 35655679 2097152 82 Linux swap / Solaris
/dev/sdb6 35657728 56629247 10485760 83 Linux
5、将第一个主分区格式化为ext4
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 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
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
6、将第二个主分区格式化为xfs
[root@localhost ~]# mkfs.xfs /dev/sdb2
meta-data=/dev/sdb2 isize=256 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
7、将第三个主分区格式化为FAT32
[root@localhost ~]# mkfs -t vfat -F 32 /dev/sdb3
mkfs.fat 3.0.20 (12 Jun 2013)
8、创建 /data1 /data2 /data3
[root@localhost ~]# mkdir /data1 /data2 /data3 && ls / | grep "^data"
data1
data2
data3
9、将第一个主分区挂载到/data1,在目录中创建文件测试,并实现 /etc/fstab
[root@localhost ~]# mount /dev/sdb1 /data1/ && touch /data1/1.txt && echo "/dev/sdb1 /data1 ext4 auto 1 2" >> /etc/fstab &&ls /data1/ && tail -1 /etc/fstab
1.txt lost+found
/dev/sdb1 /data1 ext4 auto 1 2
10、将第二个主分区挂载到/data2,在目录中创建文件测试,并实现 /etc/fstab
[root@localhost ~]# mount /dev/sdb2 /data2/ && touch /data2/1.txt && echo "/dev/sdb2 /data2 xfs auto 1 2" >> /etc/fstab &&ls /data1/ && tail -1 /etc/fstab
1.txt lost+found
/dev/sdb2 /data2 xfs auto 1 2
11、将第三个主分区挂载到/data3,在目录中创建文件测试,并基于UUID实现 /etc/fstab
[root@localhost ~]# mount /dev/sdb3 /data3/ && touch /data3/1.txt && echo "UUID=83D3-36C2 /data vfat auto 1 2" >> /etc/fstab &&ls /data3/ && tail -1 /etc/fstab
1.txt
UUID=83D3-36C2 /data vfat auto 1 2
12、将第一个逻辑分区格式化swap格式,将swap分区扩展,测试查看
[root@localhost ~]# mkswap /dev/sdb5
正在设置交换空间版本 1,大小 = 2097148 KiB
无标签,UUID=fde91455-d522-48bb-92cc-801f0632250f
[root@localhost ~]# swapon /dev/sdb5
[root@localhost ~]# cat /proc/meminfo | grep -i "swaptotal"
SwapTotal: 4194296 kB
13、通过xftp等工具将linux.iso 传到linux虚拟机中,并挂载查看内容
[root@localhost ~]# mount /dev/sr0 /media/
mount: /dev/sr0 写保护,将以只读方式挂载
mount: /dev/sr0 已经挂载或 /media 忙
/dev/sr0 已经挂载到 /media 上
14、基于文件方式将SWAP扩大500M
[root@localhost ~]# dd if=/dev/zero of=/root/1 bs=1M count=500
记录了500+0 的读入
记录了500+0 的写出
524288000字节(524 MB)已复制,1.61545 秒,325 MB/秒
[root@localhost ~]# mkswap 1
正在设置交换空间版本 1,大小 = 511996 KiB
无标签,UUID=20b2cc61-0605-4d0e-8ded-25c6dbb871a8
[root@localhost ~]# swapon 1
swapon: /root/1:不安全的权限 0644,建议使用 0600。
[root@localhost ~]# grep -i "swaptotal" /proc/meminfo
SwapTotal: 4706292 kB
15、利用dd命令将光盘内容制作成iso镜像文件
[root@localhost ~]# dd if=/dev/sr0 of=/root/linux.ios
记录了8419328+0 的读入
记录了8419328+0 的写出
4310695936字节(4.3 GB)已复制,201.359 秒,21.4 MB/秒
[root@localhost ~]# ls
anaconda-ks.cfg linux.ios partedsdb.sh
16、查看磁盘的使用情况
[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 38G 4.6G 33G 13% /
devtmpfs devtmpfs 481M 0 481M 0% /dev
tmpfs tmpfs 490M 92K 490M 1% /dev/shm
tmpfs tmpfs 490M 7.1M 483M 2% /run
tmpfs tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 107M 391M 22% /boot
/dev/sr0 iso9660 4.1G 4.1G 0 100% /run/media/tianyuan/CentOS 7 x86_64
/dev/sdb1 ext4 4.5G 19M 4.2G 1% /data1
/dev/sdb2 xfs 4.7G 33M 4.7G 1% /data2
/dev/sdb3 vfat 4.7G 4.0K 4.7G 1% /data3
17、利用parted命令将上述分区过程对另一个硬盘重做一遍
#!/bin/bash
if [ -d "/data1" ];then
rm -fr /data1
fi
if [ -d "/data2" ];then
rm -fr /data2
fi
if [ -d "/data3" ];then
rm -fr /data3
fi
echo "mklabel
gpt
mkpart
sdb1
ext4
1
5G
mkpart
sdb2
ext4
5G
10G
mkpart
sdb3
ext4
10G
15G
p
q
" | parted /dev/sdb
mkfs.xfs /dev/sdb2
mkfs.ext4 /dev/sdb1
mkfs.vfat -F 32 /dev/sdb3
mkdir /data{1..3}
mount /dev/sdb1 /data1
touch /data1/1.txt
echo "/dev/sdb1 /data1 ext4 defaults 1 0" >> /etc/fstab
mount /dev/sdb2 /data2
touch /data2/2.txt
echo "/dev/sdb2 /data2 xfs defaults 1 0" >> /etc/fstab
mount /dev/sdb3 /data3
touch /data3/3.txt
echo "dev/sdb3 /data3 vfat defaults 1 0" >> /etc/fstab
if [ -f "/data1/1.txt" ];then
echo "sdb1挂载成功!"
else
echo "挂载失败!"
fi
if [ -f "/data2/2.txt" ];then
echo "sdb2挂载成功!"
else
echo "挂载失败!"
fi
if [ -f "/data3/3.txt" ];then
echo "sdb3挂载成功!"
else
echo "挂载失败!"
fi
tail -3 /etc/fstab
mount | tail -3
=====================================================
GNU Parted 3.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
新的磁盘标签类型? gpt
警告: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
(parted) mkpart
分区名称? []? sdb1
文件系统类型? [ext2]? ext4
起始点? 1
结束点? 5G
(parted) mkpart
分区名称? []? sdb2
文件系统类型? [ext2]? ext4
起始点? 5G
结束点? 10G
(parted) mkpart
分区名称? []? sdb3
文件系统类型? [ext2]? ext4
起始点? 10G
结束点? 15G
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 5000MB 4999MB ext4 sdb1
2 5000MB 10.0GB 5001MB xfs sdb2
3 10.0GB 15.0GB 5000MB fat32 sdb3
(parted) q
信息: You may need to update /etc/fstab.
mkfs.xfs: /dev/sdb2 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
305216 inodes, 1220352 blocks
61017 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1249902592
38 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
mkfs.fat 3.0.20 (12 Jun 2013)
sdb1挂载成功!
sdb2挂载成功!
sdb3挂载成功!
/dev/sdb1 /data1 ext4 defaults 1 0
/dev/sdb2 /data2 xfs defaults 1 0
dev/sdb3 /data3 vfat defaults 1 0
/dev/sdb1 on /data1 type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb2 on /data2 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdb3 on /data3 type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
18、尝试利用shell脚本配置yum仓库
delyum.sh
#!/bin/bash
a="/etc/yum.repos.d/a"
l="/etc/yum.repos.d/local.repo"
m="/media/Packages"
cd /etc/yum.r*
if [ -d "$a" ]; then
mv a/C* ./
rm -fr a
echo "以剪切复制"
else
echo "不存在a目录"
fi
if [ -f "$l" ]; then
rm -f local.repo
echo "已删除文件"
else
echo "不存在local.repo"
fi
if [ -d "$m" ]; then
umount /media
echo "已取消挂载"
else
echo "media未挂载"
fi
echo "全部清除可以重新建立yum仓库"
yum.sh
#!/bin/bash
a="/root/delyum.sh"
if [ ! -x "$a" ]; then
chmod u+x /root/delyum.sh
sh delyum.sh
else
sh delyum.sh
fi
umount /media
mount /dev/sr0 /media
cd /etc/yum.r*
mkdir ./a
mv C* ./a/
echo -e "[cdrom] name=cdrom baseurl=file:///media enabled=1 gpgcheck=0" >> ./local.repo
yum -y clean all
yum makecache
19、尝试利用shell脚本配置httpd服务
delyuan.sh
#!/bin/bash
a="/usr/src/httpd-2.2.17"
b="/usr/local/apache"
/usr/local/apache/bin/apachectl stop
if [ -d "$a" ]; then
rm -fr /usr/src/httpd*
echo "文件夹删除成功"
else
echo " 没有httpd的文件夹"
fi
if [ -d "$b" ]; then
rm -fr /usr/local/apache
echo "文件夹删除成功"
else
echo " 没有apache的文件夹"
fi
echo "清理完成可以创建源码安装"
yuanmahttpd.sh
#!/bin/bash
h="/root/httpd-2.2.17.tar.gz"
rmyuan="/root/delyuan.sh"
sh /root/delyum.sh
sh /root/yum.sh
yum -y install gcc gcc-c++ make lynx
if [ ! -x "$rmyuan" ]; then
chmod u+x /root/delyuan.sh
sh delyuan.sh
else
sh delyuan.sh
fi
if [ -e "$h" ]; then
tar -xf httpd* -C /usr/src/
echo "解压源码包"
else
echo "源码包不存在,退出程序 "
exit
fi
cd /usr/src/httpd*/
./configure --prefix=/usr/local/apache
make
make install
cd /usr/local/apache/conf
cp httpd.conf httpd.conf.brb
sed -i "s/#ServerName www/ServerName www/g" httpd.conf
/usr/local/apache/bin/apachectl start
lynx 127.0.0.1
echo "完成安装"
20、尝试利用shell脚本将2~12题实现