Created
July 18, 2022 19:26
Revisions
-
omarmciver created this gist
Jul 18, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ # Usage copydisk.sh <newdiskdev> <olddiskmountpoint> <temporary mountpoint> # e.g. copydisk.sh /dev/sdc /datadisk /tmpdatadisk echo New disk attached is at $1 echo Existing disk mount point is at $2 echo Temporary mount point for data copy is at $3 ## Add partition table parted $1 mklabel gpt ## Create partition ext4 100% of the available space parted $1 mkpart primary ext4 0% 100% ## Format the ext4 partition mkfs.ext4 $11 ## Create a mount point mkdir $3 ## Mount the partition mount $11 $3 ## Copy the data from the old partition to the new partition cp -p $2 $3 ## Unmount the temporary partition umount $3 ## Unmount the old partition umount $2 ## Backup existing fstab cp /etc/fstab /etc/fstab.bak ## Remove the old fstab partition grep -v $2 /etc/fstab > tmpfile && mv tmpfile m/etc/fstab ## Add the new fstab entry echo "$1 /$2 ext4 defaults 0 0" | sudo tee /etc/fstab -a ## Remove the temporary mount point rmdir $3