suggestion: what about restoring the disklabel from stdin instead of a given file (if not specified) ?
nacho Lariguet
lariguet at gmail.com
Tue Aug 11 19:26:40 PDT 2020
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