suggestion: what about restoring the disklabel from stdin instead of a given file (if not specified) ?

nacho Lariguet lariguet at gmail.com
Wed Aug 12 19:43:57 PDT 2020


On Wed, 12 Aug 2020 16:05:42 -0900
Matthew Dillon <dillon at backplane.com> wrote:

> There is nothing particularly onerous in the code that would prevent it,
> but I would still require that an argument be specified.  Something like
> "-" is typically indicative of stdin.  If someone wanted to submit a patch
> to use stdin for the protofile in that situation then sure.

ACK

> However, generally speaking, I would not recommend doing this because it
> creates a situation where you, or others, write scripts expecting that
> disklabel -R can take input from stdin and these scripts would then not
> work properly on older systems.  So even though it may seem a little
> annoying to generate a temporary file, that's going to be the most portable
> method to use whether we add the stdin option or not.

I must admit I didn't think a little on backward compatibility issues.

Creating a temporary file may not be "elegant" to me but if it works (and it
is working fine) leave it as it is. After all that's what really matter. Your
advice is what really counts on the end.

Sorry to choke up this list a bit lately. Besides some issues I encountered
attempting to run it on my hardware I do really want to use this OS daily,
and I am doing my best to learn it. Please, spare me any dumb question but do
not hesitate to state that this or that is a dumb question or go read the
manuals first. I assure you I will never take offense for such replies, they
are part of the learning process.

By the way, I need to say you I have a LOT of respect for your work.

And its sincere :)

> -Matt
> 
> On Tue, Aug 11, 2020 at 5:26 PM nacho Lariguet <lariguet at gmail.com> wrote:
> 
> > This is only a minor suggestion:
> >
> > echo "${strPartitionLayout}" | /sbin/disklabel64 -R -r -B
> > "/dev/whatever/'; ### what about restoring the slice label from stdin
> > instead of a temp file (if not specified) ?
> >
> > This way we can avoid to:
> >
> > - create a temporary file to hold the (edited) partition layout
> > - add the partition layout example produced by default by disklabel after
> > creating the label itself to the temporary file
> > - cut the partition layout example
> > - add the partition layout as needed (the real one)
> > - run disklabel64 -R to import the temporary file to modify the real label
> > on the drive
> > - delete the temporary file
> >
> > I think building the label in a string variable and then passing it to
> > disklabel64 will be a far more elegant solution.
> >
> > A practical example (actually an excerpt for my ongoing installation
> > script):
> >
> > #!/bin/csh -f
> >
> > if ( ! -l '/sbin/newfs_ufs' ) then
> >
> >    /bin/ln -s /sbin/newfs /sbin/newfs_ufs; ### allow me this for a while :)
> >
> > endif ;
> >
> > set strDriveName = 'Intel-SSD-180-GB'; ### whatever you want: for file
> > name purposes only (mainly to report on the drive status)
> > set strDriveSN = 'CVCV2034019Y180EGN'; ### to find the right drive use:
> > /bin/ls -l /dev/da*;
> > set strDriveSNdevice = "/dev/serno/${strDriveSN}";
> > set strDrive = 'da0'; ### improvements: should be automatically set from
> > given SN
> > set strDriveSlice0 = "${strDrive}s0"; ### intended to hold the ESP slice
> > set strDriveSlice1 = "${strDrive}s1"; ### intended to hold the BSD slice
> > set strDriveSlice1Partitions = ( \
> >    'a:   1G 0  4.2BSD ###_ie:_boot_volume' \
> >    'd:  32G * HAMMER2 ###_ie:_system_volume' \
> >    'e:  16G * HAMMER2 ###_ie:_build_volume' \
> >    'f: 128G * HAMMER2 ###_ie:_data_volume' \
> >    ); ### please: use underscore instead of spaces for comments; otherwise
> > they will be translated to TABs
> > set strDriveSlice1FileSystems = ( \
> >    "ufs     -i '65536' -L 'boot'   '${strDriveSNdevice}.s1a';" \
> >    "hammer2            -L 'system' '${strDriveSNdevice}.s1d';" \
> >    "hammer2            -L 'build'  '${strDriveSNdevice}.s1e';" \
> >    "hammer2            -L 'data'   '${strDriveSNdevice}.s1f';" \
> >    ); ### ie: the file-systems to be created on each of the above
> > partitions (for HAMMER#2 use -f only if size ≤ 10 GB)
> >
> > set strDriveSlice1DL = './whatever'; ### the temporary file in question
> >
> > set bolGOdriveFormatBSD = (0);
> >
> > if ( $bolGOdriveFormatBSD == (1) ) then ### 2.2 formatting the BSD
> > partition for the boot, system, and any other volumes:
> >
> >    /usr/bin/printf "formatting the BSD partition for the boot, system, and
> > any other volumes on /dev/${strDriveSlice1}:\n\n";
> >
> >    ### enabling disklabel writing:
> >
> >    /sbin/disklabel64 -W "/dev/${strDriveSlice1}";
> >
> >    ### cleaning-up and labeling the BSD slice:
> >
> >    /bin/dd if=/dev/zero of="/dev/${strDriveSlice1}" bs='32K' count='16';
> >
> >    /sbin/disklabel64 -w -r -B "/dev/${strDriveSlice1}" 'auto' 'BSD'; ###
> > creates a slice label (also writing bootstrap code)
> >
> >    ### editing/restoring current slice label for a custom partition layout:
> >
> >    /sbin/disklabel64 -r "/dev/${strDriveSlice1}" > "${strDriveSlice1DL}";
> > ### outputs current slice label to given file
> >    /usr/bin/head -n 24 "${strDriveSlice1DL}" > "${strDriveSlice1DL}.temp";
> > ### discards default partition layout (example)
> >
> >    set intDriveSlice1Partitions = ("${#strDriveSlice1Partitions}");
> >    set intDriveSlice1Partition = (1);
> >
> >    while ( $intDriveSlice1Partition <= ("${intDriveSlice1Partitions}") )
> > ### translate custom partition layout metadata to proper DISKLABEL64 file
> > format
> >
> >       /usr/bin/printf
> > "${strDriveSlice1Partitions[${intDriveSlice1Partition}]}" \
> >          | /usr/bin/tr -s ' ' \
> >          | /usr/bin/tr ' _' '\t ' \  
> >          >> "${strDriveSlice1DL}.temp" \  
> >          ; ### trimming one (or more consecutive) spaces to a single tab
> > character
> >
> >       @ intDriveSlice1Partition++;
> >
> >    end;
> >
> >    unset intDriveSlice1Partition;
> >    unset intDriveSlice1Partitions;
> >
> >    /sbin/disklabel64 -R -r -B "/dev/${strDriveSlice1}"
> > "${strDriveSlice1DL}.temp"; ### restores the edited slice label from given
> > file
> >    /sbin/disklabel64 "/dev/${strDriveSlice1}" > "${strDriveSlice1DL}"; ###
> > outputs current (kernel in-core copy) slice label to given file
> >    /bin/rm "${strDriveSlice1DL}.temp";
> >
> >    ### disabling disklabel writing:
> >
> >    /sbin/disklabel64 -N "/dev/${strDriveSlice1}";
> >
> >    /usr/bin/printf "\n";
> >
> > endif ;
> >
> > unset bolGOdriveFormatBSD;
> >
> > unset strDriveSlice1DL;
> >
> > unset strDriveSlice1FileSystems;
> > unset strDriveSlice1Partitions;
> > unset strDriveSlice1;
> > unset strDriveSlice0;
> > unset strDrive;
> > unset strDriveSNdevice;
> > unset strDriveSN;
> > unset strDriveName;
> >
> > if ( -l '/sbin/newfs_ufs' ) then
> >
> >    /bin/rm /sbin/newfs_ufs; ### thanks :) !
> >
> > endif ;
> >  




More information about the Users mailing list