我有创建分区的 bash 脚本
dmesg | grep SCSI
echo "Partition number. ex 1..2..3"
read partnumber
echo "Provide folder name for mounting"
read datadrivefolder
(
echo o
echo n
echo p
echo $partnumber
echo
echo
echo w
) | sudo fdisk /dev/sdc
sudo mkfs -t ext4 /dev/sdc$partnumber
sudo mkdir /$datadrivefolder
sudo mount /dev/sdc$partnumber /$datadrivefolder
现在我想自动添加到 fstab 但需要获取 UUIDsudo -i blkid
并将其添加到 fstab。
- 如何提取 UUID
- 如何将数据信息自动附加到 fstab 的行尾?
谢谢
答案1
提取UUID
OUTPUT="$(sudo blkid -s UUID -o value /dev/sdc$partnumber)"
自动将数据信息附加到 fstab 行尾
echo "/dev/sdc$partnumber /$datadrivefolder ext4 defaults 0 1" | sudo tee -a /etc/fstab
或者
echo "UUID="$OUTPUT" /$datadrivefolder ext4 defaults 0 1" | sudo tee -a /etc/fstab