[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Please check my sudo bash script



On 8/31/25 07:55, Tom Browder wrote:
I just added three new SSD and want to prep them for use.

I plan to use a script to do that incrementally. Given the disks show
the following when running "lsblk -o ..." ('#  ' added):

# NAME     SIZE FSTYPE MOUNTPOINT
# sda      3.6T                   # <= new disk   sda
# sdb    465.8G
# |-sdb1   512M vfat   /boot/efi
# |-sdb2 464.3G ext4   /
# `-sdb3   976M swap   [SWAP]
# sdc    931.5G                   # <= new disk   sdc
# sdd    931.5G                   # <= new disk   sdd

Does this bash fragment look safe for using bash vars for the first disk:

SDX=sda
sudo parted /dev/${SDX} mklabel gpt
sudo parted -a opt /dev/${SDX} mkpart primary ext4=0% 100%
sudo mkfs.ext4 /dev/${SDX}

Thanks.

-Tom


It is all too easy to make a mistake while working on disks, partitions, file systems, etc.. Either use another computer, or disconnect all the drives in your computer. Connect one SSD at a time, boot a live OS device, and do the work.


While working, insert a USB flash drive, mount it, open a log.txt file in an editor, and keep records of everything you do and why. Cut and paste your console sessions into the log.txt file -- prompts, commands entered, and output displayed.


I use Bash as my interactive shell, with the following prompt:

2025-08-31 14:37:34 dpchrist@laalaa ~
$ grep PS1 .profile | grep -v '#'
export PS1='\n\D{%Y-%m-%d %H:%M:%S} ${USER}@\h \w\n\$ '


I would do a security erase of each SSD first. This gives you a known good starting point and best performance. I use the hdparm(8) method described here:

https://linuxvox.com/blog/secure-wipe-ssd-linux/


As for the partitioning commands, here are some examples from a 180 GB SSD on /dev/sdb:

        # parted /dev/sdb mklabel gpt
Information: You may need to update /etc/fstab.

        # parted /dev/sdb mkpart -a optimal primary 0% 100%
        Information: You may need to update /etc/fstab.

        # mkfs.ext4 /dev/sdb1
        mke2fs 1.42.5 (29-Jul-2012)
        Discarding device blocks: done
        Filesystem label=
        OS type: Linux
        Block size=4096 (log=2)
        Fragment size=4096 (log=2)
        Stride=0 blocks, Stripe width=0 blocks
	<snip>


For three drives, I would do the first by hand and the other two by cut/ paste/ edit from the log.txt file. If you connect each SSD to the same port and choose your command options wisely (e.g. 100% for partition size), drives two and three might be simple cut and paste without any edits. If I had many drives, a script would make sense.


But if you really want a script, use the transcript of the first SSD console session as the starting point. I would split the functionality into two scripts -- one to do the security erase and another to do the partitioning/ formatting.


On 8/31/25 09:00, Tom Browder wrote:
> I forget about gparted, thanks. But one reason I'm interested in
> scripts is to eventually build a new server with CLS scripts as much
> as possible. I'm sure there is such a tool available, and I'm  always
> open to suggestions.
>
> Another reason to use scripts and double check is old age, bad
> eyesight, bad memory, and shaky fingers.


If you put a bunch of blank disks into a computer, boot the Debian installer (d-i), and choose manual partitioning, d-i provides a character UI that can simplify partitioning, encrypting, configuring LVM physical and logical volumes, allocating swap, creating file systems, etc.. You specify the layout you want (in the correct order), and d-i does the details.


Finally, it looks like your OS disk is /dev/sdb. Out of habit and superstition, I would rearrange the drive, racks, cabling, HBA, ports, etc., so that the primary OS disk is /dev/sda during operations and maintenance.


David


Reply to: