Alpine setup scripts: Difference between revisions

From Alpine Linux
(→‎setup-cryptswap: remove comments)
(remove comments, add links and todo)
Line 97: Line 97:


If you have complex partitioning needs, you can partition, format, and mount your volumes manually, then just supply the root mountpoint to <code>setup-disk</code>. Doing so implicitly behaves as though '''-m sys''' had also been specified.
If you have complex partitioning needs, you can partition, format, and mount your volumes manually, then just supply the root mountpoint to <code>setup-disk</code>. Doing so implicitly behaves as though '''-m sys''' had also been specified.
See [[Setting up disks manually]] for more information.




Line 117: Line 119:


If you instead want to build your LVM system manually, see [[Setting up Logical Volumes with LVM]]. Then format and mount the disks, and supply the root mountpoint to <code>setup-disk</code>.
If you instead want to build your LVM system manually, see [[Setting up Logical Volumes with LVM]]. Then format and mount the disks, and supply the root mountpoint to <code>setup-disk</code>.


<!--
<!--
Line 166: Line 167:
   Run without installing to disk.
   Run without installing to disk.


-->
<!--
Create partition with with type "Linux" (83).
apk_add e2fsprogs rsync
mkfs.ext3 /dev/hda1
mount -t ext3 /dev/hda1 /mnt
ROOT=/mnt apk_add uclibc busybox apk-tools alpine-baselayout alpine-conf
# Install busybox links
mkdir /mnt/proc && mount --bind /proc /mnt/proc && chroot /mnt /bin/busybox --install -s && umount /mnt/proc
# Copy the apk repository
rsync -ruav /media/cdrom/apks /mnt
mkdir /mnt/etc/apk && echo "APK_PATH=file://apks" > /mnt/etc/apk/apk.conf
# Copy the hd/ext3 initramfs image, kernel and kernel modules
rsync -ruav /media/cdrom/kernel/generic/hd-ext3.gz /media/cdrom/kernel/generic/bzImage /mnt
rsync -ruav /lib/modules/* /mnt/lib/modules/
-->
-->


Line 205: Line 190:
The script will ensure that <i>source</i> and <i>dest</i> are available; will copy the contents of <i>source</i> to <i>dest</i>, ensuring first that there's enough space; and unless '''-u''' was specified, will make <i>dest</i> bootable.
The script will ensure that <i>source</i> and <i>dest</i> are available; will copy the contents of <i>source</i> to <i>dest</i>, ensuring first that there's enough space; and unless '''-u''' was specified, will make <i>dest</i> bootable.


<!--
== Setting up the RAID ==
Set up a raid array as described [[Setting up a software raid1 array|here]].
In this document two raid arrays are configured: md0 for swap (512MB) and md1 for /var.
== Create filesystem ==
We need to install the software to create the filesystem ("format" the partition).
apk_add e2fsprogs
If you use an Alpine release older than 1.3.8 you will need to manually create a link to /etc/mtab.
ln -fs /proc/mounts /etc/mtab
Create the filesystem. The -j option makes it ext'''3'''. Without the -j option it will become non-journaling ext'''2'''. This step might take some time if your partition is big.
mke2fs -j /dev/md1
Now edit /etc/fstab and add your new partitions. Mine looks like this:
none            /proc          proc    defaults 0 0
none            /sys            sysfs  defaults 0 0
udev            /dev            tmpfs  size=100k 0 0
none            /dev/pts        devpts  defaults 0 0
tmpfs          /dev/shm        tmpfs  defaults 0 0
/dev/cdrom      /media/cdrom    iso9660 ro 0 0
/dev/fd0        /media/floppy  vfat    noauto  0 0
/dev/usba1      /media/usb      vfat    noauto  0 0
none            /proc/bus/usb  usbfs noauto 0 0
 
/dev/md0        swap            swap    defaults 0 0
/dev/md1        /var            ext3    defaults 0 0
== Move the data ==
Now you should stop all services running that put anything in /var (syslog for example). If you have booted on a clean installation and not run setup-alpine, then no services should be running. However, some packages might have created dirs in /var so we need to backup /var mount the new and move all backed up dirs back to the raided /var.
mv /var /var.tmp
mkdir /var
mount /var
mv /var.tmp/* /var
rmdir /var.tmp
Verify that everyting looks ok with the ''df'' utility.
~ $ df
Filesystem          1k-blocks      Used Available Use% Mounted on
none                    255172    23544    231628  9% /
udev                      100        0      100  0% /dev
/dev/cdrom              142276    142276        0 100% /media/cdrom
/dev/md1              37977060    181056  35866876  1% /var
== Survive reboots ==
Now we have everything up and running. We need to make sure that everything will be restored during next reboot.
Create an initscript that will mount /var for you during boot. I call it /etc/init.d/mountdisk and it looks like this:
#!/sbin/runscript
start() {
        ebegin "Mounting /var"
        mount /var
        eend $?
}
stop() {
        ebegin "Unmounting /var"
        umount /var
        eend $?
}
Make it exectutable:
chmod +x /etc/init.d/mountdisk
'''NOTE:''' Since Alpine-1.7.3 there is a ''localmount'' script shipped so you will not need to create your own ''mountdisk'' script.
And that /var is mounted *after* raid is created. The -k option will make alpine to unmount the /Var partition during boot. Also add start of swap too boot
rc_add -k -s 06 mountdisk
rc_add -k -s 06 swap
The /dev/md* device nodes will not be created automatically so we need to put the on floppy too.
lbu include /dev/md*
If you have users on the server and want /home to be permanent, you can create a directory /var/home and create links to /var/home.
mkdir /var/home
mv /home/* /var/home/
ln -s /var/home/* /home/
'''NOTE:''' You cannot just replace /home with a link that points to /var/home since the base has a /home directory. When the boot tries to copy the config from floppy it will fail because of the already existing /home directory.
Make sure the links are stored to floppy:
lbu include /home/*
Also remember to move any newly created users to /var/home and create a link:
adduser bob
mv /home/bob /var/home/
ln -s /var/home/bob /home/bob
lbu include /home/bob
Save to floppy:
lbu commit floppy
== Test it works ==
Reboot computer. Now should the raid start and /var should be mounted. Check with df:
~ $ df
Filesystem          1k-blocks      Used Available Use% Mounted on
none                    255172    23976    231196  9% /
mdev                      100        0      100  0% /dev
/dev/cdrom              140932    140932        0 100% /media/cdrom
/dev/md1              37977060    180984  35866948  1% /var
== Upgrades ==
Since the package database is placed on disk, you cannot update by simply replacing the CDROM. You will have to either run the upgrade on the new CDROM or run ''apk_add -u ... && update-conf'' manually.
-->


== setup-cryptswap ==
== setup-cryptswap ==
Line 319: Line 195:


:<code>setup-cryptswap</code> [<i>partition</i> | none]
:<code>setup-cryptswap</code> [<i>partition</i> | none]
{{Todo|Does this script still work? At what stage can it be run: only after setup-alpine?}}


== setup-xorg-base ==
== setup-xorg-base ==

Revision as of 06:23, 5 March 2012

This material is work-in-progress ...

Do not follow instructions here until this notice is removed.
(Last edited by Dubiousjim on 5 Mar 2012.)

This page summarizes the low-level behavior of the /sbin/setup-* scripts on the Alpine ISO (and in a normal Alpine install).

setup-alpine

For a higher-level walkthrough (using the "sys" installmode), see Basic HDD install.

This script accepts the following command-line switches (you can run setup-alpine -h to see a usage message).

-a
Create an overlay file: this creates a temporary directory and saves its location in ROOT; however, the script doesn't export this variable so I think this feature isn't currently functional.

-c answerfile
Create a new "answerfile", with default choices. You can edit the file and then invoke setup-alpine -f answerfile.
-f answerfile
Use an existing "answerfile", which may override some or all of the interactive prompts.

-q
Run in "quick mode." See below for details.

The script's behavior is to do the following, in order. Bracketed options represent extra configuration choices that can be supplied when running the auxiliary setup scripts manually, or by supplying an "answerfile".

  1. setup-keymap [us us]
  2. setup-hostname [-n alpine-test]
  3. setup-interfaces [-i < interfaces-file]
  4. /etc/init.d/networking --quiet start &
  5. if none of the networking interfaces were configured using dhcp, then: setup-dns [-d example.com -n "8.8.8.8 [...]"]
  6. set the root password
  7. if not in quick mode, then: setup-timezone [-z UTC | -z America/New_York | -p EST+5]
  8. enable the new hostname (/etc/init.d/hostname --quiet restart)
  9. add networking and urandom to the boot rc level, and acpid and cron to the default rc level, and start the boot and default rc services
  10. extract the fully-qualified domain name and hostname from /etc/resolv.conf and hostname, and update /etc/hosts
  11. setup-apkrepos [-r (to select a mirror randomly)]
  12. if not in quick mode, then: setup-sshd [-c openssh | dropbear | none]
  13. if not in quick mode, then: setup-ntp [-c chrony | openntpd | none]
  14. if not in quick mode, then: DEFAULT_DISK=none setup-disk -q [-m data /dev/sda]
  15. if installation mode selected during setup-disk was "data" instead of "sys", then: setup-lbu [/media/sdb1]
  16. if installation mode selected during setup-disk was "data" instead of "sys", then: setup-apkcache [/media/sdb1/cache | none]

setup-interfaces

setup-interfaces [-i < interfaces-file]

An interfaces file has the format of /etc/network/interfaces, such as:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
    hostname alpine-test

setup-timezone

setup-timezone [-z UTC | -z America/New_York | -p EST+5]

Can pre-select the timezone using either of these switches:

  • -z subfolder of /usr/share/zoneinfo
  • -p POSIX TZ format

setup-disk

DEFAULT_DISK=none setup-disk -q [-m data | sys] [mountpoint directory | /dev/sda ...]

This script accepts the following command-line switches:

-k kernel flavor
-o apkovl file
Restore system from apkovl file
-m data | sys
Don't prompt for installation mode. With -m data, the supplied devices are formatted using ext4 to use as a /var volume.

-r
Use RAID1 with a single disk (degraded mode)

-L
Create and use volumes in a LVM group

-s swap size in MB
Use 0 to disable swap

-q
Exit quietly if no disks are found

-v
Verbose mode

The script also honors the following environment variables:

BOOT_SIZE

Size of the boot partition in MB; defaults to 100. Only used if -m sys is specified or interactively selected.

SWAP_SIZE

Size of the swap volume in MB; set to 0 to disable swap. If not specified, will default to twice RAM, up to 4096, but won't be more than 1/3 the size of the smallest disk, and if less than 64 will just be 0. Only used if -m sys is specified or interactively selected.

ROOTFS

Filesystem to use for the / volume; defaults to ext4. Only used if -m sys is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.

BOOTFS

Filesystem to use for the /boot volume; defaults to ext4. Only used if -m sys is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.

MBR

Path of MBR binary code, defaults to /usr/share/syslinux/mbr.bin.


Partitioning

If you have complex partitioning needs, you can partition, format, and mount your volumes manually, then just supply the root mountpoint to setup-disk. Doing so implicitly behaves as though -m sys had also been specified.

See Setting up disks manually for more information.


RAID

setup-disk will automatically build a RAID array if you supply the -r switch, or if you specify more than one device. The array will always be RAID1 (and --metadata=0.90) for the /boot volumes, but will be RAID5 for non-boot volumes when 3 or more devices are supplied.

If you instead want to build your RAID array manually, see Setting up a software raid1 array. Then format and mount the disks, and supply the root mountpoint to setup-disk.

LVM

setup-disk will automatically build and use volumes in a LVM group if you supply the -L switch. The group and volumes created by the script will have the following names:

  • volume group: vg0
  • swap volume: lv_swap (only created when swap size > 0)
  • root volume: lv_root (only created when -m sys is specified or interactively selected)
  • var volume: lv_var (only created when -m data is specified or interactively selected); also these volumes are currently always formatted as ext4.

The lv_var or lv_root volumes are created to occupy all remaining space in the volume group.

If you need to change any of these settings, you can use vgrename, lvrename, lvreduce or lvresize.

If you instead want to build your LVM system manually, see Setting up Logical Volumes with LVM. Then format and mount the disks, and supply the root mountpoint to setup-disk.


setup-bootable

This is a standalone script; it's not invoked by setup-alpine but must be run manually.

Its purpose is to create media that boots into tmpfs by copying the contents of an ISO onto a USB key, CF, or similar media.

For a higher-level walkthrough, see Creating a bootable Alpine Linux USB Stick from the command line.

This script accepts the following arguments and command-line switches (you can run setup-bootable -h to see a usage message).

setup-bootable source [dest]

The argument source can be a directory or an ISO (will be mounted to MNT or /mnt) or a URL (will be downloaded with WGET or wget). The argument dest can be a directory mountpoint, or will default to /media/usb if not supplied.

-k
Keep alpine_dev in syslinux.cfg; otherwise, replace with UUID.

-u
Upgrade mode: keep existing syslinux.cfg and don't run syslinux

-f
Overwrite syslinux.cfg even if -u was specified.

-s
Force the running of syslinux even if -u was specified.

-v
Verbose mode

The script will ensure that source and dest are available; will copy the contents of source to dest, ensuring first that there's enough space; and unless -u was specified, will make dest bootable.


setup-cryptswap

This is a standalone script; it's not invoked by setup-alpine but must be run manually.

setup-cryptswap [partition | none]
Todo: Does this script still work? At what stage can it be run: only after setup-alpine?



setup-xorg-base

This is a standalone script; it's not invoked by setup-alpine but must be run manually.

Installs the following packages: xorg-server xf86-video-vesa xf86-input-evdev xf86-input-mouse xf86-input-keyboard udev.

Additional packages can be supplied as arguments to setup-xorg-base. You might need, for example, some of: xf86-input-synaptics xf86-video-something xinit.


Documentation needed

setup-gparted-desktop

Uses openbox.

This is a standalone script; it's not invoked by setup-alpine but must be run manually.

setup-mta

Uses ssmtp.

This is a standalone script; it's not invoked by setup-alpine but must be run manually.

setup-alpine-web

This is a standalone script; it's not invoked by setup-alpine but must be run manually.

setup-acf

This is a standalone script; it's not invoked by setup-alpine but must be run manually.

setup-ads

This is a standalone script; it's not invoked by setup-alpine but must be run manually.