Showing posts with label home server. Show all posts
Showing posts with label home server. Show all posts

Wednesday, March 2, 2011

mount on plug of external disk

For the home server we got an external USB powered hard disk for the public file share. Because this disk may not be present when the computer is started up, and may change device name since it is USB attached, I desired a way to mount that specific hard disk when it was plugged in.

The answer was a fairly long but simple udev rule, and a script to do the mounting.

/etc/udev/rules.d/storage.rules
ATTRS{idVendor}=="0bc2", ATTRS{idProduct}=="5031", ATTRS{serial}=="NA0B3DKV", ENV{DEVTYPE}=="partition", ACTION=="add", RUN+="/usr/local/sbin/mount-storage"

/usr/local/sbin/mount-storage
#!/bin/sh
mount -t vfat -o uid=nobody,gid=nogroup,dmask=000,fmask=111 \
 "$DEVNAME" /mnt/store

I found how to write the rule after referring to Writing udev rules and an example of a rule that matches the type of device.

It is still required to unmount the disk before unplugging it, as is the case with any operating system at the moment.

Sunday, January 16, 2011

Backup MySQL to a file per database

The objective is to make a backup of a MySQL database server, and end up with a file for each database, named based on the database.

This is part of a server migration where not all of the databases will be created on the target host, and some will be renamed as they are moved to the new host.

It turned out to be a single line of shell to do the task:
mysql --user=root --password=password --batch --skip-column-names --execute 'show databases' |
while read x ; do
 echo "dumping $x..."
 mysqldump --user=root --password=password --all "$x" > "$x".sql
done
The script was run in the target directory for the backup files.

It was also revealed that one of the databases had some corruption during the backup run, which was fixed with a quick invocation of the mysqlrepair command.

DNS Server basic setup

The objective is to set up a name server on a Ubuntu server that serves some domains to the Internet. The domains being served are too complex to be managed by the provider of the domain name, as a result they are being hosted on a home server on a dynamic IP.

The environment is Ubuntu 10.10 (Maverick Meerkat) Desktop freshly installed and updates done.

In the process of offloading as much DNS responsibility as possible to external services I found that MX and CNAME records clash, so if there are MX records for a domain, then the top of the domain should not have a CNAME record, so I used an A record that points at the yi.org url redirector server, in the future I may actually update the A record dynamically.

Given that, the following is the minimal steps required to configure the name server.

install the name server software:
sudo apt-get install bind9

Set up the zone file, the top level records should include the top level records that are also provided by the external services.
/etc/bind/db.happy.yi.org:
$TTL 604800
@ 3600 IN SOA happy.yi.org. happy.happy.yi.org. (
 2011011601 ; serial
 604800 ; refresh
 86400 ; retry
 2419200 ; expire
 3600 ) ; default ttl
@ 86400 IN NS sunriseyoga.dyndns.org.
@ 3600 IN A 173.203.238.64
@ 86400 IN MX 10 ASPMX.L.GOOGLE.COM.
@ 86400 IN MX 20 ALT1.ASPMX.L.GOOGLE.COM.
www 86400 IN CNAME sunriseyoga.dyndns.org.
vnc 86400 IN CNAME sunriseyoga.dyndns.org.
mail 86400 CNAME ghs.google.com.
pages 86400 CNAME ghs.google.com.
docs 86400 CNAME ghs.google.com.
sites 86400 CNAME ghs.google.com.
site 86400 CNAME ghs.google.com.
app 86400 CNAME ghs.google.com.
blog 86400 CNAME ghs.google.com.
feather-wiki 86400 CNAME ghs.google.com.

tell the name server to load the zone by adding the following line to /etc/bind/named.conf.local:
zone "happy.yi.org" { type master; file "/etc/bind/db.happy.yi.org"; };

reload the name server
sudo /etc/init.d/bind9 reload

now the domain is being served, and will be accessible from the Internet if the NS records point at the server.

If you want to know more, read the Ubuntu BIND9 Server HOWTO.

Friday, January 7, 2011

Public file share

