Approach: create one partition on /dev/sdb, format ext4, mount at /data, set ownership, and add a persistent /etc/fstab entry using the partition UUID so it survives reboots.Commands and explanations:1) Inspect device:Shows block devices, existing partitions and filesystems.2) Create a single partition (GPT) that fills the disk:sudo parted -s /dev/sdb mklabel gpt mkpart primary 0% 100%
- parted -s: script mode (no interactive).- mklabel gpt: create GPT partition table.- mkpart primary 0% 100%: one partition using entire device (creates /dev/sdb1).3) Verify partition created:lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT /dev/sdb
4) Format the new partition as ext4:sudo mkfs.ext4 -F /dev/sdb1
- -F forces; mkfs.ext4 creates an ext4 filesystem on /dev/sdb1.5) Create mount point and mount:sudo mkdir -p /data
sudo mount /dev/sdb1 /data
- mount attaches the filesystem to /data.6) Set ownership to user and group 'app':sudo chown app:app /data
sudo chmod 750 /data # optional: limits access
7) Get the partition UUID (use this in /etc/fstab):sudo blkid -s UUID -o value /dev/sdb1
This prints the UUID (e.g. 1234-abcd-...).8) Add persistent /etc/fstab entry (using the UUID you obtained). Example append:UUID=YOUR-UUID-HERE /data ext4 defaults,noatime 0 2
To append safely:sudo sh -c "echo 'UUID=$(blkid -s UUID -o value /dev/sdb1) /data ext4 defaults,noatime 0 2' >> /etc/fstab"
- defaults,noatime: sensible defaults and avoid updating atime.- dump=0, fsck order=2 (root is 1).9) Test fstab entry without reboot:sudo umount /data
sudo mount -a
- mount -a mounts all fstab entries; if there is an error it will report.Verification:- Confirm mounted:findmnt /data
df -h | grep /data
lsblk -f
mount | grep /dev/sdb1
- Confirm ownership:- Confirm fstab entry:Edge cases / notes:- If /dev/sdb already had partitions, adapt commands (use correct partition name).- Use careful maintenance windows if device holds critical data.- If using MBR instead of GPT, change mklabel to msdos.- For large disks or special alignment needs, specify start/end in MiB.