install nfs server on centos

假設cntos ip是172.16.1.1,想要分享的資料夾是/volume1/nfs
只需要用下列指令就可以架設好nfs server

yum install nfs-utils -y
echo "/volume1/nfs 172.16.0.0/16(rw,sync,no_root_squash,no_all_squash)" >> /etc/exports

systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap

client端部分只需要:

echo "172.16.1.1:/volume1/nfs /nfs nfs rw 0 0" >> /etc/fstab
mkdir -p /nfs
mount -a

dd disk image 建立與擴展

測試dd image的建立與擴展

#建立
dd if=/dev/zero of=test001.img bs=10M count=10
#格式化
mkfs -F test001.img
#建立掛載資料夾
mkdir -p /tmp/disk/test001
#掛載
mount -t ext2 -o loop $PWD/test001.img /tmp/disk/test001
#隨便產生一個90Mb的檔案
dd if=/dev/zero of=/tmp/disk/test001/xxxx.img bs=10M count=9
#查看可用空間
df -h | grep /dev/loop
#解除掛載
umount /tmp/disk/test001

#磁碟檢查
e2fsck -f test001.img -y
#調整空間大小至200M
resize2fs test001.img 200M
#重新掛載
mount -t ext2 -o loop $PWD/test001.img /tmp/disk/test001
#調整空間
losetup -c /dev/loop0
resize2fs /dev/loop0
#查看可用空間
df -h | grep /dev/loop
#解除掛載
umount /tmp/disk/test001

#刪除測試檔案
rm -f -r test001.img