The objective is some basic network attached storage (NAS), or public file share, where any attached computer can create, read, update, and delete any file without authentication. I would not consider this secure, as anyone who can attach to the network can do whatever they want to the file space, however secure is not the objective at this time. Also if a user is accessing the same shared file space locally on the server it should behave the same as if it was being accessed over the network.

The environment is Ubuntu Desktop 10.10 (Maverick Meerkat) freshly installed and updates done.

Given that, the following are the minimal steps and configuration required to achieve the objective.

Make a public file space based on "HowTo: Create shared directory for local users (with bindfs)", this works much better than access control lists can.

install bindfs
sudo apt-get install bindfs

configure the public space to be set up on startup.
/etc/init/bind-public.conf:
description "Remount public with different permissions"

start on stopped mountall

pre-start exec install --owner=nobody --group=nogroup --mode=0777 \
--directory /export/public

exec bindfs -f --owner=nobody --group=nogroup --perms=a=rwD \
--create-for-user=nobody --create-for-group=nogroup \
--create-with-perms=a=rwD --chown-ignore --chgrp-ignore --chmod-ignore \
/export/public /export/public

and make the public space active
sudo initctl start bind-public

Now to make the space available over the network using Samba.

Install samba
sudo apt-get install samba

And here is a minimal Samba configuration to do the job.
/etc/samba/smb.conf:
[global]
       map to guest = Bad User

[public]
       path = /export/public
       guest ok = yes
       read only = no

It is not necessary to restart samba for the changes to take effect.

At this point the objective is achieved for remote connections, and any local methods for accessing the directory.

For restricted access, configure Samba to require a log-on, or only allow particular users to access the public share.

Sunday, November 7, 2010

disabling idle sleep timeouts

I left the server on a shelf for a bit and tried to connect to it remotely, I found it asleep.

so I turned off the only sleep time I could find:
sudo gconftool-2 \
 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
 /apps/gnome-power-manager/timeout/sleep_computer_battery --set --type integer 0

and restarted gdm
sudo /etc/init.d/gdm restart

hopefully the server doesn't go to sleep any longer.

Creating a user account with a previously set password

The user accounts that will exist on the new home server already exist on the previous server, so when they get created the passwords should be copied forward, although this might be a good time to get them set again by the users.

the existing password hashes are stored in /etc/shadow:
happy:$1$xxxxxxxx$xxxxxxxxxxxxxxxxxxxxxx:14667:0:99999:7:::

To create a user account with the same password as listed there, just provide the password hash:
sudo useradd happy -p '$1$xxxxxxxx$xxxxxxxxxxxxxxxxxxxxxx' -s /bin/bash -m

The entire contents of the home directory could also be copied to bring application settings forward as well. Be sure to make sure that the copied files end up owned by the user they were copied for, the user ids will not necessarily be the same.

Ubuntu 10.10 disabling suspend on lid close

The default settings in Ubuntu on a laptop include suspending with the cover is closed, which is reasonable for normal laptop usage, however I am building a server from a laptop with a broken screen, so it will be closed and in the corner most of the time, and not being suspended would be a good thing.

The method that I used on Ubuntu 10.04 did not seem to work, and the control panel does not seem to have the options available on this laptop, so I had to figure out another way to do it.

After reading on how to change some other power manager settings, I came up with a command that changes the settings I want to change. However this just changed it when my user was logged in to the console, to change the default required the commands I had used before and a restart to gdm to load the changed settings.

# make the changes
sudo gconftool-2 \
 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
 /apps/gnome-power-manager/buttons/lid_ac --set --type string nothing
sudo gconftool-2 \
 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
 /apps/gnome-power-manager/buttons/lid_battery --set --type string nothing

# restart gdm
sudo /etc/init.d/gdm restart

The current settings can be viewed with
gconftool-2 /apps/gnome-power-manager/buttons -R

Now the laptop does not suspend when the cover is closed.

Installing Ubuntu 10.10 and verifying the hard disk in the process

