[root@localhost ~]# fdisk /dev/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): n
All primary partitions are in use
Adding logical partition 6
First sector (141940736-419430399, default 141940736):
Using default value 141940736
Last sector, +sectors or +size{K,M,G} (141940736-419430399, default 419430399): +10G
Partition 6 of type Linux and of size 10 GiB is set
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.
(2)mkfs创建文件系统:
在祥云等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计、网站制作 网站设计制作按需定制,公司网站建设,企业网站建设,成都品牌网站建设,成都全网营销,成都外贸网站建设,祥云网站建设费用合理。[root@localhost ~]# mkfs.ext4 -b 2048 -m 20 -L MYDATA /dev/sda6/
mke2fs 1.42.9 (28-Dec-2013)
Could not stat /dev/sda6/ --- Not a directory
[root@localhost ~]# mkfs.ext4 -b 2048 -m 20 -L MYDATA /dev/sda6
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=MYDATA
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 5242880 blocks
1048576 blocks (20.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=273678336
320 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
2048000, 3981312
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
(3)挂载至/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳。并设置开机自动挂载
[root@localhost ~]# mkdir -p /mydata
[root@localhost ~]# vim /etc/fstab
/dev/sda6 /mydata ext4 defaults,noatime,noexec 0 0
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 47G 5.2G 42G 12% /
devtmpfs 523M 0 523M 0% /dev
tmpfs 538M 0 538M 0% /dev/shm
tmpfs 538M 7.8M 530M 2% /run
tmpfs 538M 0 538M 0% /sys/fs/cgroup
/dev/sda1 497M 151M 346M 31% /boot
/dev/sda3 19G 39M 19G 1% /data
tmpfs 108M 4.0K 108M 1% /run/user/42
tmpfs 108M 32K 108M 1% /run/user/1000
/dev/sr0 8.1G 8.1G 0 100% /run/media/wl/CentOS 7 x86_64
tmpfs 108M 0 108M 0% /run/user/0
/dev/sda6 9.8G 13M 7.8G 1% /mydata
[root@localhost ~]# fdisk /dev/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): n
All primary partitions are in use
Adding logical partition 7
First sector (162914304-419430399, default 162914304):
Using default value 162914304
Last sector, +sectors or +size{K,M,G} (162914304-419430399, default 419430399): +1G
Partition 7 of type Linux and of size 1 GiB is set
Command (m for help): t
Partition number (1-7, default 7): 7
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@localhost ~]# mkswap /dev/sda7
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=ba42d9ae-41a0-4829-bd14-a32834cf6ec9
[root@localhost ~]# swapon /dev/sda7
[root@localhost ~]# vim /etc/fstab
/dev/sda7 swap swap defaults 0 0
#!/bin/bash
#判断系统是否存在20个用户
id_sum=$( cat /etc/passwd | wc -l )
[ ${id_sum} -lt 20 ] && echo "用户个数小于20" && exit 2
id1=$(head -10 /etc/passwd | tail -1 | cut -d: -f3)
id2=$(head -20 /etc/passwd | tail -1 | cut -d: -f3)
idsum=$[${id1}+${id2}]
echo "Ths sum is $idsum"
[root@localhost scripts]# bash -x idsum2.sh
++ cat /etc/passwd
++ wc -l
+ id_sum=58
+ '[' 58 -lt 20 ']'
++ head -10 /etc/passwd
++ tail -1
++ cut -d: -f3
+ id1=11
++ head -20 /etc/passwd
++ tail -1
++ cut -d: -f3
+ id2=997
+ idsum=1008
+ echo 'Ths sum is 1008'
Ths sum is 1008
#!/bin/bash
hostName=$(hostname)
[ -z "${hostName}" -o "${hostName}" == "localhost.localdomain" -o "${hostName}" == "locahost" ] && hostnamectl set-hostname www.magedu.com || echo "主机名:${hostName},不要修改"
[root@localhost scripts]# bash -x hostname.sh
++ hostname
+ hostName=localhost.localdomain
+ '[' -z localhost.localdomain -o localhost.localdomain == localhost.localdomain -o localhost.localdomain == locahost ']'
+ hostnamectl set-hostname www.magedu.com
#!/bin/bash
#脚本判断参数用户ID奇偶类型
[ $# -lt 1 ] && echo "At least a username " && exit 1
! id $1 && echo "No such user" && exit 2
userid=$(id -u $1)
useri=$[${userid}%2]
if [ ${useri} -eq 0 ];then
echo "$1 ID 是偶数"
else
echo "$1 ID 是奇数"
fi
root@localhost scripts]# bash -xv id.sh user3
#!/bin/bash
#脚本判断参数用户ID奇偶类型
[ $# -lt 1 ] && echo "At least a username " && exit 1
+ '[' 1 -lt 1 ']'
! id $1 && echo "No such user" && exit 2
+ id user3
uid=1003(user3) gid=1003(user3) groups=1003(user3)
userid=$(id -u $1)
++ id -u user3
+ userid=1003
useri=$[${userid}%2]
+ useri=1
if [ ${useri} -eq 0 ];then
echo "$1 ID 是偶数"
else
echo "$1 ID 是奇数"
fi
+ '[' 1 -eq 0 ']'
+ echo 'user3 ID 是奇数'
user3 ID 是奇数
(2)LVM 基本术语:
(a)物理存储介质(PhysicalStorageMedia):
指系统上最底层的物理存储设备:磁盘,例如:/dev/sda、/dev/sdb等
(b)物理卷(Physical Volume, PV):
指磁盘、磁盘分区或RAID设备,使用LVM前需要先将之制作成便于识别的物理卷PV
(c)卷组(Volume Group, VG):
卷组由一个或多个物理卷PV组成,在卷组之上可创建一个或多个逻辑卷LV。卷组VG类似于非LVM系统的 物理磁盘
(d)逻辑卷(Logical Volume, LV):
建立在卷组VG之上,相当于逻辑分区,可在逻辑卷LV上进行一系列操作(例如:格式化、挂载等)。 逻辑卷LV类似于非LVM系统的磁盘分区
(d)物理扩展块(Physical Extent, PE):
当物理卷PV加入某一卷组VG后即被划分为基本单元PE,PE是LVM寻址的最小单元。PE的大小是可配置的,默认为4M。
(e)逻辑扩展块(Logical Extent, LE):
卷组VG将PE划分给逻辑卷LV,在逻辑卷LV中的PE称为LE。在同一卷组VG中,PE和LE大小相同,且相互对应。LE也是LVM的最小寻址单位。
(3)LVM基本操作:
(a)pv管理工具:
pvs:简要pv信息显示
pvdisplay:显示pv的详细信息
pvcreate /dev/DEVICE: 创建pv
(b)vg管理工具:
vgs
vgdisplay
vgcreate [-s #[kKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
先做pvmove
vgremove
(c)lv管理工具:
lvs
lvdisplay
lvcreate -L #[mMgGtT] -n NAME VolumeGroup
vremove /dev/VG_NAME/LV_NAME
(d)扩展逻辑卷:
# lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME
# resize2fs /dev/VG_NAME/LV_NAME(e)缩减逻辑卷:
# umount /dev/VG_NAME/LV_NAME# e2fsck -f /dev/VG_NAME/LV_NAME
# resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT]
# lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME
# mount
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享标题:GPT,LVM概念以及shell脚本基础-创新互联
文章来源:https://www.cdcxhl.com/article14/josde.html
成都网站建设公司_创新互联,为您提供服务器托管、网站设计、搜索引擎优化、品牌网站设计、关键词优化、域名注册
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联