您好,登錄后才能下訂單哦!
[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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。