I have a 160GB hard drive with some bad blocks that I wish to install ubuntu onto. The installer does not have an option to verify the disk during formatting, so I needed to boot up the live cd to do that step myself. I had actually gone through the install already on this disk without marking the bad blocks, so there is a damaged file system on the disk due to the bad blocks.

After the initial installation round I have the partition table configured, so I just re-create the root filesystem with “mkfs.ext4 /dev/sda1 -c -V” to get the blank root with all the bad blocks marked.

After making the file system, start the installer and tell it to do manual partitions, then tell it to use the freshly formatted partition as root and to not format it.

The rest of the install proceeds as normal.

Monday, October 25, 2010

Ubuntu 10.10 VNC Login Screen

I figured out how to get a graphical login screen over VNC on Ubuntu 10.10 today. The method that worked before Ubuntu 10.04 stopped working when XDMCP support was removed from gdm (source).

This procedure starts from a fresh install of Ubuntu-Desktop-10.10.

install xdm, vnc4server, and xinetd.
sudo apt-get install xdm vnc4server xinetd
When asked during installation what the default display manager should be, keep the setting as gdm.

Configure xdm to be able to answer XDMCP requests, comment out the following line in /etc/X11/xdm/xdm-config:
! SECURITY: do not listen for XDMCP or Chooser requests
! Comment out this line if you want to manage X terminals with xdm
!DisplayManager.requestPort:    0
Configure XDM to answer XDMCP requests from localhost, and to listen to just localhost by adding the following lines to /etc/X11/xdm/Xaccess:
localhost
LISTEN localhost

Configure XDM to not bring up a physical display by commenting out the following line in /etc/X11/xdm/Xservers:
#:0 local /usr/bin/X :0 vt7 -nolisten tcp

Configure the startup script to allow XDM to start despite gdm taking care of the screen by removing /etc/X11/default-display-manager:
sudo mv /etc/X11/default-display-manager /etc/X11/default-display-manager.disable

Add the VNC port definition to /etc/services if it has not already been added:
vnc 5900/tcp

Configure the VNC incoming port by creating /etc/xinetd.d/vnc:
service vnc
{
        only_from = localhost 192.168.0.0/24
        disable = no
        id = vnc
        socket_type = stream
        protocol = tcp
        wait = no
        user = nobody
        server = /usr/bin/Xvnc4
        server_args = -inetd -query localhost -once -SecurityTypes=None -pn -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -desktop Ubuntu
        log_on_failure += USERID
}
In this configuration connections are restricted to the local network (192.168.0.*).

After all these pieces are done, restart the services to load the new configurations:
sudo /etc/init.d/xdm restart
sudo /etc/init.d/xinetd restart

Now you should be able to use VNC to get a login screen.

There is a problem with gnome in this setup where it has a keyboard shortcut assigned to 'd', which can be fixed by going into System -> Preferences -> Keyboard Shortcuts and disabling, or reassigning the "Hide all normal windows and set focus to the desktop" shortcut key (source). This may happen because the default key binding is Mod4+D, and there is no Mod4 modifier key on the VNC connection.

Monday, July 5, 2010

server from laptop, round three

I re-started the building of the home server from the broken laptop, using Debian Lenny this time. After a basic install, I have added openssh-server and avahi-daemon to allow for remote access.

Samba will follow shortly.

Sunday, June 6, 2010

server from laptop, round two

I got gifted a larger hard drive for the laptop based home server, 160 GB, the original disk is 40 GB.

I decided to do a fresh install using the newest ubuntu-desktop (ubuntu-alternate) distribution, 10.04, and have encountered some challenges.

After the first install the hard disk would not boot, which I found was due to a bad block, so I eventually figured out how to create the file system on the disk myself and verify the disk in the process.

After the second install the system froze when the graphical display came up, so far I have found how to boot into a rescue mode with a text prompt, from which I installed openssh-server, and successfully logged into the server.

At this point it is time to leave it for the night and sleep, next I shall figure out how to disable the graphical display.

The easiest option would seem to be installing ubuntu-server instead, but I wish to serve graphical desktops from this server as well.

Monday, April 12, 2010

setting gnome options

