Create make_disk.sh
#!/bin/bash
V_DISK=/mnt/hdd10tb/virtual_disks
while test $# -gt 0; do
case "$1" in
-u|--user)
U_DISK="$V_DISK/$2.ext4"
touch "$U_DISK"
dd if=/dev/zero of=$U_DISK bs=1M count=1
mkfs.ext4 $U_DISK
e2fsck -f $U_DISK
resize2fs -p $U_DISK 50G
mkdir "/home/$2"
chown "$2.$2" "/home/$2"
mount -o loop,rw,usrquota,grpquota $U_DISK "/home/$2/"
exit 1
;;
-h|--help|*)
echo "$package - attempt to capture frames"
echo " "
echo "$package [options] [arguments]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-u, --user username"
exit 0
;;
esac
done
$ mkdir /mnt/hdd10tb/virtual_disks
$ sh make_disk.sh -u duong
The virtual disk named duong.ext4 will stored at /mnt/hddt10tb/virtual_disk/duong.ext4
Edit file /etc/fstab
Add this line to end of file
/mnt/hdd10tb/virtual_disks/duong.ext4 /home/duong ext4 defaults 0 3