Busybox ash (Almquist shell) shell and Debian dash (Debian Almquist shell) are lightweight Unix shell and they are a variant of System V.4 variant of the Bourne shell. Ash/dash shell is known to be very small and is used mainly in embedded (ash) devices and installation scripts (Debian/Ubuntu setup).
Unfortunately they do not support arrays, which could be really a problem in many cases. But we can simulate the arrays with eval function.
So if you need to write a ash/dash script let’s say for an installation script of Ubuntu or Debian or a script for an embedded device, which uses busybox or even you do not want to use arrays in bash, you can follow the consepts below – create variable with a “name” concatenated with a number.
1) Set a variable
It can be done with two ways:
for myi in 0 1 2 ; do
setvar mvar$myi "Payload: $myi"
done
for myi in 0 1 2 ; do
eval mvar$myi=\"Payload: $myi\"
done
This will create variables with names:
mvar1, mvar2, mvar3
and they can be used in any place of your script after the creation of the variables using “eval” or accessing them with the names.
* bash shell do not support the command “setvar”, so for bash scripts use only eval version.
2) Use a variable
using “eval”
for myi in 0 1 2 ; do
eval echo \$mvar$myi
done
myi=1
eval newvar="\$mvar$myi"
echo $newvar
When using LXC containers booting the lxc container would not populate it as the normal boot process. Or when you create a chroot jail /dev is not mounted or just some devices are created.
There is an option to populate (when using LXC containers) it with minimal required devices:
lxc.autodev = 1
which will create a tmpfs mount under /dev and create some basic devices, it will ensure /dev/shm to be mounted on with tmpfs!
If you omit this option, the /dev directory won’t be populated and will stay with the devices you made or copied when you made the LXC container (or the chroot jail) and /dev/shm will not be mounted using tmps, which could create numerous bad issues.
If you get errors like
* configure has detected that the sem_open function is broken.
* Please ensure that /dev/shm is mounted as a tmpfs with mode 1777.
You could mount the /dev/shm of the LXC container or the chroot jail (usually you can tune the size half of the server’s RAM) with
mkdir -p /dev/shm
mount -t tmpfs -o nodev,nosuid,noexec,mode=1777,size=6144m tmpfs /dev/shm
Or reboot your LXC container with a new configuration (probably in the “/var/lxc/[lxc_name]/config”) adding the following line:
Thus you ensure the /dev/shm to be mounted on tmpfs and all semaphore functions to work properly.
* Real output of Gentoo failed compilation of python package:
* configure has detected that the sem_open function is broken.
* Please ensure that /dev/shm is mounted as a tmpfs with mode 1777.
* ERROR: dev-lang/python-3.3.4-r1::gentoo failed (configure phase):
* Broken sem_open function (bug 496328)
*
* Call stack:
* ebuild.sh, line 124: Called src_configure
* environment, line 3542: Called die
* The specific snippet of code:
* die "Broken sem_open function (bug 496328)";
*
* If you need support, post the output of `emerge --info '=dev-lang/python-3.3.4-r1::gentoo'`,
* the complete build log and the output of `emerge -pqv '=dev-lang/python-3.3.4-r1::gentoo'`.
* The complete build log is located at '/var/tmp/portage/dev-lang/python-3.3.4-r1/temp/build.log'.
* The ebuild environment file is located at '/var/tmp/portage/dev-lang/python-3.3.4-r1/temp/environment'.
* Working directory: '/var/tmp/portage/dev-lang/python-3.3.4-r1/work/x86_64-pc-linux-gnu'
* S: '/var/tmp/portage/dev-lang/python-3.3.4-r1/work/Python-3.3.4'
>>> Failed to emerge dev-lang/python-3.3.4-r1, Log file:
After the previous howto “SUPERMICRO IPMI to use one of the one interfaces or dedicated LAN port” (in the howto is showed how to install the needed tool for managing the IPMI/KVM unit under console) of setting the network configuration there are a couple of interesting and important tips when working with the IPMI/KVM module. Here are they are:
Reset IPMI/KVM module – sometimes it happen the keyboard or mouse not to work when the Console Redirection is loaded, it is easy to reset the unit from the web interface, but there are case when the web interface is not working – so ssh to your server and try one of the following commands:
* warm reset – it’s like a reboot, inform the IPMI/KVM to reboot itself.
ipmitool -I open bmc reset warm
It does not work in all situations! So try a cold reset
* cold reset – resets the IPMI/KVM, it’s like unplug and plug the power to the unit.
ipmitool -I open bmc reset cold
Reset the configuration of an IPMI/KVM module to factory defaults. It is useful when something goes wrong when upgrading the firmware of the unit and the old configuration is not supported or it says it is, but at the end the unit does not work properly. In rare cases it might help when the KVM (Keyboard, Video, Monitor part aka Console redirection does not work)
Here is the command for resetting to factory defaults:
ipmitool -I open raw 0x3c 0x40
Reset admin password – reset the password for the administrator login of the IPMI/KVM unit. It’s trivial losing the password so with the help of the local console to the server you can reset the password to a simple one and then change it from the web interface.
ipmitool -I open user set password 2 ADMIN
The number “2” is the ID of the user, check it with:
Sometimes if a hacker got to your IPMI/KVM you could see the user table with the above command. There was a serious bug aka backdoor in some of these units, the ID of the ADMIN user or even the username could be changed, so you should use the list command to list the current user table.
Use set name to set the username of the user.
The best security for the remote management unit in your server such as IPMI/KVM is to have local IP. All IPMI/KVM IP should be switched to a separated switch and a local sub-network used for the LAN Settings. So to be able to connect to the IPMI/KVM module you need a VPN connection to gain access to the local sub-network used for your servers’ management modules. However, sometimes the VPN cannot be used or it just happened the server is down, or you are at a place restricting unknown ports (or ports above 1024), which your VPN uses (that’s why the VPN server should use only one port from the most popular – 80, 443, but that’s a thing for another howto…) and so on. So you end with no ability to connect to the VPN server or you think you do not need at all a VPN server, because you always could use
openssh
to do the trick of tunneling ports from your computer to the IPMI/KVM module of your server through a server, which has an access to the local sub-network of the IPMI/KVM modules.
So here is what you need to get to the remote management of your server just using ssh for tunneling:
STEP 1) A server, which has access to the IP network of the IPMI/KVM modules.
Let’s say you set to all your servers’ IPMI/KVM modules IPs from network 192.168.7.0/24, so your server must have an IP from 192.168.7.0/24, for example 192.168.7.1, add it as an alias or to a dedicated LAN connected to the switch, in which of all your IPMI/KVM modules are plugged in. This server will be used as a transfer point to a selected IPMI/KVM IP.
STEP 2) Tunnel local selected ports using ssh to the server from STEP 1)
With the above command you can use the web interface (https://127.0.0.1/, you could replace 127.0.0.1 with a local IP or a local IP alias of your machine), the java web start “Console Redirection” (the KVM – Keyboard, Video and Mouse) and you can mount Virtual Media from your computer to your server’s virtual CD/DVD device. Unfortunately to use properly the Virtual CD/DVD you must tunnel the UDP on port 623 (not only TCP 623), which is a little bit tricky. To tunnel the UDP packets
socat – Multipurpose relay (SOcket CAT)
program must be used.
STEP 3) Tunnel local selected ports using ssh to the server from STEP 1) and UDP port using socat
This will start a UDP listening socket on localhost port 8000. Every packet will be relayed using TCP to localhost 8000, which will be tunneled using ssh command to the remote server, where there is a started another socat listening TCP socket on port 8000, which will relay every packet to the UDP port 623 of IP 192.168.7.150. Replace the IP 192.168.7.150 with your IPMI/KVM IP.
* Here are the required ports for SUPERMICRO IPMI functionality in X9 and X10 motherboards
Sometimes the output of the last command (that using the lanplus) will output:
Unable to send RAW command (channel=0x0 netfn=0x30 lun=0x0 cmd=0x70)
But it sets the value despite the error output “Unable to send”. You could check it with the read command (the last example).
Get the current value with:
[root@srv0 ~]# ipmitool -I open raw 0x30 0x70 0x0c 0
02
[root@srv0 ~]#
Default (failover): you will see 02
Onboard LAN: you will see 01
Dedicated LAN: you will see 00
The 192.168.7.157 is the IP of the IPMI KVM module and the -U ADMIN and -P ADMIN are username and the password login details to the module (ADMIN/ADMIN are just default settings for the Supermicro IPMI/KVM)
IPMI/KVM module is a pretty useful add-on module to every server. In fact, every server should have IPMI module installed for fast management of the server in critical cases!
Here are the commands to set a static IP to the IPMI/KVM module with ipmitool using a console to the server:
ipmitool -I open lan set 1 ipsrc static
ipmitool -I open lan set 1 ipaddr [IPADDR]
ipmitool -I open lan set 1 netmask [NETMASK]
ipmitool -I open lan set 1 defgw ipaddr [GW IPADDR]
ipmitool -I open lan set 1 access on
[IPADDR] – the IP address of the IPMI/KVM
[NETMASK] – the netmask of the network
[GW IPADDR] – the gateway of the network
Here is a real world example of setting properly the LAN settings of the IPMI module.
[root@srv0 ~]# ipmitool -I open lan set 1 ipsrc static
[root@srv0 ~]# ipmitool -I open lan set 1 ipaddr 192.168.6.45
Setting LAN IP Address to 192.168.6.45
[root@srv0 ~]# ipmitool -I open lan set 1 netmask 255.255.255.0
Setting LAN Subnet Mask to 255.255.255.0
[root@srv0 ~]# ipmitool -I open lan set 1 defgw ipaddr 192.168.6.1
Setting LAN Default Gateway IP to 192.168.6.1
[root@srv0 ~]# ipmitool -I open lan set 1 access on
Set Channel Access for channel 1 was successful.
[root@srv0 ~]#
To see the current settings use:
[root@srv0 ~]# ipmitool -I open lan print
Set in Progress : Set Complete
Auth Type Support : NONE MD2 MD5 PASSWORD
Auth Type Enable : Callback : MD2 MD5 PASSWORD
: User : MD2 MD5 PASSWORD
: Operator : MD2 MD5 PASSWORD
: Admin : MD2 MD5 PASSWORD
: OEM : MD2 MD5 PASSWORD
IP Address Source : Static Address
IP Address : 192.168.6.45
Subnet Mask : 255.255.255.0
MAC Address : 00:25:90:18:8b:c9
SNMP Community String : public
IP Header : TTL=0x00 Flags=0x00 Precedence=0x00 TOS=0x00
BMC ARP Control : ARP Responses Enabled, Gratuitous ARP Disabled
Default Gateway IP : 192.168.6.1
Default Gateway MAC : 00:00:00:00:00:00
Backup Gateway IP : 0.0.0.0
Backup Gateway MAC : 00:00:00:00:00:00
802.1q VLAN ID : Disabled
802.1q VLAN Priority : 0
RMCP+ Cipher Suites : 1,2,3,6,7,8,11,12
Cipher Suite Priv Max : aaaaXXaaaXXaaXX
: X=Cipher Suite Unused
: c=CALLBACK
: u=USER
: o=OPERATOR
: a=ADMIN
: O=OEM
Bad Password Threshold : Not Available
*Dependencies
Installation of ipmitool:
CentOS 7
yum -y install ipmitool
Ubuntu 16+
apt-get install ipmitool
Gentoo
emerge -vu sys-apps/ipmitool
*Troubleshooting
If you receive errors when you execute ipmitool:
[root@srv0 ~]# ipmitool -I open lan set 1 ipaddr 192.168.6.45
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
[root@srv0 ~]# ipmitool -I open lan set 1 netmask 255.255.255.0
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
[root@srv0 ~]# ipmitool -I open lan set 1 defgw ipaddr 192.168.6.1
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
The kernel module for the IPMI/KVM is not loaded by the system, so just execute:
Sometimes we need to start a rebuild with a disk in failed state when using a LSI hardware controller, but if we just return the good state of the failed disk, it will return immediately in the array and our filesystem will be broken for sure! In addition it happens that when we replace a disk the new disk to be in failed state, too.
So here are simple and tested steps for proper resetting a failed state of a disk to a good state and starting a rebuild. In the example below the disk in failed state is [32:1], replace with the proper [enclosure_id:slot_id] in your case.
Make “Failed State” in “Unconfigured(BAD)”
megacli -pdmarkmissing -physdrv[32:1] -aAll
Prepare for removal (this command could fail, not a critical one)
megacli -pdprprmv -physdrv[32:1] -a0
Make the state of the disk “Unconfigured(Good), Spun Up”
megacli -PDMakeGood -PhysDrv[32:1] -a0
Start rebuild (this command could fail) – if the command fails continue with the next step, if not, the rebuild is restarted successfully.
megacli -PDRbld -Start -PhysDrv[32:1] -a0
Or
megacli -pdlocate -start -physdrv[32:1] -a0
One of the two commands will probably start the rebuild, but if the two fail then continue to the next step.
Start rebuild, first clean the foreign configuration and then make the device hot spare (only if 4 the above command failed)
ifenslave is no more needed when configuring bonding under Linux. There are situations when we could have no network link without bonding, because of specific switch configuration and we do not have ifenslave package installed. We can configure bonding manually via Sysfs.
Here are the steps to configure bond0 in adaptive load balancing with two network cards in slave mode:
The adaptive load balancing does not require any special network setup. On the contrary, the mode “802.3ad” could be used only if you enable bonding of the interfaces of your server to have a network link.
Lately many linux distributions do not ship by default with
ifconfig
which is considered as old style of setting the network when we need to do it manually.
The command is simple and self-explanatory but there is a catch! Just adding the IP won’t help you to bring up the network interface of your server. In fact we need two commands to instruct the network interface to bring up with an IP and then a third command to add a default gateway.
So here are the steps and commands to bring up an interface, set IP and gateway:
STEP 1) Add the IP to the network interface with
ip addr add 192.168.0.100/24 dev eth0
Change the IP with your IP address.
STEP 2) Bring up the interface link
ip link set eth0 up
If you omit this step a network interface, which is down won’t start and the next command (in step 3) will output an error! If your interface has been up already and you just add an additional IP to it you can skip this step (and probably the one below with the default gateway, but we do not describe this case here).
STEP 3) Bring up the interface link
ip route add default via 192.168.0.1
* The all three in one place for the right way of bringing up a network interface under linux with “ip” command:
ip addr add 192.168.0.100/24 dev eth0
ip link set eth0 up
ip route add default via 192.168.0.1
* Troubleshooting
as it was said: just adding an IP to a network interface, which is in down state, would not help to set an IP, but you would not understand it and when you tried to add the default route your would see not so informative error:
srv@local ~# ip addr add 192.168.0.100/24 dev eth0
srv@local ~# ip route add default via 192.168.0.1
ip: RTNETLINK answers: Network is unreachable
Network unreachable, but why I just added an IP. It is not enough just to add the IP, the link must also be set up, it’s like the
ifconfig eth0 up
.
Manage Cookie Consent
We use technologies like cookies to store and/or access device information. We do this to improve browsing experience and to show (non-) personalized ads. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.