While searching for how to disable the face browser (list of available users on the login screen) in gnome 2.22, I found the command line method for updating system wide gnome settings.

First to disable the face browser and shutdown buttons on the gnome login screen
sudo gconftool-2 --direct \
 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
 --type bool --set /apps/gdm/simple-greeter/disable_user_list true
sudo gconftool-2 --direct \
 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
 --type bool --set /apps/gdm/simple-greeter/disable_restart_buttons true

And while initially installing the server I wanted to change the power settings for the laptop lid, ideally from the command line, I see that I can do these with these commands,
sudo gconftool-2 --direct \
 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
 --type string --set /apps/gnome-power-manager/buttons/lid_ac blank
sudo gconftool-2 --direct \
 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
 --type string --set /apps/gnome-power-manager/buttons/lid_battery blank
to make the closing of the lid just blank the screen instead of going to sleep. I actually set these through the power configuration applet when I did them the first time.

Sunday, April 11, 2010

samba listening to ipv4 and ipv6

I was having a problem with windows boxes connecting to the server that is being built. After some investigating I figured out that samba was not listening on ipv4, just ipv6.

The solution that worked for me I found on "Flameeyes's Weblog: Tip of the day: if Samba 3.4 fails to work...".

I had to add listen directives to smb.conf.
[global]
interfaces = 127.0.0.1 eth0
bind interfaces only = yes

Now the file server is operational for all the computers on the network.

simple samba configuration

I am building a new home server from a laptop with a smashed screen, and I just configured the file server part of it.

After stripping out the comments and most of the configuration directives from the stock smb.conf file, I was left with a nice short file that works. The objective was to have the home directory available for users that are configured, and a public directory for anyone, also there should be no permissions restrictions on the public directory, people should be able to modify each others files.

The resulting /etc/samba/smb.conf file is
[global]
dns proxy = no
map to guest = Bad User
guest account = guest
unix extensions = no

server string = Home server
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0

[homes]
browsable = no
read only = no
valid users = %S

[public]
read only = no
guest ok = yes
force user = guest
path = /export/public

I had also created a guest account for this setup.
sudo useradd guest -m -p \*

And of course the public directory to share
sudo mkdir /export
sudo mkdir /export/public
sudo chown guest /export/public

The server is behind a home router, which acts as a firewall, I would not put a configuration like this directly attached to the internet.

Wednesday, April 7, 2010

VNC Login on Ubuntu 9.10

I am setting up a new home server to replace the existing one, in the hope of reducing power consumption. The new server is a laptop with a broken screen.

I just configured a VNC Login screen, so here are the notes that I made. (The previous post used an earlier version of Ubuntu.)

The first requirement for the VNC login screen is a XDMCP server, such as GDM. The new GDM configuration applet does not provide much, but after a quick search I found a guide on Enabling XDMCP on Karmic Koala.

I created the file /etc/gdm/custom.conf containing
[xdmcp]
Enable=true
and restarted gdm
sudo restart gdm
which enabled XDMCP.

I also installed a VNC server
sudo apt-get install vnc4server
which will provide the X server for VNC logins.

Finally, an inetd needed to be installed
sudo apt-get install xinetd
so that the vnc service can be configured.

To configure the VNC service I created the configuration file /etc/xinetd.d/vnc
service vnc
{
    type = UNLISTED
    port = 5900
    only_from = localhost 192.168.0.0/24
    disable = no
    socket_type = stream
    protocol = tcp
    wait = no
    user = nobody
    server = /usr/local/bin/xvnc-inetd
}
and the script /usr/local/bin/xvnc-inetd
#!/bin/sh
exec /usr/bin/Xvnc \
 -inetd \
 -query localhost \
 -once \
 -SecurityTypes=None \
 -pn \
 -extension XFIXES
which was named in the configuration. The script is just to keep the line lengths down, making things look cleaner.

Finally I restarted xinetd.
sudo /etc/init.d/xinetd restart

And it works.

The problems I have with the setup at the moment is that the login screen lists the users instead of asking for the name to be typed, and allows shutdown of the system from the login screen.